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.
- package/config/k2hr3-init.sh.templ +2 -2
- package/dist/.gitkeep +0 -0
- package/dist/src/app.js +262 -0
- package/{bin → dist/src/bin}/run.sh +1 -1
- package/dist/src/bin/watcher.js +113 -0
- package/dist/src/bin/www.js +217 -0
- package/dist/src/lib/basicipcheck.js +392 -0
- package/dist/src/lib/cacerts.js +106 -0
- package/dist/src/lib/dbglogging.js +190 -0
- package/dist/src/lib/dummyuserapi.js +719 -0
- package/dist/src/lib/ipwatch.js +354 -0
- package/dist/src/lib/k2hr3acrutil.js +532 -0
- package/dist/src/lib/k2hr3apiutil.js +1444 -0
- package/dist/src/lib/k2hr3cliutil.js +183 -0
- package/dist/src/lib/k2hr3config.js +832 -0
- package/dist/src/lib/k2hr3cryptutil.js +258 -0
- package/dist/src/lib/k2hr3dkc.js +12121 -0
- package/dist/src/lib/k2hr3extdata.js +198 -0
- package/dist/src/lib/k2hr3keys.js +207 -0
- package/dist/src/lib/k2hr3resutil.js +111 -0
- package/dist/src/lib/k2hr3template.js +6546 -0
- package/dist/src/lib/k2hr3tokens.js +2643 -0
- package/dist/src/lib/k2hr3userdata.js +296 -0
- package/dist/src/lib/k8soidc.js +1000 -0
- package/dist/src/lib/openstackapiv2.js +695 -0
- package/dist/src/lib/openstackapiv3.js +932 -0
- package/dist/src/lib/openstackep.js +667 -0
- package/{tests/auto_common.js → dist/src/lib/types.js} +4 -38
- package/dist/src/routes/acr.js +704 -0
- package/dist/src/routes/debugVerify.js +294 -0
- package/dist/src/routes/extdata.js +219 -0
- package/dist/src/routes/list.js +264 -0
- package/dist/src/routes/policy.js +840 -0
- package/dist/src/routes/resource.js +1489 -0
- package/dist/src/routes/role.js +2627 -0
- package/dist/src/routes/service.js +908 -0
- package/dist/src/routes/tenant.js +1141 -0
- package/dist/src/routes/userTokens.js +482 -0
- package/dist/src/routes/userdata.js +212 -0
- package/dist/src/routes/version.js +103 -0
- package/package.json +152 -121
- package/ChangeLog +0 -372
- package/app.js +0 -292
- package/bin/watcher +0 -122
- package/bin/www +0 -180
- package/eslint.config.mjs +0 -68
- package/lib/basicipcheck.js +0 -376
- package/lib/cacerts.js +0 -71
- package/lib/dbglogging.js +0 -151
- package/lib/dummyuserapi.js +0 -766
- package/lib/ipwatch.js +0 -379
- package/lib/k2hr3acrutil.js +0 -516
- package/lib/k2hr3apiutil.js +0 -1494
- package/lib/k2hr3cliutil.js +0 -191
- package/lib/k2hr3config.js +0 -826
- package/lib/k2hr3cryptutil.js +0 -254
- package/lib/k2hr3dkc.js +0 -12632
- package/lib/k2hr3extdata.js +0 -198
- package/lib/k2hr3keys.js +0 -234
- package/lib/k2hr3resutil.js +0 -100
- package/lib/k2hr3template.js +0 -6925
- package/lib/k2hr3tokens.js +0 -2799
- package/lib/k2hr3userdata.js +0 -312
- package/lib/k8soidc.js +0 -1012
- package/lib/openstackapiv2.js +0 -764
- package/lib/openstackapiv3.js +0 -1032
- package/lib/openstackep.js +0 -553
- package/routes/acr.js +0 -738
- package/routes/debugVerify.js +0 -263
- package/routes/extdata.js +0 -232
- package/routes/list.js +0 -270
- package/routes/policy.js +0 -869
- package/routes/resource.js +0 -1441
- package/routes/role.js +0 -2664
- package/routes/service.js +0 -894
- package/routes/tenant.js +0 -1095
- package/routes/userTokens.js +0 -511
- package/routes/userdata.js +0 -218
- package/routes/version.js +0 -108
- package/templ/Dockerfile.templ +0 -71
- package/tests/auto_acr.js +0 -1101
- package/tests/auto_acr_spec.js +0 -79
- package/tests/auto_all_spec.js +0 -142
- package/tests/auto_control_subprocess.sh +0 -243
- package/tests/auto_extdata.js +0 -220
- package/tests/auto_extdata_spec.js +0 -79
- package/tests/auto_init_config_json.sh +0 -275
- package/tests/auto_k2hdkc_server.ini +0 -109
- package/tests/auto_k2hdkc_slave.ini +0 -83
- package/tests/auto_list.js +0 -439
- package/tests/auto_list_spec.js +0 -79
- package/tests/auto_policy.js +0 -1579
- package/tests/auto_policy_spec.js +0 -79
- package/tests/auto_resource.js +0 -10956
- package/tests/auto_resource_spec.js +0 -79
- package/tests/auto_role.js +0 -6150
- package/tests/auto_role_spec.js +0 -79
- package/tests/auto_service.js +0 -770
- package/tests/auto_service_spec.js +0 -79
- package/tests/auto_subprocesses.js +0 -114
- package/tests/auto_template.sh +0 -126
- package/tests/auto_tenant.js +0 -1100
- package/tests/auto_tenant_spec.js +0 -79
- package/tests/auto_token_util.js +0 -219
- package/tests/auto_userdata.js +0 -292
- package/tests/auto_userdata_spec.js +0 -79
- package/tests/auto_usertokens.js +0 -565
- package/tests/auto_usertokens_spec.js +0 -79
- package/tests/auto_version.js +0 -127
- package/tests/auto_version_spec.js +0 -79
- package/tests/auto_watcher.js +0 -157
- package/tests/auto_watcher_spec.js +0 -79
- package/tests/k2hdkc_test.data +0 -986
- package/tests/k2hdkc_test_load.sh +0 -255
- package/tests/k2hr3template_test.js +0 -187
- package/tests/k2hr3template_test.sh +0 -339
- package/tests/k2hr3template_test_async.js +0 -216
- package/tests/k2hr3template_test_template.result +0 -7117
- package/tests/k2hr3template_test_template.txt +0 -3608
- package/tests/k2hr3template_test_vars.js +0 -194
- package/tests/manual_acr_delete.js +0 -143
- package/tests/manual_acr_get.js +0 -297
- package/tests/manual_acr_postput.js +0 -215
- package/tests/manual_allusertenant_get.js +0 -113
- package/tests/manual_extdata_get.js +0 -191
- package/tests/manual_k2hr3keys_get.js +0 -84
- package/tests/manual_list_gethead.js +0 -230
- package/tests/manual_policy_delete.js +0 -132
- package/tests/manual_policy_gethead.js +0 -275
- package/tests/manual_policy_postput.js +0 -297
- package/tests/manual_resource_delete.js +0 -433
- package/tests/manual_resource_gethead.js +0 -423
- package/tests/manual_resource_postput.js +0 -487
- package/tests/manual_role_delete.js +0 -404
- package/tests/manual_role_gethead.js +0 -547
- package/tests/manual_role_postput.js +0 -544
- package/tests/manual_service_delete.js +0 -153
- package/tests/manual_service_gethead.js +0 -178
- package/tests/manual_service_postput.js +0 -348
- package/tests/manual_tenant_delete.js +0 -186
- package/tests/manual_tenant_gethead.js +0 -268
- package/tests/manual_tenant_postput.js +0 -293
- package/tests/manual_test.sh +0 -352
- package/tests/manual_userdata_get.js +0 -173
- package/tests/manual_usertoken_gethead.js +0 -136
- package/tests/manual_usertoken_postput.js +0 -310
- package/tests/manual_version_get.js +0 -127
- package/tests/run_local_test_k2hdkc.sh +0 -174
- package/tests/test.sh +0 -333
|
@@ -1,339 +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 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 echo "$1" | grep -q -i -e "^-h$" -e "^--help$"; then
|
|
71
|
-
PrintUsage "${PRGNAME}"
|
|
72
|
-
exit 0
|
|
73
|
-
|
|
74
|
-
elif echo "$1" | grep -q -i -e "^-i$" -e "^--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 echo "$1" | grep -q -i -e "^-d$" -e "^--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 echo "$1" | grep -q -i -e "^dbg$" -e "^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 echo "$1" | grep -q -i -e "^msg$" -e "^message$" -e "^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 echo "$1" | grep -q -i -e "^wan$" -e "^warn$" -e "^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 echo "$1" | grep -q -i -e "^err$" -e "^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 echo "$1" | grep -q -i -e "^-v$" -e "^--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 echo "$1" | grep -q -i -e "^-t$" -e "^--templ$" -e "^--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 echo "$1" | grep -q -i -e "^-s$" -e "^--str$" -e "^--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 echo "$1" | grep -q -i -e "^-a$" -e "^--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 echo "${TEMPLLINE}" | grep -q -i "^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,216 +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 12 2017
|
|
17
|
-
* REVISION:
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
'use strict';
|
|
22
|
-
|
|
23
|
-
var fs = require('fs');
|
|
24
|
-
|
|
25
|
-
var r3templeng = require('../lib/k2hr3template');
|
|
26
|
-
var apiutil = require('../lib/k2hr3apiutil');
|
|
27
|
-
|
|
28
|
-
// Debug logging objects
|
|
29
|
-
var r3logger = require('../lib/dbglogging');
|
|
30
|
-
|
|
31
|
-
// [NOTE]
|
|
32
|
-
// The processing in this file is the same as k2hr3template_test.js.
|
|
33
|
-
// Since I don't want to make the code of k2hr3template_test.js complicated,
|
|
34
|
-
// we make it a separate file as an asynchronous test.
|
|
35
|
-
// Thus please be careful when making corrections.
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
// check environments
|
|
40
|
-
//
|
|
41
|
-
var templfile = apiutil.getSafeString(process.env.R3TEMPLFILE);
|
|
42
|
-
var varfile = apiutil.getSafeString(process.env.R3VARFILE);
|
|
43
|
-
if(!apiutil.isSafeString(templfile) || ('' !== varfile && !apiutil.isSafeString(varfile))){
|
|
44
|
-
r3logger.elog('Environments are wrong : R3TEMPLFILE=' + JSON.stringify(templfile) + ', R3VARFILE=' + JSON.stringify(varfile));
|
|
45
|
-
process.exit(0);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
//
|
|
49
|
-
// execute main
|
|
50
|
-
//
|
|
51
|
-
function execTemplateEngine(templString, varmap, callback)
|
|
52
|
-
{
|
|
53
|
-
if(!apiutil.isSafeEntity(callback) || 'function' !== typeof callback){
|
|
54
|
-
r3logger.elog('parameter callback is wrong.');
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
var _callback = callback;
|
|
58
|
-
var _errorstr = null;
|
|
59
|
-
var r3templ = new r3templeng.r3template;
|
|
60
|
-
|
|
61
|
-
// load template string
|
|
62
|
-
r3templ.load(templString, function(error, result){
|
|
63
|
-
if(null !== error || !result){
|
|
64
|
-
_errorstr = 'could not load string to k2hr3 template engine : string=' + JSON.stringify(templString) + ', error = ' + JSON.stringify(error);
|
|
65
|
-
r3logger.elog(_errorstr);
|
|
66
|
-
_callback(_errorstr);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// print variable names in template
|
|
71
|
-
r3templ.getVariableNames(function(error, vars){
|
|
72
|
-
if(null !== error){
|
|
73
|
-
r3logger.wlog(error);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
console.log('----------------------------------------------------------------');
|
|
77
|
-
if(apiutil.isEmptyArray(vars)){
|
|
78
|
-
console.log('var names = n/a');
|
|
79
|
-
}else{
|
|
80
|
-
console.log('var names = ' + r3logger.dump(vars));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// execute template engine
|
|
84
|
-
r3templ.execute(varmap, function(resobj){
|
|
85
|
-
|
|
86
|
-
console.log('----------------------------------------------------------------');
|
|
87
|
-
console.log('RESULT');
|
|
88
|
-
console.log('----------------------------------------------------------------');
|
|
89
|
-
if(resobj.result){
|
|
90
|
-
console.log('result = succeed');
|
|
91
|
-
console.log('input string = ' + templString);
|
|
92
|
-
console.log('output string = ' + resobj.getString());
|
|
93
|
-
}else{
|
|
94
|
-
console.log('result = failed');
|
|
95
|
-
console.log('input string = ' + templString);
|
|
96
|
-
}
|
|
97
|
-
console.log('----------------------------------------------------------------');
|
|
98
|
-
_callback(null);
|
|
99
|
-
return;
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
//
|
|
106
|
-
// load template file
|
|
107
|
-
//
|
|
108
|
-
fs.readFile(templfile, 'utf8', function(err, templString)
|
|
109
|
-
{
|
|
110
|
-
if(null !== err){
|
|
111
|
-
r3logger.elog('could not load template string from file : ' + JSON.stringify(templfile));
|
|
112
|
-
r3logger.dump(err);
|
|
113
|
-
process.exit(0);
|
|
114
|
-
}
|
|
115
|
-
if(!apiutil.isSafeString(templString)){
|
|
116
|
-
r3logger.elog('loaded template string is empty : ' + JSON.stringify(templString));
|
|
117
|
-
process.exit(0);
|
|
118
|
-
}
|
|
119
|
-
//r3logger.dlog('Template string : ' + JSON.stringify(templString));
|
|
120
|
-
|
|
121
|
-
//
|
|
122
|
-
// check variable file type(allow varfile is null)
|
|
123
|
-
//
|
|
124
|
-
var is_varfile_json = false;
|
|
125
|
-
if('' === varfile){
|
|
126
|
-
r3logger.dlog('variable file(' + varfile + ') is not specified.');
|
|
127
|
-
is_varfile_json = false;
|
|
128
|
-
}else if(apiutil.compareCaseString('.json5', varfile.substr(-6))){
|
|
129
|
-
r3logger.dlog('variable file(' + varfile + ') is JSON5 type.');
|
|
130
|
-
is_varfile_json = true;
|
|
131
|
-
}else if(apiutil.compareCaseString('.json', varfile.substr(-5))){
|
|
132
|
-
r3logger.dlog('variable file(' + varfile + ') is JSON type.');
|
|
133
|
-
is_varfile_json = true;
|
|
134
|
-
}else if(apiutil.compareCaseString('.js', varfile.substr(-3))){
|
|
135
|
-
r3logger.dlog('variable file(' + varfile + ') is JS type.');
|
|
136
|
-
is_varfile_json = false;
|
|
137
|
-
}else{
|
|
138
|
-
r3logger.dlog('variable file(' + varfile + ') is unknown type, then we will load it as JSON type.');
|
|
139
|
-
is_varfile_json = true;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
//
|
|
143
|
-
// load variable file type
|
|
144
|
-
//
|
|
145
|
-
var varmap = {}; // default for varfile is null
|
|
146
|
-
if(is_varfile_json){
|
|
147
|
-
// json file
|
|
148
|
-
fs.readFile(varfile, 'utf8', function(err, jsonVarString)
|
|
149
|
-
{
|
|
150
|
-
if(null !== err){
|
|
151
|
-
r3logger.elog('could not load variable JSON string fromm file : ' + JSON.stringify(varfile));
|
|
152
|
-
r3logger.dump(err);
|
|
153
|
-
process.exit(0);
|
|
154
|
-
}
|
|
155
|
-
if(apiutil.isSafeString(jsonVarString)){
|
|
156
|
-
// parse JSON
|
|
157
|
-
varmap = jsonVarString;
|
|
158
|
-
if(apiutil.checkSimpleJSON(jsonVarString)){
|
|
159
|
-
varmap = JSON.parse(jsonVarString);
|
|
160
|
-
}
|
|
161
|
-
if(!apiutil.isSafeEntity(varmap)){
|
|
162
|
-
r3logger.elog('loaded variable file(.json) is something wrong : ' + JSON.stringify(varmap));
|
|
163
|
-
process.exit(0);
|
|
164
|
-
}
|
|
165
|
-
}else{
|
|
166
|
-
// allow empty string
|
|
167
|
-
r3logger.dlog('loaded variable JSON string is empty.');
|
|
168
|
-
}
|
|
169
|
-
//r3logger.dump(varmap);
|
|
170
|
-
|
|
171
|
-
// execute
|
|
172
|
-
execTemplateEngine(templString, varmap, function(error){
|
|
173
|
-
if(null !== error){
|
|
174
|
-
r3logger.elog('failed to execute k2hr3 template engine.');
|
|
175
|
-
}
|
|
176
|
-
process.exit(0);
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
}else{
|
|
181
|
-
// js file
|
|
182
|
-
// (js file must be like following contents)
|
|
183
|
-
//
|
|
184
|
-
// module.exports = {
|
|
185
|
-
// 'key1': 'value1',
|
|
186
|
-
// 'key2': 'value2',
|
|
187
|
-
// ...
|
|
188
|
-
// };
|
|
189
|
-
//
|
|
190
|
-
if('' !== varfile){
|
|
191
|
-
varmap = require(varfile);
|
|
192
|
-
if(!apiutil.isSafeEntity(varmap)){
|
|
193
|
-
r3logger.elog('loaded variable file(.js) is something wrong : ' + JSON.stringify(varmap));
|
|
194
|
-
process.exit(0);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
//r3logger.dump(varmap);
|
|
198
|
-
|
|
199
|
-
// execute
|
|
200
|
-
execTemplateEngine(templString, varmap, function(error){
|
|
201
|
-
if(null !== error){
|
|
202
|
-
r3logger.elog('failed to execute k2hr3 template engine.');
|
|
203
|
-
}
|
|
204
|
-
process.exit(0);
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
/*
|
|
210
|
-
* Local variables:
|
|
211
|
-
* tab-width: 4
|
|
212
|
-
* c-basic-offset: 4
|
|
213
|
-
* End:
|
|
214
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
215
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
216
|
-
*/
|