k2hr3-api 1.0.42 → 2.0.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.
- package/config/k2hr3-init.sh.templ +2 -2
- 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
package/routes/list.js
DELETED
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* K2HR3 REST API
|
|
3
|
-
*
|
|
4
|
-
* Copyright 2017 Yahoo Japan Corporation.
|
|
5
|
-
*
|
|
6
|
-
* K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
|
|
7
|
-
* common management information for the cloud.
|
|
8
|
-
* K2HR3 can dynamically manage information as "who", "what", "operate".
|
|
9
|
-
* These are stored as roles, resources, policies in K2hdkc, and the
|
|
10
|
-
* client system can dynamically read and modify these information.
|
|
11
|
-
*
|
|
12
|
-
* For the full copyright and license information, please view
|
|
13
|
-
* the license file that was distributed with this source code.
|
|
14
|
-
*
|
|
15
|
-
* AUTHOR: Takeshi Nakatani
|
|
16
|
-
* CREATE: Mon Sep 11 2017
|
|
17
|
-
* REVISION:
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
'use strict';
|
|
22
|
-
|
|
23
|
-
var express = require('express');
|
|
24
|
-
var router = express.Router();
|
|
25
|
-
|
|
26
|
-
var r3token = require('../lib/k2hr3tokens');
|
|
27
|
-
var apiutil = require('../lib/k2hr3apiutil');
|
|
28
|
-
var resutil = require('../lib/k2hr3resutil');
|
|
29
|
-
var k2hr3 = require('../lib/k2hr3dkc');
|
|
30
|
-
var r3keys = require('../lib/k2hr3keys').getK2hr3Keys;
|
|
31
|
-
|
|
32
|
-
// Debug logging objects
|
|
33
|
-
var r3logger = require('../lib/dbglogging');
|
|
34
|
-
|
|
35
|
-
//
|
|
36
|
-
// Common Utility function
|
|
37
|
-
//
|
|
38
|
-
function rawGetChildrenList(req, expand)
|
|
39
|
-
{
|
|
40
|
-
var result;
|
|
41
|
-
if( !apiutil.isSafeEntity(req) ||
|
|
42
|
-
!apiutil.isSafeEntity(req.baseUrl) )
|
|
43
|
-
{
|
|
44
|
-
result = {
|
|
45
|
-
result: false,
|
|
46
|
-
message: 'GET/HEAD request or url is wrong',
|
|
47
|
-
status: 400 // 400: Bad Request
|
|
48
|
-
};
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
//------------------------------
|
|
53
|
-
// check token
|
|
54
|
-
//------------------------------
|
|
55
|
-
var token_result = r3token.checkToken(req, true, true); // scoped, user token
|
|
56
|
-
if(!token_result.result){
|
|
57
|
-
return token_result;
|
|
58
|
-
}
|
|
59
|
-
var token_info = token_result.token_info;
|
|
60
|
-
var keys = r3keys(token_info.user, token_info.tenant);
|
|
61
|
-
|
|
62
|
-
//------------------------------
|
|
63
|
-
// parse uri
|
|
64
|
-
//------------------------------
|
|
65
|
-
var requestptn = new RegExp('^/v1/list/(.*)'); // regex = /^\/v1\/list\/(.*)/
|
|
66
|
-
var reqmatchs = decodeURI(req.baseUrl).match(requestptn);
|
|
67
|
-
if(apiutil.isEmptyArray(reqmatchs) || reqmatchs.length < 2 || '' === apiutil.getSafeString(reqmatchs[1])){
|
|
68
|
-
result = {
|
|
69
|
-
result: false,
|
|
70
|
-
message: 'GET/HEAD request url does not have list type{role, resource, policy}',
|
|
71
|
-
status: 400 // 400: Bad Request
|
|
72
|
-
};
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// parse type & path
|
|
77
|
-
var _pos = reqmatchs[1].indexOf('/');
|
|
78
|
-
var _firstpath = null;
|
|
79
|
-
var _secondpath = null;
|
|
80
|
-
var _type = null;
|
|
81
|
-
var _path = null;
|
|
82
|
-
var _service = null;
|
|
83
|
-
|
|
84
|
-
if(-1 !== _pos){
|
|
85
|
-
_firstpath = reqmatchs[1].substr(0, _pos);
|
|
86
|
-
_secondpath = reqmatchs[1].substr(_pos + 1);
|
|
87
|
-
}else{
|
|
88
|
-
_firstpath = reqmatchs[1];
|
|
89
|
-
}
|
|
90
|
-
// check
|
|
91
|
-
if(apiutil.compareCaseString(keys.TYPE_ROLE, _firstpath)){
|
|
92
|
-
_type = keys.TYPE_ROLE;
|
|
93
|
-
_path = _secondpath;
|
|
94
|
-
}else if(apiutil.compareCaseString(keys.TYPE_RESOURCE, _firstpath)){
|
|
95
|
-
_type = keys.TYPE_RESOURCE;
|
|
96
|
-
_path = _secondpath;
|
|
97
|
-
}else if(apiutil.compareCaseString(keys.TYPE_POLICY, _firstpath)){
|
|
98
|
-
_type = keys.TYPE_POLICY;
|
|
99
|
-
_path = _secondpath; // should be empty
|
|
100
|
-
}else if(apiutil.compareCaseString(keys.TYPE_SERVICE, _firstpath)){
|
|
101
|
-
_type = keys.TYPE_SERVICE;
|
|
102
|
-
|
|
103
|
-
}else if(apiutil.isSafeString(_secondpath)){
|
|
104
|
-
// try to check firstpath is service name
|
|
105
|
-
var _thirdpath = null;
|
|
106
|
-
_pos = _secondpath.indexOf('/');
|
|
107
|
-
if(-1 !== _pos){
|
|
108
|
-
_thirdpath = _secondpath.substr(_pos + 1);
|
|
109
|
-
_secondpath = _secondpath.substr(0, _pos);
|
|
110
|
-
}
|
|
111
|
-
_service = _firstpath.toLowerCase();
|
|
112
|
-
|
|
113
|
-
if(apiutil.compareCaseString(keys.TYPE_ROLE, _secondpath)){
|
|
114
|
-
_type = keys.TYPE_ROLE;
|
|
115
|
-
_path = _thirdpath;
|
|
116
|
-
}else if(apiutil.compareCaseString(keys.TYPE_RESOURCE, _secondpath)){
|
|
117
|
-
_type = keys.TYPE_RESOURCE;
|
|
118
|
-
_path = _thirdpath;
|
|
119
|
-
}else if(apiutil.compareCaseString(keys.TYPE_POLICY, _secondpath)){
|
|
120
|
-
_type = keys.TYPE_POLICY;
|
|
121
|
-
_path = _thirdpath; // should be empty
|
|
122
|
-
}else{
|
|
123
|
-
result = {
|
|
124
|
-
result: false,
|
|
125
|
-
message: 'GET/HEAD request url has wrong list type, it must be "service/role" or "service/resource" or "service/policy"',
|
|
126
|
-
status: 400 // 400: Bad Request
|
|
127
|
-
};
|
|
128
|
-
return result;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
}else{
|
|
132
|
-
result = {
|
|
133
|
-
result: false,
|
|
134
|
-
message: 'GET/HEAD request url has wrong list type, it must be "role" or "resource" or "policy" or "service"',
|
|
135
|
-
status: 400 // 400: Bad Request
|
|
136
|
-
};
|
|
137
|
-
return result;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
//------------------------------
|
|
141
|
-
// expand type(only user token type)
|
|
142
|
-
//------------------------------
|
|
143
|
-
var is_expand = false;
|
|
144
|
-
if(undefined === expand && 'boolean' === typeof expand){
|
|
145
|
-
// Case for HEAD
|
|
146
|
-
is_expand = expand;
|
|
147
|
-
|
|
148
|
-
}else if(apiutil.isSafeEntity(req.query) && apiutil.isSafeString(req.query.expand)){
|
|
149
|
-
if(apiutil.compareCaseString(keys.VALUE_TRUE, req.query.expand)){
|
|
150
|
-
is_expand = true;
|
|
151
|
-
}else if(apiutil.compareCaseString(keys.VALUE_FALSE, req.query.expand)){
|
|
152
|
-
is_expand = false;
|
|
153
|
-
}else{
|
|
154
|
-
result = {
|
|
155
|
-
result: false,
|
|
156
|
-
message: 'GET/HEAD expand url argument parameter(' + JSON.stringify(req.query.expand) + ') is wrong, it must be ' + keys.VALUE_TRUE + ' or ' + keys.VALUE_FALSE + '.',
|
|
157
|
-
status: 400 // 400: Bad Request
|
|
158
|
-
};
|
|
159
|
-
return result;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
//------------------------------
|
|
164
|
-
// get children list
|
|
165
|
-
//------------------------------
|
|
166
|
-
result = k2hr3.getChildrenList(token_info.tenant, _service, _type, _path, is_expand);
|
|
167
|
-
if(!apiutil.isSafeEntity(result) || !apiutil.isSafeEntity(result.result) || false === result.result){
|
|
168
|
-
if(!apiutil.isSafeEntity(result)){
|
|
169
|
-
result = {
|
|
170
|
-
result: false,
|
|
171
|
-
message: 'Could not get response from getChildrenList',
|
|
172
|
-
status: 400 // 400: Bad Request
|
|
173
|
-
};
|
|
174
|
-
}else{
|
|
175
|
-
if(!apiutil.isSafeEntity(result.result)){
|
|
176
|
-
result.result = false;
|
|
177
|
-
}
|
|
178
|
-
if(!apiutil.isSafeEntity(result.message)){
|
|
179
|
-
result.message = 'Could not get error message in response from getChildrenList';
|
|
180
|
-
}
|
|
181
|
-
result.status = 400; // 400: Bad Request(if children are not exists, but we should get empty object.)
|
|
182
|
-
}
|
|
183
|
-
return result;
|
|
184
|
-
}
|
|
185
|
-
return result;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
//
|
|
189
|
-
// Mountpath : '/v1/list/{role, resource, policy, service}{/...}'
|
|
190
|
-
// : '/v1/list/<service>/{role, resource, policy}{/...}'
|
|
191
|
-
//
|
|
192
|
-
// GET '/v1/list/.../{path}' : get list on version 1
|
|
193
|
-
// HEADER : X-Auth-Token = User token
|
|
194
|
-
// URL arguments : expand = "true"(default) or "false"
|
|
195
|
-
//
|
|
196
|
-
// response body : result => true/false
|
|
197
|
-
// message => error message
|
|
198
|
-
// object => nested objects...
|
|
199
|
-
//
|
|
200
|
-
router.get('/', function(req, res, next)
|
|
201
|
-
{
|
|
202
|
-
r3logger.dlog('CALL:', req.method, req.url);
|
|
203
|
-
|
|
204
|
-
if('GET' !== req.method){
|
|
205
|
-
// HEAD request comes here, so it should be routed to head function.
|
|
206
|
-
next();
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
res.type('application/json; charset=utf-8');
|
|
210
|
-
|
|
211
|
-
//
|
|
212
|
-
// get children list
|
|
213
|
-
//
|
|
214
|
-
var result = rawGetChildrenList(req);
|
|
215
|
-
if(!result.result){
|
|
216
|
-
r3logger.elog(result.message);
|
|
217
|
-
var _status = result.status;
|
|
218
|
-
delete result.status;
|
|
219
|
-
resutil.errResponse(req, res, _status, result);
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
r3logger.dlog('succeed : ' + result.message);
|
|
223
|
-
res.status(200); // 200: OK
|
|
224
|
-
res.send(JSON.stringify(result));
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
//
|
|
228
|
-
// Mountpath : '/v1/list/{role, resource, policy, service}{/...}'
|
|
229
|
-
// : '/v1/list/<service>/{role, resource, policy}{/...}'
|
|
230
|
-
//
|
|
231
|
-
// HEAD '/v1/list/.../{path}' : get list on version 1
|
|
232
|
-
// HEADER : X-Auth-Token = User token
|
|
233
|
-
// URL arguments : expand = "true"(default) or "false"
|
|
234
|
-
//
|
|
235
|
-
router.head('/', function(req, res, next)
|
|
236
|
-
{
|
|
237
|
-
r3logger.dlog('CALL:', req.method, req.url);
|
|
238
|
-
|
|
239
|
-
if('HEAD' !== req.method){
|
|
240
|
-
next();
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
res.type('application/json; charset=utf-8');
|
|
244
|
-
|
|
245
|
-
//
|
|
246
|
-
// get children list
|
|
247
|
-
//
|
|
248
|
-
var result = rawGetChildrenList(req, false); // Force set expand as false
|
|
249
|
-
if(!result.result){
|
|
250
|
-
r3logger.elog(result.message);
|
|
251
|
-
var _status = result.status;
|
|
252
|
-
delete result.status;
|
|
253
|
-
resutil.errResponse(req, res, _status);
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
r3logger.dlog('succeed : ' + result.message);
|
|
257
|
-
res.status(204); // 204: No Content
|
|
258
|
-
res.send(JSON.stringify(result));
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
module.exports = router;
|
|
262
|
-
|
|
263
|
-
/*
|
|
264
|
-
* Local variables:
|
|
265
|
-
* tab-width: 4
|
|
266
|
-
* c-basic-offset: 4
|
|
267
|
-
* End:
|
|
268
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
269
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
270
|
-
*/
|