k2hr3-api 1.0.11 → 1.0.12

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 (121) hide show
  1. package/ChangeLog +18 -0
  2. package/app.js +7 -4
  3. package/bin/run.sh +218 -172
  4. package/bin/watcher +7 -4
  5. package/bin/www +7 -4
  6. package/config/default.json +7 -4
  7. package/config/development.json +7 -4
  8. package/config/dummyuser.json +8 -5
  9. package/config/extdata-dummy.sh.templ +12 -9
  10. package/config/k2hr3-cloud-config.txt.templ +7 -4
  11. package/config/k2hr3-init-error.sh.templ +8 -5
  12. package/config/k2hr3-init.sh.templ +127 -207
  13. package/config/keystone_v2.json +7 -4
  14. package/config/keystone_v3.json +7 -4
  15. package/lib/basicipcheck.js +7 -4
  16. package/lib/cacerts.js +7 -4
  17. package/lib/dbglogging.js +7 -4
  18. package/lib/dummyuserapi.js +7 -4
  19. package/lib/ipwatch.js +7 -4
  20. package/lib/k2hr3acrutil.js +7 -5
  21. package/lib/k2hr3apiutil.js +7 -4
  22. package/lib/k2hr3cliutil.js +7 -4
  23. package/lib/k2hr3config.js +7 -4
  24. package/lib/k2hr3cryptutil.js +7 -4
  25. package/lib/k2hr3dkc.js +7 -4
  26. package/lib/k2hr3extdata.js +7 -4
  27. package/lib/k2hr3keys.js +7 -4
  28. package/lib/k2hr3resutil.js +7 -4
  29. package/lib/k2hr3template.js +7 -4
  30. package/lib/k2hr3tokens.js +7 -4
  31. package/lib/k2hr3userdata.js +8 -5
  32. package/lib/k8soidc.js +1 -1
  33. package/lib/openstackapiv2.js +7 -4
  34. package/lib/openstackapiv3.js +7 -4
  35. package/lib/openstackep.js +7 -4
  36. package/package.json +73 -72
  37. package/routes/acr.js +7 -4
  38. package/routes/debugVerify.js +7 -4
  39. package/routes/extdata.js +7 -4
  40. package/routes/list.js +7 -4
  41. package/routes/policy.js +7 -4
  42. package/routes/resource.js +7 -4
  43. package/routes/role.js +7 -4
  44. package/routes/service.js +7 -4
  45. package/routes/userTokens.js +7 -4
  46. package/routes/userdata.js +7 -4
  47. package/routes/version.js +7 -4
  48. package/templ/Dockerfile.templ +35 -52
  49. package/{test → tests}/auto_acr.js +7 -4
  50. package/{test → tests}/auto_acr_spec.js +7 -4
  51. package/{test → tests}/auto_all_spec.js +7 -4
  52. package/{test → tests}/auto_common.js +7 -4
  53. package/tests/auto_control_subprocess.sh +239 -0
  54. package/{test → tests}/auto_extdata.js +7 -4
  55. package/{test → tests}/auto_extdata_spec.js +7 -4
  56. package/tests/auto_init_config_json.sh +275 -0
  57. package/{test → tests}/auto_k2hdkc_server.ini +7 -4
  58. package/{test → tests}/auto_k2hdkc_slave.ini +7 -4
  59. package/{test → tests}/auto_list.js +7 -4
  60. package/{test → tests}/auto_list_spec.js +7 -4
  61. package/{test → tests}/auto_policy.js +7 -4
  62. package/{test → tests}/auto_policy_spec.js +7 -4
  63. package/{test → tests}/auto_resource.js +7 -4
  64. package/{test → tests}/auto_resource_spec.js +7 -4
  65. package/{test → tests}/auto_role.js +7 -4
  66. package/{test → tests}/auto_role_spec.js +7 -4
  67. package/{test → tests}/auto_service.js +7 -4
  68. package/{test → tests}/auto_service_spec.js +7 -4
  69. package/{test → tests}/auto_subprocesses.js +14 -11
  70. package/tests/auto_template.sh +126 -0
  71. package/{test → tests}/auto_token_util.js +7 -4
  72. package/{test → tests}/auto_userdata.js +7 -4
  73. package/{test → tests}/auto_userdata_spec.js +7 -4
  74. package/{test → tests}/auto_usertokens.js +7 -4
  75. package/{test → tests}/auto_usertokens_spec.js +7 -4
  76. package/{test → tests}/auto_version.js +7 -4
  77. package/{test → tests}/auto_version_spec.js +7 -4
  78. package/{test → tests}/auto_watcher.js +7 -4
  79. package/{test → tests}/auto_watcher_spec.js +7 -4
  80. package/{test → tests}/k2hdkc_test.data +7 -4
  81. package/tests/k2hdkc_test_load.sh +255 -0
  82. package/{test → tests}/k2hr3template_test.js +7 -4
  83. package/tests/k2hr3template_test.sh +339 -0
  84. package/{test → tests}/k2hr3template_test_async.js +7 -4
  85. package/{test → tests}/k2hr3template_test_template.result +14 -8
  86. package/{test → tests}/k2hr3template_test_template.txt +7 -4
  87. package/{test → tests}/k2hr3template_test_vars.js +7 -4
  88. package/{test → tests}/manual_acr_delete.js +7 -4
  89. package/{test → tests}/manual_acr_get.js +7 -4
  90. package/{test → tests}/manual_acr_postput.js +7 -4
  91. package/{test → tests}/manual_allusertenant_get.js +7 -4
  92. package/{test → tests}/manual_extdata_get.js +7 -4
  93. package/{test → tests}/manual_k2hr3keys_get.js +7 -4
  94. package/{test → tests}/manual_list_gethead.js +7 -4
  95. package/{test → tests}/manual_policy_delete.js +7 -4
  96. package/{test → tests}/manual_policy_gethead.js +7 -4
  97. package/{test → tests}/manual_policy_postput.js +7 -4
  98. package/{test → tests}/manual_resource_delete.js +7 -4
  99. package/{test → tests}/manual_resource_gethead.js +7 -4
  100. package/{test → tests}/manual_resource_postput.js +7 -4
  101. package/{test → tests}/manual_role_delete.js +7 -4
  102. package/{test → tests}/manual_role_gethead.js +7 -4
  103. package/{test → tests}/manual_role_postput.js +7 -4
  104. package/{test → tests}/manual_service_delete.js +7 -4
  105. package/{test → tests}/manual_service_gethead.js +7 -4
  106. package/{test → tests}/manual_service_postput.js +7 -4
  107. package/tests/manual_test.sh +338 -0
  108. package/{test → tests}/manual_userdata_get.js +7 -4
  109. package/{test → tests}/manual_usertoken_gethead.js +7 -4
  110. package/{test → tests}/manual_usertoken_postput.js +7 -4
  111. package/{test → tests}/manual_version_get.js +7 -4
  112. package/tests/run_local_test_k2hdkc.sh +174 -0
  113. package/tests/test.sh +331 -0
  114. package/test/auto_control_subprocess.sh +0 -170
  115. package/test/auto_init_config_json.sh +0 -246
  116. package/test/auto_template.sh +0 -127
  117. package/test/auto_test.sh +0 -321
  118. package/test/k2hdkc_test_load.sh +0 -198
  119. package/test/k2hr3template_test.sh +0 -296
  120. package/test/manual_test.sh +0 -321
  121. package/test/run_local_test_k2hdkc.sh +0 -154
