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.
- package/config/k2hr3-init.sh.templ +4 -4
- 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 -378
- 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,487 +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 postV1Resource(method, token, querypath, name, datatype, data, reskeys, alias, port, cuk, roleyrn)
|
|
44
|
-
{
|
|
45
|
-
var strbody = '';
|
|
46
|
-
var headers = {
|
|
47
|
-
'Content-Type': 'application/json',
|
|
48
|
-
};
|
|
49
|
-
if(apiutil.isSafeString(token)){
|
|
50
|
-
headers['X-Auth-Token'] = token;
|
|
51
|
-
}
|
|
52
|
-
var options = {
|
|
53
|
-
'host': hostname,
|
|
54
|
-
'port': hostport,
|
|
55
|
-
'path': '/v1/resource' + apiutil.getSafeString(querypath),
|
|
56
|
-
'method': method
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
if(!apiutil.compareCaseString('string', datatype) && !apiutil.compareCaseString('object', datatype)){
|
|
60
|
-
datatype = 'string'; // default data type is string
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if(apiutil.compareCaseString('post', method)){
|
|
64
|
-
// case for POST
|
|
65
|
-
if(apiutil.compareCaseString('object', datatype)){
|
|
66
|
-
// If datatype is object, data is needed to decode JSON to object here.
|
|
67
|
-
data = apiutil.parseJSON(data);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
var body = {
|
|
71
|
-
'resource': {
|
|
72
|
-
'type': datatype,
|
|
73
|
-
'data': data, // if datatype is string, this includes control codes
|
|
74
|
-
'keys': reskeys
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
if(apiutil.isSafeString(name)){
|
|
79
|
-
body.resource.name = name;
|
|
80
|
-
}
|
|
81
|
-
if(apiutil.isSafeEntity(alias)){
|
|
82
|
-
body.resource.alias = alias;
|
|
83
|
-
}
|
|
84
|
-
if(apiutil.isSafeEntity(port) && !isNaN(port)){
|
|
85
|
-
body.resource.port = String(port);
|
|
86
|
-
}
|
|
87
|
-
if(apiutil.isSafeEntity(cuk)){
|
|
88
|
-
body.resource.cuk = cuk;
|
|
89
|
-
}
|
|
90
|
-
if(apiutil.isSafeString(roleyrn)){
|
|
91
|
-
body.resource.role = roleyrn;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
strbody = JSON.stringify(body);
|
|
95
|
-
headers['Content-Length'] = strbody.length;
|
|
96
|
-
options.headers = headers;
|
|
97
|
-
|
|
98
|
-
}else if(apiutil.compareCaseString('put', method)){
|
|
99
|
-
// case for PUT
|
|
100
|
-
var urlarg = '';
|
|
101
|
-
var already_set = false;
|
|
102
|
-
if(apiutil.isSafeString(name)){
|
|
103
|
-
urlarg += already_set ? '&name=' : '?name=';
|
|
104
|
-
urlarg += name;
|
|
105
|
-
already_set = true;
|
|
106
|
-
}
|
|
107
|
-
if('' === datatype || apiutil.isSafeString(datatype)){
|
|
108
|
-
urlarg += already_set ? '&type=' : '?type=';
|
|
109
|
-
urlarg += datatype;
|
|
110
|
-
already_set = true;
|
|
111
|
-
}
|
|
112
|
-
if('' === data || apiutil.isSafeString(data)){
|
|
113
|
-
urlarg += already_set ? '&data=' : '?data=';
|
|
114
|
-
if(apiutil.compareCaseString('string', datatype)){
|
|
115
|
-
urlarg += JSON.stringify(data); // if data is string, data includes control codes, so it is converted to JSON.
|
|
116
|
-
}else{
|
|
117
|
-
urlarg += data; // if data is json, data is already json formatted.
|
|
118
|
-
}
|
|
119
|
-
already_set = true;
|
|
120
|
-
}
|
|
121
|
-
if(apiutil.isSafeEntity(reskeys)){
|
|
122
|
-
urlarg += already_set ? '&keys=' : '?keys=';
|
|
123
|
-
urlarg += JSON.stringify(reskeys); // keys is converted to JSON
|
|
124
|
-
already_set = true;
|
|
125
|
-
}
|
|
126
|
-
if(apiutil.isSafeEntity(alias)){
|
|
127
|
-
urlarg += already_set ? '&alias=' : '?alias=';
|
|
128
|
-
urlarg += JSON.stringify(alias); // alias is converted to JSON
|
|
129
|
-
already_set = true;
|
|
130
|
-
}
|
|
131
|
-
if(apiutil.isSafeEntity(port) && !isNaN(port)){
|
|
132
|
-
urlarg += already_set ? '&port=' : '?port=';
|
|
133
|
-
urlarg += String(port); // port is converted to String
|
|
134
|
-
already_set = true;
|
|
135
|
-
}
|
|
136
|
-
if(apiutil.isSafeEntity(cuk)){
|
|
137
|
-
urlarg += already_set ? '&cuk=' : '?cuk=';
|
|
138
|
-
urlarg += JSON.stringify(cuk); // cuk is converted to JSON
|
|
139
|
-
already_set = true;
|
|
140
|
-
}
|
|
141
|
-
if(apiutil.isSafeString(roleyrn)){
|
|
142
|
-
urlarg += already_set ? '&role=' : '?role=';
|
|
143
|
-
urlarg += roleyrn;
|
|
144
|
-
already_set = true;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
headers['Content-Length'] = 0;
|
|
148
|
-
options.headers = headers;
|
|
149
|
-
options.path += encodeURI(urlarg);
|
|
150
|
-
|
|
151
|
-
}else{
|
|
152
|
-
console.log('method must be POST or PUT : ' + method);
|
|
153
|
-
process.exit(0);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
r3logger.dlog('request options = ' + JSON.stringify(options));
|
|
157
|
-
r3logger.dlog('request headers = ' + JSON.stringify(headers));
|
|
158
|
-
r3logger.dlog('request body = ' + strbody);
|
|
159
|
-
|
|
160
|
-
var httpobj;
|
|
161
|
-
if(is_https){
|
|
162
|
-
if(null !== cacerts.ca){
|
|
163
|
-
options.ca = cacerts.ca;
|
|
164
|
-
}
|
|
165
|
-
options.rejectUnauthorized = false; // always insecure for this manual test
|
|
166
|
-
options.agent = new https.Agent(options);
|
|
167
|
-
httpobj = https;
|
|
168
|
-
}else{
|
|
169
|
-
options.agent = new http.Agent(options);
|
|
170
|
-
httpobj = http;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
var req = httpobj.request(options, function(res)
|
|
174
|
-
{
|
|
175
|
-
var response = '';
|
|
176
|
-
console.log('RESPONSE CODE = ' + res.statusCode);
|
|
177
|
-
r3logger.dlog('response status = ' + res.statusCode);
|
|
178
|
-
r3logger.dlog('response header = ' + JSON.stringify(res.headers));
|
|
179
|
-
res.setEncoding('utf8');
|
|
180
|
-
|
|
181
|
-
res.on('data', function (chunk)
|
|
182
|
-
{
|
|
183
|
-
r3logger.dlog('response chunk = ' + chunk);
|
|
184
|
-
response += chunk;
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
res.on('end', function(result) // eslint-disable-line no-unused-vars
|
|
188
|
-
{
|
|
189
|
-
r3logger.mlog(r3logger.dump(response)); // response is object(or not)
|
|
190
|
-
console.log('RESPONSE BODY = ' + JSON.stringify(response));
|
|
191
|
-
process.exit(0);
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
req.on('error', function(e)
|
|
196
|
-
{
|
|
197
|
-
r3logger.elog('problem with request: ' + e.message);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
// write data to request body
|
|
201
|
-
if('' !== strbody){
|
|
202
|
-
req.write(strbody);
|
|
203
|
-
}
|
|
204
|
-
req.end();
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
//
|
|
208
|
-
// Utility for inputting token for three pattern
|
|
209
|
-
//
|
|
210
|
-
// callback(error, token type, token string)
|
|
211
|
-
//
|
|
212
|
-
function rawInputToken(callback)
|
|
213
|
-
{
|
|
214
|
-
var _callback = callback;
|
|
215
|
-
|
|
216
|
-
cliutil.getConsoleInput('Token type(USER/ROLE/NULL(empty)) : ', true, false, function(isbreak, token_type)
|
|
217
|
-
{
|
|
218
|
-
if(isbreak){
|
|
219
|
-
_callback('break for inputting token type');
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
var _token_type = null;
|
|
223
|
-
var _prefix = '';
|
|
224
|
-
if(!apiutil.isSafeString(token_type) || apiutil.compareCaseString('NULL', token_type)){
|
|
225
|
-
// no token
|
|
226
|
-
_callback(null, null, null);
|
|
227
|
-
return;
|
|
228
|
-
}else if(apiutil.compareCaseString('USER', token_type)){
|
|
229
|
-
// user token
|
|
230
|
-
_token_type = 'USER';
|
|
231
|
-
_prefix = 'U=';
|
|
232
|
-
}else if(apiutil.compareCaseString('ROLE', token_type)){
|
|
233
|
-
// role token
|
|
234
|
-
_token_type = 'ROLE';
|
|
235
|
-
_prefix = 'R=';
|
|
236
|
-
}else{
|
|
237
|
-
_callback('token type must be USER or ROLE or NULL(empty)');
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
cliutil.getConsoleInput(_token_type + ' Token string : ', true, false, function(isbreak, token)
|
|
242
|
-
{
|
|
243
|
-
if(isbreak){
|
|
244
|
-
_callback('break for inputting token');
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
if(!apiutil.isSafeString(_token_type) || apiutil.compareCaseString('NULL', _token_type)){
|
|
248
|
-
_callback('token must be string');
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
var _token = _prefix + token;
|
|
252
|
-
_callback(null, _token_type, _token);
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
//
|
|
258
|
-
// Utility for input keys
|
|
259
|
-
//
|
|
260
|
-
function rawGetInputKeys(str)
|
|
261
|
-
{
|
|
262
|
-
var result;
|
|
263
|
-
if('' === apiutil.getSafeString(str)){
|
|
264
|
-
// empty value
|
|
265
|
-
result = '';
|
|
266
|
-
}else if(apiutil.compareCaseString('null', apiutil.getSafeString(str))){
|
|
267
|
-
// null value
|
|
268
|
-
result = null;
|
|
269
|
-
}else{
|
|
270
|
-
// try parse str as JSON string
|
|
271
|
-
try{
|
|
272
|
-
// parse JSON
|
|
273
|
-
result = JSON.parse(str);
|
|
274
|
-
}catch(err){ // eslint-disable-line no-unused-vars
|
|
275
|
-
// key=val,key=val...
|
|
276
|
-
result = {};
|
|
277
|
-
// parse ','
|
|
278
|
-
var rkeyarr = str.split(',');
|
|
279
|
-
for(var cnt = 0; cnt < rkeyarr.length; ++cnt){
|
|
280
|
-
var rkeyval = rkeyarr[cnt].trim();
|
|
281
|
-
var rkeyvalarr = rkeyval.split('=');
|
|
282
|
-
var rkey = null;
|
|
283
|
-
var rval = null;
|
|
284
|
-
for(var cnt2 = 0; cnt2 < rkeyvalarr.length; ++cnt2){
|
|
285
|
-
if(null === rkey){
|
|
286
|
-
rkey = rkeyvalarr[cnt2].trim();
|
|
287
|
-
}else if(null === rval){
|
|
288
|
-
rval = rkeyvalarr[cnt2].trim();
|
|
289
|
-
}else{
|
|
290
|
-
// many separator(=) in value
|
|
291
|
-
console.log('input resource sub key(' + rkey + ') has many separator(=) in value(' + rkeyarr[cnt] + '), but continue...');
|
|
292
|
-
rval += '=' + rkeyvalarr[cnt2]; // not trim
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
if(apiutil.isSafeString(rkey)){
|
|
296
|
-
result[rkey] = rval;
|
|
297
|
-
}else{
|
|
298
|
-
// input error
|
|
299
|
-
console.log('input key value something wrong : ' + str);
|
|
300
|
-
return undefined;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
return result;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
//
|
|
309
|
-
// Run
|
|
310
|
-
//
|
|
311
|
-
cliutil.getConsoleInput('Method(POST/PUT) : ', true, false, function(isbreak, method)
|
|
312
|
-
{
|
|
313
|
-
if(isbreak){
|
|
314
|
-
process.exit(0);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
var _method;
|
|
318
|
-
if(apiutil.compareCaseString('post', method)){
|
|
319
|
-
_method = 'POST';
|
|
320
|
-
}else if(apiutil.compareCaseString('put', method)){
|
|
321
|
-
_method = 'PUT';
|
|
322
|
-
}else{
|
|
323
|
-
console.log('method must be POST or PUT : ' + method);
|
|
324
|
-
process.exit(0);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
rawInputToken(function(error, token_type, token)
|
|
328
|
-
{
|
|
329
|
-
if(null !== error){
|
|
330
|
-
console.log(error);
|
|
331
|
-
process.exit(0);
|
|
332
|
-
}
|
|
333
|
-
var _token_type = token_type;
|
|
334
|
-
var _token = token;
|
|
335
|
-
|
|
336
|
-
cliutil.getConsoleInput('Resource name(path) : ', true, false, function(isbreak, name)
|
|
337
|
-
{
|
|
338
|
-
if(isbreak){
|
|
339
|
-
process.exit(0);
|
|
340
|
-
}
|
|
341
|
-
var _name = name;
|
|
342
|
-
|
|
343
|
-
cliutil.getConsoleInput(' data type(string(str) or object(obj)) : ', true, false, function(isbreak, datatype)
|
|
344
|
-
{
|
|
345
|
-
if(isbreak){
|
|
346
|
-
process.exit(0);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
var _datatype = null;
|
|
350
|
-
var is_string = false;
|
|
351
|
-
if(apiutil.compareCaseString('string', datatype) || apiutil.compareCaseString('str', datatype)){
|
|
352
|
-
_datatype = 'string';
|
|
353
|
-
is_string = true;
|
|
354
|
-
}else if(apiutil.compareCaseString('object', datatype) || apiutil.compareCaseString('obj', datatype) || apiutil.compareCaseString('json', datatype)){
|
|
355
|
-
_datatype = 'object';
|
|
356
|
-
is_string = false;
|
|
357
|
-
}else{
|
|
358
|
-
console.log('data type must be STRING or OBJECT : ' + datatype);
|
|
359
|
-
process.exit(0);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
cliutil.inputObjectData(is_string, function(isbreak, data)
|
|
363
|
-
{
|
|
364
|
-
if(isbreak){
|
|
365
|
-
process.exit(0);
|
|
366
|
-
}
|
|
367
|
-
// [NOTE]
|
|
368
|
-
// if data type is string, data has CR code = '\n'
|
|
369
|
-
//
|
|
370
|
-
var _data = data;
|
|
371
|
-
|
|
372
|
-
process.stdout.write(' key-value(following for example) \n');
|
|
373
|
-
process.stdout.write(' ex.1) empty -> (empty) \n');
|
|
374
|
-
process.stdout.write(' ex.2) null -> null \n');
|
|
375
|
-
process.stdout.write(' ex.3) key=val -> key01=val01,key02=val02,.. \n');
|
|
376
|
-
process.stdout.write(' ex.4) JSON -> <JSON string for object> \n');
|
|
377
|
-
cliutil.getConsoleInput(' input key value (one of example format) : ', true, false, function(isbreak, reskeys)
|
|
378
|
-
{
|
|
379
|
-
if(isbreak){
|
|
380
|
-
process.exit(0);
|
|
381
|
-
}
|
|
382
|
-
var _reskeys;
|
|
383
|
-
var _querypath;
|
|
384
|
-
|
|
385
|
-
if(undefined === (_reskeys = rawGetInputKeys(reskeys))){
|
|
386
|
-
process.exit(0);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
if(null === _token_type){
|
|
390
|
-
// no token
|
|
391
|
-
_querypath = '/' + _name;
|
|
392
|
-
|
|
393
|
-
cliutil.getConsoleInput(' port number(0=any(empty default)) : ', true, false, function(isbreak, port)
|
|
394
|
-
{
|
|
395
|
-
if(isbreak){
|
|
396
|
-
process.exit(0);
|
|
397
|
-
}
|
|
398
|
-
var _port;
|
|
399
|
-
if(null === port || !apiutil.isSafeString(port)){
|
|
400
|
-
_port = 0;
|
|
401
|
-
}else if(!isNaN(port)){
|
|
402
|
-
_port = parseInt(port);
|
|
403
|
-
}else{
|
|
404
|
-
process.exit(0);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
cliutil.getConsoleInput(' cuk(allow empty) : ', true, false, function(isbreak, cuk)
|
|
409
|
-
{
|
|
410
|
-
if(isbreak){
|
|
411
|
-
process.exit(0);
|
|
412
|
-
}
|
|
413
|
-
var _cuk;
|
|
414
|
-
if(apiutil.isSafeString(cuk) && apiutil.isSafeString(cuk.trim())){
|
|
415
|
-
_cuk = cuk.trim();
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
cliutil.getConsoleInput(' Role full yrn path for resource : ', true, false, function(isbreak, roleyrn)
|
|
419
|
-
{
|
|
420
|
-
if(isbreak){
|
|
421
|
-
process.exit(0);
|
|
422
|
-
}
|
|
423
|
-
if(!apiutil.isSafeString(roleyrn)){
|
|
424
|
-
process.exit(0);
|
|
425
|
-
}
|
|
426
|
-
var _roleyrn = roleyrn;
|
|
427
|
-
|
|
428
|
-
// run
|
|
429
|
-
postV1Resource(_method, _token, _querypath, null, _datatype, _data, _reskeys, null, _port, _cuk, _roleyrn);
|
|
430
|
-
});
|
|
431
|
-
});
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
}else if('USER' === _token_type){
|
|
435
|
-
// user token
|
|
436
|
-
_querypath = null;
|
|
437
|
-
|
|
438
|
-
cliutil.getConsoleInput(' alias(specify null/(empty)/yrn multiple with \',\'): ', true, false, function(isbreak, alias)
|
|
439
|
-
{
|
|
440
|
-
if(isbreak){
|
|
441
|
-
process.exit(0);
|
|
442
|
-
}
|
|
443
|
-
var _alias;
|
|
444
|
-
|
|
445
|
-
if('' === apiutil.getSafeString(alias)){
|
|
446
|
-
_alias = '';
|
|
447
|
-
}else if(apiutil.compareCaseString('null', apiutil.getSafeString(alias))){
|
|
448
|
-
_alias = null;
|
|
449
|
-
}else{
|
|
450
|
-
// parse ','
|
|
451
|
-
_alias = new Array(0);
|
|
452
|
-
var strarray= alias.split(',');
|
|
453
|
-
for(var cnt = 0; cnt < strarray.length; ++cnt){
|
|
454
|
-
var strtmp = strarray[cnt].trim();
|
|
455
|
-
_alias.push(strtmp);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
// run
|
|
460
|
-
postV1Resource(_method, _token, _querypath, _name, _datatype, _data, _reskeys, _alias);
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
}else if('ROLE' === _token_type){
|
|
464
|
-
// role token
|
|
465
|
-
_querypath = '/' + _name;
|
|
466
|
-
|
|
467
|
-
// run
|
|
468
|
-
postV1Resource(_method, _token, _querypath, null, _datatype, _data, _reskeys, null);
|
|
469
|
-
}else{
|
|
470
|
-
// why?
|
|
471
|
-
process.exit(0);
|
|
472
|
-
}
|
|
473
|
-
});
|
|
474
|
-
});
|
|
475
|
-
});
|
|
476
|
-
});
|
|
477
|
-
});
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
/*
|
|
481
|
-
* Local variables:
|
|
482
|
-
* tab-width: 4
|
|
483
|
-
* c-basic-offset: 4
|
|
484
|
-
* End:
|
|
485
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
486
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
487
|
-
*/
|