Skip to content

Commit c276e5c

Browse files
authored
Merge branch 'master' into cookie-auth
2 parents a7ad258 + 0ed3c25 commit c276e5c

4 files changed

Lines changed: 104 additions & 4 deletions

File tree

departments/department-programs-config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@
7373
{
7474
"uuid": "203571d6-a4f2-4953-9e8b-e1105e2340f5",
7575
"name": "OTZ PROGRAM"
76-
},
77-
{
78-
"uuid": "4b738a10-b952-4e62-b215-30520fd9e113",
79-
"name": "NCD PROGRAM"
8076
}
8177
]
8278
},
@@ -167,6 +163,10 @@
167163
{
168164
"uuid": "6976b7eb-6d66-4aba-bcc0-cd8be80041cd",
169165
"name": "MENTAL HEALTH PROGRAM"
166+
},
167+
{
168+
"uuid": "4b738a10-b952-4e62-b215-30520fd9e113",
169+
"name": "NCD PROGRAM"
170170
}
171171
]
172172
},

etl-routes.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ import EmailService from './service/email/email.service.js';
9191
import OtpService from './service/otp/otp.service.js';
9292
import OtpStore from './service/otp-store/otp-store.service.js';
9393
import { LogoService } from './service/logo/logo-service.js';
94+
import SupersetService from './service/superset/superset.service.js';
95+
import {
96+
loadAndMaplocationUuidToId,
97+
getlocationIdFromUuid
98+
} from './location/location.service.js';
9499

95100
module.exports = (function () {
96101
var routes = [
@@ -6713,6 +6718,36 @@ module.exports = (function () {
67136718
description: 'Get a users location logo',
67146719
notes: 'Returns the current users location logo'
67156720
}
6721+
},
6722+
{
6723+
method: 'GET',
6724+
path: '/etl/superset-token',
6725+
config: {
6726+
auth: 'simple',
6727+
handler: async function (request, reply) {
6728+
const locationUuid = request.query.location_uuid;
6729+
const supersetService = new SupersetService();
6730+
try {
6731+
await loadAndMaplocationUuidToId();
6732+
const locationId = await getlocationIdFromUuid(locationUuid);
6733+
const res = await supersetService.getSupersetGuestToken(locationId);
6734+
reply({
6735+
access_token: res,
6736+
code: 200
6737+
});
6738+
} catch (err) {
6739+
return reply
6740+
.response({
6741+
success: false,
6742+
message: err.message
6743+
})
6744+
.code(400);
6745+
}
6746+
},
6747+
plugins: {},
6748+
description: 'Get superset guest token',
6749+
notes: 'Returns a superset guest token'
6750+
}
67166751
}
67176752
];
67186753

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"ampath-json2sql": "github:AMPATH/ampath-json2sql.git#v1.0.12",
3434
"array-merge-by-key": "1.0.1",
3535
"async": "^2.6.1",
36+
"axios": "^1.13.5",
3637
"bcryptjs": "^2.4.3",
3738
"bluebird": "^3.4.0",
3839
"body-parser": "^1.15.1",
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import axios from 'axios';
2+
3+
var config = require('../../conf/config.json');
4+
5+
class SupersetService {
6+
constructor() {
7+
this.secretKey = config.superset.GUEST_TOKEN_JWT_SECRET;
8+
this.dashboardId = config.superset.DASHBOARD_ID;
9+
this.supersetUrl = config.superset.SUPERSET_URL;
10+
this.username = config.superset.SUPERSET_USERNAME;
11+
this.password = config.superset.SUPERSET_PASSWORD;
12+
}
13+
14+
async getAccessToken() {
15+
const response = await axios.post(
16+
`${this.supersetUrl}/api/v1/security/login`,
17+
{
18+
username: this.username,
19+
password: this.password,
20+
provider: 'db',
21+
refresh: true
22+
},
23+
{
24+
headers: {
25+
'Content-Type': 'application/json'
26+
}
27+
}
28+
);
29+
30+
return response.data.access_token;
31+
}
32+
33+
async getSupersetGuestToken(locationId) {
34+
const token = await this.getAccessToken();
35+
36+
const response = await axios.post(
37+
`${this.supersetUrl}/api/v1/security/guest_token`,
38+
{
39+
user: {
40+
first_name: 'ampath',
41+
last_name: 'ampath',
42+
username: 'admin'
43+
},
44+
resources: [{ type: 'dashboard', id: this.dashboardId }],
45+
rls: [
46+
{
47+
clause: `location_id = ${locationId}`
48+
}
49+
],
50+
aud: 'superset',
51+
type: 'guest'
52+
},
53+
{
54+
headers: {
55+
Authorization: `Bearer ${token}`,
56+
'Content-Type': 'application/json'
57+
}
58+
}
59+
);
60+
return response.data.token;
61+
}
62+
}
63+
64+
module.exports = SupersetService;

0 commit comments

Comments
 (0)