Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Set identity on request #8

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
66bb83c
Update config for prod
coderdan Nov 23, 2023
b14f833
Trigger Heroku deploy after adding cipherstash buildpack
coderdan Nov 23, 2023
6a5be75
Trigger Heroku deploy after updating cipherstash buildpack
coderdan Nov 23, 2023
de60ece
Trigger Heroku deploy after updating cipherstash buildpack
coderdan Nov 23, 2023
68f4296
Trigger Heroku deploy after updating cipherstash buildpack
coderdan Nov 23, 2023
ba75f95
Trigger Heroku deploy after updating cipherstash buildpack
coderdan Nov 23, 2023
574b416
Trigger Heroku deploy after updating cipherstash buildpack
coderdan Nov 23, 2023
8624c28
Trigger Heroku deploy after updating cipherstash buildpack
coderdan Nov 23, 2023
f0df4e9
Trigger Heroku deploy after updating cipherstash buildpack
coderdan Nov 23, 2023
4b6ca26
Trigger Heroku deploy after updating cipherstash buildpack
coderdan Nov 23, 2023
a70058e
Add Heroku Procfile
coderdan Nov 23, 2023
dd8a564
Add tandem to Profile
coderdan Nov 23, 2023
aeea072
Add tandem to Profile
coderdan Nov 23, 2023
e9e1990
Trigger Heroku deploy after updating cipherstash buildpack
coderdan Nov 23, 2023
3bb82e1
Trigger Heroku deploy after updating cipherstash buildpack
coderdan Nov 23, 2023
49603e8
Trigger Heroku deploy after updating cipherstash buildpack
coderdan Nov 23, 2023
2c5aca2
Trigger Heroku deploy after updating cipherstash buildpack
coderdan Nov 23, 2023
22c4c99
Trigger Heroku deploy after updating cipherstash buildpack
coderdan Nov 23, 2023
7b94c6e
Added Tandem config
coderdan Nov 23, 2023
d85e6b1
Add tandem to web dyno for shits and giggles
coderdan Nov 23, 2023
cb190f7
Rough demo of identity passthrough with Proxy
coderdan Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/

# Don't accidentally commit local credentials
.envrc
tandem.toml
6 changes: 3 additions & 3 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
nodejs 19.7.0
postgres 15.1
direnv 2.32.2
nodejs 19.7.0
postgres 15
direnv 2.32.2
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: tandem npm start
tandem: tandem
9 changes: 4 additions & 5 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"development": {
"password": null,
"user": "dan",
"password": "12qwaszx",
"database": "sequelize-example",
"host": "127.0.0.1",
"dialect": "postgres",
Expand All @@ -16,11 +17,9 @@
"timezone": "Australia/Sydney"
},
"production": {
"password": null,
"database": "sequelize-example",
"host": "127.0.0.1",
"dialect": "postgres",
"native": true,
"timezone": "Australia/Sydney"
"timezone": "Australia/Sydney",
"use_env_variable": "DATABASE_URL"
}
}
12 changes: 11 additions & 1 deletion models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.json')[env];
const db = {};

const setPort = (config) => !!process.env.TANDEM_PORT ? { ...config, port: parseInt(process.env.TANDEM_PORT, 10) } : config;
//const setPort = (config) => ({ ...config, port: parseInt(process.env.STASH_DB_PORT, 10) })

let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
sequelize = new Sequelize(
process.env.STASH_DB_HOST || config.database,
config.username,
config.password,
setPort(config)
);
}

//console.debug(sequelize);

fs
.readdirSync(__dirname)
.filter(file => {
Expand Down
18 changes: 18 additions & 0 deletions models/patient.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ module.exports = (sequelize, DataTypes) => {
allergies: DataTypes.STRING,
medications: DataTypes.STRING
}, {
hooks: {
beforeFind: async (options) => {
console.error('beforeFind hook', options);
if (options.__identity) {
await sequelize.query(
// Uncomment this line when using with Proxy
'--SET IDENTITY TO ?', {
replacements: [options.__identity],
}
);
delete options.__identity;
}
},
beforeFindAfterOptions: (options) => {
// __identity is not present because it has been removed in the beforeFind hook
console.error('beforeFindAfterOptions hook', options);
},
},
sequelize,
modelName: 'patient',
});
Expand Down
3 changes: 2 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ app.get(

const patients = await models.patient.findAll({
order,
where
where,
__identity: "some-long-token" // Set the JWT here
});

res.status(200).json(patients);
Expand Down