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,194 +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 Jul 14 2017
17
- * REVISION:
18
- *
19
- */
20
-
21
- 'use strict';
22
-
23
- //
24
- // This file is test variable map object.
25
- //
26
- // This file is used by k2hr3template_test_template.txt test template
27
- // for testing. You can specify these files for k2hr3template_test.sh
28
- //
29
-
30
- module.exports = {
31
- 'statement_print_test_00': 'value_00',
32
- 'formula_variable_00': 'value_name_00',
33
- 'formula_variable_01': [
34
- 'value_01[0]'
35
- ],
36
- 'formula_variable_02': {
37
- 'value_name_00': 'value_02{value_name_00}'
38
- },
39
- 'formula_variable_array_01': [
40
- 'array_value_00',
41
- 'array_value_01'
42
- ],
43
- 'formula_variable_object_01': {
44
- 'object_key_00': 'object_value_00',
45
- 'object_key_01': 'object_value_01',
46
- 'object_key_02': [
47
- 'object_value_02_01',
48
- 'object_value_02_02'
49
- ],
50
- 'object_key_03': {
51
- 'object_valkey_03_00': true,
52
- 'object_valkey_03_01': 'object_valval_03_01'
53
- }
54
- },
55
- 'formula_calculate_not_00': true,
56
- 'formula_calculate_not_01': false,
57
- 'formula_calculate_inc_00': 0,
58
- 'formula_calculate_dec_00': 2,
59
- 'formula_calculate_set_00': 0,
60
- 'formula_calculate_set_01': 100,
61
- 'formula_calculate_plus_00': 10,
62
- 'formula_calculate_plus_01': 20,
63
- 'formula_calculate_plus_02': 'test',
64
- 'formula_calculate_plus_03': 'string',
65
- 'formula_calculate_sub_00': 100,
66
- 'formula_calculate_sub_01': 10,
67
- 'formula_calculate_div_00': 100,
68
- 'formula_calculate_div_01': 10,
69
- 'formula_calculate_mul_00': 5,
70
- 'formula_calculate_mul_01': 20,
71
- 'formula_calculate_rem_00': 35,
72
- 'formula_calculate_rem_01': 6,
73
- 'formula_calculate_lshift_00': 10,
74
- 'formula_calculate_lshift_01': 4,
75
- 'formula_calculate_rshift_00': 43690,
76
- 'formula_calculate_rshift_01': 4,
77
- 'formula_calculate_amp_00': 65535,
78
- 'formula_calculate_amp_01': 43690,
79
- 'formula_calculate_amp_02': true,
80
- 'formula_calculate_amp_03': false,
81
- 'formula_calculate_vartbar_00': 21845,
82
- 'formula_calculate_vartbar_01': 43690,
83
- 'formula_calculate_vartbar_02': true,
84
- 'formula_calculate_vartbar_03': false,
85
- 'formula_cond_and_00': null,
86
- 'formula_cond_and_01': true,
87
- 'formula_cond_and_02': false,
88
- 'formula_cond_and_03': 0,
89
- 'formula_cond_and_04': 1,
90
- 'formula_cond_and_05': 'string',
91
- 'formula_cond_or_00': null,
92
- 'formula_cond_or_01': true,
93
- 'formula_cond_or_02': false,
94
- 'formula_cond_or_03': 0,
95
- 'formula_cond_or_04': 1,
96
- 'formula_cond_or_05': 'string',
97
- 'formula_cond_less_00': 0,
98
- 'formula_cond_less_01': 1,
99
- 'formula_cond_less_02': 2,
100
- 'formula_cond_great_00': 0,
101
- 'formula_cond_great_01': 1,
102
- 'formula_cond_great_02': 2,
103
- 'formula_cond_lesseq_00': 0,
104
- 'formula_cond_lesseq_01': 1,
105
- 'formula_cond_lesseq_02': 2,
106
- 'formula_cond_greateq_00': 0,
107
- 'formula_cond_greateq_01': 1,
108
- 'formula_cond_greateq_02': 2,
109
- 'formula_cond_eq_00': null,
110
- 'formula_cond_eq_01': true,
111
- 'formula_cond_eq_02': false,
112
- 'formula_cond_eq_03': 0,
113
- 'formula_cond_eq_04': 1,
114
- 'formula_cond_eq_05': 'string',
115
- 'formula_cond_noteq_00': null,
116
- 'formula_cond_noteq_01': true,
117
- 'formula_cond_noteq_02': false,
118
- 'formula_cond_noteq_03': 0,
119
- 'formula_cond_noteq_04': 1,
120
- 'formula_cond_noteq_05': 'string',
121
- 'formula_syntax_if_00': null,
122
- 'formula_syntax_if_01': true,
123
- 'formula_syntax_if_02': false,
124
- 'formula_syntax_if_03': 0,
125
- 'formula_syntax_if_04': 1,
126
- 'formula_syntax_if_05': 'string',
127
- 'formula_syntax_while_00': null,
128
- 'formula_syntax_while_01': true,
129
- 'formula_syntax_while_02': false,
130
- 'formula_syntax_while_03': 0,
131
- 'formula_syntax_while_04': 1,
132
- 'formula_syntax_while_05': 'string',
133
- 'formula_syntax_do_00': null,
134
- 'formula_syntax_do_01': true,
135
- 'formula_syntax_do_02': false,
136
- 'formula_syntax_do_03': 0,
137
- 'formula_syntax_do_04': 1,
138
- 'formula_syntax_do_05': 'string',
139
- 'formula_syntax_for_00': null,
140
- 'formula_syntax_for_01': true,
141
- 'formula_syntax_for_02': false,
142
- 'formula_syntax_for_03': 0,
143
- 'formula_syntax_for_04': 1,
144
- 'formula_syntax_for_05': 'string',
145
- 'formula_syntax_for_06': [
146
- 'string00',
147
- 'string01'
148
- ],
149
- 'formula_syntax_for_07': {
150
- 'key_1': true,
151
- 'key_2': false
152
- },
153
- 'formula_syntax_foreach_00': [],
154
- 'formula_syntax_foreach_01': [
155
- null
156
- ],
157
- 'formula_syntax_foreach_02': [
158
- true,
159
- false
160
- ],
161
- 'formula_syntax_foreach_03': [
162
- 0,
163
- 1
164
- ],
165
- 'formula_syntax_foreach_04': [
166
- 'string00',
167
- 'string01'
168
- ],
169
- 'formula_syntax_foreach_10': {},
170
- 'formula_syntax_foreach_11': {
171
- 'key': null
172
- },
173
- 'formula_syntax_foreach_12': {
174
- 'key_1': true,
175
- 'key_2': false
176
- },
177
- 'formula_syntax_foreach_13': {
178
- 'key_1': 0,
179
- 'key_2': 1
180
- },
181
- 'formula_syntax_foreach_14': {
182
- 'key_1': 'string00',
183
- 'key_2': 'string01'
184
- }
185
- };
186
-
187
- /*
188
- * Local variables:
189
- * tab-width: 4
190
- * c-basic-offset: 4
191
- * End:
192
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
193
- * vim<600: noexpandtab sw=4 ts=4
194
- */
@@ -1,143 +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 rawDeleteV1Acr(token, service)
44
- {
45
- var headers = {
46
- 'Content-Type': 'application/json',
47
- 'X-Auth-Token': token
48
- };
49
- var options = {
50
- 'host': hostname,
51
- 'port': hostport,
52
- 'path': '/v1/acr/' + service,
53
- 'method': 'DELETE',
54
- 'headers': headers
55
- };
56
-
57
- r3logger.dlog('request options = ' + JSON.stringify(options));
58
- r3logger.dlog('request headers = ' + JSON.stringify(headers));
59
-
60
- var httpobj;
61
- if(is_https){
62
- if(null !== cacerts.ca){
63
- options.ca = cacerts.ca;
64
- }
65
- options.rejectUnauthorized = false; // always insecure for this manual test
66
- options.agent = new https.Agent(options);
67
- httpobj = https;
68
- }else{
69
- options.agent = new http.Agent(options);
70
- httpobj = http;
71
- }
72
-
73
- var req = httpobj.request(options, function(res)
74
- {
75
- var response = '';
76
- console.log('RESPONSE CODE = ' + res.statusCode);
77
- r3logger.dlog('response status = ' + res.statusCode);
78
- r3logger.dlog('response header = ' + JSON.stringify(res.headers));
79
- res.setEncoding('utf8');
80
-
81
- res.on('data', function (chunk)
82
- {
83
- r3logger.dlog('response chunk = ' + chunk);
84
- response += chunk;
85
- });
86
-
87
- res.on('end', function(result) // eslint-disable-line no-unused-vars
88
- {
89
- r3logger.mlog(r3logger.dump(response)); // response is object(or not)
90
- console.log('RESPONSE BODY = ' + JSON.stringify(response));
91
- process.exit(0);
92
- });
93
- });
94
-
95
- req.on('error', function(e)
96
- {
97
- r3logger.elog('problem with request: ' + e.message);
98
- });
99
-
100
- req.end();
101
- }
102
-
103
- //
104
- // run
105
- //
106
- cliutil.getConsoleInput('Service name : ', true, false, function(isbreak, service)
107
- {
108
- if(isbreak){
109
- process.exit(0);
110
- }
111
- if(!apiutil.isSafeString(service)){
112
- console.log('service must be service name.');
113
- process.exit(0);
114
- }
115
- var _service = service;
116
-
117
-
118
- cliutil.getConsoleInput('User scoped token : ', true, false, function(isbreak, token)
119
- {
120
- if(isbreak){
121
- process.exit(0);
122
- }
123
- if(!apiutil.isSafeString(token)){
124
- console.log('token must be not empty.');
125
- process.exit(0);
126
- }
127
- var _token = 'U=' + token;
128
-
129
- //
130
- // run DELETE
131
- //
132
- rawDeleteV1Acr(_token, _service);
133
- });
134
- });
135
-
136
- /*
137
- * Local variables:
138
- * tab-width: 4
139
- * c-basic-offset: 4
140
- * End:
141
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
142
- * vim<600: noexpandtab sw=4 ts=4
143
- */
@@ -1,297 +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 rawGetV1Acr(token, service, inputdata)
44
- {
45
- var urlarg = '';
46
- if(apiutil.isSafeEntity(inputdata)){
47
- urlarg += '?crole=' + inputdata.client_role;
48
- urlarg += '&cip=' + inputdata.client_ip;
49
- urlarg += '&srole=' + inputdata.service_role;
50
- if(apiutil.isSafeEntity(inputdata.client_port)){
51
- urlarg += '&cport=' + inputdata.client_port;
52
- }
53
- if(apiutil.isSafeEntity(inputdata.service_port)){
54
- urlarg += '&sport=' + inputdata.service_port;
55
- }
56
- if(apiutil.isSafeEntity(inputdata.client_cuk)){
57
- urlarg += '&ccuk=' + inputdata.client_cuk;
58
- }
59
- if(apiutil.isSafeEntity(inputdata.service_cuk)){
60
- urlarg += '&scuk=' + inputdata.service_cuk;
61
- }
62
- urlarg = encodeURI(urlarg);
63
- }
64
-
65
- var headers = {
66
- 'Content-Type': 'application/json'
67
- };
68
- var options = {
69
- 'host': hostname,
70
- 'port': hostport,
71
- 'path': '/v1/acr/' + service + urlarg,
72
- 'method': 'GET'
73
- };
74
-
75
- if(apiutil.isSafeString(token)){
76
- headers['X-Auth-Token'] = token;
77
- }
78
- options.headers = headers;
79
-
80
- r3logger.dlog('request options = ' + JSON.stringify(options));
81
- r3logger.dlog('request headers = ' + JSON.stringify(headers));
82
-
83
- var httpobj;
84
- if(is_https){
85
- if(null !== cacerts.ca){
86
- options.ca = cacerts.ca;
87
- }
88
- options.rejectUnauthorized = false; // always insecure for this manual test
89
- options.agent = new https.Agent(options);
90
- httpobj = https;
91
- }else{
92
- options.agent = new http.Agent(options);
93
- httpobj = http;
94
- }
95
-
96
- var req = httpobj.request(options, function(res)
97
- {
98
- var response = '';
99
- console.log('RESPONSE CODE = ' + res.statusCode);
100
- r3logger.dlog('response status = ' + res.statusCode);
101
- r3logger.dlog('response header = ' + JSON.stringify(res.headers));
102
- res.setEncoding('utf8');
103
-
104
- res.on('data', function (chunk)
105
- {
106
- r3logger.dlog('response chunk = ' + chunk);
107
- response += chunk;
108
- });
109
-
110
- res.on('end', function(result) // eslint-disable-line no-unused-vars
111
- {
112
- r3logger.mlog(r3logger.dump(response)); // response is object(or not)
113
- console.log('RESPONSE BODY = ' + JSON.stringify(response));
114
- process.exit(0);
115
- });
116
- });
117
-
118
- req.on('error', function(e)
119
- {
120
- r3logger.elog('problem with request: ' + e.message);
121
- });
122
-
123
- req.end();
124
- }
125
-
126
- //
127
- // Utility
128
- //
129
- function rawGetParametersForGetResourceType(callback)
130
- {
131
- var result = {
132
- client_role: null,
133
- client_ip: null,
134
- client_port: null,
135
- client_cuk: null,
136
- service_role: null,
137
- service_port: null,
138
- service_cuk: null
139
- };
140
- var _callback = callback;
141
-
142
- cliutil.getConsoleInput(' Client Role(full yrn path) : ', true, false, function(isbreak, crole)
143
- {
144
- if(isbreak){
145
- _callback('break input');
146
- return;
147
- }
148
- if(!apiutil.isSafeString(crole)){
149
- _callback('Input data must be not empty.');
150
- return;
151
- }
152
- result.client_role = crole;
153
-
154
- cliutil.getConsoleInput(' Client IP Address : ', true, false, function(isbreak, cip)
155
- {
156
- if(isbreak){
157
- _callback('break input');
158
- return;
159
- }
160
- if(!apiutil.isSafeString(cip)){
161
- _callback('Input data must be not empty.');
162
- return;
163
- }
164
- result.client_ip = cip;
165
-
166
- cliutil.getConsoleInput(' Client Port(allow empty) : ', true, false, function(isbreak, cport)
167
- {
168
- if(isbreak){
169
- _callback('break input');
170
- return;
171
- }
172
- if(apiutil.isSafeString(cport)){
173
- result.client_port = cport;
174
- }
175
-
176
- cliutil.getConsoleInput(' Client CUK string(allow empty) : ', true, false, function(isbreak, ccuk)
177
- {
178
- if(isbreak){
179
- _callback('break input');
180
- return;
181
- }
182
- if(apiutil.isSafeString(ccuk)){
183
- result.client_cuk = ccuk;
184
- }
185
-
186
- cliutil.getConsoleInput(' Service Role(full yrn path) : ', true, false, function(isbreak, srole)
187
- {
188
- if(isbreak){
189
- _callback('break input');
190
- return;
191
- }
192
- if(!apiutil.isSafeString(srole)){
193
- _callback('Input data must be not empty.');
194
- return;
195
- }
196
- result.service_role = srole;
197
-
198
- cliutil.getConsoleInput(' Service Port(allow empty) : ', true, false, function(isbreak, sport)
199
- {
200
- if(isbreak){
201
- _callback('break input');
202
- return;
203
- }
204
- if(apiutil.isSafeString(sport)){
205
- result.service_port = sport;
206
- }
207
-
208
- cliutil.getConsoleInput(' Service CUK string(allow empty) : ', true, false, function(isbreak, scuk)
209
- {
210
- if(isbreak){
211
- _callback('break input');
212
- return;
213
- }
214
- if(apiutil.isSafeString(scuk)){
215
- result.service_cuk = scuk;
216
- }
217
- _callback(null, result);
218
- });
219
- });
220
- });
221
- });
222
- });
223
- });
224
- });
225
- }
226
-
227
- //
228
- // run
229
- //
230
- cliutil.getConsoleInput('Service name : ', true, false, function(isbreak, service)
231
- {
232
- if(isbreak){
233
- process.exit(0);
234
- }
235
- if(!apiutil.isSafeString(service)){
236
- console.log('must be service name.');
237
- process.exit(0);
238
- }
239
- var _service = service;
240
-
241
- cliutil.getConsoleInput('Type(TOKEN=token info, RESOURCE=get resource) : ', true, false, function(isbreak, type)
242
- {
243
- if(isbreak){
244
- process.exit(0);
245
- }
246
- if(apiutil.compareCaseString('TOKEN', type)){
247
- //
248
- // type: token information
249
- //
250
- cliutil.getConsoleInput('User scoped token : ', true, false, function(isbreak, token)
251
- {
252
- if(isbreak){
253
- process.exit(0);
254
- }
255
- if(!apiutil.isSafeString(token)){
256
- console.log('token must be not empty.');
257
- process.exit(0);
258
- }
259
- var _token = 'U=' + token;
260
-
261
- //
262
- // run GET for getting token information
263
- //
264
- rawGetV1Acr(_token, _service, null);
265
- });
266
-
267
- }else if(apiutil.compareCaseString('RESOURCE', type)){
268
- //
269
- // type: getting resource
270
- //
271
- rawGetParametersForGetResourceType(function(error, inputdata)
272
- {
273
- if(null !== error){
274
- console.log(error);
275
- process.exit(0);
276
- }
277
-
278
- //
279
- // run GET for getting resources
280
- //
281
- rawGetV1Acr(null, _service, inputdata);
282
- });
283
- }else{
284
- console.log('type must be TOKEN or RESOURCE.');
285
- process.exit(0);
286
- }
287
- });
288
- });
289
-
290
- /*
291
- * Local variables:
292
- * tab-width: 4
293
- * c-basic-offset: 4
294
- * End:
295
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
296
- * vim<600: noexpandtab sw=4 ts=4
297
- */