Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
NewsHub v2.0.0 Alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
bharatari committed Aug 16, 2018
1 parent 9765654 commit 5dafb07
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 5 deletions.
2 changes: 2 additions & 0 deletions gateway/src/services/proxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module.exports = async (ctx, next) => {
'content-type': 'application/json; charset=utf-8',
'authorization': headers['authorization'],
});

// headers['newshub-user'] = JSON.stringify(await data.getUser(userId, headers));
}

// Don't dynamically resolve method names
Expand Down
32 changes: 32 additions & 0 deletions gateway/src/services/roomReservation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,38 @@ const access = require('../../utils/access');
const proxy = require('../proxy/index');

module.exports = (router) => {
router.get('/api/room-reservation', async (ctx, next) => {
const path = ctx.request.path;
const query = ctx.request.search;
const headers = ctx.request.headers;
const userId = ctx.state.user ? ctx.state.user.userId : '';

try {
headers['newshub-user-id'] = userId;

headers['newshub-user'] = JSON.stringify(await data.getUser(userId, headers));

if (userId) {
headers['newshub-organization-id'] = await data.getOrganizationId(userId, {
'content-type': 'application/json; charset=utf-8',
'authorization': headers['authorization'],
});

headers['newshub-user'] = JSON.stringify(await data.getUser(userId, headers));
}

const response = await data.get(path, query, headers);

data.respond(ctx, response, next);
} catch (e) {
data.handleError(ctx, e, next);
}
// Pass user JSON in header
// Or pass JWT with claims as user JSON
// Have a docker shared secret file so all docker services
// can have access to the jwt secret
});

router.post('/api/room-reservation', async (ctx, next) => {
const path = ctx.request.path;
const body = ctx.request.body;
Expand Down
13 changes: 13 additions & 0 deletions gateway/src/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,18 @@ module.exports = {
} else {
return '';
}
},
async getUser(userId, headers) {
try {
let user = JSON.parse(await data.get(`/api/user/${userId}`, '', headers));

if (user) {
user.roles = JSON.parse(await data.get(`/api/role`, '?roles=all', headers));
}

return user;
} catch (e) {
return null;
}
}
};
2 changes: 1 addition & 1 deletion services/authentication/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "newshub-authentication",
"description": "",
"version": "1.0.0-beta.2",
"version": "2.0.0-alpha",
"homepage": "",
"main": "src/",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion services/events/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "newshub-events",
"description": "",
"version": "1.0.0-beta",
"version": "2.0.0-alpha",
"homepage": "",
"main": "src",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion services/files/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "newshub-files",
"version": "1.0.0",
"version": "2.0.0-alpha",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion services/reservations/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "newshub-reservations",
"description": "",
"version": "0.0.0",
"version": "2.0.0-alpha",
"homepage": "",
"main": "src",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion services/room-reservations/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "newshub-room-reservations",
"description": "",
"version": "0.0.0",
"version": "2.0.0-alpha",
"homepage": "",
"main": "src",
"keywords": [
Expand Down

0 comments on commit 5dafb07

Please sign in to comment.