k2hr3-api 1.0.41 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/config/k2hr3-init.sh.templ +2 -2
  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 -372
  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,352 +0,0 @@
1
- #!/bin/sh
2
- #
3
- # K2HR3 REST API
4
- #
5
- # Copyright 2017 Yahoo Japan Corporation.
6
- #
7
- # K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
8
- # common management information for the cloud.
9
- # K2HR3 can dynamically manage information as "who", "what", "operate".
10
- # These are stored as roles, resources, policies in K2hdkc, and the
11
- # client system can dynamically read and modify these information.
12
- #
13
- # For the full copyright and license information, please view
14
- # the license file that was distributed with this source code.
15
- #
16
- # AUTHOR: Takeshi Nakatani
17
- # CREATE: Wed Jun 8 2017
18
- # REVISION:
19
- #
20
-
21
- #==========================================================
22
- # Common Variables
23
- #==========================================================
24
- PRGNAME=$(basename "$0")
25
- SCRIPTDIR=$(dirname "$0")
26
- SCRIPTDIR=$(cd "${SCRIPTDIR}" || exit 1; pwd)
27
- SRCTOP=$(cd "${SCRIPTDIR}/.." || exit 1; pwd)
28
-
29
- #
30
- # Variables
31
- #
32
- COMMAND=""
33
- CMD_PREFIX="manual_"
34
- CMD_SUFFIX=".js"
35
-
36
- #
37
- # Commands
38
- #
39
- COMMANDS="
40
- version_get
41
- usertoken_gethead
42
- usertoken_postput
43
- policy_delete
44
- policy_gethead
45
- policy_postput
46
- resource_delete
47
- resource_gethead
48
- resource_postput
49
- role_delete
50
- role_gethead
51
- role_postput
52
- tenant_delete
53
- tenant_gethead
54
- tenant_postput
55
- service_postput
56
- service_gethead
57
- service_delete
58
- acr_postput
59
- acr_get
60
- acr_delete
61
- list_gethead
62
- userdata_get
63
- extdata_get
64
- allusertenant_get
65
- k2hr3keys_get
66
- "
67
-
68
- #==============================================================
69
- # Utility functions
70
- #==============================================================
71
- #
72
- # Usage
73
- #
74
- PrintUsage()
75
- {
76
- echo "Usage: $1 [--apihost(-a) hostname]"
77
- echo " [--apiport(-p) port]"
78
- echo " [--https | --http]"
79
- echo " [--debuglevel(-d) DBG/MSG/WARN/ERR/(custom debug level)]"
80
- echo " <Command>"
81
- echo ""
82
- echo "Option:"
83
- echo " --apihost(-a) : Specify k2hr3 API hostname used by this test"
84
- echo " --apiport(-p) : Specify k2hr3 API port used by this test"
85
- echo " --sec(-s) : Use HTTPS to access k2hr3 API server"
86
- echo " --https : Same as '--sec' option"
87
- echo " --debuglevel(-d) : Specify the level of debug output."
88
- echo " (DBG/MSG/WARN/ERR/custom debug level)"
89
- echo ""
90
- echo "Command:"
91
- echo " version_get : Get version information"
92
- echo ""
93
- echo " usertoken_postput : Get User Token(v1)"
94
- echo " usertoken_gethead : Get User Token Information(v1)"
95
- echo ""
96
- echo " resource_postput : Post(Put) resource(v1)"
97
- echo " resource_gethead : Get(Head) resource(v1)"
98
- echo " resource_delete : Delete resource(v1)"
99
- echo ""
100
- echo " policy_postput : Post(Put) policy(v1)"
101
- echo " policy_gethead : Get(Head) policy(v1)"
102
- echo " policy_delete : Delete policy(v1)"
103
- echo ""
104
- echo " role_postput : Post(Put) role(v1)"
105
- echo " role_gethead : Get(Head) role(v1)"
106
- echo " role_delete : Delete role(v1)"
107
- echo ""
108
- echo " tenant_postput : Post(Put) tenant(v1)"
109
- echo " tenant_gethead : Get(Head) tenant(v1)"
110
- echo " tenant_delete : Delete tenant(v1)"
111
- echo ""
112
- echo " service_postput : Post(Put) service(v1)"
113
- echo " service_gethead : Get(head) service(v1)"
114
- echo " service_delete : Delete service(v1)"
115
- echo ""
116
- echo " acr_postput : Post(Put) ACR(v1)"
117
- echo " acr_get : Get ACR(v1)"
118
- echo " acr_delete : Delete ACR(v1)"
119
- echo ""
120
- echo " list_gethead : Get(Head) children list for path(v1)"
121
- echo ""
122
- echo " userdata_get : Get userdata for openstack instance(v1)"
123
- echo ""
124
- echo " extdata_get : Get extdata for user defined data(v1)"
125
- echo ""
126
- echo " allusertenant_get : Get all user and tenant list in k2hr3"
127
- echo " k2hr3keys_get : Get common key name object for debug"
128
- echo ""
129
- }
130
-
131
- #
132
- # Check Commands
133
- #
134
- CheckCommands()
135
- {
136
- if [ -n "$1" ]; then
137
- for command in ${COMMANDS}; do
138
- if [ "$1" = "${command}" ]; then
139
- echo "${command}"
140
- return 0
141
- fi
142
- done
143
- fi
144
- echo ""
145
- return 1
146
- }
147
-
148
- #==========================================================
149
- # Parse options
150
- #==========================================================
151
- APIPORT=0
152
- APIHOST=""
153
- HTTPS_ENV=""
154
- DEBUG_ENV_LEVEL=0
155
- DEBUG_ENV_CUSTOM=""
156
-
157
- while [ $# -ne 0 ]; do
158
- if [ -z "$1" ]; then
159
- break
160
-
161
- elif echo "$1" | grep -q -i -e "^-h$" -e "^--help$"; then
162
- PrintUsage "${PRGNAME}"
163
- exit 0
164
-
165
- elif echo "$1" | grep -q -i -e "^-a$" -e "^--apihost$"; then
166
- #
167
- # API HOST
168
- #
169
- if [ -n "${APIHOST}" ]; then
170
- echo "[ERROR] already specified --apihost option"
171
- exit 1
172
- fi
173
- shift
174
- if [ $# -eq 0 ]; then
175
- echo "[ERROR] --apihost(-h) option needs parameter(hostname)"
176
- exit 1
177
- fi
178
- APIHOST="$1"
179
-
180
- elif echo "$1" | grep -q -i -e "^-p$" -e "^--apiport$"; then
181
- #
182
- # API PORT
183
- #
184
- if [ "${APIPORT}" -ne 0 ]; then
185
- echo "[ERROR] already specified --apiport option"
186
- exit 1
187
- fi
188
- shift
189
- if [ $# -eq 0 ]; then
190
- echo "[ERROR] --apiport(-p) option needs parameter(port number)"
191
- exit 1
192
- fi
193
- if echo "$1" | grep -q '[^0-9]'; then
194
- echo "[ERROR] --apiport(-p) option parameter must be number"
195
- exit 1
196
- elif [ "$1" -eq 0 ]; then
197
- echo "[ERROR] --apiport(-p) option parameter must be positive number"
198
- exit 1
199
- fi
200
- APIPORT="$1"
201
-
202
- elif echo "$1" | grep -q -i "^--https$"; then
203
- if [ -n "${HTTPS_ENV}" ]; then
204
- echo "[ERROR] already specified --https or --http option"
205
- exit 1
206
- fi
207
- HTTPS_ENV="yes"
208
-
209
- elif echo "$1" | grep -q -i "^--http$"; then
210
- if [ -n "${HTTPS_ENV}" ]; then
211
- echo "[ERROR] already specified --https or --http option"
212
- exit 1
213
- fi
214
- HTTPS_ENV="no"
215
-
216
- elif echo "$1" | grep -q -i -e "^-d$" -e "^--debuglevel$"; then
217
- #
218
- # DEBUG option
219
- #
220
- shift
221
- if [ $# -eq 0 ]; then
222
- echo "[ERROR] --debuglevel(-d) option needs parameter(dbg/msg/warn/err)"
223
- exit 1
224
- fi
225
- if echo "$1" | grep -q -i -e "^dbg$" -e "^debug$"; then
226
- if [ "${DEBUG_ENV_LEVEL}" -ne 0 ]; then
227
- echo "[ERROR] --debuglevel(-d) option already is set"
228
- exit 1
229
- fi
230
- DEBUG_ENV_LEVEL=4
231
- elif echo "$1" | grep -q -i -e "^msg$" -e "^message$" -e "^info$"; then
232
- if [ "${DEBUG_ENV_LEVEL}" -ne 0 ]; then
233
- echo "[ERROR] --debuglevel(-d) option already is set"
234
- exit 1
235
- fi
236
- DEBUG_ENV_LEVEL=3
237
- elif echo "$1" | grep -q -i -e "^wan$" -e "^warn$" -e "^warning$"; then
238
- if [ "${DEBUG_ENV_LEVEL}" -ne 0 ]; then
239
- echo "[ERROR] --debuglevel(-d) option already is set"
240
- exit 1
241
- fi
242
- DEBUG_ENV_LEVEL=2
243
- elif echo "$1" | grep -q -i -e "^err$" -e "^error$"; then
244
- if [ "${DEBUG_ENV_LEVEL}" -ne 0 ]; then
245
- echo "[ERROR] --debuglevel(-d) option already is set"
246
- exit 1
247
- fi
248
- DEBUG_ENV_LEVEL=1
249
- else
250
- #
251
- # Custom debug level value
252
- #
253
- if [ -n "${DEBUG_ENV_CUSTOM}" ]; then
254
- DEBUG_ENV_CUSTOM="${DEBUG_ENV_CUSTOM},"
255
- fi
256
- DEBUG_ENV_CUSTOM="${DEBUG_ENV_CUSTOM}$1"
257
- fi
258
-
259
- else
260
- #
261
- # Run test command
262
- #
263
- if [ -n "${COMMAND}" ]; then
264
- echo "[ERROR] Already specified command name(${COMMAND}), could not specify multi command $1"
265
- exit 1
266
- fi
267
- if ! COMMAND=$(CheckCommands "$1"); then
268
- echo "[ERROR] $1 is not command name"
269
- exit 1
270
- fi
271
- fi
272
- shift
273
- done
274
-
275
- #
276
- # Check Command
277
- #
278
- if [ -z "${COMMAND}" ]; then
279
- echo "[ERROR] Command name is not specified"
280
- exit 1
281
- fi
282
-
283
- #
284
- # Make NODE_DEBUG environment
285
- #
286
- DEBUG_ENV_PARAM=""
287
- if [ "${DEBUG_ENV_LEVEL}" -ge 4 ]; then
288
- DEBUG_ENV_PARAM="LOGLEVEL_DBG"
289
- elif [ "${DEBUG_ENV_LEVEL}" -ge 3 ]; then
290
- DEBUG_ENV_PARAM="LOGLEVEL_MSG"
291
- elif [ "${DEBUG_ENV_LEVEL}" -ge 2 ]; then
292
- DEBUG_ENV_PARAM="LOGLEVEL_WAN"
293
- elif [ "${DEBUG_ENV_LEVEL}" -ge 1 ]; then
294
- DEBUG_ENV_PARAM="LOGLEVEL_ERR"
295
- else
296
- DEBUG_ENV_PARAM="LOGLEVEL_SILENT"
297
- fi
298
- if [ -n "${DEBUG_ENV_CUSTOM}" ]; then
299
- if [ -n "${DEBUG_ENV_PARAM}" ]; then
300
- DEBUG_ENV_PARAM="${DEBUG_ENV_PARAM},"
301
- fi
302
- DEBUG_ENV_PARAM="${DEBUG_ENV_PARAM}${DEBUG_ENV_CUSTOM}"
303
- fi
304
-
305
- #
306
- # Check HTTPS
307
- #
308
- if [ -z "${HTTPS_ENV}" ]; then
309
- HTTPS_ENV="yes"
310
- fi
311
-
312
- #
313
- # Check K2HR3 API HOST/PORT
314
- #
315
- if [ -z "${APIHOST}" ]; then
316
- APIHOST="$(hostname | tr -d '\n')"
317
- fi
318
- if [ "${APIPORT}" -eq 0 ]; then
319
- if [ "${HTTPS_ENV}" = "yes" ]; then
320
- APIPORT=443
321
- else
322
- APIPORT=3000
323
- fi
324
- fi
325
-
326
- #==========================================================
327
- # Do work
328
- #==========================================================
329
- cd "${SRCTOP}" || exit 1
330
-
331
- if [ "${DEBUG_ENV_LEVEL}" -ge 4 ]; then
332
- echo "***** RUN *****"
333
- echo "NODE_PATH=${NODE_PATH} NODE_DEBUG=${DEBUG_ENV_PARAM} APIHOST=${APIHOST} APIPORT=${APIPORT} HTTPS_ENV=${HTTPS_ENV} node ${DEBUG_OPTION} tests/${CMD_PREFIX}${COMMAND}${CMD_SUFFIX}"
334
- echo "***************"
335
- fi
336
-
337
- if ! /bin/sh -c "NODE_PATH=${NODE_PATH} NODE_DEBUG=${DEBUG_ENV_PARAM} APIHOST=${APIHOST} APIPORT=${APIPORT} HTTPS_ENV=${HTTPS_ENV} node ${DEBUG_OPTION} tests/${CMD_PREFIX}${COMMAND}${CMD_SUFFIX}"; then
338
- EXIT_CODE="$?"
339
- echo "[ERROR] Failed to run command with exit code : ${EXIT_CODE}"
340
- exit "${EXIT_CODE}"
341
- fi
342
-
343
- exit 0
344
-
345
- #
346
- # Local variables:
347
- # tab-width: 4
348
- # c-basic-offset: 4
349
- # End:
350
- # vim600: noexpandtab sw=4 ts=4 fdm=marker
351
- # vim<600: noexpandtab sw=4 ts=4
352
- #
@@ -1,173 +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: Tue Oct 9 2018
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 cryptutil = require('../lib/k2hr3cryptutil');
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 getV1UserData(registerpath, is_gzip)
45
- {
46
- var headers;
47
- if(is_gzip){
48
- headers = {
49
- 'Content-Type': 'application/octet-stream',
50
- 'User-Agent': 'Cloud-Init',
51
- 'Accept-Encoding': 'gzip'
52
- };
53
- }else{
54
- headers = {
55
- 'Content-Type': 'application/octet-stream',
56
- 'User-Agent': 'Cloud-Init'
57
- };
58
- }
59
- var options = {
60
- 'host': hostname,
61
- 'port': hostport,
62
- 'method': 'GET'
63
- };
64
-
65
- options.headers = headers;
66
- options.path = '/v1/userdata/' + encodeURI(registerpath);
67
-
68
- r3logger.dlog('request options = ' + JSON.stringify(options));
69
- r3logger.dlog('request headers = ' + JSON.stringify(headers));
70
-
71
- var _is_gzip = is_gzip;
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
-
90
- console.log('RESPONSE CODE = ' + res.statusCode);
91
- r3logger.dlog('response status = ' + res.statusCode);
92
- r3logger.dlog('response header = ' + JSON.stringify(res.headers));
93
-
94
- if(_is_gzip){
95
- response = [];
96
- }else{
97
- res.setEncoding('utf8');
98
- response = '';
99
- }
100
-
101
- res.on('data', function(chunk)
102
- {
103
- if(_is_gzip){
104
- response.push(chunk);
105
- }else{
106
- r3logger.dlog('response chunk = ' + chunk);
107
- response += chunk;
108
- }
109
- });
110
-
111
- res.on('end', function(result) // eslint-disable-line no-unused-vars
112
- {
113
- if(_is_gzip){
114
- // Buffer
115
- var buffer = Buffer.concat(response);
116
- r3logger.mlog(r3logger.dump(buffer)); // response is object(or not)
117
-
118
- var gunzipString= cryptutil.r3Gunzip(buffer);
119
- console.log('RESPONSE BODY(GUNZIP) = <<<\n' + gunzipString + '\n<<<');
120
- }else{
121
- // Text
122
- r3logger.mlog(r3logger.dump(response)); // response is object(or not)
123
- console.log('RESPONSE BODY = ' + JSON.stringify(response));
124
- }
125
- process.exit(0);
126
- });
127
- });
128
- req.on('error', function(e) {
129
- r3logger.elog('problem with request: ' + e.message);
130
- });
131
- req.end();
132
- }
133
-
134
- cliutil.getConsoleInput('Response Type (gzip or text(default)) : ', true, false, function(isbreak, type)
135
- {
136
- if(isbreak){
137
- process.exit(0);
138
- }
139
- var _type = type;
140
- var _is_gzip= false;
141
-
142
- if('' === apiutil.getSafeString(_type) || apiutil.compareCaseString('text', apiutil.getSafeString(_type))){
143
- _is_gzip = false;
144
- }else if(apiutil.compareCaseString('gzip', apiutil.getSafeString(_type))){
145
- _is_gzip = true;
146
- }else{
147
- process.exit(0);
148
- }
149
-
150
- cliutil.getConsoleInput('Register URI path : ', true, false, function(isbreak, registerpath)
151
- {
152
- if(isbreak){
153
- process.exit(0);
154
- }
155
- var _registerpath = registerpath;
156
-
157
- if('' === apiutil.getSafeString(_registerpath)){
158
- process.exit(0);
159
- }
160
-
161
- // run
162
- getV1UserData(_registerpath, _is_gzip);
163
- });
164
- });
165
-
166
- /*
167
- * Local variables:
168
- * tab-width: 4
169
- * c-basic-offset: 4
170
- * End:
171
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
172
- * vim<600: noexpandtab sw=4 ts=4
173
- */
@@ -1,136 +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 headV1UserTokens(token, method)
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/user/tokens',
54
- 'method': method,
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
- req.on('error', function(e) {
96
- r3logger.elog('problem with request: ' + e.message);
97
- });
98
-
99
- // send request
100
- req.end();
101
- }
102
-
103
- //
104
- // run
105
- //
106
- cliutil.getConsoleInput('Method(GET/HEAD) : ', true, false, function(isbreak, method)
107
- {
108
- if(isbreak){
109
- process.exit(0);
110
- }
111
-
112
- if(!apiutil.compareCaseString(method, 'GET') && !apiutil.compareCaseString(method, 'HEAD')){
113
- console.log('Method parameter(' + method + ') must be GET or HEAD\n');
114
- process.exit(0);
115
- }
116
- var _method = method.toUpperCase();
117
-
118
- cliutil.getConsoleInput('Token : ', true, false, function(isbreak, token)
119
- {
120
- if(isbreak){
121
- process.exit(0);
122
- }
123
- var _token = token;
124
-
125
- headV1UserTokens(_token, _method);
126
- });
127
- });
128
-
129
- /*
130
- * Local variables:
131
- * tab-width: 4
132
- * c-basic-offset: 4
133
- * End:
134
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
135
- * vim<600: noexpandtab sw=4 ts=4
136
- */