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,230 +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 getV1ChildrenList(method, token, type, service, path, is_expand)
45
- {
46
- var entrypath = '/v1/list/';
47
- if(apiutil.isSafeString(service)){
48
- entrypath += service + '/';
49
- }
50
- entrypath += type;
51
- if(apiutil.isSafeString(path)){
52
- entrypath += '/' + path;
53
- }
54
- if(undefined !== is_expand && 'boolean' === typeof is_expand){
55
- var keys = r3keys();
56
- if(is_expand){
57
- entrypath += '?expand=' + keys.VALUE_TRUE;
58
- }else{
59
- entrypath += '?expand=' + keys.VALUE_FALSE;
60
- }
61
- }
62
-
63
- var headers = {
64
- 'Content-Type': 'application/json',
65
- 'Content-Length': 0,
66
- 'X-Auth-Token': token
67
- };
68
- var options = {
69
- 'host': hostname,
70
- 'port': hostport,
71
- 'path': entrypath,
72
- 'method': method,
73
- 'headers': headers
74
- };
75
-
76
- r3logger.dlog('request options = ' + JSON.stringify(options));
77
- r3logger.dlog('request headers = ' + JSON.stringify(headers));
78
-
79
- var httpobj;
80
- if(is_https){
81
- if(null !== cacerts.ca){
82
- options.ca = cacerts.ca;
83
- }
84
- options.rejectUnauthorized = false; // always insecure for this manual test
85
- options.agent = new https.Agent(options);
86
- httpobj = https;
87
- }else{
88
- options.agent = new http.Agent(options);
89
- httpobj = http;
90
- }
91
-
92
- var req = httpobj.request(options, function(res)
93
- {
94
- var response = '';
95
- console.log('RESPONSE CODE = ' + res.statusCode);
96
- r3logger.dlog('response status = ' + res.statusCode);
97
- r3logger.dlog('response header = ' + JSON.stringify(res.headers));
98
- res.setEncoding('utf8');
99
-
100
- res.on('data', function (chunk)
101
- {
102
- r3logger.dlog('response chunk = ' + chunk);
103
- response += chunk;
104
- });
105
-
106
- res.on('end', function(result) // eslint-disable-line no-unused-vars
107
- {
108
- r3logger.mlog(r3logger.dump(response)); // response is object(or not)
109
- console.log('RESPONSE BODY = ' + JSON.stringify(response));
110
- process.exit(0);
111
- });
112
- });
113
-
114
- req.on('error', function(e)
115
- {
116
- r3logger.elog('problem with request: ' + e.message);
117
- });
118
- req.end();
119
- }
120
-
121
- //
122
- // run
123
- //
124
- cliutil.getConsoleInput('Method(GET/HEAD) : ', true, false, function(isbreak, method)
125
- {
126
- if(isbreak){
127
- process.exit(0);
128
- }
129
-
130
- var _method = method.toUpperCase();
131
- if(!apiutil.compareCaseString('get', _method) && !apiutil.compareCaseString('head', _method)){
132
- console.log('method must be GET or HEAD : ' + _method);
133
- process.exit(0);
134
- }
135
-
136
- cliutil.getConsoleInput('type(service/role/resource/policy) : ', true, false, function(isbreak, type)
137
- {
138
- if(isbreak){
139
- process.exit(0);
140
- }
141
- var _type;
142
- if(apiutil.compareCaseString('service', apiutil.getSafeString(type))){
143
- _type = 'service';
144
- }else if(apiutil.compareCaseString('role', apiutil.getSafeString(type))){
145
- _type = 'role';
146
- }else if(apiutil.compareCaseString('resource', apiutil.getSafeString(type))){
147
- _type = 'resource';
148
- }else if(apiutil.compareCaseString('policy', apiutil.getSafeString(type))){
149
- _type = 'policy';
150
- }else{
151
- console.log('type must be service / role / resource / policy : ' + type);
152
- process.exit(0);
153
- }
154
-
155
- cliutil.getConsoleInput('Scoped user token for tenant : ', true, false, function(isbreak, token)
156
- {
157
- if(isbreak){
158
- process.exit(0);
159
- }
160
- var _token = token;
161
- if(!apiutil.isSafeString(_token)){
162
- console.log('method must be specified token.');
163
- process.exit(0);
164
- }
165
-
166
- if(apiutil.compareCaseString('service', apiutil.getSafeString(_type))){
167
- //
168
- // service type, this is only listing service name.
169
- //
170
- getV1ChildrenList(_method, _token, _type, null);
171
- return;
172
- }
173
-
174
- cliutil.getConsoleInput('Service name(allow empty) : ', true, false, function(isbreak, service)
175
- {
176
- if(isbreak){
177
- process.exit(0);
178
- }
179
- var _service = service;
180
-
181
- cliutil.getConsoleInput('path(allow empty) : ', true, false, function(isbreak, path)
182
- {
183
- if(isbreak){
184
- process.exit(0);
185
- }
186
- var _path;
187
- if('' === apiutil.getSafeString(path) || apiutil.compareCaseString('null', apiutil.getSafeString(path))){
188
- _path = null;
189
- }else{
190
- _path = path;
191
- }
192
-
193
- if('policy' !== _type){
194
- // role/resource can expand.
195
- cliutil.getConsoleInput('expand(true/false(default)) : ', true, false, function(isbreak, is_expand)
196
- {
197
- if(isbreak){
198
- process.exit(0);
199
- }
200
- var keys = r3keys();
201
- var _is_expand;
202
- if('' === is_expand || apiutil.compareCaseString('null', apiutil.getSafeString(is_expand)) || apiutil.compareCaseString(keys.VALUE_FALSE, apiutil.getSafeString(is_expand))){
203
- _is_expand = false;
204
- }else if(apiutil.compareCaseString(keys.VALUE_TRUE, apiutil.getSafeString(is_expand))){
205
- _is_expand = true;
206
- }else{
207
- console.log('expand must be true or false or null(empty) : ' + is_expand);
208
- process.exit(0);
209
- }
210
- // run
211
- getV1ChildrenList(_method, _token, _type, _service, _path, _is_expand);
212
- });
213
- }else{
214
- // run
215
- getV1ChildrenList(_method, _token, _type, _service, _path);
216
- }
217
- });
218
- });
219
- });
220
- });
221
- });
222
-
223
- /*
224
- * Local variables:
225
- * tab-width: 4
226
- * c-basic-offset: 4
227
- * End:
228
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
229
- * vim<600: noexpandtab sw=4 ts=4
230
- */
@@ -1,132 +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
-
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 deleteV1Policy(token, name)
44
- {
45
- var headers = {
46
- 'Content-Type': 'application/json',
47
- 'Content-Length': 0,
48
- 'X-Auth-Token': token
49
- };
50
- var options = {
51
- 'host': hostname,
52
- 'port': hostport,
53
- 'path': '/v1/policy/' + name,
54
- 'method': 'DELETE',
55
- 'headers': headers
56
- };
57
-
58
- r3logger.dlog('request options = ' + JSON.stringify(options));
59
- r3logger.dlog('request headers = ' + JSON.stringify(headers));
60
-
61
- var httpobj;
62
- if(is_https){
63
- if(null !== cacerts.ca){
64
- options.ca = cacerts.ca;
65
- }
66
- options.rejectUnauthorized = false; // always insecure for this manual test
67
- options.agent = new https.Agent(options);
68
- httpobj = https;
69
- }else{
70
- options.agent = new http.Agent(options);
71
- httpobj = http;
72
- }
73
-
74
- var req = httpobj.request(options, function(res)
75
- {
76
- var response = '';
77
- console.log('RESPONSE CODE = ' + res.statusCode);
78
- r3logger.dlog('response status = ' + res.statusCode);
79
- r3logger.dlog('response header = ' + JSON.stringify(res.headers));
80
- res.setEncoding('utf8');
81
-
82
- res.on('data', function (chunk)
83
- {
84
- r3logger.dlog('response chunk = ' + chunk);
85
- response += chunk;
86
- });
87
-
88
- res.on('end', function(result) // eslint-disable-line no-unused-vars
89
- {
90
- r3logger.mlog(r3logger.dump(response)); // response is object(or not)
91
- console.log('RESPONSE BODY = ' + JSON.stringify(response));
92
- process.exit(0);
93
- });
94
- });
95
-
96
- req.on('error', function(e)
97
- {
98
- r3logger.elog('problem with request: ' + e.message);
99
- });
100
- req.end();
101
- }
102
-
103
- //
104
- // run
105
- //
106
- cliutil.getConsoleInput('Scoped user token for tenant : ', true, false, function(isbreak, token)
107
- {
108
- if(isbreak){
109
- process.exit(0);
110
- }
111
- var _token = token;
112
-
113
- cliutil.getConsoleInput('Policy name : ', true, false, function(isbreak, name)
114
- {
115
- if(isbreak){
116
- process.exit(0);
117
- }
118
- var _name = name;
119
-
120
- // run
121
- deleteV1Policy(_token, _name);
122
- });
123
- });
124
-
125
- /*
126
- * Local variables:
127
- * tab-width: 4
128
- * c-basic-offset: 4
129
- * End:
130
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
131
- * vim<600: noexpandtab sw=4 ts=4
132
- */
@@ -1,275 +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 getV1Policy(token, name, service)
45
- {
46
- var urlarg = '';
47
- if(apiutil.isSafeString(service)){
48
- urlarg = encodeURI('?service=' + service);
49
- }
50
-
51
- var headers = {
52
- 'Content-Type': 'application/json',
53
- 'Content-Length': 0,
54
- 'X-Auth-Token': token
55
- };
56
- var options = {
57
- 'host': hostname,
58
- 'port': hostport,
59
- 'path': '/v1/policy/' + name + urlarg,
60
- 'method': 'GET',
61
- 'headers': headers
62
- };
63
-
64
- r3logger.dlog('request options = ' + JSON.stringify(options));
65
- r3logger.dlog('request headers = ' + JSON.stringify(headers));
66
-
67
- var httpobj;
68
- if(is_https){
69
- if(null !== cacerts.ca){
70
- options.ca = cacerts.ca;
71
- }
72
- options.rejectUnauthorized = false; // always insecure for this manual test
73
- options.agent = new https.Agent(options);
74
- httpobj = https;
75
- }else{
76
- options.agent = new http.Agent(options);
77
- httpobj = http;
78
- }
79
-
80
- var req = httpobj.request(options, function(res)
81
- {
82
- var response = '';
83
- console.log('RESPONSE CODE = ' + res.statusCode);
84
- r3logger.dlog('response status = ' + res.statusCode);
85
- r3logger.dlog('response header = ' + JSON.stringify(res.headers));
86
- res.setEncoding('utf8');
87
-
88
- res.on('data', function (chunk)
89
- {
90
- r3logger.dlog('response chunk = ' + chunk);
91
- response += chunk;
92
- });
93
-
94
- res.on('end', function(result) // eslint-disable-line no-unused-vars
95
- {
96
- r3logger.mlog(r3logger.dump(response)); // response is object(or not)
97
- console.log('RESPONSE BODY = ' + JSON.stringify(response));
98
- process.exit(0);
99
- });
100
- });
101
-
102
- req.on('error', function(e)
103
- {
104
- r3logger.elog('problem with request: ' + e.message);
105
- });
106
- req.end();
107
- }
108
-
109
- function headV1Policy(tenant, name, action, resource)
110
- {
111
- var headers = {
112
- 'Content-Type': 'application/json',
113
- 'Content-Length': 0
114
- };
115
-
116
- var urlarg = '?resource=' + resource + '&action=' + action;
117
- if(apiutil.isSafeString(tenant)){
118
- urlarg += '&tenant=' + tenant;
119
- }
120
-
121
- var options = {
122
- 'host': hostname,
123
- 'port': hostport,
124
- 'path': '/v1/policy/' + name + encodeURI(urlarg),
125
- 'method': 'HEAD',
126
- 'headers': headers
127
- };
128
-
129
- r3logger.dlog('request options = ' + JSON.stringify(options));
130
- r3logger.dlog('request headers = ' + JSON.stringify(headers));
131
-
132
- var httpobj;
133
- if(is_https){
134
- if(null !== cacerts.ca){
135
- options.ca = cacerts.ca;
136
- }
137
- options.rejectUnauthorized = false; // always insecure for this manual test
138
- options.agent = new https.Agent(options);
139
- httpobj = https;
140
- }else{
141
- options.agent = new http.Agent(options);
142
- httpobj = http;
143
- }
144
-
145
- var req = httpobj.request(options, function(res)
146
- {
147
- var response = '';
148
- console.log('RESPONSE CODE = ' + res.statusCode);
149
- r3logger.dlog('response status = ' + res.statusCode);
150
- r3logger.dlog('response header = ' + JSON.stringify(res.headers));
151
- res.setEncoding('utf8');
152
-
153
- res.on('data', function (chunk)
154
- {
155
- r3logger.dlog('response chunk = ' + chunk);
156
- response += chunk;
157
- });
158
-
159
- res.on('end', function(result) // eslint-disable-line no-unused-vars
160
- {
161
- r3logger.mlog(r3logger.dump(response)); // response is object(or not)
162
- console.log('RESPONSE BODY = ' + JSON.stringify(response));
163
- process.exit(0);
164
- });
165
- });
166
-
167
- req.on('error', function(e)
168
- {
169
- r3logger.elog('problem with request: ' + e.message);
170
- });
171
- req.end();
172
- }
173
-
174
- //
175
- // run
176
- //
177
- cliutil.getConsoleInput('Method(GET/HEAD) : ', true, false, function(isbreak, method)
178
- {
179
- if(isbreak){
180
- process.exit(0);
181
- }
182
-
183
- var _method = method;
184
- if(apiutil.compareCaseString('get', _method)){
185
-
186
- cliutil.getConsoleInput('Service name(allow empty) : ', true, false, function(isbreak, service)
187
- {
188
- if(isbreak){
189
- process.exit(0);
190
- }
191
- var _service = apiutil.isSafeString(service) ? apiutil.getSafeString(service) : null;
192
-
193
- cliutil.getConsoleInput('Scoped user token for tenant : ', true, false, function(isbreak, token)
194
- {
195
- if(isbreak){
196
- process.exit(0);
197
- }
198
- var _token = token;
199
-
200
- cliutil.getConsoleInput('Policy name : ', true, false, function(isbreak, name)
201
- {
202
- if(isbreak){
203
- process.exit(0);
204
- }
205
- var _name = name;
206
-
207
- // run
208
- getV1Policy(_token, _name, _service);
209
- });
210
- });
211
- });
212
-
213
- }else if(apiutil.compareCaseString('head', _method)){
214
- cliutil.getConsoleInput('Tenant name(allow null) : ', true, false, function(isbreak, tenant)
215
- {
216
- if(isbreak){
217
- process.exit(0);
218
- }
219
- var _tenant = null;
220
- if('' === apiutil.getSafeString(tenant) || apiutil.compareCaseString('null', apiutil.getSafeString(tenant))){
221
- _tenant = null;
222
- }else{
223
- _tenant = tenant;
224
- }
225
-
226
- cliutil.getConsoleInput('Policy name : ', true, false, function(isbreak, name)
227
- {
228
- if(isbreak){
229
- process.exit(0);
230
- }
231
- var _name = name;
232
-
233
- cliutil.getConsoleInput('Action(read/write) : ', true, false, function(isbreak, action)
234
- {
235
- if(isbreak){
236
- process.exit(0);
237
- }
238
- var keys = r3keys();
239
- var _action = apiutil.getSafeString(action);
240
- if(keys.VALUE_READ !== _action && keys.VALUE_WRITE !== _action){
241
- process.exit(0);
242
- }
243
-
244
- cliutil.getConsoleInput('Resource : ', true, false, function(isbreak, resource)
245
- {
246
- if(isbreak){
247
- process.exit(0);
248
- }
249
- var _resource = null;
250
- if('' === apiutil.getSafeString(resource) || apiutil.compareCaseString('null', apiutil.getSafeString(resource))){
251
- _resource = null;
252
- }else{
253
- _resource = resource;
254
- }
255
-
256
- // run
257
- headV1Policy(_tenant, _name, _action, _resource);
258
- });
259
- });
260
- });
261
- });
262
- }else{
263
- console.log('method must be GET or HEAD : ' + _method);
264
- process.exit(0);
265
- }
266
- });
267
-
268
- /*
269
- * Local variables:
270
- * tab-width: 4
271
- * c-basic-offset: 4
272
- * End:
273
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
274
- * vim<600: noexpandtab sw=4 ts=4
275
- */