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.
Files changed (149) hide show
  1. package/config/k2hr3-init.sh.templ +4 -4
  2. package/dist/.gitkeep +0 -0
  3. package/dist/src/app.js +262 -0
  4. package/{bin → dist/src/bin}/run.sh +1 -1
  5. package/dist/src/bin/watcher.js +113 -0
  6. package/dist/src/bin/www.js +217 -0
  7. package/dist/src/lib/basicipcheck.js +392 -0
  8. package/dist/src/lib/cacerts.js +106 -0
  9. package/dist/src/lib/dbglogging.js +190 -0
  10. package/dist/src/lib/dummyuserapi.js +719 -0
  11. package/dist/src/lib/ipwatch.js +354 -0
  12. package/dist/src/lib/k2hr3acrutil.js +532 -0
  13. package/dist/src/lib/k2hr3apiutil.js +1444 -0
  14. package/dist/src/lib/k2hr3cliutil.js +183 -0
  15. package/dist/src/lib/k2hr3config.js +832 -0
  16. package/dist/src/lib/k2hr3cryptutil.js +258 -0
  17. package/dist/src/lib/k2hr3dkc.js +12121 -0
  18. package/dist/src/lib/k2hr3extdata.js +198 -0
  19. package/dist/src/lib/k2hr3keys.js +207 -0
  20. package/dist/src/lib/k2hr3resutil.js +111 -0
  21. package/dist/src/lib/k2hr3template.js +6546 -0
  22. package/dist/src/lib/k2hr3tokens.js +2643 -0
  23. package/dist/src/lib/k2hr3userdata.js +296 -0
  24. package/dist/src/lib/k8soidc.js +1000 -0
  25. package/dist/src/lib/openstackapiv2.js +695 -0
  26. package/dist/src/lib/openstackapiv3.js +932 -0
  27. package/dist/src/lib/openstackep.js +667 -0
  28. package/{tests/auto_common.js → dist/src/lib/types.js} +4 -38
  29. package/dist/src/routes/acr.js +704 -0
  30. package/dist/src/routes/debugVerify.js +294 -0
  31. package/dist/src/routes/extdata.js +219 -0
  32. package/dist/src/routes/list.js +264 -0
  33. package/dist/src/routes/policy.js +840 -0
  34. package/dist/src/routes/resource.js +1489 -0
  35. package/dist/src/routes/role.js +2627 -0
  36. package/dist/src/routes/service.js +908 -0
  37. package/dist/src/routes/tenant.js +1141 -0
  38. package/dist/src/routes/userTokens.js +482 -0
  39. package/dist/src/routes/userdata.js +212 -0
  40. package/dist/src/routes/version.js +103 -0
  41. package/package.json +152 -121
  42. package/ChangeLog +0 -378
  43. package/app.js +0 -292
  44. package/bin/watcher +0 -122
  45. package/bin/www +0 -180
  46. package/eslint.config.mjs +0 -68
  47. package/lib/basicipcheck.js +0 -376
  48. package/lib/cacerts.js +0 -71
  49. package/lib/dbglogging.js +0 -151
  50. package/lib/dummyuserapi.js +0 -766
  51. package/lib/ipwatch.js +0 -379
  52. package/lib/k2hr3acrutil.js +0 -516
  53. package/lib/k2hr3apiutil.js +0 -1494
  54. package/lib/k2hr3cliutil.js +0 -191
  55. package/lib/k2hr3config.js +0 -826
  56. package/lib/k2hr3cryptutil.js +0 -254
  57. package/lib/k2hr3dkc.js +0 -12632
  58. package/lib/k2hr3extdata.js +0 -198
  59. package/lib/k2hr3keys.js +0 -234
  60. package/lib/k2hr3resutil.js +0 -100
  61. package/lib/k2hr3template.js +0 -6925
  62. package/lib/k2hr3tokens.js +0 -2799
  63. package/lib/k2hr3userdata.js +0 -312
  64. package/lib/k8soidc.js +0 -1012
  65. package/lib/openstackapiv2.js +0 -764
  66. package/lib/openstackapiv3.js +0 -1032
  67. package/lib/openstackep.js +0 -553
  68. package/routes/acr.js +0 -738
  69. package/routes/debugVerify.js +0 -263
  70. package/routes/extdata.js +0 -232
  71. package/routes/list.js +0 -270
  72. package/routes/policy.js +0 -869
  73. package/routes/resource.js +0 -1441
  74. package/routes/role.js +0 -2664
  75. package/routes/service.js +0 -894
  76. package/routes/tenant.js +0 -1095
  77. package/routes/userTokens.js +0 -511
  78. package/routes/userdata.js +0 -218
  79. package/routes/version.js +0 -108
  80. package/templ/Dockerfile.templ +0 -71
  81. package/tests/auto_acr.js +0 -1101
  82. package/tests/auto_acr_spec.js +0 -79
  83. package/tests/auto_all_spec.js +0 -142
  84. package/tests/auto_control_subprocess.sh +0 -243
  85. package/tests/auto_extdata.js +0 -220
  86. package/tests/auto_extdata_spec.js +0 -79
  87. package/tests/auto_init_config_json.sh +0 -275
  88. package/tests/auto_k2hdkc_server.ini +0 -109
  89. package/tests/auto_k2hdkc_slave.ini +0 -83
  90. package/tests/auto_list.js +0 -439
  91. package/tests/auto_list_spec.js +0 -79
  92. package/tests/auto_policy.js +0 -1579
  93. package/tests/auto_policy_spec.js +0 -79
  94. package/tests/auto_resource.js +0 -10956
  95. package/tests/auto_resource_spec.js +0 -79
  96. package/tests/auto_role.js +0 -6150
  97. package/tests/auto_role_spec.js +0 -79
  98. package/tests/auto_service.js +0 -770
  99. package/tests/auto_service_spec.js +0 -79
  100. package/tests/auto_subprocesses.js +0 -114
  101. package/tests/auto_template.sh +0 -126
  102. package/tests/auto_tenant.js +0 -1100
  103. package/tests/auto_tenant_spec.js +0 -79
  104. package/tests/auto_token_util.js +0 -219
  105. package/tests/auto_userdata.js +0 -292
  106. package/tests/auto_userdata_spec.js +0 -79
  107. package/tests/auto_usertokens.js +0 -565
  108. package/tests/auto_usertokens_spec.js +0 -79
  109. package/tests/auto_version.js +0 -127
  110. package/tests/auto_version_spec.js +0 -79
  111. package/tests/auto_watcher.js +0 -157
  112. package/tests/auto_watcher_spec.js +0 -79
  113. package/tests/k2hdkc_test.data +0 -986
  114. package/tests/k2hdkc_test_load.sh +0 -255
  115. package/tests/k2hr3template_test.js +0 -187
  116. package/tests/k2hr3template_test.sh +0 -339
  117. package/tests/k2hr3template_test_async.js +0 -216
  118. package/tests/k2hr3template_test_template.result +0 -7117
  119. package/tests/k2hr3template_test_template.txt +0 -3608
  120. package/tests/k2hr3template_test_vars.js +0 -194
  121. package/tests/manual_acr_delete.js +0 -143
  122. package/tests/manual_acr_get.js +0 -297
  123. package/tests/manual_acr_postput.js +0 -215
  124. package/tests/manual_allusertenant_get.js +0 -113
  125. package/tests/manual_extdata_get.js +0 -191
  126. package/tests/manual_k2hr3keys_get.js +0 -84
  127. package/tests/manual_list_gethead.js +0 -230
  128. package/tests/manual_policy_delete.js +0 -132
  129. package/tests/manual_policy_gethead.js +0 -275
  130. package/tests/manual_policy_postput.js +0 -297
  131. package/tests/manual_resource_delete.js +0 -433
  132. package/tests/manual_resource_gethead.js +0 -423
  133. package/tests/manual_resource_postput.js +0 -487
  134. package/tests/manual_role_delete.js +0 -404
  135. package/tests/manual_role_gethead.js +0 -547
  136. package/tests/manual_role_postput.js +0 -544
  137. package/tests/manual_service_delete.js +0 -153
  138. package/tests/manual_service_gethead.js +0 -178
  139. package/tests/manual_service_postput.js +0 -348
  140. package/tests/manual_tenant_delete.js +0 -186
  141. package/tests/manual_tenant_gethead.js +0 -268
  142. package/tests/manual_tenant_postput.js +0 -293
  143. package/tests/manual_test.sh +0 -352
  144. package/tests/manual_userdata_get.js +0 -173
  145. package/tests/manual_usertoken_gethead.js +0 -136
  146. package/tests/manual_usertoken_postput.js +0 -310
  147. package/tests/manual_version_get.js +0 -127
  148. package/tests/run_local_test_k2hdkc.sh +0 -174
  149. package/tests/test.sh +0 -333
