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

Commit 63676f2

Browse files
committed
Rough demo of identity passthrough with Proxy
1 parent d85e6b1 commit 63676f2

File tree

6 files changed

+38
-7
lines changed

6 files changed

+38
-7
lines changed

.tool-versions

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
nodejs 19.7.0
2-
postgres 15.1
3-
direnv 2.32.2
1+
nodejs 19.7.0
2+
postgres 15
3+
direnv 2.32.2

config/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"development": {
3-
"password": null,
3+
"user": "dan",
4+
"password": "12qwaszx",
45
"database": "sequelize-example",
56
"host": "127.0.0.1",
67
"dialect": "postgres",

models/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const env = process.env.NODE_ENV || 'development';
99
const config = require(__dirname + '/../config/config.json')[env];
1010
const db = {};
1111

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

1515
let sequelize;

models/patient.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ module.exports = (sequelize, DataTypes) => {
2121
allergies: DataTypes.STRING,
2222
medications: DataTypes.STRING
2323
}, {
24+
hooks: {
25+
beforeFind: async (options) => {
26+
console.error('beforeFind hook', options);
27+
if (options.__identity) {
28+
await sequelize.query(
29+
// Uncomment this line when using with Proxy
30+
'--SET IDENTITY TO ?', {
31+
replacements: [options.__identity],
32+
}
33+
);
34+
delete options.__identity;
35+
}
36+
},
37+
beforeFindAfterOptions: (options) => {
38+
// __identity is not present because it has been removed in the beforeFind hook
39+
console.error('beforeFindAfterOptions hook', options);
40+
},
41+
},
2442
sequelize,
2543
modelName: 'patient',
2644
});

server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ app.get(
7474

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

8081
res.status(200).json(patients);

tandem.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
log_level = "info"
1+
# Sample tandem config file
2+
port = 5442
3+
database_url = "postgres://dan:@localhost:5432/sequelize-example"
4+
client_id = "1505033d-d637-4887-b1d2-1c946c30cd0b"
5+
client_key = "a4627031a16b7065726d75746174696f6e900f0a020b0d060e0c09010500040803076770325f66726f6da16b7065726d75746174696f6e9004010d030f020e050b080a0c090706006570325f746fa16b7065726d75746174696f6e9003090e0b060c00050a0d02040708010f627033a16b7065726d75746174696f6e9821100d05161819181f0804181e0c12181c1718180700111301181a1820181d0a030e02150b0f090614181b"
6+
#client_id = "1505033d-d637-4887-b1d2-1c946c30cd0b"
7+
#client_key = "clientkeyhere"
8+
workspace_id = "R7MMSPNCFRY7ZBNH"
9+
passthrough = false
10+
client_access_key = "CSAKLZSXWF5EJPYCBQ3B.YMGSVUMHWZTYJK25BAZ3COCW47OR3LREFP6KUGR3QKBIVIY4"
11+
log_level = "debug"
12+
# socket_path = "/tmp/tandem.sock"

0 commit comments

Comments
 (0)