k2hr3-api 1.0.25 → 1.0.27
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.
- package/ChangeLog +12 -0
- package/lib/k2hr3dkc.js +230 -59
- package/lib/k2hr3tokens.js +94 -60
- package/package.json +5 -5
- package/routes/tenant.js +120 -39
- package/routes/userTokens.js +77 -126
- package/tests/auto_tenant.js +119 -8
- package/tests/auto_usertokens.js +6 -6
- package/tests/manual_tenant_delete.js +46 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "k2hr3-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@kubernetes/client-node": "^0.18.1",
|
|
6
6
|
"body-parser": "^1.20.2",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"jose": "^4.14.4",
|
|
13
13
|
"k2hdkc": "^1.0.5",
|
|
14
14
|
"morgan": "~1.10.0",
|
|
15
|
-
"rotating-file-stream": "^3.1.
|
|
15
|
+
"rotating-file-stream": "^3.1.1"
|
|
16
16
|
},
|
|
17
17
|
"bin": {
|
|
18
18
|
"k2hr3-api": "./bin/www",
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"chai": "^4.3.7",
|
|
32
32
|
"chai-http": "^4.4.0",
|
|
33
|
-
"eslint": "^8.
|
|
33
|
+
"eslint": "^8.45.0",
|
|
34
34
|
"mocha": "^10.2.0",
|
|
35
35
|
"nyc": "^15.1.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
|
-
"help": "echo 'command list:\n npm run start\n npm run start:prod\n npm run start:production\n npm run start:prod:dbg\n npm run start:prod:debug\n npm run start:prod:debug:break\n npm run start:prod:debug:nobreak\n npm run start:dev\n npm run start:develop\n npm run start:dev:dbg\n npm run start:dev:debug\n npm run start:dev:debug:break\n npm run start:dev:debug:nobreak\n npm run start:watcher:prod\n npm run start:watcher:production\n npm run start:watcher:dev\n npm run start:watcher:develop\n npm run start:watcher:dbg\n npm run start:watcher:debug\n npm run start:watcher:debug:break\n npm run start:watcher:debug:nobreak\n npm run start:watcher:oneshot:prod\n npm run start:watcher:oneshot:production\n npm run start:watcher:oneshot:dev\n npm run start:watcher:oneshot:develop\n npm run start:watcher:oneshot:dbg\n npm run start:watcher:oneshot:debug\n npm run start:watcher:oneshot:debug:break\n npm run start:watcher:oneshot:debug:nobreak\n npm run stop\n npm run stop:watcher\n npm run test\n npm run test:lint\n npm run test:cover\n npm run test:auto:all{:dbg}\n npm run test:auto:version{:dbg}\n npm run test:auto:usertokens{:dbg}\n npm run test:auto:list{:dbg}\n npm run test:auto:resource{:dbg}\n npm run test:auto:policy{:dbg}\n npm run test:auto:role{:dbg}\n npm run test:auto:service{:dbg}\n npm run test:auto:acr{:dbg}\n npm run test:auto:userdata{:dbg}\n npm run test:auto:extdata{:dbg}\n npm run test:auto:watcher{:dbg}\n npm run test:auto:templengine\n npm run test:auto:templengine:async\n npm run test:manual:apis:version_get\n npm run test:manual:apis:usertoken_postput\n npm run test:manual:apis:usertoken_gethead\n npm run test:manual:apis:policy_postput\n npm run test:manual:apis:policy_gethead\n npm run test:manual:apis:policy_delete\n npm run test:manual:apis:resource_postput\n npm run test:manual:apis:resource_gethead\n npm run test:manual:apis:resource_delete\n npm run test:manual:apis:role_postput\n npm run test:manual:apis:role_gethead\n npm run test:manual:apis:role_delete\n npm run test:manual:apis:tenant_postput\n npm run test:manual:apis:tenant_gethead\n npm run test:manual:apis:tenant_delete\n npm run test:manual:apis:service_postput\n npm run test:manual:apis:service_gethead\n npm run test:manual:apis:service_delete\n npm run test:manual:apis:acr_postput\n npm run test:manual:apis:acr_get\n npm run test:manual:apis:acr_delete\n npm run test:manual:apis:list_gethead\n npm run test:manual:apis:userdata_get\n npm run test:manual:apis:extdata_get\n npm run test:manual:apis:allusertenant_get\n npm run test:manual:apis:k2hr3keys_get\n npm run test:manual:load:k2hdkcdata:auto\n npm run test:manual:load:k2hdkcdata:local\n npm run test:manual:templengine\n npm run test:manual:templengine:async\n'",
|
|
38
|
+
"help": "echo 'command list:\n npm run start\n npm run start:prod\n npm run start:production\n npm run start:prod:dbg\n npm run start:prod:debug\n npm run start:prod:debug:break\n npm run start:prod:debug:nobreak\n npm run start:dev\n npm run start:develop\n npm run start:dev:dbg\n npm run start:dev:debug\n npm run start:dev:debug:break\n npm run start:dev:debug:nobreak\n npm run start:watcher:prod\n npm run start:watcher:production\n npm run start:watcher:dev\n npm run start:watcher:develop\n npm run start:watcher:dbg\n npm run start:watcher:debug\n npm run start:watcher:debug:break\n npm run start:watcher:debug:nobreak\n npm run start:watcher:oneshot:prod\n npm run start:watcher:oneshot:production\n npm run start:watcher:oneshot:dev\n npm run start:watcher:oneshot:develop\n npm run start:watcher:oneshot:dbg\n npm run start:watcher:oneshot:debug\n npm run start:watcher:oneshot:debug:break\n npm run start:watcher:oneshot:debug:nobreak\n npm run stop\n npm run stop:watcher\n npm run test\n npm run test:lint\n npm run test:cover\n npm run test:auto:all{:dbg}\n npm run test:auto:version{:dbg}\n npm run test:auto:usertokens{:dbg}\n npm run test:auto:list{:dbg}\n npm run test:auto:resource{:dbg}\n npm run test:auto:policy{:dbg}\n npm run test:auto:role{:dbg}\n npm run test:auto:tenant{:dbg}\n npm run test:auto:service{:dbg}\n npm run test:auto:acr{:dbg}\n npm run test:auto:userdata{:dbg}\n npm run test:auto:extdata{:dbg}\n npm run test:auto:watcher{:dbg}\n npm run test:auto:templengine\n npm run test:auto:templengine:async\n npm run test:manual:apis:version_get\n npm run test:manual:apis:usertoken_postput\n npm run test:manual:apis:usertoken_gethead\n npm run test:manual:apis:policy_postput\n npm run test:manual:apis:policy_gethead\n npm run test:manual:apis:policy_delete\n npm run test:manual:apis:resource_postput\n npm run test:manual:apis:resource_gethead\n npm run test:manual:apis:resource_delete\n npm run test:manual:apis:role_postput\n npm run test:manual:apis:role_gethead\n npm run test:manual:apis:role_delete\n npm run test:manual:apis:tenant_postput\n npm run test:manual:apis:tenant_gethead\n npm run test:manual:apis:tenant_delete\n npm run test:manual:apis:service_postput\n npm run test:manual:apis:service_gethead\n npm run test:manual:apis:service_delete\n npm run test:manual:apis:acr_postput\n npm run test:manual:apis:acr_get\n npm run test:manual:apis:acr_delete\n npm run test:manual:apis:list_gethead\n npm run test:manual:apis:userdata_get\n npm run test:manual:apis:extdata_get\n npm run test:manual:apis:allusertenant_get\n npm run test:manual:apis:k2hr3keys_get\n npm run test:manual:load:k2hdkcdata:auto\n npm run test:manual:load:k2hdkcdata:local\n npm run test:manual:templengine\n npm run test:manual:templengine:async\n'",
|
|
39
39
|
"start": "npm run start:production",
|
|
40
40
|
"start:prod": "npm run start:production",
|
|
41
41
|
"start:production": "bin/run.sh -bg --production && echo '' && echo 'Start on production - Success' && echo ''",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"test": "npm run test:cover",
|
|
71
71
|
"test:lint": "eslint lib/*.js app.js bin/www bin/watcher routes/*.js tests/*.js",
|
|
72
72
|
"test:cover": "echo 'Test with coverage' && nyc --reporter=lcov --reporter=text npm run test:auto:all",
|
|
73
|
-
"test:auto": "echo 'Auto test : npm run test:auto:*\n test:auto:all{:dbg}\n test:auto:version{:dbg}\n test:auto:usertokens{:dbg}\n test:auto:list{:dbg}\n test:auto:resource{:dbg}\n test:auto:policy{:dbg}\n test:auto:role{:dbg}\n test:auto:tenant{:dbg}\n test:auto:service{:dbg}\n test:auto:acr{:dbg}\n test:auto:userdata{:dbg}\n test:auto:extdata{:dbg}\n test:auto:watcher{:dbg}\n test:auto:templengine\n test:auto:templengine:async\n'",
|
|
73
|
+
"test:auto": "echo 'Auto test : npm run test:auto:*\n test:auto:all{:dbg}\n test:auto:version{:dbg}\n test:auto:usertokens{:dbg}\n test:auto:list{:dbg}\n test:auto:resource{:dbg}\n test:auto:policy{:dbg}\n test:auto:role{:dbg}\n test:auto:tenant{:dbg}\n test:auto:tenant{:dbg}\n test:auto:service{:dbg}\n test:auto:acr{:dbg}\n test:auto:userdata{:dbg}\n test:auto:extdata{:dbg}\n test:auto:watcher{:dbg}\n test:auto:templengine\n test:auto:templengine:async\n'",
|
|
74
74
|
"test:auto:all": "echo 'All test' && npm run test:lint && tests/test.sh -t 8000 all && npm run test:auto:templengine && npm run test:auto:templengine:async && echo 'Succeed test' && echo ''",
|
|
75
75
|
"test:auto:all:dbg": "echo 'All test with debugging' && npm run test:lint && tests/test.sh -t 8000 -d dbg all && echo 'Succeed test' && echo ''",
|
|
76
76
|
"test:auto:version": "echo 'Test Version' && tests/test.sh -t 8000 version && echo 'Succeed test' && echo ''",
|
package/routes/tenant.js
CHANGED
|
@@ -393,7 +393,23 @@ router.post('/', function(req, res, next) // eslint-disable-line no-unused-v
|
|
|
393
393
|
// add own user
|
|
394
394
|
apiutil.tryAddStringToArray(tenant_users, comparam.user_name);
|
|
395
395
|
}else{
|
|
396
|
-
if(
|
|
396
|
+
if(apiutil.isEmptyArray(tenant_users)){
|
|
397
|
+
result.result = false;
|
|
398
|
+
result.message = 'POST request tenant(' + tenant_name + ') does not have any user list.';
|
|
399
|
+
r3logger.elog(result.message);
|
|
400
|
+
resutil.errResponse(req, res, 400, result); // 400: Bad Request
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
var findobj = k2hr3.findTenant(tenant_name, comparam.user_name, tenant_id);
|
|
405
|
+
if( !apiutil.isSafeEntity(findobj) ||
|
|
406
|
+
!apiutil.isSafeEntity(findobj.result) ||
|
|
407
|
+
false === findobj.result ||
|
|
408
|
+
!apiutil.isSafeEntity(findobj.tenant) ||
|
|
409
|
+
!apiutil.isSafeEntity(findobj.tenant.name) ||
|
|
410
|
+
!apiutil.getSafeArray(findobj.tenant.users) ||
|
|
411
|
+
!apiutil.findStringInArray(findobj.tenant.users, comparam.user_name) )
|
|
412
|
+
{
|
|
397
413
|
result.result = false;
|
|
398
414
|
result.message = 'POST request tenant(' + tenant_name + ') does not allow user(' + comparam.user_name + ').';
|
|
399
415
|
r3logger.elog(result.message);
|
|
@@ -604,21 +620,37 @@ router.put('/', function(req, res, next) // eslint-disable-line no-unused-va
|
|
|
604
620
|
tenant_users = apiutil.parseJSON(req.query.users);
|
|
605
621
|
if(!apiutil.isArray(tenant_users) && apiutil.isSafeString(tenant_users)){
|
|
606
622
|
tenant_users = [tenant_users];
|
|
607
|
-
}else
|
|
608
|
-
tenant_users =
|
|
623
|
+
}else{
|
|
624
|
+
tenant_users = apiutil.getSafeArray(tenant_users);
|
|
609
625
|
}
|
|
610
|
-
}else if(apiutil.isArray(req.query.users)){
|
|
611
|
-
tenant_users = req.query.users;
|
|
612
|
-
}else if(apiutil.isSafeString(req.query.users)){
|
|
626
|
+
}else if(!apiutil.isArray(req.query.users) && apiutil.isSafeString(req.query.users)){
|
|
613
627
|
tenant_users = [req.query.users];
|
|
614
628
|
}else{
|
|
615
|
-
tenant_users =
|
|
629
|
+
tenant_users = apiutil.getSafeArray(req.query.users);
|
|
616
630
|
}
|
|
631
|
+
|
|
617
632
|
if(is_create){
|
|
618
633
|
// add own user
|
|
619
634
|
apiutil.tryAddStringToArray(tenant_users, comparam.user_name);
|
|
620
635
|
}else{
|
|
621
|
-
|
|
636
|
+
// check user in current tenant users
|
|
637
|
+
if(apiutil.isEmptyArray(tenant_users)){
|
|
638
|
+
result.result = false;
|
|
639
|
+
result.message = 'PUT request tenant(' + tenant_name + ') does not have any user list.';
|
|
640
|
+
r3logger.elog(result.message);
|
|
641
|
+
resutil.errResponse(req, res, 400, result); // 400: Bad Request
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
var findobj = k2hr3.findTenant(tenant_name, comparam.user_name, tenant_id);
|
|
646
|
+
if( !apiutil.isSafeEntity(findobj) ||
|
|
647
|
+
!apiutil.isSafeEntity(findobj.result) ||
|
|
648
|
+
false === findobj.result ||
|
|
649
|
+
!apiutil.isSafeEntity(findobj.tenant) ||
|
|
650
|
+
!apiutil.isSafeEntity(findobj.tenant.name) ||
|
|
651
|
+
!apiutil.getSafeArray(findobj.tenant.users) ||
|
|
652
|
+
!apiutil.findStringInArray(findobj.tenant.users, comparam.user_name) )
|
|
653
|
+
{
|
|
622
654
|
result.result = false;
|
|
623
655
|
result.message = 'PUT request tenant(' + tenant_name + ') does not allow user(' + comparam.user_name + ').';
|
|
624
656
|
r3logger.elog(result.message);
|
|
@@ -917,11 +949,26 @@ router.head('/', function(req, res, next)
|
|
|
917
949
|
// Router DELETE
|
|
918
950
|
//=========================================================
|
|
919
951
|
//
|
|
920
|
-
// Mountpath
|
|
952
|
+
// Mountpath : '/v1/tenant'
|
|
921
953
|
//
|
|
922
|
-
|
|
954
|
+
//---------------------------------------------------------
|
|
955
|
+
// [DELETE] No tenant path
|
|
956
|
+
//---------------------------------------------------------
|
|
957
|
+
// DELETE '/v1/tenant' : delete tenant version 1
|
|
923
958
|
// HEADER : X-Auth-Token = <User token>
|
|
924
|
-
// url argument : "
|
|
959
|
+
// url argument : "tenant" = <tenant name>
|
|
960
|
+
// url argument : "id" = <id> => key is "yrn:yahoo:::<tenant>:id"
|
|
961
|
+
// response status code : 204 or 4xx/5xx
|
|
962
|
+
// response body : nothing
|
|
963
|
+
//
|
|
964
|
+
// This mount point deletes the specified <K2HR3 cluster LOCAL> tenant.
|
|
965
|
+
//
|
|
966
|
+
//---------------------------------------------------------
|
|
967
|
+
// [DELETE] With tenant path
|
|
968
|
+
//---------------------------------------------------------
|
|
969
|
+
// DELETE '/v1/tenant/tenant' : delete tenant version 1
|
|
970
|
+
// HEADER : X-Auth-Token = <User token>
|
|
971
|
+
// url argument : "id" = <id> => key is "yrn:yahoo:::<tenant>:id"
|
|
925
972
|
// response status code : 204 or 4xx/5xx
|
|
926
973
|
// response body : nothing
|
|
927
974
|
//
|
|
@@ -930,7 +977,7 @@ router.head('/', function(req, res, next)
|
|
|
930
977
|
// [NOTE]
|
|
931
978
|
// Only users registered in the tenant to be deleted can delete this tenant.
|
|
932
979
|
//
|
|
933
|
-
router.delete('/', function(req, res, next)
|
|
980
|
+
router.delete('/', function(req, res, next) // eslint-disable-line no-unused-vars
|
|
934
981
|
{
|
|
935
982
|
r3logger.dlog('CALL:', req.method, req.url);
|
|
936
983
|
|
|
@@ -940,7 +987,7 @@ router.delete('/', function(req, res, next) // eslint-disable-line no-unu
|
|
|
940
987
|
!apiutil.isSafeEntity(req.baseUrl) )
|
|
941
988
|
{
|
|
942
989
|
r3logger.elog('DELETE request or url or query is wrong');
|
|
943
|
-
resutil.errResponse(req, res, 400);
|
|
990
|
+
resutil.errResponse(req, res, 400); // 400: Bad Request
|
|
944
991
|
return;
|
|
945
992
|
}
|
|
946
993
|
|
|
@@ -965,39 +1012,73 @@ router.delete('/', function(req, res, next) // eslint-disable-line no-unu
|
|
|
965
1012
|
}
|
|
966
1013
|
|
|
967
1014
|
//------------------------------
|
|
968
|
-
// Check uri paths
|
|
1015
|
+
// Check uri paths
|
|
969
1016
|
//------------------------------
|
|
1017
|
+
var tenant_name;
|
|
1018
|
+
var tenant_id;
|
|
970
1019
|
if(!apiutil.isSafeString(comparam.tenant_name)){
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
1020
|
+
//------------------------------
|
|
1021
|
+
// Check argments(tenant)
|
|
1022
|
+
//------------------------------
|
|
1023
|
+
tenant_name = apiutil.getSafeString(req.query.tenant);
|
|
1024
|
+
if(!apiutil.isSafeString(tenant_name)){
|
|
1025
|
+
r3logger.elog('DELETE request tenant must specify in argument');
|
|
1026
|
+
resutil.errResponse(req, res, 400); // 400: Bad Request
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
975
1029
|
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
1030
|
+
//------------------------------
|
|
1031
|
+
// Check argments(id)
|
|
1032
|
+
//------------------------------
|
|
1033
|
+
tenant_id = apiutil.getSafeString(req.query.id);
|
|
1034
|
+
if(!apiutil.isSafeString(tenant_id)){
|
|
1035
|
+
r3logger.elog('DELETE request id must specify in argument');
|
|
1036
|
+
resutil.errResponse(req, res, 400); // 400: Bad Request
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
985
1039
|
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
1040
|
+
//------------------------------
|
|
1041
|
+
// Processing
|
|
1042
|
+
//------------------------------
|
|
1043
|
+
resobj = k2hr3.removeLocalTenant(tenant_name, comparam.user_name, tenant_id);
|
|
1044
|
+
if(!apiutil.isSafeEntity(resobj) || !apiutil.isSafeEntity(resobj.result) || false === resobj.result){
|
|
1045
|
+
if(apiutil.isSafeEntity(resobj) && apiutil.isSafeString(resobj.message)){
|
|
1046
|
+
r3logger.elog('DELETE request failed to remove user from tenant by ' + resobj.message);
|
|
1047
|
+
}else{
|
|
1048
|
+
r3logger.elog('DELETE request failed to remove user from tenant by unknown reason');
|
|
1049
|
+
}
|
|
1050
|
+
resutil.errResponse(req, res, 400); // 400: Bad Request
|
|
1051
|
+
return;
|
|
995
1052
|
}
|
|
996
|
-
|
|
997
|
-
|
|
1053
|
+
r3logger.dlog('DELETE request succeed - remove tenant');
|
|
1054
|
+
|
|
1055
|
+
}else{
|
|
1056
|
+
//------------------------------
|
|
1057
|
+
// Check argments(id)
|
|
1058
|
+
//------------------------------
|
|
1059
|
+
tenant_id = apiutil.getSafeString(req.query.id);
|
|
1060
|
+
if(!apiutil.isSafeString(tenant_id)){
|
|
1061
|
+
r3logger.elog('DELETE request id must specify in argument');
|
|
1062
|
+
resutil.errResponse(req, res, 400); // 400: Bad Request
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
//------------------------------
|
|
1067
|
+
// Processing
|
|
1068
|
+
//------------------------------
|
|
1069
|
+
resobj = k2hr3.removeUserFromLocalTenant(comparam.tenant_name, comparam.user_name, tenant_id);
|
|
1070
|
+
if(!apiutil.isSafeEntity(resobj) || !apiutil.isSafeEntity(resobj.result) || false === resobj.result){
|
|
1071
|
+
if(apiutil.isSafeEntity(resobj) && apiutil.isSafeString(resobj.message)){
|
|
1072
|
+
r3logger.elog('DELETE request failed to remove user from tenant by ' + resobj.message);
|
|
1073
|
+
}else{
|
|
1074
|
+
r3logger.elog('DELETE request failed to remove user from tenant by unknown reason');
|
|
1075
|
+
}
|
|
1076
|
+
resutil.errResponse(req, res, 400); // 400: Bad Request
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
r3logger.dlog('DELETE request succeed - remove user from tenant');
|
|
998
1080
|
}
|
|
999
1081
|
|
|
1000
|
-
r3logger.dlog('DELETE request succeed - remove user from tenant');
|
|
1001
1082
|
res.status(204); // 204: No Content
|
|
1002
1083
|
res.send();
|
|
1003
1084
|
});
|
package/routes/userTokens.js
CHANGED
|
@@ -50,13 +50,10 @@ function rawCommonGetUserToken(req, res, unscopedToken, otherToken, username, pa
|
|
|
50
50
|
// Get token from User Credentials
|
|
51
51
|
//
|
|
52
52
|
if(!apiutil.isSafeString(username)){
|
|
53
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
54
53
|
error = {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
59
|
-
|
|
54
|
+
result: false,
|
|
55
|
+
message: 'Some parameter(user name or unscoped token) is wrong.'
|
|
56
|
+
};
|
|
60
57
|
r3logger.elog(error.message);
|
|
61
58
|
resutil.errResponse(req, res, 400, error); // 400: Bad Request
|
|
62
59
|
return;
|
|
@@ -65,27 +62,21 @@ function rawCommonGetUserToken(req, res, unscopedToken, otherToken, username, pa
|
|
|
65
62
|
r3token.getUserToken(_username, _passwd, _tenant, function(err, token)
|
|
66
63
|
{
|
|
67
64
|
if(null !== err){
|
|
68
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
69
65
|
var error = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
74
|
-
|
|
66
|
+
result: false,
|
|
67
|
+
message: 'could not get scoped user token for user=' + _username + ', tenant=' + _tenant + ' by ' + err.message
|
|
68
|
+
};
|
|
75
69
|
r3logger.elog(error.message);
|
|
76
70
|
resutil.errResponse(_req, _res, 404, error); // 404: Not Found
|
|
77
71
|
return;
|
|
78
72
|
}
|
|
79
73
|
r3logger.dlog('get user token jsonres = ' + JSON.stringify(token));
|
|
80
74
|
|
|
81
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
82
75
|
var result = { result: true,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
88
|
-
|
|
76
|
+
message: 'succeed',
|
|
77
|
+
scoped: apiutil.isSafeString(_tenant),
|
|
78
|
+
token: token
|
|
79
|
+
};
|
|
89
80
|
_res.status(201); // 201: Created
|
|
90
81
|
_res.send(JSON.stringify(result));
|
|
91
82
|
});
|
|
@@ -95,13 +86,10 @@ function rawCommonGetUserToken(req, res, unscopedToken, otherToken, username, pa
|
|
|
95
86
|
// Get Scoped token from Unscoped token
|
|
96
87
|
//
|
|
97
88
|
if(!apiutil.isSafeString(username)){
|
|
98
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
99
89
|
error = {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
104
|
-
|
|
90
|
+
result: false,
|
|
91
|
+
message: 'Some parameter(user name or unscoped token) is wrong.'
|
|
92
|
+
};
|
|
105
93
|
r3logger.elog(error.message);
|
|
106
94
|
resutil.errResponse(req, res, 400, error); // 400: Bad Request
|
|
107
95
|
return;
|
|
@@ -110,27 +98,22 @@ function rawCommonGetUserToken(req, res, unscopedToken, otherToken, username, pa
|
|
|
110
98
|
r3token.getScopedUserToken(_unscopedToken, _username, _tenant, function(err, token)
|
|
111
99
|
{
|
|
112
100
|
if(null !== err){
|
|
113
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
114
101
|
var error = {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
119
|
-
|
|
102
|
+
result: false,
|
|
103
|
+
message: 'could not get scoped user token for user=' + _username + ', tenant=' + _tenant + ' by ' + err.message
|
|
104
|
+
};
|
|
120
105
|
r3logger.elog(error.message);
|
|
121
106
|
resutil.errResponse(_req, _res, 404, error); // 404: Not Found
|
|
122
107
|
return;
|
|
123
108
|
}
|
|
124
109
|
r3logger.dlog('get user token jsonres = ' + JSON.stringify(token));
|
|
125
110
|
|
|
126
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
127
111
|
var result = {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
112
|
+
result: true,
|
|
113
|
+
message: 'succeed',
|
|
114
|
+
scoped: apiutil.isSafeString(_tenant),
|
|
115
|
+
token: token
|
|
116
|
+
};
|
|
134
117
|
|
|
135
118
|
_res.status(201); // 201: Created
|
|
136
119
|
_res.send(JSON.stringify(result));
|
|
@@ -143,28 +126,22 @@ function rawCommonGetUserToken(req, res, unscopedToken, otherToken, username, pa
|
|
|
143
126
|
r3token.getUserTokenByToken(_otherToken, _tenant, function(err, token)
|
|
144
127
|
{
|
|
145
128
|
if(null !== err){
|
|
146
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
147
129
|
var error = {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
152
|
-
|
|
130
|
+
result: false,
|
|
131
|
+
message: 'could not get scoped user token for other token, tenant=' + _tenant + ' by ' + err.message
|
|
132
|
+
};
|
|
153
133
|
r3logger.elog(error.message);
|
|
154
134
|
resutil.errResponse(_req, _res, 404, error); // 404: Not Found
|
|
155
135
|
return;
|
|
156
136
|
}
|
|
157
137
|
r3logger.dlog('get user token jsonres = ' + JSON.stringify(token));
|
|
158
138
|
|
|
159
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
160
139
|
var result = {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
167
|
-
|
|
140
|
+
result: true,
|
|
141
|
+
message: 'succeed',
|
|
142
|
+
scoped: apiutil.isSafeString(_tenant),
|
|
143
|
+
token: token
|
|
144
|
+
};
|
|
168
145
|
_res.status(201); // 201: Created
|
|
169
146
|
_res.send(JSON.stringify(result));
|
|
170
147
|
});
|
|
@@ -188,13 +165,11 @@ function rawGetUnscopedUserToken(req)
|
|
|
188
165
|
!apiutil.isSafeString(resobj.token_info.user) ||
|
|
189
166
|
false !== resobj.token_info.scoped )
|
|
190
167
|
{
|
|
191
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
192
168
|
return {
|
|
193
169
|
result: false,
|
|
194
170
|
status: 400, // 400: Bad Request
|
|
195
171
|
message: 'could not get unscoped user token in request.'
|
|
196
172
|
};
|
|
197
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
198
173
|
}
|
|
199
174
|
|
|
200
175
|
return {
|
|
@@ -223,13 +198,10 @@ router.post('/', function(req, res, next) // eslint-disable-line no-unused-
|
|
|
223
198
|
if( !apiutil.isSafeEntity(req) ||
|
|
224
199
|
!apiutil.isSafeEntity(req.body) )
|
|
225
200
|
{
|
|
226
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
227
201
|
error = {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
232
|
-
|
|
202
|
+
result: false,
|
|
203
|
+
message: 'POST body does not have auth key'
|
|
204
|
+
};
|
|
233
205
|
r3logger.elog(error.message);
|
|
234
206
|
resutil.errResponse(req, res, 400, error); // 400: Bad Request
|
|
235
207
|
return;
|
|
@@ -260,13 +232,10 @@ router.post('/', function(req, res, next) // eslint-disable-line no-unused-
|
|
|
260
232
|
// (1) case of unscoped token registered in k2hr3
|
|
261
233
|
//
|
|
262
234
|
if(!apiutil.isSafeEntity(req.body.auth) || !apiutil.isSafeString(req.body.auth.tenantName)){
|
|
263
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
264
235
|
error = {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
269
|
-
|
|
236
|
+
result: false,
|
|
237
|
+
message: 'POST body does not have tenant name(or user credentials)'
|
|
238
|
+
};
|
|
270
239
|
r3logger.elog(error.message);
|
|
271
240
|
resutil.errResponse(req, res, 400, error); // 400: Bad Request
|
|
272
241
|
return;
|
|
@@ -280,13 +249,10 @@ router.post('/', function(req, res, next) // eslint-disable-line no-unused-
|
|
|
280
249
|
//
|
|
281
250
|
otherToken = r3token.getAuthTokenHeader(req, false);
|
|
282
251
|
if(!apiutil.isSafeString(otherToken)){
|
|
283
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
284
252
|
error = {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
289
|
-
|
|
253
|
+
result: false,
|
|
254
|
+
message: resobj.message
|
|
255
|
+
};
|
|
290
256
|
r3logger.elog(resobj.message);
|
|
291
257
|
resutil.errResponse(req, res, resobj.status, error); // 40X
|
|
292
258
|
return;
|
|
@@ -320,13 +286,10 @@ router.put('/', function(req, res, next) // eslint-disable-line no-unused-v
|
|
|
320
286
|
if( !apiutil.isSafeEntity(req) ||
|
|
321
287
|
!apiutil.isSafeEntity(req.query) )
|
|
322
288
|
{
|
|
323
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
324
289
|
error = {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
329
|
-
|
|
290
|
+
result: false,
|
|
291
|
+
message: 'PUT argument does not have any data'
|
|
292
|
+
};
|
|
330
293
|
r3logger.elog(error.message);
|
|
331
294
|
resutil.errResponse(req, res, 400, error); // 400: Bad Request
|
|
332
295
|
return;
|
|
@@ -357,13 +320,10 @@ router.put('/', function(req, res, next) // eslint-disable-line no-unused-v
|
|
|
357
320
|
// (1) case of unscoped token registered in k2hr3
|
|
358
321
|
//
|
|
359
322
|
if(!apiutil.isSafeString(req.query.tenantname)){
|
|
360
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
361
323
|
error = {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
366
|
-
|
|
324
|
+
result: false,
|
|
325
|
+
message: 'POST body does not have tenant name(or user credentials)'
|
|
326
|
+
};
|
|
367
327
|
r3logger.elog(error.message);
|
|
368
328
|
resutil.errResponse(req, res, 400, error); // 400: Bad Request
|
|
369
329
|
return;
|
|
@@ -378,13 +338,10 @@ router.put('/', function(req, res, next) // eslint-disable-line no-unused-v
|
|
|
378
338
|
//
|
|
379
339
|
otherToken = r3token.getAuthTokenHeader(req, false);
|
|
380
340
|
if(!apiutil.isSafeString(otherToken)){
|
|
381
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
382
341
|
error = {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
387
|
-
|
|
342
|
+
result: false,
|
|
343
|
+
message: resobj.message
|
|
344
|
+
};
|
|
388
345
|
r3logger.elog(resobj.message);
|
|
389
346
|
resutil.errResponse(req, res, resobj.status, error); // 40X
|
|
390
347
|
return;
|
|
@@ -411,8 +368,10 @@ router.put('/', function(req, res, next) // eslint-disable-line no-unused-v
|
|
|
411
368
|
// user => user name
|
|
412
369
|
// tenants => [
|
|
413
370
|
// {
|
|
414
|
-
// name:
|
|
415
|
-
// display:
|
|
371
|
+
// name: "tenant name"
|
|
372
|
+
// display: "display name"
|
|
373
|
+
// id: "tenant id"
|
|
374
|
+
// description: "tenant description"
|
|
416
375
|
// },
|
|
417
376
|
// ...
|
|
418
377
|
// ]
|
|
@@ -453,21 +412,20 @@ router.get('/', function(req, res, next) // eslint-disable-line no-unused-v
|
|
|
453
412
|
// build response body
|
|
454
413
|
if(token_info.scoped){
|
|
455
414
|
// scoped token
|
|
456
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
457
415
|
result = {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
416
|
+
result: true,
|
|
417
|
+
message: 'succeed',
|
|
418
|
+
scoped: true,
|
|
419
|
+
user: token_info.user,
|
|
420
|
+
tenants: [
|
|
421
|
+
{
|
|
422
|
+
name: token_info.tenant,
|
|
423
|
+
display: token_info.display,
|
|
424
|
+
id: token_info.id,
|
|
425
|
+
description: token_info.description
|
|
426
|
+
}
|
|
427
|
+
]
|
|
428
|
+
};
|
|
471
429
|
_res.status(200); // 200: OK
|
|
472
430
|
_res.send(JSON.stringify(result));
|
|
473
431
|
|
|
@@ -476,13 +434,10 @@ router.get('/', function(req, res, next) // eslint-disable-line no-unused-v
|
|
|
476
434
|
r3token.initializeTenantList(token_result.token, token_info.user, function(error, tenant_list)
|
|
477
435
|
{
|
|
478
436
|
if(null !== error){
|
|
479
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
480
437
|
var result = {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
485
|
-
|
|
438
|
+
result: false,
|
|
439
|
+
message: 'failed to get tenant list for user (' + token_info.user + ') by unscoped token(' + token_result.token + ')'
|
|
440
|
+
};
|
|
486
441
|
r3logger.elog(result.message);
|
|
487
442
|
resutil.errResponse(_req, _res, 404, result); // 404: Not Found
|
|
488
443
|
return;
|
|
@@ -491,26 +446,22 @@ router.get('/', function(req, res, next) // eslint-disable-line no-unused-v
|
|
|
491
446
|
// reget tenant list
|
|
492
447
|
tenant_list = r3token.getTenantList(token_info.user);
|
|
493
448
|
if(null === tenant_list || apiutil.isEmptyArray(tenant_list)){
|
|
494
|
-
/* eslint-disable indent, no-mixed-spaces-and-tabs */
|
|
495
449
|
result = {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
/* eslint-enable indent, no-mixed-spaces-and-tabs */
|
|
500
|
-
|
|
450
|
+
result: false,
|
|
451
|
+
message: 'token(' + token_result.token + ') for user (' + token_info.user + ') does not have any tenant.'
|
|
452
|
+
};
|
|
501
453
|
r3logger.elog(result.message);
|
|
502
454
|
resutil.errResponse(_req, _res, 404, result); // 404: Not Found
|
|
503
455
|
return;
|
|
504
456
|
}
|
|
505
457
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
458
|
+
result = {
|
|
459
|
+
result: true,
|
|
460
|
+
message: 'succeed',
|
|
461
|
+
scoped: false,
|
|
462
|
+
user: token_info.user,
|
|
463
|
+
tenants: tenant_list
|
|
464
|
+
};
|
|
514
465
|
_res.status(200); // 200: OK
|
|
515
466
|
_res.send(JSON.stringify(result));
|
|
516
467
|
});
|