@@ -0,0 +1,255 @@
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: Thu Nov 9 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
+ K2HR3_DKC_DIR=$(cd "${SRCTOP}/../k2hr3_dkc" || exit 1; pwd)
33
+ K2HR3_DKC_CONF_PATH="${K2HR3_DKC_DIR}/conf"
34
+
35
+ TEST_DATA_FILENAME="k2hdkc_test.data"
36
+ TEST_DATA_TEMPLATE_FILE="${SCRIPTDIR}/${TEST_DATA_FILENAME}"
37
+ TEST_DATA_CUSTOMIZED_FILE="/tmp/${TEST_DATA_FILENAME}"
38
+
39
+ AUTO_K2HDKC_CONF_PATH="${SRCTOP}/tests/auto_k2hdkc_slave.ini"
40
+ AUTO_K2HDKC_CTRL_PORT=18031
41
+
42
+ DEFAULT_REMOTE_K2HDKC_CONF_PATH="${K2HR3_DKC_CONF_PATH}/slave.ini"
43
+ DEFAULT_REMOTE_K2HDKC_CTRL_PORT=8031
44
+ DEFAULT_TENANT_MAIN="tenant0"
45
+ DEFAULT_TENANT_SUB="tenant1"
46
+
47
+ #==============================================================
48
+ # Utility functions
49
+ #==============================================================
50
+ #
51
+ # Usage
52
+ #
53
+ PrintUsage()
54
+ {
55
+ echo "Usage: $1 --for_auto_test(-f)"
56
+ echo " $1 --main(-m) <main tenant name> --sub(-s) <sub tenant name> [--conf(-c) <conf file>] [--port(-p) <port>]"
57
+ echo ""
58
+ echo "Option:"
59
+ echo " --for_auto_test(-f) for local k2hdkc as auto testing(dummyuser)"
60
+ echo " --main(-m) specify main tenant name for remote k2hr3 cluster"
61
+ echo " --sub(-s) specify sub tenant name for remote k2hr3 cluster"
62
+ echo " --conf(-c) specify slave chmpx conf file for remote k2hr3 cluster(default is ../k2hr3_dkc/conf)"
63
+ echo " --port(-p) specify slave chmpx port for remote k2hr3 cluster(default is ../k2hr3_dkc/conf)"
64
+ echo ""
65
+ }
66
+
67
+ #==========================================================
68
+ # Parse options
69
+ #==========================================================
70
+ EXEC_MODE=""
71
+ TENANT_MAIN=""
72
+ TENANT_SUB=""
73
+ REMOTE_K2HDKC_CONF_PATH=""
74
+ REMOTE_K2HDKC_CTRL_PORT=""
75
+
76
+ while [ $# -ne 0 ]; do
77
+ if [ -z "$1" ]; then
78
+ break
79
+
80
+ elif [ "$1" = "-h" ] || [ "$1" = "-H" ] || [ "$1" = "--help" ] || [ "$1" = "--HELP" ]; then
81
+ PrintUsage "${PRGNAME}"
82
+ exit 0
83
+
84
+ elif [ "$1" = "-f" ] || [ "$1" = "-F" ] || [ "$1" = "--for_auto_test" ] || [ "$1" = "--FOR_AUTO_TEST" ]; then
85
+ if [ -n "${EXEC_MODE}" ]; then
86
+ echo "[ERROR] Already specified --for_auto_test(-f) or --main(-m) or --sub(-s) option."
87
+ exit 1
88
+ fi
89
+ EXEC_MODE="auto"
90
+
91
+ elif [ "$1" = "--main" ] || [ "$1" = "--MAIN" ] || [ "$1" = "-m" ] || [ "$1" = "-M" ]; then
92
+ #
93
+ # input main tenant name
94
+ #
95
+ if [ -n "${EXEC_MODE}" ] && [ "${EXEC_MODE}" = "auto" ]; then
96
+ echo "[ERROR] Already specified --for_auto_test(-f) or --main(-m) or --sub(-s) option."
97
+ exit 1
98
+ fi
99
+ if [ -n "${TENANT_MAIN}" ]; then
100
+ echo "[ERROR] Already specified --main(-m) option."
101
+ exit 1
102
+ fi
103
+ shift
104
+ if [ $# -eq 0 ]; then
105
+ echo "[ERROR] --main(-m) option needs parameter"
106
+ exit 1
107
+ fi
108
+ TENANT_MAIN="$1"
109
+ EXEC_MODE="notauto"
110
+
111
+ elif [ "$1" = "--sub" ] || [ "$1" = "--SUB" ] || [ "$1" = "-s" ] || [ "$1" = "-S" ]; then
112
+ #
113
+ # input sub tenant name
114
+ #
115
+ if [ -n "${EXEC_MODE}" ] && [ "${EXEC_MODE}" = "auto" ]; then
116
+ echo "[ERROR] Already specified --for_auto_test(-f) or --main(-m) or --sub(-s) option."
117
+ exit 1
118
+ fi
119
+ if [ -n "${TENANT_SUB}" ]; then
120
+ echo "[ERROR] Already specified --sub(-s) option."
121
+ exit 1
122
+ fi
123
+ shift
124
+ if [ $# -eq 0 ]; then
125
+ echo "[ERROR] --sub(-s) option needs parameter"
126
+ exit 1
127
+ fi
128
+ TENANT_SUB="$1"
129
+ EXEC_MODE="notauto"
130
+
131
+ elif [ "$1" = "--conf" ] || [ "$1" = "--CONF" ] || [ "$1" = "-c" ] || [ "$1" = "-C" ]; then
132
+ if [ -n "${EXEC_MODE}" ] && [ "${EXEC_MODE}" = "auto" ]; then
133
+ echo "[ERROR] --conf(-c) option is specified, but already set --for_auto_test(-f) option."
134
+ exit 1
135
+ fi
136
+ if [ -n "${REMOTE_K2HDKC_CONF_PATH}" ]; then
137
+ echo "[ERROR] Already specified --conf(-c) option."
138
+ exit 1
139
+ fi
140
+ shift
141
+ if [ $# -eq 0 ]; then
142
+ echo "[ERROR] --conf(-c) option needs parameter"
143
+ exit 1
144
+ fi
145
+ if [ ! -f "$1" ]; then
146
+ echo "[ERROR] $1 file is not existed"
147
+ exit 1
148
+ fi
149
+ REMOTE_K2HDKC_CONF_PATH="$1"
150
+ EXEC_MODE="notauto"
151
+
152
+ elif [ "$1" = "--port" ] || [ "$1" = "--PORT" ] || [ "$1" = "-p" ] || [ "$1" = "-P" ]; then
153
+ if [ -n "${EXEC_MODE}" ] && [ "${EXEC_MODE}" = "auto" ]; then
154
+ echo "[ERROR] --port(-p) option is specified, but already set --for_auto_test(-f) option."
155
+ exit 1
156
+ fi
157
+ if [ "${REMOTE_K2HDKC_CTRL_PORT}" -ne 0 ]; then
158
+ echo "[ERROR] Already specified --port(-p) option."
159
+ exit 1
160
+ fi
161
+ shift
162
+ if [ $# -eq 0 ]; then
163
+ echo "[ERROR] --port(-p) option needs parameter"
164
+ exit 1
165
+ fi
166
+ if echo "$1" | grep -q '[^0-9]'; then
167
+ echo "[ERROR] --port(-p) option parameter must be number"
168
+ exit 1
169
+ elif [ "$1" -eq 0 ]; then
170
+ echo "[ERROR] --port(-p) option parameter must be positive number"
171
+ exit 1
172
+ fi
173
+ REMOTE_K2HDKC_CTRL_PORT="$1"
174
+ EXEC_MODE="notauto"
175
+
176
+ else
177
+ echo "[ERROR] Unknown option $1"
178
+ exit 1
179
+ fi
180
+ shift
181
+ done
182
+
183
+ #
184
+ # Check options
185
+ #
186
+ if [ -z "${EXEC_MODE}" ]; then
187
+ echo "[ERROR] no option is specified."
188
+ exit 1
189
+ fi
190
+
191
+ #
192
+ # Check and set values
193
+ #
194
+ if [ -z "${TENANT_MAIN}" ]; then
195
+ TENANT_MAIN="${DEFAULT_TENANT_MAIN}"
196
+ fi
197
+ if [ -z "${TENANT_SUB}" ]; then
198
+ TENANT_SUB="${DEFAULT_TENANT_SUB}"
199
+ fi
200
+ if [ -z "${REMOTE_K2HDKC_CONF_PATH}" ]; then
201
+ REMOTE_K2HDKC_CONF_PATH="${DEFAULT_REMOTE_K2HDKC_CONF_PATH}"
202
+ fi
203
+ if [ -z "${REMOTE_K2HDKC_CTRL_PORT}" ]; then
204
+ REMOTE_K2HDKC_CTRL_PORT="${DEFAULT_REMOTE_K2HDKC_CTRL_PORT}"
205
+ fi
206
+
207
+ if [ "${EXEC_MODE}" = "auto" ]; then
208
+ K2HDKC_CONF_PATH="${AUTO_K2HDKC_CONF_PATH}"
209
+ K2HDKC_CTRL_PORT="${AUTO_K2HDKC_CTRL_PORT}"
210
+ LOCAL_HOSTNAME="$(hostname | tr -d '\n')"
211
+ IPADDR="127.10.10.10"
212
+ else
213
+ K2HDKC_CONF_PATH="${REMOTE_K2HDKC_CONF_PATH}"
214
+ K2HDKC_CTRL_PORT="${REMOTE_K2HDKC_CTRL_PORT}"
215
+ LOCAL_HOSTNAME="$(hostname | tr -d '\n')"
216
+ IPADDR="$(nslookup "${LOCAL_HOSTNAME}" | grep 'Address' | grep -v '#' | awk '{print $2}' | head -1 | tr -d '\n')"
217
+ fi
218
+
219
+ if [ ! -f "${K2HDKC_CONF_PATH}" ]; then
220
+ echo "[ERROR] slave chmpx configuration file(${K2HDKC_CONF_PATH}) does not exist."
221
+ exit 1
222
+ fi
223
+
224
+ #==========================================================
225
+ # Do work
226
+ #==========================================================
227
+ #
228
+ # Copy file with convert
229
+ #
230
+ if ! sed -e "s#__LOCAL_HOST_NAME__#${LOCAL_HOSTNAME}#g" -e "s#__LOCAL_HOST_IP__#${IPADDR}#g" -e "s#__TENANT_NAME_MAIN__#${TENANT_MAIN}#g" -e "s#__TENANT_NAME_SUB__#${TENANT_SUB}#g" "${TEST_DATA_TEMPLATE_FILE}" >"${TEST_DATA_CUSTOMIZED_FILE}" 2>/dev/null; then
231
+ echo "[ERROR] Failed to convert and copy file(${SCRIPTDIR}/k2hdkc_test.data) to /tmp."
232
+ exit 1
233
+ fi
234
+
235
+ #
236
+ # Run process
237
+ #
238
+ if ! k2hdkclinetool -conf "${K2HDKC_CONF_PATH}" -ctlport "${K2HDKC_CTRL_PORT}" -run "${TEST_DATA_CUSTOMIZED_FILE}" >/dev/null 2>&1; then
239
+ echo "[ERROR] Failed to load test data."
240
+ rm -f "${TEST_DATA_CUSTOMIZED_FILE}"
241
+ exit 1
242
+ fi
243
+ rm -f "${TEST_DATA_CUSTOMIZED_FILE}"
244
+ echo "[SUCCEED] Loaded test data."
245
+
246
+ exit 0
247
+
248
+ #
249
+ # Local variables:
250
+ # tab-width: 4
251
+ # c-basic-offset: 4
252
+ # End:
253
+ # vim600: noexpandtab sw=4 ts=4 fdm=marker
254
+ # vim<600: noexpandtab sw=4 ts=4
255
+ #
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * K2HR3 REST API
3
3
  *
4
- * Copyright 2017 Yahoo! Japan Corporation.
4
+ * Copyright 2017 Yahoo Japan Corporation.
5
5
  *
6
6
  * K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
7
7
  * common management information for the cloud.
@@ -175,7 +175,10 @@ fs.readFile(templfile, 'utf8', function(err, templString)
175
175
  });
176
176
 
177
177
  /*
178
- * VIM modelines
179
- *
180
- * vim:set ts=4 fenc=utf-8:
178
+ * Local variables:
179
+ * tab-width: 4
180
+ * c-basic-offset: 4
181
+ * End:
182
+ * vim600: noexpandtab sw=4 ts=4 fdm=marker
183
+ * vim<600: noexpandtab sw=4 ts=4
181
184
  */
@@ -0,0 +1,339 @@
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 Jul 12 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
+ LOCAL_HOSTNAME="$(hostname | tr -d '\n')"
33
+ DEFAULT_TEST_PROG="tests/k2hr3template_test.js"
34
+ ASYNC_TEST_PROG="tests/k2hr3template_test_async.js"
35
+
36
+ #==============================================================
37
+ # Utility functions
38
+ #==============================================================
39
+ #
40
+ # Usage
41
+ #
42
+ PrintUsage()
43
+ {
44
+ echo "Usage: $1 [--inspect(-i)]"
45
+ echo " [--debuglevel(-d) DBG/MSG/WARN/ERR/(custom debug level)]"
46
+ echo " [--varlist(-v) \"variables JSON file path\"]"
47
+ echo " {--templ(-t) \"template file path\" | --string(-s) \"template string\"}"
48
+ echo " {--async(-a)}"
49
+ echo ""
50
+ echo " If you do not specify input file path or template string,"
51
+ echo " $1 prompts you to enter a template string from stdin."
52
+ echo ""
53
+ }
54
+
55
+ #==========================================================
56
+ # Parse options
57
+ #==========================================================
58
+ INPUT_TEMPLFILE=""
59
+ INPUT_TEMPLSTR=""
60
+ INPUT_VARFILE=""
61
+ INPUT_ASYNCMODE=0
62
+ DEBUG_USE_INSPECT=0
63
+ DEBUG_ENV_LEVEL=0
64
+ DEBUG_ENV_CUSTOM=""
65
+
66
+ while [ $# -ne 0 ]; do
67
+ if [ -z "$1" ]; then
68
+ break
69
+
70
+ elif [ "$1" = "-h" ] || [ "$1" = "-H" ] || [ "$1" = "--help" ] || [ "$1" = "--HELP" ]; then
71
+ PrintUsage "${PRGNAME}"
72
+ exit 0
73
+
74
+ elif [ "$1" = "-i" ] || [ "$1" = "-I" ] || [ "$1" = "--inspect" ] || [ "$1" = "--INSPECT" ]; then
75
+ if [ "${DEBUG_USE_INSPECT}" -ne 0 ]; then
76
+ echo "[ERROR] Already specified --inspect(-i) option"
77
+ exit 1
78
+ fi
79
+ DEBUG_USE_INSPECT=1
80
+
81
+ elif [ "$1" = "-d" ] || [ "$1" = "-D" ] || [ "$1" = "--debuglevel" ] || [ "$1" = "--DEBUGLEVEL" ]; then
82
+ #
83
+ # DEBUG option
84
+ #
85
+ shift
86
+ if [ $# -eq 0 ]; then
87
+ echo "[ERROR] --debuglevel(-dl) option needs parameter(dbg/msg/warn/err/custom debug level)"
88
+ exit 1
89
+ fi
90
+ if [ "$1" = "dbg" ] || [ "$1" = "DBG" ] || [ "$1" = "debug" ] || [ "$1" = "DEBUG" ]; then
91
+ if [ "${DEBUG_ENV_LEVEL}" -ne 0 ]; then
92
+ echo "[ERROR] --debuglevel(-dl) option already is set"
93
+ exit 1
94
+ fi
95
+ DEBUG_ENV_LEVEL=4
96
+ elif [ "$1" = "msg" ] || [ "$1" = "MSG" ] || [ "$1" = "message" ] || [ "$1" = "MESSAGE" ] || [ "$1" = "info" ] || [ "$1" = "INFO" ]; then
97
+ if [ "${DEBUG_ENV_LEVEL}" -ne 0 ]; then
98
+ echo "[ERROR] --debuglevel(-dl) option already is set"
99
+ exit 1
100
+ fi
101
+ DEBUG_ENV_LEVEL=3
102
+ elif [ "$1" = "warn" ] || [ "$1" = "WARN" ] || [ "$1" = "warning" ] || [ "$1" = "WARNING" ]; then
103
+ if [ "${DEBUG_ENV_LEVEL}" -ne 0 ]; then
104
+ echo "[ERROR] --debuglevel(-dl) option already is set"
105
+ exit 1
106
+ fi
107
+ DEBUG_ENV_LEVEL=2
108
+ elif [ "$1" = "err" ] || [ "$1" = "ERR" ] || [ "$1" = "error" ] || [ "$1" = "ERROR" ]; then
109
+ if [ "${DEBUG_ENV_LEVEL}" -ne 0 ]; then
110
+ echo "[ERROR] --debuglevel(-dl) option already is set"
111
+ exit 1
112
+ fi
113
+ DEBUG_ENV_LEVEL=1
114
+ else
115
+ #
116
+ # Custom debug level value
117
+ #
118
+ if [ -n "${DEBUG_ENV_CUSTOM}" ]; then
119
+ DEBUG_ENV_CUSTOM="${DEBUG_ENV_CUSTOM},"
120
+ fi
121
+ DEBUG_ENV_CUSTOM="${DEBUG_ENV_CUSTOM}$1"
122
+ fi
123
+
124
+ elif [ "$1" = "-v" ] || [ "$1" = "-V" ] || [ "$1" = "--varlist" ] || [ "$1" = "--VARLIST" ]; then
125
+ #
126
+ # input variable list file path
127
+ #
128
+ if [ -n "${INPUT_VARFILE}" ]; then
129
+ echo "[ERROR] Already specified variable list file ${INPUT_VARFILE}"
130
+ exit 1
131
+ fi
132
+ shift
133
+ if [ $# -eq 0 ]; then
134
+ echo "[ERROR] --varlist(-v) option needs parameter( input variable JSON file path )"
135
+ exit 1
136
+ fi
137
+ if [ ! -f "$1" ]; then
138
+ echo "[ERROR] could not find variable list file $1"
139
+ exit 1
140
+ fi
141
+ INPUT_VARFILE="$1"
142
+
143
+ elif [ "$1" = "-t" ] || [ "$1" = "-T" ] || [ "$1" = "--templ" ] || [ "$1" = "--TEMPL" ] || [ "$1" = "--template" ] || [ "$1" = "--TEMPLATE" ]; then
144
+ #
145
+ # input template file path
146
+ #
147
+ if [ -n "${INPUT_TEMPLFILE}" ]; then
148
+ echo "[ERROR] Already specified template file ${INPUT_TEMPLFILE}"
149
+ exit 1
150
+ fi
151
+ if [ -n "${INPUT_TEMPLSTR}" ]; then
152
+ echo "[ERROR] Already specified template string \"${INPUT_TEMPLSTR}\""
153
+ exit 1
154
+ fi
155
+ shift
156
+ if [ $# -eq 0 ]; then
157
+ echo "[ERROR] --templ(-t) option needs parameter( input template file path )"
158
+ exit 1
159
+ fi
160
+ if [ ! -f "$1" ]; then
161
+ echo "[ERROR] could not find template file $1"
162
+ exit 1
163
+ fi
164
+ INPUT_TEMPLFILE="$1"
165
+
166
+ elif [ "$1" = "-s" ] || [ "$1" = "-S" ] || [ "$1" = "--str" ] || [ "$1" = "--STR" ] || [ "$1" = "--string" ] || [ "$1" = "--STRING" ]; then
167
+ #
168
+ # input template string
169
+ #
170
+ if [ -n "${INPUT_TEMPLSTR}" ]; then
171
+ echo "[ERROR] Already specified template string ${INPUT_TEMPLSTR}"
172
+ exit 1
173
+ fi
174
+ if [ -n "${INPUT_TEMPLFILE}" ]; then
175
+ echo "[ERROR] Already specified template file ${INPUT_TEMPLFILE}"
176
+ exit 1
177
+ fi
178
+ shift
179
+ if [ $# -eq 0 ]; then
180
+ echo "[ERROR] --string(-s) option needs parameter( input template string )"
181
+ exit 1
182
+ fi
183
+ INPUT_TEMPLSTR="$1"
184
+
185
+ elif [ "$1" = "-a" ] || [ "$1" = "-A" ] || [ "$1" = "--async" ] || [ "$1" = "--ASYNC" ]; then
186
+ #
187
+ # async mode
188
+ #
189
+ if [ "${INPUT_ASYNCMODE}" -ne 0 ]; then
190
+ echo "[ERROR] --async(-a) option is already specified"
191
+ exit 1
192
+ fi
193
+ INPUT_ASYNCMODE=1
194
+
195
+ else
196
+ echo "[ERROR] unknown option $1"
197
+ exit 1
198
+ fi
199
+ shift
200
+ done
201
+
202
+ #----------------------------------------------------------
203
+ # Set varibales and files
204
+ #----------------------------------------------------------
205
+ #
206
+ # Checking async mode
207
+ #
208
+ if [ "${INPUT_ASYNCMODE}" -eq 0 ]; then
209
+ TEST_PROG="${DEFAULT_TEST_PROG}"
210
+ else
211
+ TEST_PROG="${ASYNC_TEST_PROG}"
212
+ fi
213
+
214
+ #
215
+ # Make NODE_DEBUG environment
216
+ #
217
+ DEBUG_ENV_PARAM=""
218
+ if [ "${DEBUG_ENV_LEVEL}" -ge 4 ]; then
219
+ DEBUG_ENV_PARAM="LOGLEVEL_DBG"
220
+ elif [ "${DEBUG_ENV_LEVEL}" -ge 3 ]; then
221
+ DEBUG_ENV_PARAM="LOGLEVEL_MSG"
222
+ elif [ "${DEBUG_ENV_LEVEL}" -ge 2 ]; then
223
+ DEBUG_ENV_PARAM="LOGLEVEL_WAN"
224
+ elif [ "${DEBUG_ENV_LEVEL}" -ge 1 ]; then
225
+ DEBUG_ENV_PARAM="LOGLEVEL_ERR"
226
+ else
227
+ DEBUG_ENV_PARAM="LOGLEVEL_SILENT"
228
+ fi
229
+ if [ -n "${DEBUG_ENV_CUSTOM}" ]; then
230
+ if [ -n "${DEBUG_ENV_PARAM}" ]; then
231
+ DEBUG_ENV_PARAM="${DEBUG_ENV_PARAM},"
232
+ fi
233
+ DEBUG_ENV_PARAM="${DEBUG_ENV_PARAM}${DEBUG_ENV_CUSTOM}"
234
+ fi
235
+
236
+ #
237
+ # Create Template file
238
+ #
239
+ rm -f /tmp/"${PRGNAME}".templ.*
240
+
241
+ if [ -z "${INPUT_TEMPLFILE}" ]; then
242
+ #
243
+ # Temporary template file
244
+ #
245
+ INPUT_TEMPLFILE="/tmp/${PRGNAME}.templ.$$"
246
+
247
+ if [ "${INPUT_TEMPLSTR}" != "" ]; then
248
+ #
249
+ # Put input template string to temporary file
250
+ #
251
+ if ! echo "${INPUT_TEMPLSTR}" >"${INPUT_TEMPLFILE}"; then
252
+ echo "[ERROR] Could not create ${INPUT_TEMPLFILE} file"
253
+ exit 1
254
+ fi
255
+ else
256
+ #
257
+ # Get template string from stdin
258
+ #
259
+ if ! touch "${INPUT_TEMPLFILE}"; then
260
+ echo "[ERROR] Could not create ${INPUT_TEMPLFILE} file"
261
+ exit 1
262
+ fi
263
+
264
+ echo "---------------------------------------------------------------"
265
+ echo " Please input template string."
266
+ echo " You can end template string input by entering \"EOF\"."
267
+ echo "---------------------------------------------------------------"
268
+
269
+ IS_EOF=0
270
+ while [ "${IS_EOF}" -eq 0 ]; do
271
+ printf '> '
272
+ read -r TEMPLLINE
273
+
274
+ if [ "${TEMPLLINE}" = "EOF" ] || [ "${TEMPLLINE}" = "eof" ]; then
275
+ IS_EOF=1
276
+ else
277
+ echo "${TEMPLLINE}" >> "${INPUT_TEMPLFILE}"
278
+ fi
279
+ done
280
+ echo ""
281
+ fi
282
+ fi
283
+
284
+ #
285
+ # Input template string
286
+ #
287
+ if [ "${DEBUG_ENV_LEVEL}" -ge 4 ]; then
288
+ echo "---------------------------------------------------------------"
289
+ echo " Template string"
290
+ echo "---------------------------------------------------------------"
291
+ sed -e 's/^/ /g' "${INPUT_TEMPLFILE}"
292
+ echo "---------------------------------------------------------------"
293
+ fi
294
+
295
+ #==========================================================
296
+ # Do work
297
+ #==========================================================
298
+ cd "${SRCTOP}" || exit 1
299
+
300
+ if [ "${DEBUG_USE_INSPECT}" -eq 1 ]; then
301
+ DEBUG_INSPECT_OPTION="--inspect"
302
+ DEBUG_BREAK_OPTION="--debug-brk"
303
+ DEBUG_PRINT_OPTIONS="${DEBUG_INSPECT_OPTION} ${DEBUG_BREAK_OPTION} "
304
+ DEBUG_PRINT_PIPELINE=" | sed -e 's/127.0.0.1/${LOCAL_HOSTNAME}/'"
305
+ else
306
+ DEBUG_PRINT_OPTIONS=""
307
+ DEBUG_PRINT_PIPELINE=""
308
+ fi
309
+
310
+ if [ "${DEBUG_ENV_LEVEL}" -ge 4 ]; then
311
+ echo "***** Run *****"
312
+ echo "NODE_PATH=${NODE_PATH} NODE_DEBUG=${DEBUG_ENV_PARAM} R3TEMPLFILE=${INPUT_TEMPLFILE} R3VARFILE=${INPUT_VARFILE} node ${DEBUG_PRINT_OPTIONS}${TEST_PROG}${DEBUG_PRINT_PIPELINE}"
313
+ echo ""
314
+ fi
315
+
316
+ if [ "${DEBUG_USE_INSPECT}" -eq 1 ]; then
317
+ if ! NODE_PATH="${NODE_PATH}" NODE_DEBUG="${DEBUG_ENV_PARAM}" R3TEMPLFILE="${INPUT_TEMPLFILE}" R3VARFILE="${INPUT_VARFILE}" node "${DEBUG_INSPECT_OPTION}" "${DEBUG_BREAK_OPTION}" "${TEST_PROG}" 2>&1 | sed -e "s/127.0.0.1/${LOCAL_HOSTNAME}/"; then
318
+ EXIT_CODE="$?"
319
+ echo "[ERROR] Failed to run test with error code : ${EXIT_CODE}"
320
+ exit 1
321
+ fi
322
+ else
323
+ if ! NODE_PATH="${NODE_PATH}" NODE_DEBUG="${DEBUG_ENV_PARAM}" R3TEMPLFILE="${INPUT_TEMPLFILE}" R3VARFILE="${INPUT_VARFILE}" node "${TEST_PROG}"; then
324
+ EXIT_CODE="$?"
325
+ echo "[ERROR] Failed to run test with error code : ${EXIT_CODE}"
326
+ exit 1
327
+ fi
328
+ fi
329
+
330
+ exit 0
331
+
332
+ #
333
+ # Local variables:
334
+ # tab-width: 4
335
+ # c-basic-offset: 4
336
+ # End:
337
+ # vim600: noexpandtab sw=4 ts=4 fdm=marker
338
+ # vim<600: noexpandtab sw=4 ts=4
339
+ #
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * K2HR3 REST API
3
3
  *
4
- * Copyright 2017 Yahoo! Japan Corporation.
4
+ * Copyright 2017 Yahoo Japan Corporation.
5
5
  *
6
6
  * K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
7
7
  * common management information for the cloud.
@@ -204,7 +204,10 @@ fs.readFile(templfile, 'utf8', function(err, templString)
204
204
  });
205
205
 
206
206
  /*
207
- * VIM modelines
208
- *
209
- * vim:set ts=4 fenc=utf-8:
207
+ * Local variables:
208
+ * tab-width: 4
209
+ * c-basic-offset: 4
210
+ * End:
211
+ * vim600: noexpandtab sw=4 ts=4 fdm=marker
212
+ * vim<600: noexpandtab sw=4 ts=4
210
213
  */
@@ -7,7 +7,7 @@ result = succeed
7
7
  input string = #
8
8
  # K2HR3 REST API
9
9
  #
10
- # Copyright 2017 Yahoo! Japan Corporation.
10
+ # Copyright 2017 Yahoo Japan Corporation.
11
11
  #
12
12
  # K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
13
13
  # common management information for the cloud.
@@ -3605,15 +3605,18 @@ input string = #
3605
3605
  #### TEST END
3606
3606
  ############################################################
3607
3607
  #
3608
- # VIM modelines
3609
- #
3610
- # vim:set ts=4 fenc=utf-8:
3608
+ # Local variables:
3609
+ # tab-width: 4
3610
+ # c-basic-offset: 4
3611
+ # End:
3612
+ # vim600: noexpandtab sw=4 ts=4 fdm=marker
3613
+ # vim<600: noexpandtab sw=4 ts=4
3611
3614
  #
3612
3615
 
3613
3616
  output string = #
3614
3617
  # K2HR3 REST API
3615
3618
  #
3616
- # Copyright 2017 Yahoo! Japan Corporation.
3619
+ # Copyright 2017 Yahoo Japan Corporation.
3617
3620
  #
3618
3621
  # K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
3619
3622
  # common management information for the cloud.
@@ -7103,9 +7106,12 @@ false
7103
7106
  #### TEST END
7104
7107
  ############################################################
7105
7108
  #
7106
- # VIM modelines
7107
- #
7108
- # vim:set ts=4 fenc=utf-8:
7109
+ # Local variables:
7110
+ # tab-width: 4
7111
+ # c-basic-offset: 4
7112
+ # End:
7113
+ # vim600: noexpandtab sw=4 ts=4 fdm=marker
7114
+ # vim<600: noexpandtab sw=4 ts=4
7109
7115
  #
7110
7116
 
7111
7117
  ----------------------------------------------------------------