@@ -1,433 +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: Wed Jun 8 2017
17
- * REVISION:
18
- *
19
- */
20
-
21
- 'use strict';
22
-
23
- var http = require('http');
24
- var https = require('https');
25
-
26
- var cacerts = require('../lib/cacerts');
27
- var apiutil = require('../lib/k2hr3apiutil');
28
- var cliutil = require('../lib/k2hr3cliutil');
29
- var r3keys = require('../lib/k2hr3keys').getK2hr3Keys;
30
-
31
- // Debug logging objects
32
- var r3logger = require('../lib/dbglogging');
33
-
34
- //
35
- // Hostname and port from env
36
- //
37
- var hostname = apiutil.getSafeString(process.env.APIHOST);
38
- var hostport = apiutil.getSafeString(process.env.APIPORT);
39
- var is_https = apiutil.compareCaseString('yes', process.env.HTTPS_ENV);
40
-
41
- //
42
- // Request API for test
43
- //
44
- function deleteV1Resource(token_type, token, name, data_type, keynames, aliases, port, cuk, roleyrn)
45
- {
46
- var headers = {
47
- 'Content-Type': 'application/json',
48
- 'Content-Length': 0,
49
- };
50
-
51
- if(apiutil.isSafeString(token)){
52
- headers['X-Auth-Token'] = token;
53
- }
54
-
55
- // data type & key name & aliases
56
- var urlarg = '';
57
- var already_set = false;
58
- var keys = r3keys();
59
-
60
- // data type
61
- if(null === data_type){
62
- // remove all resource data, so no parameter
63
-
64
- }else if(apiutil.compareCaseString(keys.VALUE_ANYDATA_TYPE, data_type) || apiutil.compareCaseString(keys.VALUE_STRING_TYPE, data_type) || apiutil.compareCaseString(keys.VALUE_OBJECT_TYPE, data_type) || apiutil.compareCaseString(keys.VALUE_EXPIRE_TYPE, data_type)){
65
- urlarg += already_set ? '&type=' : '?type=';
66
- urlarg += data_type;
67
- already_set = true;
68
-
69
- }else if(apiutil.compareCaseString(keys.VALUE_KEYS_TYPE, data_type)){
70
- urlarg += already_set ? '&type=' : '?type=';
71
- urlarg += data_type;
72
-
73
- if(null !== keynames){
74
- if(apiutil.isEmptyArray(keynames)){
75
- console.log('Internal error in test script : Something wrong');
76
- process.exit(0);
77
- }
78
- urlarg += '&keynames=';
79
- urlarg += JSON.stringify(keynames);
80
- }
81
- already_set = true;
82
-
83
- }else if(apiutil.compareCaseString(keys.VALUE_ALIAS_TYPE, data_type)){
84
- urlarg += already_set ? '&type=' : '?type=';
85
- urlarg += data_type;
86
-
87
- if(null !== aliases){
88
- if(apiutil.isEmptyArray(aliases)){
89
- console.log('Internal error in test script : Something wrong');
90
- process.exit(0);
91
- }
92
- urlarg += '&aliases=';
93
- urlarg += JSON.stringify(aliases);
94
- }
95
- already_set = true;
96
-
97
- }else{
98
- console.log('Internal error in test script : Something wrong');
99
- process.exit(0);
100
- }
101
-
102
- // no token
103
- if(null === token_type){
104
- // no token
105
- if(apiutil.isSafeEntity(port) && !isNaN(port)){
106
- urlarg += already_set ? '&port=' : '?port=';
107
- urlarg += String(port); // port is converted to String
108
- already_set = true;
109
- }
110
- if(apiutil.isSafeEntity(cuk)){
111
- urlarg += already_set ? '&cuk=' : '?cuk=';
112
- urlarg += cuk;
113
- already_set = true;
114
- }
115
- if(apiutil.isSafeString(roleyrn)){
116
- urlarg += already_set ? '&role=' : '?role=';
117
- urlarg += roleyrn;
118
- already_set = true;
119
- }
120
- }
121
-
122
- var options = {
123
- 'host': hostname,
124
- 'port': hostport,
125
- 'path': '/v1/resource/' + name + encodeURI(urlarg),
126
- 'method': 'DELETE',
127
- 'headers': headers
128
- };
129
-
130
- r3logger.dlog('request options = ' + JSON.stringify(options));
131
- r3logger.dlog('request headers = ' + JSON.stringify(headers));
132
-
133
- var httpobj;
134
- if(is_https){
135
- if(null !== cacerts.ca){
136
- options.ca = cacerts.ca;
137
- }
138
- options.rejectUnauthorized = false; // always insecure for this manual test
139
- options.agent = new https.Agent(options);
140
- httpobj = https;
141
- }else{
142
- options.agent = new http.Agent(options);
143
- httpobj = http;
144
- }
145
-
146
- var req = httpobj.request(options, function(res)
147
- {
148
- var response = '';
149
- console.log('RESPONSE CODE = ' + res.statusCode);
150
- r3logger.dlog('response status = ' + res.statusCode);
151
- r3logger.dlog('response header = ' + JSON.stringify(res.headers));
152
- res.setEncoding('utf8');
153
-
154
- res.on('data', function (chunk)
155
- {
156
- r3logger.dlog('response chunk = ' + chunk);
157
- response += chunk;
158
- });
159
-
160
- res.on('end', function(result) // eslint-disable-line no-unused-vars
161
- {
162
- r3logger.mlog(r3logger.dump(response)); // response is object(or not)
163
- console.log('RESPONSE BODY = ' + JSON.stringify(response));
164
- process.exit(0);
165
- });
166
- });
167
-
168
- req.on('error', function(e)
169
- {
170
- r3logger.elog('problem with request: ' + e.message);
171
- });
172
- req.end();
173
- }
174
-
175
- //
176
- // Utility for inputting token for three pattern
177
- //
178
- // callback(error, token type, token string)
179
- //
180
- function rawInputToken(callback)
181
- {
182
- var _callback = callback;
183
-
184
- cliutil.getConsoleInput('Token type(USER/ROLE/NULL(empty)) : ', true, false, function(isbreak, token_type)
185
- {
186
- if(isbreak){
187
- _callback('break for inputting token type');
188
- return;
189
- }
190
- var _token_type = null;
191
- var _prefix = '';
192
- if(!apiutil.isSafeString(token_type) || apiutil.compareCaseString('NULL', token_type)){
193
- // no token
194
- _callback(null, null, null);
195
- return;
196
- }else if(apiutil.compareCaseString('USER', token_type)){
197
- // user token
198
- _token_type = 'USER';
199
- _prefix = 'U=';
200
- }else if(apiutil.compareCaseString('ROLE', token_type)){
201
- // role token
202
- _token_type = 'ROLE';
203
- _prefix = 'R=';
204
- }else{
205
- _callback('token type must be USER or ROLE or NULL(empty)');
206
- return;
207
- }
208
-
209
- cliutil.getConsoleInput(_token_type + ' Token string : ', true, false, function(isbreak, token)
210
- {
211
- if(isbreak){
212
- _callback('break for inputting token');
213
- return;
214
- }
215
- if(!apiutil.isSafeString(_token_type) || apiutil.compareCaseString('NULL', _token_type)){
216
- _callback('token must be string');
217
- return;
218
- }
219
- var _token = _prefix + token;
220
- _callback(null, _token_type, _token);
221
- });
222
- });
223
- }
224
-
225
- //
226
- // Utility for inputting token for three pattern
227
- //
228
- // callback(error, token type, token string)
229
- //
230
- function rawInputDataType(token_type, callback)
231
- {
232
- var _callback = callback;
233
-
234
- if('USER' === token_type){
235
- // user token
236
- cliutil.getConsoleInput(' Remove data type(ANY/STR/OBJ/KEYS/ALIAS/NULL(all)) : ', true, false, function(isbreak, data_type)
237
- {
238
- if(isbreak){
239
- _callback('break for inputting data type');
240
- return;
241
- }
242
- var keys = r3keys();
243
-
244
- if(null === data_type || apiutil.compareCaseString('NULL', data_type)){
245
- _callback(null, null, null, null);
246
-
247
- }else if(apiutil.compareCaseString('ANY', data_type)){
248
- _callback(null, keys.VALUE_ANYDATA_TYPE, null, null);
249
-
250
- }else if(apiutil.compareCaseString('STR', data_type)){
251
- _callback(null, keys.VALUE_STRING_TYPE, null, null);
252
-
253
- }else if(apiutil.compareCaseString('OBJ', data_type)){
254
- _callback(null, keys.VALUE_OBJECT_TYPE, null, null);
255
-
256
- }else if(apiutil.compareCaseString('KEYS', data_type)){
257
- cliutil.getConsoleInput(' Key Name(in keys) : ', true, false, function(isbreak, keyname)
258
- {
259
- if(isbreak){
260
- _callback('break for inputting key name');
261
- return;
262
- }
263
- var _keyname;
264
- if(null === keyname || '' === apiutil.getSafeString(keyname) || apiutil.compareCaseString('NULL', keyname)){
265
- _keyname = null;
266
- }else if(apiutil.isSafeString(keyname)){
267
- _keyname = keyname.split(',');
268
- }else{
269
- _callback('something wrong value for keyname');
270
- return;
271
- }
272
- _callback(null, keys.VALUE_KEYS_TYPE, _keyname, null);
273
- });
274
-
275
- }else if(apiutil.compareCaseString('ALIAS', data_type)){
276
- cliutil.getConsoleInput(' Alias Names(null(all), one yrn, or multi yrn with \',\') : ', true, false, function(isbreak, aliases)
277
- {
278
- if(isbreak){
279
- _callback('break for inputting aliases');
280
- return;
281
- }
282
- var _aliases;
283
- if(null === aliases || '' === apiutil.getSafeString(aliases) || apiutil.compareCaseString('NULL', aliases)){
284
- _aliases = null;
285
- }else if(apiutil.isSafeString(aliases)){
286
- _aliases = aliases.split(',');
287
- }else{
288
- _callback('something wrong value for aliases');
289
- return;
290
- }
291
- _callback(null, keys.VALUE_ALIAS_TYPE, null, _aliases);
292
- });
293
-
294
- }else{
295
- _callback('inputting wrong data type: ' + data_type);
296
- return;
297
- }
298
- });
299
-
300
- }else{
301
- // role token/no token
302
- cliutil.getConsoleInput(' Remove data type(ANY/STR/OBJ/KEYS) : ', true, false, function(isbreak, data_type)
303
- {
304
- if(isbreak){
305
- _callback('break for inputting data type');
306
- return;
307
- }
308
- var keys = r3keys();
309
-
310
- if(apiutil.compareCaseString('ANY', data_type)){
311
- _callback(null, keys.VALUE_ANYDATA_TYPE, null, null);
312
-
313
- }else if(apiutil.compareCaseString('STR', data_type)){
314
- _callback(null, keys.VALUE_STRING_TYPE, null, null);
315
-
316
- }else if(apiutil.compareCaseString('OBJ', data_type)){
317
- _callback(null, keys.VALUE_OBJECT_TYPE, null, null);
318
-
319
- }else if(apiutil.compareCaseString('KEYS', data_type)){
320
- cliutil.getConsoleInput(' Key Name(in keys) : ', true, false, function(isbreak, keyname)
321
- {
322
- if(isbreak){
323
- _callback('break for inputting key name');
324
- return;
325
- }
326
- var _keyname;
327
- if(null === keyname || '' === apiutil.getSafeString(keyname) || apiutil.compareCaseString('NULL', keyname)){
328
- _keyname = null;
329
- }else if(apiutil.isSafeString(keyname)){
330
- _keyname = keyname.split(',');
331
- }else{
332
- _callback('something wrong value for keyname');
333
- return;
334
- }
335
- _callback(null, keys.VALUE_KEYS_TYPE, _keyname, null);
336
- });
337
-
338
- }else{
339
- _callback('inputting wrong data type: ' + data_type);
340
- return;
341
- }
342
- });
343
- }
344
- }
345
-
346
- //
347
- // run
348
- //
349
- rawInputToken(function(error, token_type, token)
350
- {
351
- if(null !== error){
352
- console.log(error);
353
- process.exit(0);
354
- }
355
- var _token_type = token_type;
356
- var _token = token;
357
-
358
- cliutil.getConsoleInput('Resource name(path) : ', true, false, function(isbreak, name)
359
- {
360
- if(isbreak){
361
- process.exit(0);
362
- }
363
- var _name = name;
364
-
365
- rawInputDataType(_token_type, function(error, data_type, keynames, aliases)
366
- {
367
- if(null !== error){
368
- console.log(error);
369
- process.exit(0);
370
- }
371
- var _data_type = data_type;
372
- var _keynames = keynames;
373
- var _aliases = aliases;
374
-
375
- if('USER' === _token_type || 'ROLE' === _token_type){
376
- // user token / role token
377
- // run
378
- deleteV1Resource(_token_type, _token, _name, _data_type, _keynames, _aliases);
379
-
380
- }else{
381
- // no token
382
- cliutil.getConsoleInput(' Port number(0=any(empty)) : ', true, false, function(isbreak, port)
383
- {
384
- if(isbreak){
385
- process.exit(0);
386
- }
387
- var _port;
388
- if(null === port || !apiutil.isSafeString(port)){
389
- _port = 0;
390
- }else if(!isNaN(port)){
391
- _port = parseInt(port);
392
- }else{
393
- process.exit(0);
394
- }
395
-
396
- cliutil.getConsoleInput(' CUK(allow empty) : ', true, false, function(isbreak, cuk)
397
- {
398
- if(isbreak){
399
- process.exit(0);
400
- }
401
- var _cuk;
402
- if(apiutil.isSafeString(cuk) && apiutil.isSafeString(cuk.trim())){
403
- _cuk = cuk.trim();
404
- }
405
-
406
- cliutil.getConsoleInput(' Role full yrn path : ', true, false, function(isbreak, roleyrn)
407
- {
408
- if(isbreak){
409
- process.exit(0);
410
- }
411
- if(!apiutil.isSafeString(roleyrn)){
412
- process.exit(0);
413
- }
414
- var _roleyrn = roleyrn;
415
-
416
- // run
417
- deleteV1Resource(_token_type, _token, _name, _data_type, _keynames, _aliases, _port, _cuk, _roleyrn);
418
- });
419
- });
420
- });
421
- }
422
- });
423
- });
424
- });
425
-
426
- /*
427
- * Local variables:
428
- * tab-width: 4
429
- * c-basic-offset: 4
430
- * End:
431
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
432
- * vim<600: noexpandtab sw=4 ts=4
433
- */