soajs.controller 4.0.51 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright SOAJS All Rights Reserved.
|
|
6
|
+
*
|
|
7
|
+
* Use of this source code is governed by an Apache license that can be
|
|
8
|
+
* found in the LICENSE file at the root of this repository
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const get = (p, o) => p.reduce((xs, x) => (xs && xs[x]) ? xs[x] : null, o);
|
|
12
|
+
|
|
13
|
+
module.exports = () => {
|
|
14
|
+
|
|
15
|
+
return (req, res, next) => {
|
|
16
|
+
|
|
17
|
+
let maintenanceMode = get(["registry", "custom", "gateway", "value", "maintenanceMode"], req.soajs);
|
|
18
|
+
if (maintenanceMode && maintenanceMode.on) {
|
|
19
|
+
req.soajs.controllerResponse({
|
|
20
|
+
'status': maintenanceMode.status || 503,
|
|
21
|
+
'msg': maintenanceMode.message || "Maintenance mode is on, come back soon"
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
return next();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
};
|
package/mw/mt/index.js
CHANGED
|
@@ -157,6 +157,9 @@ module.exports = (configuration) => {
|
|
|
157
157
|
if (err && err.message) {
|
|
158
158
|
req.soajs.log.error(err.message);
|
|
159
159
|
}
|
|
160
|
+
if (err && err.name === "OAuth2Error") {
|
|
161
|
+
return next(err);
|
|
162
|
+
}
|
|
160
163
|
//doesn't work if you are not logged in
|
|
161
164
|
return next(158);
|
|
162
165
|
} else {
|
package/mw/mt/urac.js
CHANGED
|
@@ -32,14 +32,17 @@ function Urac(param) {
|
|
|
32
32
|
}
|
|
33
33
|
if (param.oauth.bearerToken.user.loginMode === "oauth") {
|
|
34
34
|
_self.userRecord = param.oauth.bearerToken.user;
|
|
35
|
-
}
|
|
36
|
-
else if (_self.soajs.registry.serviceConfig.oauth.getUserFromToken) {
|
|
35
|
+
} else if (_self.soajs.registry.serviceConfig.oauth.getUserFromToken) {
|
|
37
36
|
// NOTE:
|
|
38
37
|
// if roaming, must load again user
|
|
39
38
|
// if the clientId is not the same as _self.soajs.tenant.id then we should get the record
|
|
40
39
|
if (!_self.soajs.tenant.roaming && (param.oauth.bearerToken.clientId === _self.soajs.tenant.id)) {
|
|
41
40
|
_self.userRecord = param.oauth.bearerToken.user;
|
|
42
41
|
}
|
|
42
|
+
} else {
|
|
43
|
+
if (_self.soajs.tenant.roaming) {
|
|
44
|
+
_self.userRecord = param.oauth.bearerToken.user;
|
|
45
|
+
}
|
|
43
46
|
}
|
|
44
47
|
} else if (param._id) {
|
|
45
48
|
_self.id = param._id;
|
|
@@ -248,4 +251,4 @@ Urac.prototype.getAllowedPackages = function () {
|
|
|
248
251
|
return allowedPackages;
|
|
249
252
|
};
|
|
250
253
|
|
|
251
|
-
module.exports = Urac;
|
|
254
|
+
module.exports = Urac;
|
package/mw/mt/utils.js
CHANGED
|
@@ -586,10 +586,10 @@ let utils = {
|
|
|
586
586
|
if (obj.skipOAUTH) {
|
|
587
587
|
return cb(null, obj);
|
|
588
588
|
}
|
|
589
|
-
let callURACDriver = function () {
|
|
589
|
+
let callURACDriver = function (roaming) {
|
|
590
590
|
obj.req.soajs.uracDriver = new UracDriver({"soajs": obj.req.soajs, "oauth": obj.req.oauth});
|
|
591
591
|
obj.req.soajs.uracDriver.init((error) => {
|
|
592
|
-
if (error) {
|
|
592
|
+
if (error && !roaming) {
|
|
593
593
|
obj.req.soajs.log.error(error.message);
|
|
594
594
|
return cb (146);
|
|
595
595
|
}
|
|
@@ -674,11 +674,10 @@ let utils = {
|
|
|
674
674
|
if (response.registry && response.registry.tenantMetaDB) {
|
|
675
675
|
obj.req.soajs.tenant.roaming.tenantMetaDB = response.registry.tenantMetaDB;
|
|
676
676
|
}
|
|
677
|
-
|
|
678
|
-
return callURACDriver();
|
|
677
|
+
return callURACDriver(true);
|
|
679
678
|
});
|
|
680
679
|
} else {
|
|
681
|
-
return callURACDriver();
|
|
680
|
+
return callURACDriver(false);
|
|
682
681
|
}
|
|
683
682
|
} else {
|
|
684
683
|
return cb(null, obj);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soajs.controller",
|
|
3
3
|
"description": "soajs multi tenant API gateway",
|
|
4
|
-
"version": "4.0
|
|
4
|
+
"version": "4.1.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "soajs team",
|
|
7
7
|
"email": "team@soajs.org"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"test": "grunt test"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"async": "3.2.
|
|
21
|
+
"async": "3.2.4",
|
|
22
22
|
"connect": "3.7.0",
|
|
23
23
|
"http-proxy": "1.18.1",
|
|
24
24
|
"jsonwebtoken": "8.5.1",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"path-to-regexp": "6.2.0",
|
|
31
31
|
"request": "2.88.2",
|
|
32
32
|
"soajs.core.libs": "1.2.0",
|
|
33
|
-
"soajs.core.modules": "5.
|
|
34
|
-
"soajs.urac.driver": "3.
|
|
33
|
+
"soajs.core.modules": "5.1.2",
|
|
34
|
+
"soajs.urac.driver": "3.1.2",
|
|
35
35
|
"useragent": "2.3.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
package/server/controller.js
CHANGED
|
@@ -27,6 +27,7 @@ const favicon_mw = require('../mw/favicon/index');
|
|
|
27
27
|
const cors_mw = require('../mw/cors/index');
|
|
28
28
|
const soajs_mw = require('../mw/soajs/index');
|
|
29
29
|
const response_mw = require('../mw/response/index');
|
|
30
|
+
const maintenanceMode_mw = require('../mw/maintenanceMode/index');
|
|
30
31
|
const enhancer_mw = require('../mw/enhancer/index');
|
|
31
32
|
const awareness_mw = require('../mw/awareness/index');
|
|
32
33
|
const awarenessEnv_mw = require("../mw/awarenessEnv/index");
|
|
@@ -85,6 +86,7 @@ Controller.prototype.init = function (callback) {
|
|
|
85
86
|
}));
|
|
86
87
|
app.use(cors_mw());
|
|
87
88
|
app.use(response_mw({"controllerResponse": true}));
|
|
89
|
+
app.use(maintenanceMode_mw()); //NOTE: this is for global maintenance mode
|
|
88
90
|
|
|
89
91
|
log.info("Loading Provision ...");
|
|
90
92
|
let dbConfig = registry.coreDB.provision;
|
|
@@ -131,6 +133,8 @@ Controller.prototype.init = function (callback) {
|
|
|
131
133
|
|
|
132
134
|
app.use(key_mw({"provision": provision, "regEnvironment": regEnvironment}));
|
|
133
135
|
|
|
136
|
+
//TODO: add maintenance by tenant here req.soajs.controller.serviceParams.keyObj.config
|
|
137
|
+
|
|
134
138
|
app.use(keyACL_mw());
|
|
135
139
|
|
|
136
140
|
app.use(gotoService_mw({
|
|
@@ -68,7 +68,7 @@ describe("Integration for Usecase 1", function () {
|
|
|
68
68
|
requester('get', options, (error, body) => {
|
|
69
69
|
assert.ok(body);
|
|
70
70
|
assert.strictEqual(body.result, false);
|
|
71
|
-
assert.deepStrictEqual(body.errors.codes, [
|
|
71
|
+
assert.deepStrictEqual(body.errors.codes, [400]);
|
|
72
72
|
done();
|
|
73
73
|
});
|
|
74
74
|
});
|