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,178 +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 Nor 6 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
-
30
- // Debug logging objects
31
- var r3logger = require('../lib/dbglogging');
32
-
33
- //
34
- // Hostname and port from env
35
- //
36
- var hostname = apiutil.getSafeString(process.env.APIHOST);
37
- var hostport = apiutil.getSafeString(process.env.APIPORT);
38
- var is_https = apiutil.compareCaseString('yes', process.env.HTTPS_ENV);
39
-
40
- //
41
- // Request API for test
42
- //
43
- function rawGetHeadV1Service(method, token, service, tenant)
44
- {
45
- var basepath = '/v1/service/' + service;
46
- if(apiutil.compareCaseString('HEAD', method) && apiutil.isSafeString(tenant)){
47
- basepath += '?tenant=' + encodeURI(tenant);
48
- }
49
-
50
- var headers = {
51
- 'Content-Type': 'application/json',
52
- 'X-Auth-Token': 'U=' + token
53
- };
54
- var options = {
55
- 'host': hostname,
56
- 'port': hostport,
57
- 'path': basepath,
58
- 'method': method,
59
- 'headers': headers
60
- };
61
-
62
- r3logger.dlog('request options = ' + JSON.stringify(options));
63
- r3logger.dlog('request headers = ' + JSON.stringify(headers));
64
-
65
- var httpobj;
66
- if(is_https){
67
- if(null !== cacerts.ca){
68
- options.ca = cacerts.ca;
69
- }
70
- options.rejectUnauthorized = false; // always insecure for this manual test
71
- options.agent = new https.Agent(options);
72
- httpobj = https;
73
- }else{
74
- options.agent = new http.Agent(options);
75
- httpobj = http;
76
- }
77
-
78
- var req = httpobj.request(options, function(res)
79
- {
80
- var response = '';
81
- console.log('RESPONSE CODE = ' + res.statusCode);
82
- r3logger.dlog('response status = ' + res.statusCode);
83
- r3logger.dlog('response header = ' + JSON.stringify(res.headers));
84
- res.setEncoding('utf8');
85
-
86
- res.on('data', function (chunk)
87
- {
88
- r3logger.dlog('response chunk = ' + chunk);
89
- response += chunk;
90
- });
91
-
92
- res.on('end', function(result) // eslint-disable-line no-unused-vars
93
- {
94
- r3logger.mlog(r3logger.dump(response)); // response is object(or not)
95
- console.log('RESPONSE BODY = ' + JSON.stringify(response));
96
- process.exit(0);
97
- });
98
- });
99
-
100
- req.on('error', function(e)
101
- {
102
- r3logger.elog('problem with request: ' + e.message);
103
- });
104
-
105
- req.end();
106
- }
107
-
108
- //
109
- // run
110
- //
111
- cliutil.getConsoleInput('Method(GET/HEAD) : ', true, false, function(isbreak, method)
112
- {
113
- if(isbreak){
114
- process.exit(0);
115
- }
116
-
117
- var _method;
118
- if(apiutil.compareCaseString('get', method)){
119
- _method = 'GET';
120
- }else if(apiutil.compareCaseString('head', method)){
121
- _method = 'HEAD';
122
- }else{
123
- console.log('method must be GET or HEAD : ' + method);
124
- process.exit(0);
125
- }
126
-
127
- cliutil.getConsoleInput('Scoped user token for service owner tenant : ', true, false, function(isbreak, token)
128
- {
129
- if(isbreak){
130
- process.exit(0);
131
- }
132
- var _token = token;
133
-
134
- cliutil.getConsoleInput('Service name : ', true, false, function(isbreak, service)
135
- {
136
- if(isbreak){
137
- process.exit(0);
138
- }
139
- if(!apiutil.isSafeString(service)){
140
- console.log('must be service name.');
141
- process.exit(0);
142
- }
143
- var _service = service;
144
-
145
- if(apiutil.compareCaseString('GET', _method)){
146
- //
147
- // run GET
148
- //
149
- rawGetHeadV1Service(_method, _token, _service, null);
150
-
151
- }else{
152
- cliutil.getConsoleInput('Check tenant name(empty(null)->check service exist) : ', true, false, function(isbreak, tenant)
153
- {
154
- if(isbreak){
155
- process.exit(0);
156
- }
157
- var _tenant = tenant;
158
- if(!apiutil.isSafeString(tenant)){
159
- _tenant = null;
160
- }
161
- //
162
- // run HEAD
163
- //
164
- rawGetHeadV1Service(_method, _token, _service, _tenant);
165
- });
166
- }
167
- });
168
- });
169
- });
170
-
171
- /*
172
- * Local variables:
173
- * tab-width: 4
174
- * c-basic-offset: 4
175
- * End:
176
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
177
- * vim<600: noexpandtab sw=4 ts=4
178
- */
@@ -1,348 +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 Nor 6 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
-
30
- // Debug logging objects
31
- var r3logger = require('../lib/dbglogging');
32
-
33
- //
34
- // Hostname and port from env
35
- //
36
- var hostname = apiutil.getSafeString(process.env.APIHOST);
37
- var hostport = apiutil.getSafeString(process.env.APIPORT);
38
- var is_https = apiutil.compareCaseString('yes', process.env.HTTPS_ENV);
39
-
40
- //
41
- // Request API for test
42
- //
43
- function rawPutPostV1Service(method, token, service, is_create, verify, is_verify_url, tenant)
44
- {
45
- var basepath = '/v1/service'; // Create service = '/v1/service'
46
- if(!is_create){
47
- basepath += '/' + service; // Update = '/v1/service/<service name>'
48
- }
49
-
50
- var strbody = null;
51
- if(apiutil.compareCaseString('POST', method)){
52
- // post
53
- var body = {};
54
- if(is_create){
55
- // create service
56
- body.name = service;
57
- if(is_verify_url){
58
- if(apiutil.isSafeString(verify)){
59
- body.verify = verify;
60
- }
61
- }else{
62
- if(!apiutil.isSafeString(verify)){
63
- verify = null;
64
- }
65
- body.verify = JSON.stringify(verify);
66
- }
67
- }else{
68
- // add tenant or update verify url
69
- if(apiutil.isSafeString(tenant)){
70
- body.tenant = tenant;
71
- }else{
72
- if(is_verify_url){
73
- if(apiutil.isSafeString(verify)){
74
- body.verify = verify;
75
- }
76
- }else{
77
- if(!apiutil.isSafeString(verify)){
78
- verify = null;
79
- }
80
- body.verify = JSON.stringify(verify);
81
- }
82
- }
83
- }
84
- strbody = JSON.stringify(body);
85
- }else{
86
- // put
87
- if(is_create){
88
- // create service
89
- basepath += '?name=' + encodeURI(service);
90
- if(is_verify_url){
91
- if(apiutil.isSafeString(verify)){
92
- basepath += '&verify=' + encodeURI(verify);
93
- }
94
- }else{
95
- if(!apiutil.isSafeString(verify)){
96
- verify = null;
97
- }
98
- basepath += '&verify=' + encodeURI(JSON.stringify(verify));
99
- }
100
- }else{
101
- // add tenant or update verify url
102
- if(apiutil.isSafeString(tenant)){
103
- basepath += '?tenant=' + encodeURI(tenant);
104
- }else{
105
- if(is_verify_url){
106
- if(apiutil.isSafeString(verify)){
107
- basepath += '?verify=' + encodeURI(verify);
108
- }
109
- }else{
110
- if(!apiutil.isSafeString(verify)){
111
- verify = null;
112
- }
113
- basepath += '?verify=' + encodeURI(JSON.stringify(verify));
114
- }
115
- }
116
- }
117
- }
118
-
119
- var headers = {
120
- 'Content-Type': 'application/json',
121
- 'X-Auth-Token': 'U=' + token
122
- };
123
- var options = {
124
- 'host': hostname,
125
- 'port': hostport,
126
- 'path': basepath,
127
- 'method': method
128
- };
129
-
130
- if(apiutil.compareCaseString('POST', method)){
131
- headers['Content-Length'] = strbody.length;
132
- }
133
- options.headers = headers;
134
-
135
- r3logger.dlog('request options = ' + JSON.stringify(options));
136
- r3logger.dlog('request headers = ' + JSON.stringify(headers));
137
- r3logger.dlog('request body = ' + apiutil.getSafeString(strbody));
138
-
139
- var httpobj;
140
- if(is_https){
141
- if(null !== cacerts.ca){
142
- options.ca = cacerts.ca;
143
- }
144
- options.rejectUnauthorized = false; // always insecure for this manual test
145
- options.agent = new https.Agent(options);
146
- httpobj = https;
147
- }else{
148
- options.agent = new http.Agent(options);
149
- httpobj = http;
150
- }
151
-
152
- var req = httpobj.request(options, function(res)
153
- {
154
- var response = '';
155
- console.log('RESPONSE CODE = ' + res.statusCode);
156
- r3logger.dlog('response status = ' + res.statusCode);
157
- r3logger.dlog('response header = ' + JSON.stringify(res.headers));
158
- res.setEncoding('utf8');
159
-
160
- res.on('data', function (chunk)
161
- {
162
- r3logger.dlog('response chunk = ' + chunk);
163
- response += chunk;
164
- });
165
-
166
- res.on('end', function(result) // eslint-disable-line no-unused-vars
167
- {
168
- r3logger.mlog(r3logger.dump(response)); // response is object(or not)
169
- console.log('RESPONSE BODY = ' + JSON.stringify(response));
170
- process.exit(0);
171
- });
172
- });
173
-
174
- req.on('error', function(e)
175
- {
176
- r3logger.elog('problem with request: ' + e.message);
177
- });
178
-
179
- // write data to request body
180
- if(null !== strbody){
181
- req.write(strbody);
182
- }
183
- req.end();
184
- }
185
-
186
- //
187
- // run
188
- //
189
- cliutil.getConsoleInput('Method(POST/PUT) : ', true, false, function(isbreak, method)
190
- {
191
- if(isbreak){
192
- process.exit(0);
193
- }
194
-
195
- var _method;
196
- if(apiutil.compareCaseString('post', method)){
197
- _method = 'POST';
198
- }else if(apiutil.compareCaseString('put', method)){
199
- _method = 'PUT';
200
- }else{
201
- console.log('method must be POST or PUT : ' + method);
202
- process.exit(0);
203
- }
204
-
205
- cliutil.getConsoleInput('Scoped user token for service owner tenant : ', true, false, function(isbreak, token)
206
- {
207
- if(isbreak){
208
- process.exit(0);
209
- }
210
- var _token = token;
211
-
212
- cliutil.getConsoleInput('Create service( yes(y)-default / no(n) ) : ', true, false, function(isbreak, is_create_yes)
213
- {
214
- if(isbreak){
215
- process.exit(0);
216
- }
217
- var _is_create = true;
218
- if(apiutil.compareCaseString('no', is_create_yes) || apiutil.compareCaseString('n', is_create_yes)){
219
- _is_create = false;
220
- }
221
-
222
- if(_is_create){
223
- // type: create service
224
- cliutil.getConsoleInput('Create service name : ', true, false, function(isbreak, service)
225
- {
226
- if(isbreak){
227
- process.exit(0);
228
- }
229
- if(!apiutil.isSafeString(service)){
230
- console.log('service must be service name.');
231
- process.exit(0);
232
- }
233
- var _service = service;
234
-
235
- cliutil.getConsoleInput('Verify URL(allow empty) : ', true, false, function(isbreak, verify)
236
- {
237
- if(isbreak){
238
- process.exit(0);
239
- }
240
- var _verify = null;
241
- var _is_verify_url = false;
242
- if(!apiutil.isSafeString(verify)){
243
- _verify = null;
244
- _is_verify_url = false;
245
- }else if(apiutil.isSafeUrl(verify)){
246
- _verify = verify;
247
- _is_verify_url = true;
248
- }else if(apiutil.checkSimpleJSON(verify)){
249
- _verify = JSON.parse(verify);
250
- _is_verify_url = false;
251
- }else{
252
- _verify = verify;
253
- _is_verify_url = false;
254
- }
255
-
256
- //
257
- // run (create service)
258
- //
259
- rawPutPostV1Service(_method, _token, _service, _is_create, _verify, _is_verify_url, null);
260
- });
261
- });
262
-
263
- }else{
264
- // type: update service
265
- cliutil.getConsoleInput('Update service name : ', true, false, function(isbreak, service)
266
- {
267
- if(isbreak){
268
- process.exit(0);
269
- }
270
- if(!apiutil.isSafeString(service)){
271
- console.log('service must be service name.');
272
- process.exit(0);
273
- }
274
- var _service = service;
275
-
276
- cliutil.getConsoleInput('Add tenant(TENANT) or Update verify URL(VERIFY) : ', true, false, function(isbreak, update_type)
277
- {
278
- if(isbreak){
279
- process.exit(0);
280
- }
281
- if(apiutil.compareCaseString('tenant', update_type)){
282
- // add tenant
283
- cliutil.getConsoleInput('Add tenant name : ', true, false, function(isbreak, tenant)
284
- {
285
- if(isbreak){
286
- process.exit(0);
287
- }
288
- if(!apiutil.isSafeString(tenant)){
289
- console.log('method must be tenant name.');
290
- process.exit(0);
291
- }
292
- var _tenant = tenant;
293
-
294
- //
295
- // run (add tenant)
296
- //
297
- rawPutPostV1Service(_method, _token, _service, _is_create, null, false, _tenant);
298
- });
299
-
300
- }else if(apiutil.compareCaseString('verify', update_type)){
301
- // update verify
302
- cliutil.getConsoleInput('Update verify url(allow null, object, url) : ', true, false, function(isbreak, verify)
303
- {
304
- if(isbreak){
305
- process.exit(0);
306
- }
307
- var _verify = null;
308
- var _is_verify_url = false;
309
- if(!apiutil.isSafeString(verify)){
310
- _verify = null;
311
- _is_verify_url = false;
312
- }else if(apiutil.isSafeUrl(verify)){
313
- _verify = verify;
314
- _is_verify_url = true;
315
- }else if(apiutil.checkSimpleJSON(verify)){
316
- _verify = JSON.parse(verify);
317
- _is_verify_url = false;
318
- }else{
319
- _verify = verify;
320
- _is_verify_url = false;
321
- }
322
-
323
- //
324
- // run (update verify)
325
- //
326
- rawPutPostV1Service(_method, _token, _service, _is_create, _verify, _is_verify_url, null);
327
- });
328
-
329
- }else{
330
- console.log('Update must be TENANT or VERIFY.');
331
- process.exit(0);
332
- }
333
-
334
- });
335
- });
336
- }
337
- });
338
- });
339
- });
340
-
341
- /*
342
- * Local variables:
343
- * tab-width: 4
344
- * c-basic-offset: 4
345
- * End:
346
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
347
- * vim<600: noexpandtab sw=4 ts=4
348
- */
@@ -1,186 +0,0 @@
1
- /*
2
- * K2HR3 REST API
3
- *
4
- * Copyright 2023 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 Jun 3 2023
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
-
30
- // Debug logging objects
31
- var r3logger = require('../lib/dbglogging');
32
-
33
- //
34
- // Hostname and port from env
35
- //
36
- var hostname = apiutil.getSafeString(process.env.APIHOST);
37
- var hostport = apiutil.getSafeString(process.env.APIPORT);
38
- var is_https = apiutil.compareCaseString('yes', process.env.HTTPS_ENV);
39
-
40
- //
41
- // Request API for test
42
- //
43
- function deleteV1Tenant(token, name, id, remove_all)
44
- {
45
- var headers = {
46
- 'Content-Type': 'application/json',
47
- 'Content-Length': 0,
48
- 'X-Auth-Token': token
49
- };
50
-
51
- var options;
52
- if(remove_all){
53
- options = {
54
- 'host': hostname,
55
- 'port': hostport,
56
- 'path': '/v1/tenant' + encodeURI('?tenant=' + name) + '&' + encodeURI('id=' + id),
57
- 'method': 'DELETE',
58
- 'headers': headers
59
- };
60
- }else{
61
- options = {
62
- 'host': hostname,
63
- 'port': hostport,
64
- 'path': '/v1/tenant/' + name + encodeURI('?id=' + id),
65
- 'method': 'DELETE',
66
- 'headers': headers
67
- };
68
- }
69
-
70
- r3logger.dlog('request options = ' + JSON.stringify(options));
71
- r3logger.dlog('request headers = ' + JSON.stringify(headers));
72
-
73
- var httpobj;
74
- if(is_https){
75
- if(null !== cacerts.ca){
76
- options.ca = cacerts.ca;
77
- }
78
- options.rejectUnauthorized = false; // always insecure for this manual test
79
- options.agent = new https.Agent(options);
80
- httpobj = https;
81
- }else{
82
- options.agent = new http.Agent(options);
83
- httpobj = http;
84
- }
85
-
86
- var req = httpobj.request(options, function(res)
87
- {
88
- var response = '';
89
- console.log('RESPONSE CODE = ' + res.statusCode);
90
- r3logger.dlog('response status = ' + res.statusCode);
91
- r3logger.dlog('response header = ' + JSON.stringify(res.headers));
92
- res.setEncoding('utf8');
93
-
94
- res.on('data', function (chunk)
95
- {
96
- r3logger.dlog('response chunk = ' + chunk);
97
- response += chunk;
98
- });
99
-
100
- res.on('end', function(result) // eslint-disable-line no-unused-vars
101
- {
102
- r3logger.mlog(r3logger.dump(response)); // response is object(or not)
103
- console.log('RESPONSE BODY = ' + JSON.stringify(response));
104
- process.exit(0);
105
- });
106
- });
107
-
108
- req.on('error', function(e)
109
- {
110
- r3logger.elog('problem with request: ' + e.message);
111
- });
112
- req.end();
113
- }
114
-
115
- //
116
- // run
117
- //
118
- cliutil.getConsoleInput('Unscoped(or Scoped) user token : ', true, false, function(isbreak, token)
119
- {
120
- if(isbreak){
121
- process.exit(0);
122
- }
123
- var _token = token;
124
-
125
- cliutil.getConsoleInput('Tenant name : ', true, false, function(isbreak, tenant)
126
- {
127
- if(isbreak){
128
- process.exit(0);
129
- }
130
-
131
- if(!apiutil.isSafeString(tenant)){
132
- console.log('method DELETE must specify tenant name');
133
- process.exit(0);
134
- }
135
- var _tenant = apiutil.getSafeString(tenant);
136
-
137
- cliutil.getConsoleInput('Tenant id : ', true, false, function(isbreak, id)
138
- {
139
- if(isbreak){
140
- process.exit(0);
141
- }
142
-
143
- if(!apiutil.isSafeString(id)){
144
- console.log('method DELETE must specify tenant id');
145
- process.exit(0);
146
- }
147
- var _id = apiutil.getSafeString(id);
148
-
149
- cliutil.getConsoleInput('Remove tenant(yes/no(default)) : ', true, false, function(isbreak, remove_all)
150
- {
151
- if(isbreak){
152
- process.exit(0);
153
- }
154
-
155
- var _remove_all;
156
- if(!apiutil.isSafeString(remove_all) || 'no' == remove_all || 'n' == remove_all){
157
- _remove_all = false;
158
- }else if('yes' == remove_all || 'y' == remove_all){
159
- _remove_all = true;
160
-
161
- if(0 !== _tenant.indexOf('local@')){
162
- console.log('Need tenant name started with local@ for remove it.');
163
- process.exit(0);
164
- }
165
- }else{
166
- console.log('input must be yes or no(null)');
167
- process.exit(0);
168
- }
169
-
170
- //
171
- // Run
172
- //
173
- deleteV1Tenant(_token, _tenant, _id, _remove_all);
174
- });
175
- });
176
- });
177
- });
178
-
179
- /*
180
- * Local variables:
181
- * tab-width: 4
182
- * c-basic-offset: 4
183
- * End:
184
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
185
- * vim<600: noexpandtab sw=4 ts=4
186
- */