k2hr3-api 1.0.42 → 2.0.1
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/config/k2hr3-init.sh.templ +4 -4
- package/dist/.gitkeep +0 -0
- package/dist/src/app.js +262 -0
- package/{bin → dist/src/bin}/run.sh +1 -1
- package/dist/src/bin/watcher.js +113 -0
- package/dist/src/bin/www.js +217 -0
- package/dist/src/lib/basicipcheck.js +392 -0
- package/dist/src/lib/cacerts.js +106 -0
- package/dist/src/lib/dbglogging.js +190 -0
- package/dist/src/lib/dummyuserapi.js +719 -0
- package/dist/src/lib/ipwatch.js +354 -0
- package/dist/src/lib/k2hr3acrutil.js +532 -0
- package/dist/src/lib/k2hr3apiutil.js +1444 -0
- package/dist/src/lib/k2hr3cliutil.js +183 -0
- package/dist/src/lib/k2hr3config.js +832 -0
- package/dist/src/lib/k2hr3cryptutil.js +258 -0
- package/dist/src/lib/k2hr3dkc.js +12121 -0
- package/dist/src/lib/k2hr3extdata.js +198 -0
- package/dist/src/lib/k2hr3keys.js +207 -0
- package/dist/src/lib/k2hr3resutil.js +111 -0
- package/dist/src/lib/k2hr3template.js +6546 -0
- package/dist/src/lib/k2hr3tokens.js +2643 -0
- package/dist/src/lib/k2hr3userdata.js +296 -0
- package/dist/src/lib/k8soidc.js +1000 -0
- package/dist/src/lib/openstackapiv2.js +695 -0
- package/dist/src/lib/openstackapiv3.js +932 -0
- package/dist/src/lib/openstackep.js +667 -0
- package/{tests/auto_common.js → dist/src/lib/types.js} +4 -38
- package/dist/src/routes/acr.js +704 -0
- package/dist/src/routes/debugVerify.js +294 -0
- package/dist/src/routes/extdata.js +219 -0
- package/dist/src/routes/list.js +264 -0
- package/dist/src/routes/policy.js +840 -0
- package/dist/src/routes/resource.js +1489 -0
- package/dist/src/routes/role.js +2627 -0
- package/dist/src/routes/service.js +908 -0
- package/dist/src/routes/tenant.js +1141 -0
- package/dist/src/routes/userTokens.js +482 -0
- package/dist/src/routes/userdata.js +212 -0
- package/dist/src/routes/version.js +103 -0
- package/package.json +152 -121
- package/ChangeLog +0 -378
- package/app.js +0 -292
- package/bin/watcher +0 -122
- package/bin/www +0 -180
- package/eslint.config.mjs +0 -68
- package/lib/basicipcheck.js +0 -376
- package/lib/cacerts.js +0 -71
- package/lib/dbglogging.js +0 -151
- package/lib/dummyuserapi.js +0 -766
- package/lib/ipwatch.js +0 -379
- package/lib/k2hr3acrutil.js +0 -516
- package/lib/k2hr3apiutil.js +0 -1494
- package/lib/k2hr3cliutil.js +0 -191
- package/lib/k2hr3config.js +0 -826
- package/lib/k2hr3cryptutil.js +0 -254
- package/lib/k2hr3dkc.js +0 -12632
- package/lib/k2hr3extdata.js +0 -198
- package/lib/k2hr3keys.js +0 -234
- package/lib/k2hr3resutil.js +0 -100
- package/lib/k2hr3template.js +0 -6925
- package/lib/k2hr3tokens.js +0 -2799
- package/lib/k2hr3userdata.js +0 -312
- package/lib/k8soidc.js +0 -1012
- package/lib/openstackapiv2.js +0 -764
- package/lib/openstackapiv3.js +0 -1032
- package/lib/openstackep.js +0 -553
- package/routes/acr.js +0 -738
- package/routes/debugVerify.js +0 -263
- package/routes/extdata.js +0 -232
- package/routes/list.js +0 -270
- package/routes/policy.js +0 -869
- package/routes/resource.js +0 -1441
- package/routes/role.js +0 -2664
- package/routes/service.js +0 -894
- package/routes/tenant.js +0 -1095
- package/routes/userTokens.js +0 -511
- package/routes/userdata.js +0 -218
- package/routes/version.js +0 -108
- package/templ/Dockerfile.templ +0 -71
- package/tests/auto_acr.js +0 -1101
- package/tests/auto_acr_spec.js +0 -79
- package/tests/auto_all_spec.js +0 -142
- package/tests/auto_control_subprocess.sh +0 -243
- package/tests/auto_extdata.js +0 -220
- package/tests/auto_extdata_spec.js +0 -79
- package/tests/auto_init_config_json.sh +0 -275
- package/tests/auto_k2hdkc_server.ini +0 -109
- package/tests/auto_k2hdkc_slave.ini +0 -83
- package/tests/auto_list.js +0 -439
- package/tests/auto_list_spec.js +0 -79
- package/tests/auto_policy.js +0 -1579
- package/tests/auto_policy_spec.js +0 -79
- package/tests/auto_resource.js +0 -10956
- package/tests/auto_resource_spec.js +0 -79
- package/tests/auto_role.js +0 -6150
- package/tests/auto_role_spec.js +0 -79
- package/tests/auto_service.js +0 -770
- package/tests/auto_service_spec.js +0 -79
- package/tests/auto_subprocesses.js +0 -114
- package/tests/auto_template.sh +0 -126
- package/tests/auto_tenant.js +0 -1100
- package/tests/auto_tenant_spec.js +0 -79
- package/tests/auto_token_util.js +0 -219
- package/tests/auto_userdata.js +0 -292
- package/tests/auto_userdata_spec.js +0 -79
- package/tests/auto_usertokens.js +0 -565
- package/tests/auto_usertokens_spec.js +0 -79
- package/tests/auto_version.js +0 -127
- package/tests/auto_version_spec.js +0 -79
- package/tests/auto_watcher.js +0 -157
- package/tests/auto_watcher_spec.js +0 -79
- package/tests/k2hdkc_test.data +0 -986
- package/tests/k2hdkc_test_load.sh +0 -255
- package/tests/k2hr3template_test.js +0 -187
- package/tests/k2hr3template_test.sh +0 -339
- package/tests/k2hr3template_test_async.js +0 -216
- package/tests/k2hr3template_test_template.result +0 -7117
- package/tests/k2hr3template_test_template.txt +0 -3608
- package/tests/k2hr3template_test_vars.js +0 -194
- package/tests/manual_acr_delete.js +0 -143
- package/tests/manual_acr_get.js +0 -297
- package/tests/manual_acr_postput.js +0 -215
- package/tests/manual_allusertenant_get.js +0 -113
- package/tests/manual_extdata_get.js +0 -191
- package/tests/manual_k2hr3keys_get.js +0 -84
- package/tests/manual_list_gethead.js +0 -230
- package/tests/manual_policy_delete.js +0 -132
- package/tests/manual_policy_gethead.js +0 -275
- package/tests/manual_policy_postput.js +0 -297
- package/tests/manual_resource_delete.js +0 -433
- package/tests/manual_resource_gethead.js +0 -423
- package/tests/manual_resource_postput.js +0 -487
- package/tests/manual_role_delete.js +0 -404
- package/tests/manual_role_gethead.js +0 -547
- package/tests/manual_role_postput.js +0 -544
- package/tests/manual_service_delete.js +0 -153
- package/tests/manual_service_gethead.js +0 -178
- package/tests/manual_service_postput.js +0 -348
- package/tests/manual_tenant_delete.js +0 -186
- package/tests/manual_tenant_gethead.js +0 -268
- package/tests/manual_tenant_postput.js +0 -293
- package/tests/manual_test.sh +0 -352
- package/tests/manual_userdata_get.js +0 -173
- package/tests/manual_usertoken_gethead.js +0 -136
- package/tests/manual_usertoken_postput.js +0 -310
- package/tests/manual_version_get.js +0 -127
- package/tests/run_local_test_k2hdkc.sh +0 -174
- package/tests/test.sh +0 -333
|
@@ -0,0 +1,719 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* K2HR3 REST API
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2017 Yahoo Japan Corporation.
|
|
6
|
+
*
|
|
7
|
+
* K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
|
|
8
|
+
* common management information for the cloud.
|
|
9
|
+
* K2HR3 can dynamically manage information as "who", "what", "operate".
|
|
10
|
+
* These are stored as roles, resources, policies in K2hdkc, and the
|
|
11
|
+
* client system can dynamically read and modify these information.
|
|
12
|
+
*
|
|
13
|
+
* For the full copyright and license information, please view
|
|
14
|
+
* the license file that was distributed with this source code.
|
|
15
|
+
*
|
|
16
|
+
* AUTHOR: Takeshi Nakatani
|
|
17
|
+
* CREATE: Mon Dec 25 2017
|
|
18
|
+
* REVISION:
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.dummyuserapi = void 0;
|
|
26
|
+
const k2hr3apiutil_1 = __importDefault(require("./k2hr3apiutil"));
|
|
27
|
+
const k2hr3dkc_1 = __importDefault(require("./k2hr3dkc"));
|
|
28
|
+
const dbglogging_1 = __importDefault(require("./dbglogging"));
|
|
29
|
+
const k2hr3keys_1 = require("./k2hr3keys");
|
|
30
|
+
//
|
|
31
|
+
// Dummy endpoint and etc
|
|
32
|
+
//
|
|
33
|
+
const dummy_region_name = 'dummy_endpoint';
|
|
34
|
+
const dummy_endpoint_url = 'https://dummyep.k2hr3api.yahoo.co.jp/';
|
|
35
|
+
//
|
|
36
|
+
// Endpoint for user's server group(tenant) information for dummy
|
|
37
|
+
//
|
|
38
|
+
let dummy_ep = null;
|
|
39
|
+
const dummyapi_ep = () => {
|
|
40
|
+
if (k2hr3apiutil_1.default.isSafeEntity(dummy_ep)) {
|
|
41
|
+
return dummy_ep;
|
|
42
|
+
}
|
|
43
|
+
const keys = (0, k2hr3keys_1.getK2hr3Keys)();
|
|
44
|
+
let res_ep = k2hr3dkc_1.default.getKeystoneEndpoint(dummy_region_name);
|
|
45
|
+
if (res_ep.result && k2hr3apiutil_1.default.isPlainObject(res_ep.keystones)) {
|
|
46
|
+
const tmpRegion = res_ep.keystones[dummy_region_name];
|
|
47
|
+
if (k2hr3apiutil_1.default.isPlainObject(tmpRegion) &&
|
|
48
|
+
k2hr3apiutil_1.default.isSafeString(tmpRegion.url) &&
|
|
49
|
+
k2hr3apiutil_1.default.isSafeString(tmpRegion.type) &&
|
|
50
|
+
keys.VALUE_KEYSTONE_SUB === tmpRegion.type) {
|
|
51
|
+
// already has endpoint
|
|
52
|
+
dummy_ep = k2hr3apiutil_1.default.urlParse(tmpRegion.url);
|
|
53
|
+
dummy_ep.region = dummy_region_name;
|
|
54
|
+
// for debug
|
|
55
|
+
dbglogging_1.default.dlog('dummy get group information for user : end point = ' + JSON.stringify(dummy_ep));
|
|
56
|
+
return dummy_ep;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// not register yet, then register it.
|
|
60
|
+
res_ep = k2hr3dkc_1.default.setKeystoneEndpointAll(dummy_region_name, dummy_endpoint_url, keys.VALUE_KEYSTONE_SUB, 0);
|
|
61
|
+
if (res_ep.result) {
|
|
62
|
+
// succeed, retry to get
|
|
63
|
+
res_ep = k2hr3dkc_1.default.getKeystoneEndpoint(dummy_region_name);
|
|
64
|
+
if (res_ep.result && k2hr3apiutil_1.default.isSafeEntity(res_ep.keystones)) {
|
|
65
|
+
const tmpRegion = res_ep.keystones[dummy_region_name];
|
|
66
|
+
if (k2hr3apiutil_1.default.isSafeEntity(tmpRegion) &&
|
|
67
|
+
k2hr3apiutil_1.default.isSafeString(tmpRegion.url) &&
|
|
68
|
+
k2hr3apiutil_1.default.isSafeString(tmpRegion.type) &&
|
|
69
|
+
keys.VALUE_KEYSTONE_SUB === tmpRegion.type) {
|
|
70
|
+
dummy_ep = k2hr3apiutil_1.default.urlParse(tmpRegion.url);
|
|
71
|
+
dummy_ep.region = dummy_region_name;
|
|
72
|
+
// for debug
|
|
73
|
+
dbglogging_1.default.dlog('dummy get group information for user : end point = ' + JSON.stringify(dummy_ep));
|
|
74
|
+
return dummy_ep;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// failed to re-get
|
|
78
|
+
dbglogging_1.default.elog('could not set and re-get dummy endpoint into k2hdkc, then build endpoint url object in local. but create it locally.');
|
|
79
|
+
dummy_ep = k2hr3apiutil_1.default.urlParse(dummy_endpoint_url);
|
|
80
|
+
dummy_ep.region = dummy_region_name;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// failed to set
|
|
84
|
+
dbglogging_1.default.elog('could not set dummy endpoint into k2hdkc, then build endpoint url object in local. but create it locally.');
|
|
85
|
+
dummy_ep = k2hr3apiutil_1.default.urlParse(dummy_endpoint_url);
|
|
86
|
+
dummy_ep.region = dummy_region_name;
|
|
87
|
+
}
|
|
88
|
+
// for debug
|
|
89
|
+
dbglogging_1.default.dlog('dummy get group information for user : end point = ' + JSON.stringify(dummy_ep));
|
|
90
|
+
return dummy_ep;
|
|
91
|
+
};
|
|
92
|
+
//---------------------------------------------------------
|
|
93
|
+
// [User Token for case of dummy]
|
|
94
|
+
//---------------------------------------------------------
|
|
95
|
+
//
|
|
96
|
+
// Token: Token Id(################)
|
|
97
|
+
// X-Auth-Token: U=Token Id
|
|
98
|
+
// Token Id: The "Token Id" is a unique hex number string for 128bit.
|
|
99
|
+
// "Token Id" = "(<base id(64bit:8byte)> ^ <crypt id(64bit:8byte)>)" + "(<userex id(64bit:8byte)> ^ <crypt id(64bit:8byte)>)"
|
|
100
|
+
// User Token Key: "yrn:yahoo::::token:user/<Token Id>"
|
|
101
|
+
// User Token Seed: {
|
|
102
|
+
// publisher: "DUMMYUSERAPI"
|
|
103
|
+
// userexid: "user extra id(user generated extra id)"
|
|
104
|
+
// date: "UTC time at create"
|
|
105
|
+
// expire: "UTC time at expire"
|
|
106
|
+
// creator: "User full yrn"
|
|
107
|
+
// base: "generated 64bit random binary"
|
|
108
|
+
// user: "user name"
|
|
109
|
+
// ip: always null
|
|
110
|
+
// hostname: always null
|
|
111
|
+
// port: always 0
|
|
112
|
+
// cuk: always null
|
|
113
|
+
// extra: always null
|
|
114
|
+
// tenant: if scoped token, this is "tenant name". if not, this is null
|
|
115
|
+
// verify: "random 64bit id for verify token"
|
|
116
|
+
// }
|
|
117
|
+
//
|
|
118
|
+
// [NOTE]
|
|
119
|
+
// "user id from dummy" which is in "Token Id" is included from dummy user.
|
|
120
|
+
// This Seed value is secret, any API could not get this value directly.
|
|
121
|
+
//
|
|
122
|
+
// Keys in K2hdkc has the following relationship. "seed" is special key/value for dummy and like it.
|
|
123
|
+
// Token key: "yrn:yahoo::::token:user/<token>"
|
|
124
|
+
// value => "yrn:yahoo::::user:dummy:tenant/{<tenant>}/token/<token>"
|
|
125
|
+
// User token key: "yrn:yahoo::::user:dummy:tenant/{<tenant>}/token/<token>"
|
|
126
|
+
// value => "region name"
|
|
127
|
+
// subkeys => "yrn:yahoo::::user:dummy:tenant/{<tenant>}/token/<token>/seed"
|
|
128
|
+
// User token seed key: "yrn:yahoo::::user:dummy:tenant/{<tenant>}/token/<token>/seed"
|
|
129
|
+
// value => JSON seed information(token value)
|
|
130
|
+
//
|
|
131
|
+
//---------------------------------------------------------
|
|
132
|
+
// Create User Token For dummy user
|
|
133
|
+
//---------------------------------------------------------
|
|
134
|
+
// user : user name which is allowed any name
|
|
135
|
+
// result : {
|
|
136
|
+
// result: true/false
|
|
137
|
+
// message: null or error message string
|
|
138
|
+
// token: undefined(error) or user token string
|
|
139
|
+
// expire_at: expire date(UTC ISO 8601)
|
|
140
|
+
// token_seed: JSON token seed data
|
|
141
|
+
// userid: set userid
|
|
142
|
+
// }
|
|
143
|
+
//
|
|
144
|
+
// [NOTE]
|
|
145
|
+
// user token seed value is following
|
|
146
|
+
// {
|
|
147
|
+
// publisher: "DUMMYUSERAPI"
|
|
148
|
+
// userexid: "user extra id(a part of seed uuid4)"
|
|
149
|
+
// date: "UTC ISO 8601 time at create"
|
|
150
|
+
// expire: "UTC ISO 8601 time at expire"
|
|
151
|
+
// creator: "User full yrn"
|
|
152
|
+
// base: "32byte hex string"
|
|
153
|
+
// user: "user name"
|
|
154
|
+
// ip: always null
|
|
155
|
+
// hostname: always null
|
|
156
|
+
// port: always 0
|
|
157
|
+
// cuk: always null
|
|
158
|
+
// extra: always null
|
|
159
|
+
// tenant: if scoped token, this is "tenant name". if not, this is null
|
|
160
|
+
// }
|
|
161
|
+
//
|
|
162
|
+
const rawCreateUserTokenByDummyUser = (user, tenant) => {
|
|
163
|
+
const resobj = { result: true, message: null };
|
|
164
|
+
if (!k2hr3apiutil_1.default.isSafeString(user)) { // allow another parameter is null
|
|
165
|
+
resobj.result = false;
|
|
166
|
+
resobj.message = 'parameter is wrong : user=' + JSON.stringify(user);
|
|
167
|
+
dbglogging_1.default.elog(resobj.message);
|
|
168
|
+
return resobj;
|
|
169
|
+
}
|
|
170
|
+
if (!k2hr3apiutil_1.default.isSafeString(tenant)) {
|
|
171
|
+
tenant = null;
|
|
172
|
+
}
|
|
173
|
+
const dkcobj = k2hr3dkc_1.default.getK2hdkc(true, false); // use permanent object(need to clean)
|
|
174
|
+
user = user.toLowerCase();
|
|
175
|
+
const keys = (0, k2hr3keys_1.getK2hr3Keys)(user, null);
|
|
176
|
+
if (!k2hr3apiutil_1.default.isSafeEntity(dkcobj)) {
|
|
177
|
+
resobj.result = false;
|
|
178
|
+
resobj.message = 'Not initialize yet.';
|
|
179
|
+
dbglogging_1.default.elog(resobj.message);
|
|
180
|
+
return resobj;
|
|
181
|
+
}
|
|
182
|
+
// check user id exists.
|
|
183
|
+
let userid = dkcobj.getValue(keys.USER_ID_KEY, null, true, null); // yrn:yahoo::::user:<user>:id
|
|
184
|
+
if (!k2hr3apiutil_1.default.isSafeString(userid)) {
|
|
185
|
+
// make dummy user id
|
|
186
|
+
userid = k2hr3apiutil_1.default.getStrUuid4(); // Dummy user id(uuid4)
|
|
187
|
+
}
|
|
188
|
+
// user seed id(generated every time)
|
|
189
|
+
const user_ex_id = k2hr3apiutil_1.default.getStrUuid4(); // seed(uuid4)
|
|
190
|
+
// make token seed value
|
|
191
|
+
const expire_limit = 24 * 60 * 60; // default 24H expire for dummy user
|
|
192
|
+
const now_unixtime = k2hr3apiutil_1.default.getUnixtime();
|
|
193
|
+
// create key
|
|
194
|
+
for (let is_loop = true; is_loop;) { // for eslint
|
|
195
|
+
// make user token
|
|
196
|
+
const token_elements = k2hr3apiutil_1.default.makeStringToken256(user_ex_id, userid);
|
|
197
|
+
if (!k2hr3apiutil_1.default.isSafeEntity(token_elements)) {
|
|
198
|
+
resobj.result = false;
|
|
199
|
+
resobj.message = 'could not make token from ' + JSON.stringify(user_ex_id) + ' and ' + JSON.stringify(userid);
|
|
200
|
+
dbglogging_1.default.elog(resobj.message);
|
|
201
|
+
dkcobj.clean();
|
|
202
|
+
return resobj;
|
|
203
|
+
}
|
|
204
|
+
const token_seed = {
|
|
205
|
+
publisher: 'DUMMYUSERAPI', // "DUMMYUSERAPI"
|
|
206
|
+
userexid: user_ex_id, // seed(uuid4)
|
|
207
|
+
date: (new Date(now_unixtime * 1000)).toISOString(), // now date(UTC ISO 8601)
|
|
208
|
+
expire: (new Date((now_unixtime + expire_limit) * 1000)).toISOString(), // expire date(UTC ISO 8601)
|
|
209
|
+
creator: keys.USER_KEY, // "yrn:yahoo::::user:<user>"
|
|
210
|
+
user: user, // user(creator)
|
|
211
|
+
hostname: null, // hostname(creator)
|
|
212
|
+
ip: null, // ip(creator)
|
|
213
|
+
port: 0, // port(creator)
|
|
214
|
+
cuk: null, // cuk(creator)
|
|
215
|
+
extra: null, // extra(creator)
|
|
216
|
+
tenant: tenant, // tenant(if scope, not null)
|
|
217
|
+
base: token_elements.str_base // token base
|
|
218
|
+
};
|
|
219
|
+
const user_token = token_elements.str_token;
|
|
220
|
+
// user token key
|
|
221
|
+
const token_user_key = keys.TOKEN_USER_TOP_KEY + '/' + user_token; // "yrn:yahoo::::token:user/<user token>"
|
|
222
|
+
// get user token for existing check
|
|
223
|
+
const value = dkcobj.getValue(token_user_key, null, true, null);
|
|
224
|
+
if (!k2hr3apiutil_1.default.isSafeEntity(value)) {
|
|
225
|
+
// Add user token/expire/seed into result object.
|
|
226
|
+
resobj.token = user_token;
|
|
227
|
+
resobj.expire_at = token_seed.expire;
|
|
228
|
+
resobj.token_seed = JSON.stringify(token_seed);
|
|
229
|
+
resobj.userid = userid;
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
dbglogging_1.default.dlog('conflict user token(' + user_token + ') which already is used, so remake token for uniq.');
|
|
233
|
+
}
|
|
234
|
+
dkcobj.clean();
|
|
235
|
+
return resobj;
|
|
236
|
+
};
|
|
237
|
+
//---------------------------------------------------------
|
|
238
|
+
// Verify User Token Publisher For dummy user
|
|
239
|
+
//---------------------------------------------------------
|
|
240
|
+
//
|
|
241
|
+
// token_seed : token seed data
|
|
242
|
+
//
|
|
243
|
+
// result : {
|
|
244
|
+
// result: true/false
|
|
245
|
+
// message: null or error message string
|
|
246
|
+
// }
|
|
247
|
+
//
|
|
248
|
+
const rawVerifyUserTokenPublisherByDummyUser = (token_seed) => {
|
|
249
|
+
const resobj = { result: true, message: null };
|
|
250
|
+
if (!k2hr3apiutil_1.default.isSafeString(token_seed)) {
|
|
251
|
+
resobj.result = false;
|
|
252
|
+
resobj.message = 'token_seed(not printable) is not safe entity.';
|
|
253
|
+
dbglogging_1.default.elog(resobj.message);
|
|
254
|
+
return resobj;
|
|
255
|
+
}
|
|
256
|
+
// parse seed
|
|
257
|
+
if (!k2hr3apiutil_1.default.checkSimpleJSON(token_seed)) {
|
|
258
|
+
resobj.result = false;
|
|
259
|
+
resobj.message = 'token_seed(not printable) is not safe entity.';
|
|
260
|
+
dbglogging_1.default.elog(resobj.message);
|
|
261
|
+
return resobj;
|
|
262
|
+
}
|
|
263
|
+
const tmpseed = k2hr3apiutil_1.default.parseJSON(token_seed);
|
|
264
|
+
if (!k2hr3apiutil_1.default.isValTypeTokenSeed(tmpseed)) {
|
|
265
|
+
resobj.result = false;
|
|
266
|
+
resobj.message = 'token_seed(not printable) is not safe entity.';
|
|
267
|
+
dbglogging_1.default.elog(resobj.message);
|
|
268
|
+
return resobj;
|
|
269
|
+
}
|
|
270
|
+
const seed = tmpseed;
|
|
271
|
+
if (!k2hr3apiutil_1.default.isSafeString(seed.publisher) ||
|
|
272
|
+
(seed.publisher != 'DUMMYUSERAPI')) // publisher must be 'DUMMYUSERAPI'
|
|
273
|
+
{
|
|
274
|
+
resobj.result = false;
|
|
275
|
+
resobj.message = 'token_seed(not printable) is not safe entity.';
|
|
276
|
+
dbglogging_1.default.elog(resobj.message);
|
|
277
|
+
return resobj;
|
|
278
|
+
}
|
|
279
|
+
return resobj;
|
|
280
|
+
};
|
|
281
|
+
//---------------------------------------------------------
|
|
282
|
+
// Verify User Token From dummy user
|
|
283
|
+
//---------------------------------------------------------
|
|
284
|
+
//
|
|
285
|
+
// dkcobj_permanent : dkcobj object
|
|
286
|
+
// user : target user name for token
|
|
287
|
+
// tenant : target tenant name for token(if token is scoped)
|
|
288
|
+
// token : check token
|
|
289
|
+
// token_seed : token seed data
|
|
290
|
+
//
|
|
291
|
+
// result : {
|
|
292
|
+
// result: true/false
|
|
293
|
+
// message: null or error message string
|
|
294
|
+
// }
|
|
295
|
+
//
|
|
296
|
+
const rawVerifyUserTokenByDummyUser = (dkcobj_permanent, user, tenant, token, token_seed) => {
|
|
297
|
+
const resobj = { result: true, message: null };
|
|
298
|
+
if (!k2hr3apiutil_1.default.isSafeString(token) || !k2hr3apiutil_1.default.isSafeString(token_seed) || !k2hr3apiutil_1.default.isSafeString(user)) {
|
|
299
|
+
resobj.result = false;
|
|
300
|
+
resobj.message = 'some parameters are wrong : token=' + JSON.stringify(token) + ', token_seed=<not printable>, user=' + JSON.stringify(user);
|
|
301
|
+
dbglogging_1.default.elog(resobj.message);
|
|
302
|
+
return resobj;
|
|
303
|
+
}
|
|
304
|
+
// parse seed
|
|
305
|
+
if (!k2hr3apiutil_1.default.checkSimpleJSON(token_seed)) {
|
|
306
|
+
resobj.result = false;
|
|
307
|
+
resobj.message = 'token_seed(not printable) is not safe entity.';
|
|
308
|
+
dbglogging_1.default.elog(resobj.message);
|
|
309
|
+
return resobj;
|
|
310
|
+
}
|
|
311
|
+
const tmpseed = k2hr3apiutil_1.default.parseJSON(token_seed);
|
|
312
|
+
if (!k2hr3apiutil_1.default.isValTypeTokenSeed(tmpseed)) {
|
|
313
|
+
resobj.result = false;
|
|
314
|
+
resobj.message = 'token_seed(not printable) is not safe entity.';
|
|
315
|
+
dbglogging_1.default.elog(resobj.message);
|
|
316
|
+
return resobj;
|
|
317
|
+
}
|
|
318
|
+
const seed = tmpseed;
|
|
319
|
+
if (!k2hr3apiutil_1.default.isSafeString(seed.publisher) ||
|
|
320
|
+
(seed.publisher != 'DUMMYUSERAPI') || // publisher must be 'DUMMYUSERAPI'
|
|
321
|
+
!k2hr3apiutil_1.default.isSafeString(seed.userexid) ||
|
|
322
|
+
!k2hr3apiutil_1.default.isSafeString(seed.date) ||
|
|
323
|
+
!k2hr3apiutil_1.default.isSafeString(seed.expire) ||
|
|
324
|
+
!k2hr3apiutil_1.default.isSafeString(seed.creator) ||
|
|
325
|
+
!k2hr3apiutil_1.default.isSafeString(seed.base) ||
|
|
326
|
+
!k2hr3apiutil_1.default.isSafeString(seed.user) ||
|
|
327
|
+
!k2hr3apiutil_1.default.compareCaseString(seed.user, user)) {
|
|
328
|
+
resobj.result = false;
|
|
329
|
+
resobj.message = 'token_seed(not printable) is not safe entity.';
|
|
330
|
+
dbglogging_1.default.elog(resobj.message);
|
|
331
|
+
return resobj;
|
|
332
|
+
}
|
|
333
|
+
// check expire
|
|
334
|
+
if (k2hr3apiutil_1.default.isExpired(seed.expire)) {
|
|
335
|
+
resobj.result = false;
|
|
336
|
+
resobj.message = 'token is expired by expire date(' + seed.expire + ') in token_seed.';
|
|
337
|
+
dbglogging_1.default.elog(resobj.message);
|
|
338
|
+
return resobj;
|
|
339
|
+
}
|
|
340
|
+
// check tenant name(if tenant is specified, seed must have same tenant name)
|
|
341
|
+
if (k2hr3apiutil_1.default.isSafeString(seed.tenant) !== k2hr3apiutil_1.default.isSafeString(tenant) || (k2hr3apiutil_1.default.isSafeString(seed.tenant) && !k2hr3apiutil_1.default.compareCaseString(seed.tenant, tenant))) {
|
|
342
|
+
resobj.result = false;
|
|
343
|
+
resobj.message = 'token_seed(not printable) is (un)scoped, but tenant name is (not) specified. Then unmatched.';
|
|
344
|
+
dbglogging_1.default.elog(resobj.message);
|
|
345
|
+
return resobj;
|
|
346
|
+
}
|
|
347
|
+
// k2hdkc
|
|
348
|
+
const keys = (0, k2hr3keys_1.getK2hr3Keys)(seed.user, seed.tenant);
|
|
349
|
+
let dkcobj;
|
|
350
|
+
if (!k2hr3apiutil_1.default.isSafeEntity(dkcobj_permanent)) {
|
|
351
|
+
const tmpobj = k2hr3dkc_1.default.getK2hdkc(true, false); // use permanent object(need to clean)
|
|
352
|
+
if (!k2hr3apiutil_1.default.isSafeEntity(tmpobj)) {
|
|
353
|
+
resobj.result = false;
|
|
354
|
+
resobj.message = 'Not initialize yet.';
|
|
355
|
+
dbglogging_1.default.elog(resobj.message);
|
|
356
|
+
return resobj;
|
|
357
|
+
}
|
|
358
|
+
dkcobj = tmpobj;
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
dkcobj = dkcobj_permanent;
|
|
362
|
+
}
|
|
363
|
+
// get user id
|
|
364
|
+
const userid = dkcobj.getValue(keys.USER_ID_KEY, null, true, null); // get user id from "yrn:yahoo::::user:<user>:id"
|
|
365
|
+
if (!k2hr3apiutil_1.default.isSafeEntity(dkcobj_permanent)) {
|
|
366
|
+
dkcobj.clean();
|
|
367
|
+
}
|
|
368
|
+
if (!k2hr3apiutil_1.default.isSafeString(userid)) {
|
|
369
|
+
resobj.result = false;
|
|
370
|
+
resobj.message = 'could not get user id for user(' + seed.user + ').';
|
|
371
|
+
dbglogging_1.default.elog(resobj.message);
|
|
372
|
+
return resobj;
|
|
373
|
+
}
|
|
374
|
+
// make verify token
|
|
375
|
+
const token_elements = k2hr3apiutil_1.default.makeStringToken256(seed.userexid, userid, seed.base);
|
|
376
|
+
if (!k2hr3apiutil_1.default.isSafeEntity(token_elements)) {
|
|
377
|
+
resobj.result = false;
|
|
378
|
+
resobj.message = 'could not make verify token from ' + JSON.stringify(seed.userexid) + ' and ' + JSON.stringify(userid) + ' and ' + JSON.stringify(seed.base);
|
|
379
|
+
dbglogging_1.default.elog(resobj.message);
|
|
380
|
+
return resobj;
|
|
381
|
+
}
|
|
382
|
+
if (token !== token_elements.str_token) {
|
|
383
|
+
resobj.result = false;
|
|
384
|
+
resobj.message = 'token(' + token + ') verify is failure, verify token is ' + token_elements.str_token + '.';
|
|
385
|
+
dbglogging_1.default.elog(resobj.message);
|
|
386
|
+
return resobj;
|
|
387
|
+
}
|
|
388
|
+
return resobj;
|
|
389
|
+
};
|
|
390
|
+
//---------------------------------------------------------
|
|
391
|
+
// Get User/Tenant information from User Token
|
|
392
|
+
//---------------------------------------------------------
|
|
393
|
+
//
|
|
394
|
+
// Result: {
|
|
395
|
+
// result: true/false
|
|
396
|
+
// message: null or error message string
|
|
397
|
+
// user: user name
|
|
398
|
+
// userid: user id
|
|
399
|
+
// tenant: if token is scoped token, this value is set tenant name.
|
|
400
|
+
// }
|
|
401
|
+
//
|
|
402
|
+
const rawGetUserTenantInfoFromToken = (token) => {
|
|
403
|
+
const resobj = { result: true, message: null };
|
|
404
|
+
if (!k2hr3apiutil_1.default.isSafeString(token)) {
|
|
405
|
+
resobj.result = false;
|
|
406
|
+
resobj.message = 'parameter is wrong : token=' + JSON.stringify(token);
|
|
407
|
+
dbglogging_1.default.elog(resobj.message);
|
|
408
|
+
return resobj;
|
|
409
|
+
}
|
|
410
|
+
const dkcobj = k2hr3dkc_1.default.getK2hdkc(true, false); // use permanent object(need to clean)
|
|
411
|
+
let keys = (0, k2hr3keys_1.getK2hr3Keys)();
|
|
412
|
+
if (!k2hr3apiutil_1.default.isSafeEntity(dkcobj)) {
|
|
413
|
+
resobj.result = false;
|
|
414
|
+
resobj.message = 'Not initialize yet.';
|
|
415
|
+
dbglogging_1.default.elog(resobj.message);
|
|
416
|
+
return resobj;
|
|
417
|
+
}
|
|
418
|
+
// get token key under user key
|
|
419
|
+
const token_value_key = keys.TOKEN_USER_TOP_KEY + '/' + token; // "yrn:yahoo::::token:user/<token>"
|
|
420
|
+
const user_token_key = dkcobj.getValue(token_value_key, null, true, null); // "yrn:yahoo::::user:<user>:tenant/{<tenant>}/token/<token>"
|
|
421
|
+
if (!k2hr3apiutil_1.default.isSafeString(user_token_key)) {
|
|
422
|
+
resobj.result = false;
|
|
423
|
+
resobj.message = 'token key(' + token_value_key + ') for token(' + token + ') is not existed.';
|
|
424
|
+
dbglogging_1.default.elog(resobj.message);
|
|
425
|
+
dkcobj.clean();
|
|
426
|
+
return resobj;
|
|
427
|
+
}
|
|
428
|
+
// get user name and tenant name from token key yrn path
|
|
429
|
+
const pattern = new RegExp('^' + keys.MATCH_ANY_USER_TOKEN); // regex = /^yrn:yahoo::::user:(.*):tenant\/(.*)\/token\/(.*)/
|
|
430
|
+
const matches = user_token_key.match(pattern); // reverse to user/tenant names
|
|
431
|
+
if (!k2hr3apiutil_1.default.isNotEmptyArray(matches) || matches.length < 4 || '' === k2hr3apiutil_1.default.getSafeString(matches[1])) {
|
|
432
|
+
resobj.result = false;
|
|
433
|
+
resobj.message = 'token key(' + token_value_key + ') for token(' + token + ') has wrong format value(' + user_token_key + ')';
|
|
434
|
+
dbglogging_1.default.elog(resobj.message);
|
|
435
|
+
dkcobj.clean();
|
|
436
|
+
return resobj;
|
|
437
|
+
}
|
|
438
|
+
const token_user = k2hr3apiutil_1.default.getSafeString(matches[1]);
|
|
439
|
+
let token_tenant = k2hr3apiutil_1.default.getSafeString(matches[2]);
|
|
440
|
+
if ('' === token_tenant) {
|
|
441
|
+
token_tenant = null;
|
|
442
|
+
}
|
|
443
|
+
// get token seed
|
|
444
|
+
const user_token_seed_key = user_token_key + '/' + keys.SEED_KW; // "yrn:yahoo::::user:<user>:tenant/{<tenant>}/token/<token>/seed"
|
|
445
|
+
const token_seed = dkcobj.getValue(user_token_seed_key, null, true, null);
|
|
446
|
+
if (!k2hr3apiutil_1.default.isSafeString(token_seed)) {
|
|
447
|
+
resobj.result = false;
|
|
448
|
+
resobj.message = 'token key(' + token_value_key + ') for token(' + token + ') does not have token seed data.';
|
|
449
|
+
dbglogging_1.default.elog(resobj.message);
|
|
450
|
+
dkcobj.clean();
|
|
451
|
+
return resobj;
|
|
452
|
+
}
|
|
453
|
+
// verify token
|
|
454
|
+
const vres = rawVerifyUserTokenByDummyUser(dkcobj, token_user, token_tenant, token, token_seed);
|
|
455
|
+
if (!vres.result) {
|
|
456
|
+
resobj.result = false;
|
|
457
|
+
resobj.message = 'failed to verify token(' + token + ') with seed by ' + vres.message;
|
|
458
|
+
dbglogging_1.default.elog(resobj.message);
|
|
459
|
+
dkcobj.clean();
|
|
460
|
+
return resobj;
|
|
461
|
+
}
|
|
462
|
+
// get user id
|
|
463
|
+
keys = (0, k2hr3keys_1.getK2hr3Keys)(token_user, null); // remake keys
|
|
464
|
+
const userid = dkcobj.getValue(keys.USER_ID_KEY, null, true, null); // get user id from "yrn:yahoo::::user:<user>:id"
|
|
465
|
+
if (!k2hr3apiutil_1.default.isSafeString(userid)) {
|
|
466
|
+
resobj.result = false;
|
|
467
|
+
resobj.message = 'could not get user id for user(' + token_user + ').';
|
|
468
|
+
dbglogging_1.default.elog(resobj.message);
|
|
469
|
+
dkcobj.clean();
|
|
470
|
+
return resobj;
|
|
471
|
+
}
|
|
472
|
+
dkcobj.clean();
|
|
473
|
+
// make result
|
|
474
|
+
resobj.user = token_user;
|
|
475
|
+
resobj.userid = userid;
|
|
476
|
+
resobj.tenant = token_tenant;
|
|
477
|
+
return resobj;
|
|
478
|
+
};
|
|
479
|
+
//---------------------------------------------------------
|
|
480
|
+
// Get Unscoped token by user name for dummy
|
|
481
|
+
//---------------------------------------------------------
|
|
482
|
+
//
|
|
483
|
+
// callback(error, result):
|
|
484
|
+
// result = {
|
|
485
|
+
// user: user name
|
|
486
|
+
// userid: user id
|
|
487
|
+
// scoped: always false
|
|
488
|
+
// token: token string(id)
|
|
489
|
+
// expire: expire string(UTC ISO 8601)
|
|
490
|
+
// region: region string
|
|
491
|
+
// token_seed: JSON token seed data
|
|
492
|
+
// }
|
|
493
|
+
//
|
|
494
|
+
const rawGetUserUnscopedTokenDummy = (uname, callback) => {
|
|
495
|
+
// [NOTE]
|
|
496
|
+
// user name is allowed any
|
|
497
|
+
//
|
|
498
|
+
if (!k2hr3apiutil_1.default.isSafeString(uname)) {
|
|
499
|
+
const error = new Error('parameter is wrong : uname=' + JSON.stringify(uname));
|
|
500
|
+
dbglogging_1.default.elog(error.message);
|
|
501
|
+
callback(error, null);
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
//
|
|
505
|
+
// Create unscoped user token
|
|
506
|
+
//
|
|
507
|
+
const resobj = rawCreateUserTokenByDummyUser(uname, null); // not specify expire limit now(using default).
|
|
508
|
+
if (!resobj.result) {
|
|
509
|
+
const error = new Error('could not create user token for uname(' + uname + ') or something wrong result : ' + resobj.message);
|
|
510
|
+
dbglogging_1.default.elog(error.message);
|
|
511
|
+
callback(error, null);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
// make result
|
|
515
|
+
const dummyapiep = dummyapi_ep();
|
|
516
|
+
let dummyregion = '';
|
|
517
|
+
if (k2hr3apiutil_1.default.isPlainObject(dummyapiep) && k2hr3apiutil_1.default.isString(dummyapiep.region)) {
|
|
518
|
+
dummyregion = dummyapiep.region;
|
|
519
|
+
}
|
|
520
|
+
const result = {
|
|
521
|
+
user: uname,
|
|
522
|
+
userid: k2hr3apiutil_1.default.getSafeString(resobj.userid),
|
|
523
|
+
scoped: false,
|
|
524
|
+
token: k2hr3apiutil_1.default.getSafeString(resobj.token),
|
|
525
|
+
expire: k2hr3apiutil_1.default.isSafeString(resobj.expire_at) ? resobj.expire_at : null,
|
|
526
|
+
region: dummyregion,
|
|
527
|
+
token_seed: k2hr3apiutil_1.default.getSafeString(resobj.token_seed)
|
|
528
|
+
};
|
|
529
|
+
callback(null, result);
|
|
530
|
+
};
|
|
531
|
+
//---------------------------------------------------------
|
|
532
|
+
// Get Scoped token by user name for dummy
|
|
533
|
+
//---------------------------------------------------------
|
|
534
|
+
//
|
|
535
|
+
// callback(error, result):
|
|
536
|
+
// result = {
|
|
537
|
+
// user: user name
|
|
538
|
+
// userid: user id
|
|
539
|
+
// scoped: always true
|
|
540
|
+
// token: token string
|
|
541
|
+
// expire: expire string(UTC ISO 8601)
|
|
542
|
+
// region: region string
|
|
543
|
+
// token_seed: JSON token seed data
|
|
544
|
+
// }
|
|
545
|
+
//
|
|
546
|
+
// [NOTE]
|
|
547
|
+
// The token is allowed scoped token, but it must be same tenant token.
|
|
548
|
+
//
|
|
549
|
+
const rawGetUserScopedTokenDummy = (token, tenant, callback) => {
|
|
550
|
+
if (!k2hr3apiutil_1.default.isSafeString(token) || !k2hr3apiutil_1.default.isSafeString(tenant)) {
|
|
551
|
+
const error = new Error('some parameters are wrong : token=' + JSON.stringify(token) + ', tenant=' + JSON.stringify(tenant));
|
|
552
|
+
dbglogging_1.default.elog(error.message);
|
|
553
|
+
callback(error, null);
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
// verify and get user/tenant information
|
|
557
|
+
const token_info = rawGetUserTenantInfoFromToken(token);
|
|
558
|
+
if (!token_info.result) {
|
|
559
|
+
const error = new Error('could not get any information from token(' + token + '), result : ' + token_info.message);
|
|
560
|
+
dbglogging_1.default.elog(error.message);
|
|
561
|
+
callback(error, null);
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
// check tenant name
|
|
565
|
+
if (k2hr3apiutil_1.default.isSafeString(token_info.tenant) && token_info.tenant !== tenant) {
|
|
566
|
+
const error = new Error('token(' + token + ') has scoped(' + token_info.tenant + '), but it is not as same as the request tenant(' + tenant + ').');
|
|
567
|
+
dbglogging_1.default.elog(error.message);
|
|
568
|
+
callback(error, null);
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
// create scoped token
|
|
572
|
+
const resobj = rawCreateUserTokenByDummyUser(k2hr3apiutil_1.default.isSafeString(token_info.user) ? token_info.user : null, tenant); // not specify expire limit now(using default).
|
|
573
|
+
if (!resobj.result) {
|
|
574
|
+
const error = new Error('could not create user scoped token for uname(' + token_info.user + ')/user id(' + token_info.userid + ') for tenant(' + tenant + ').');
|
|
575
|
+
dbglogging_1.default.elog(error.message);
|
|
576
|
+
callback(error, null);
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
// make result
|
|
580
|
+
const dummyapiep = dummyapi_ep();
|
|
581
|
+
let dummyregion = '';
|
|
582
|
+
if (k2hr3apiutil_1.default.isPlainObject(dummyapiep) && k2hr3apiutil_1.default.isString(dummyapiep.region)) {
|
|
583
|
+
dummyregion = dummyapiep.region;
|
|
584
|
+
}
|
|
585
|
+
const result = {
|
|
586
|
+
user: k2hr3apiutil_1.default.getSafeString(token_info.user),
|
|
587
|
+
userid: k2hr3apiutil_1.default.getSafeString(token_info.userid),
|
|
588
|
+
scoped: true,
|
|
589
|
+
token: k2hr3apiutil_1.default.getSafeString(resobj.token),
|
|
590
|
+
expire: k2hr3apiutil_1.default.isSafeString(resobj.expire_at) ? resobj.expire_at : null,
|
|
591
|
+
region: dummyregion,
|
|
592
|
+
token_seed: k2hr3apiutil_1.default.getSafeString(resobj.token_seed)
|
|
593
|
+
};
|
|
594
|
+
callback(null, result);
|
|
595
|
+
};
|
|
596
|
+
//
|
|
597
|
+
// Get tenant list from username(not used) for dummy
|
|
598
|
+
//
|
|
599
|
+
// callback(error, result):
|
|
600
|
+
// result = [
|
|
601
|
+
// {
|
|
602
|
+
// name: project(tenant) name (*2 : string)
|
|
603
|
+
// id: project(tenant) id (*2)
|
|
604
|
+
// description: project(tenant) description (*4)
|
|
605
|
+
// display: display name (*3)
|
|
606
|
+
// },
|
|
607
|
+
// ...
|
|
608
|
+
// ]
|
|
609
|
+
//
|
|
610
|
+
const rawGetUserTenantListDummyByUsername = (username, callback) => {
|
|
611
|
+
// [NOTE]
|
|
612
|
+
// username is not used in this function, but check it.
|
|
613
|
+
//
|
|
614
|
+
if (!k2hr3apiutil_1.default.isSafeString(username)) {
|
|
615
|
+
const error = new Error('parameter is wrong : username=' + JSON.stringify(username));
|
|
616
|
+
dbglogging_1.default.elog(error.message);
|
|
617
|
+
callback(error, null);
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
const _callback = callback;
|
|
621
|
+
//
|
|
622
|
+
// returns static tenant list
|
|
623
|
+
//
|
|
624
|
+
const dummyResult = [
|
|
625
|
+
{
|
|
626
|
+
name: 'tenant0',
|
|
627
|
+
id: '1000',
|
|
628
|
+
description: 'dummy tenant no.0',
|
|
629
|
+
display: 'dummy_tenant_0'
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
name: 'tenant1',
|
|
633
|
+
id: '1001',
|
|
634
|
+
description: 'dummy tenant no.1',
|
|
635
|
+
display: 'dummy_tenant_1'
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
name: 'tenant2',
|
|
639
|
+
id: '1002',
|
|
640
|
+
description: 'dummy tenant no.2',
|
|
641
|
+
display: 'dummy_tenant_2'
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
name: 'tenant3',
|
|
645
|
+
id: '1003',
|
|
646
|
+
description: 'dummy tenant no.3',
|
|
647
|
+
display: 'dummy_tenant_3'
|
|
648
|
+
},
|
|
649
|
+
{
|
|
650
|
+
name: 'tenant4',
|
|
651
|
+
id: '1004',
|
|
652
|
+
description: 'dummy tenant no.4',
|
|
653
|
+
display: 'dummy_tenant_4'
|
|
654
|
+
}
|
|
655
|
+
];
|
|
656
|
+
_callback(null, dummyResult);
|
|
657
|
+
};
|
|
658
|
+
//
|
|
659
|
+
// Get tenant list from unscoped token for dummy
|
|
660
|
+
//
|
|
661
|
+
const rawGetUserTenantListDummy = (unscopedtoken, callback) => {
|
|
662
|
+
// get user/tenant information from token
|
|
663
|
+
const token_info = rawGetUserTenantInfoFromToken(unscopedtoken);
|
|
664
|
+
if (!token_info.result) {
|
|
665
|
+
const error = new Error('could not get any information from token(' + unscopedtoken + '), result : ' + token_info.message);
|
|
666
|
+
dbglogging_1.default.elog(error.message);
|
|
667
|
+
callback(error, null);
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
return rawGetUserTenantListDummyByUsername(k2hr3apiutil_1.default.isSafeString(token_info.user) ? token_info.user : null, callback);
|
|
671
|
+
};
|
|
672
|
+
//---------------------------------------------------------
|
|
673
|
+
// Exports
|
|
674
|
+
//---------------------------------------------------------
|
|
675
|
+
exports.dummyuserapi = {
|
|
676
|
+
//
|
|
677
|
+
// passwd : not used
|
|
678
|
+
//
|
|
679
|
+
getUserUnscopedToken: (uname, passwd, callback) => {
|
|
680
|
+
rawGetUserUnscopedTokenDummy(uname, callback);
|
|
681
|
+
},
|
|
682
|
+
//
|
|
683
|
+
// update token : not implemented
|
|
684
|
+
//
|
|
685
|
+
getUserUnscopedTokenByToken: (token, callback) => {
|
|
686
|
+
const error = new Error('getUserUnscopedTokenByToken is not implemented');
|
|
687
|
+
dbglogging_1.default.elog(error.message);
|
|
688
|
+
callback(error, null);
|
|
689
|
+
},
|
|
690
|
+
//
|
|
691
|
+
// tenantid : not used
|
|
692
|
+
//
|
|
693
|
+
// [NOTE]
|
|
694
|
+
// This function is not asynchronous.
|
|
695
|
+
// And allowed unscopedtoken value is scoped token specially.
|
|
696
|
+
//
|
|
697
|
+
getUserScopedToken: rawGetUserScopedTokenDummy,
|
|
698
|
+
//
|
|
699
|
+
// Verify seed publisher type
|
|
700
|
+
//
|
|
701
|
+
verifyUserTokenPublisher: rawVerifyUserTokenPublisherByDummyUser,
|
|
702
|
+
verifyUserToken: (dkcobj_permanent, user, tenant, token, token_seed) => {
|
|
703
|
+
return rawVerifyUserTokenByDummyUser(dkcobj_permanent, user, tenant, token, token_seed);
|
|
704
|
+
},
|
|
705
|
+
//
|
|
706
|
+
// userid : not used
|
|
707
|
+
//
|
|
708
|
+
getUserTenantList: (unscopedtoken, userid, callback) => {
|
|
709
|
+
rawGetUserTenantListDummy(unscopedtoken, callback);
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
/*
|
|
713
|
+
* Local variables:
|
|
714
|
+
* tab-width: 4
|
|
715
|
+
* c-basic-offset: 4
|
|
716
|
+
* End:
|
|
717
|
+
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
718
|
+
* vim<600: noexpandtab sw=4 ts=4
|
|
719
|
+
*/
|