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,268 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* K2HR3 REST API
|
|
3
|
-
*
|
|
4
|
-
* Copyright 2023 Yahoo Japan Corporation.
|
|
5
|
-
*
|
|
6
|
-
* K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
|
|
7
|
-
* common management information for the cloud.
|
|
8
|
-
* K2HR3 can dynamically manage information as "who", "what", "operate".
|
|
9
|
-
* These are stored as roles, resources, policies in K2hdkc, and the
|
|
10
|
-
* client system can dynamically read and modify these information.
|
|
11
|
-
*
|
|
12
|
-
* For the full copyright and license information, please view
|
|
13
|
-
* the license file that was distributed with this source code.
|
|
14
|
-
*
|
|
15
|
-
* AUTHOR: Takeshi Nakatani
|
|
16
|
-
* CREATE: Mon Jun 3 2023
|
|
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 getV1Tenant(token, name, is_expand)
|
|
44
|
-
{
|
|
45
|
-
var path;
|
|
46
|
-
var urlarg;
|
|
47
|
-
if(apiutil.isSafeString(name)){
|
|
48
|
-
path = '/v1/tenant/' + name;
|
|
49
|
-
urlarg = '';
|
|
50
|
-
}else{
|
|
51
|
-
path = '/v1/tenant';
|
|
52
|
-
if(is_expand){
|
|
53
|
-
urlarg = encodeURI('?expand=true');
|
|
54
|
-
}else{
|
|
55
|
-
urlarg = encodeURI('?expand=false');
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
var headers = {
|
|
60
|
-
'Content-Type': 'application/json',
|
|
61
|
-
'Content-Length': 0,
|
|
62
|
-
'X-Auth-Token': token
|
|
63
|
-
};
|
|
64
|
-
var options = {
|
|
65
|
-
'host': hostname,
|
|
66
|
-
'port': hostport,
|
|
67
|
-
'path': path + urlarg,
|
|
68
|
-
'method': 'GET',
|
|
69
|
-
'headers': headers
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
r3logger.dlog('request options = ' + JSON.stringify(options));
|
|
73
|
-
r3logger.dlog('request headers = ' + JSON.stringify(headers));
|
|
74
|
-
|
|
75
|
-
var httpobj;
|
|
76
|
-
if(is_https){
|
|
77
|
-
if(null !== cacerts.ca){
|
|
78
|
-
options.ca = cacerts.ca;
|
|
79
|
-
}
|
|
80
|
-
options.rejectUnauthorized = false; // always insecure for this manual test
|
|
81
|
-
options.agent = new https.Agent(options);
|
|
82
|
-
httpobj = https;
|
|
83
|
-
}else{
|
|
84
|
-
options.agent = new http.Agent(options);
|
|
85
|
-
httpobj = http;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
var req = httpobj.request(options, function(res)
|
|
89
|
-
{
|
|
90
|
-
var response = '';
|
|
91
|
-
console.log('RESPONSE CODE = ' + res.statusCode);
|
|
92
|
-
r3logger.dlog('response status = ' + res.statusCode);
|
|
93
|
-
r3logger.dlog('response header = ' + JSON.stringify(res.headers));
|
|
94
|
-
res.setEncoding('utf8');
|
|
95
|
-
|
|
96
|
-
res.on('data', function (chunk)
|
|
97
|
-
{
|
|
98
|
-
r3logger.dlog('response chunk = ' + chunk);
|
|
99
|
-
response += chunk;
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
res.on('end', function(result) // eslint-disable-line no-unused-vars
|
|
103
|
-
{
|
|
104
|
-
r3logger.mlog(r3logger.dump(response)); // response is object(or not)
|
|
105
|
-
console.log('RESPONSE BODY = ' + JSON.stringify(response));
|
|
106
|
-
process.exit(0);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
req.on('error', function(e)
|
|
111
|
-
{
|
|
112
|
-
r3logger.elog('problem with request: ' + e.message);
|
|
113
|
-
});
|
|
114
|
-
req.end();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function headV1Tenant(token, name)
|
|
118
|
-
{
|
|
119
|
-
var headers = {
|
|
120
|
-
'Content-Type': 'application/json',
|
|
121
|
-
'Content-Length': 0,
|
|
122
|
-
'X-Auth-Token': token
|
|
123
|
-
};
|
|
124
|
-
var options = {
|
|
125
|
-
'host': hostname,
|
|
126
|
-
'port': hostport,
|
|
127
|
-
'path': '/v1/tenant/' + name,
|
|
128
|
-
'method': 'HEAD',
|
|
129
|
-
'headers': headers
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
r3logger.dlog('request options = ' + JSON.stringify(options));
|
|
133
|
-
r3logger.dlog('request headers = ' + JSON.stringify(headers));
|
|
134
|
-
|
|
135
|
-
var httpobj;
|
|
136
|
-
if(is_https){
|
|
137
|
-
if(null !== cacerts.ca){
|
|
138
|
-
options.ca = cacerts.ca;
|
|
139
|
-
}
|
|
140
|
-
options.rejectUnauthorized = false; // always insecure for this manual test
|
|
141
|
-
options.agent = new https.Agent(options);
|
|
142
|
-
httpobj = https;
|
|
143
|
-
}else{
|
|
144
|
-
options.agent = new http.Agent(options);
|
|
145
|
-
httpobj = http;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
var req = httpobj.request(options, function(res)
|
|
149
|
-
{
|
|
150
|
-
var response = '';
|
|
151
|
-
console.log('RESPONSE CODE = ' + res.statusCode);
|
|
152
|
-
r3logger.dlog('response status = ' + res.statusCode);
|
|
153
|
-
r3logger.dlog('response header = ' + JSON.stringify(res.headers));
|
|
154
|
-
res.setEncoding('utf8');
|
|
155
|
-
|
|
156
|
-
res.on('data', function (chunk)
|
|
157
|
-
{
|
|
158
|
-
r3logger.dlog('response chunk = ' + chunk);
|
|
159
|
-
response += chunk;
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
res.on('end', function(result) // eslint-disable-line no-unused-vars
|
|
163
|
-
{
|
|
164
|
-
r3logger.mlog(r3logger.dump(response)); // response is object(or not)
|
|
165
|
-
console.log('RESPONSE BODY = ' + JSON.stringify(response));
|
|
166
|
-
process.exit(0);
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
req.on('error', function(e)
|
|
171
|
-
{
|
|
172
|
-
r3logger.elog('problem with request: ' + e.message);
|
|
173
|
-
});
|
|
174
|
-
req.end();
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
//
|
|
178
|
-
// run
|
|
179
|
-
//
|
|
180
|
-
cliutil.getConsoleInput('Method(GET/HEAD) : ', true, false, function(isbreak, method)
|
|
181
|
-
{
|
|
182
|
-
if(isbreak){
|
|
183
|
-
process.exit(0);
|
|
184
|
-
}
|
|
185
|
-
var _method = method;
|
|
186
|
-
|
|
187
|
-
cliutil.getConsoleInput('Unscoped(or Scoped) user token : ', true, false, function(isbreak, token)
|
|
188
|
-
{
|
|
189
|
-
if(isbreak){
|
|
190
|
-
process.exit(0);
|
|
191
|
-
}
|
|
192
|
-
var _token = token;
|
|
193
|
-
|
|
194
|
-
if(apiutil.compareCaseString('get', _method)){
|
|
195
|
-
cliutil.getConsoleInput('Tenant name(null is get tenant list) : ', true, false, function(isbreak, tenant)
|
|
196
|
-
{
|
|
197
|
-
if(isbreak){
|
|
198
|
-
process.exit(0);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if(apiutil.isSafeString(tenant)){
|
|
202
|
-
var _tenant = apiutil.getSafeString(tenant);
|
|
203
|
-
|
|
204
|
-
//
|
|
205
|
-
// Run
|
|
206
|
-
//
|
|
207
|
-
getV1Tenant(_token, _tenant, false);
|
|
208
|
-
|
|
209
|
-
}else{
|
|
210
|
-
cliutil.getConsoleInput('Expand tenant list(yes(default)/no) : ', true, false, function(isbreak, expand)
|
|
211
|
-
{
|
|
212
|
-
if(isbreak){
|
|
213
|
-
process.exit(0);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
var _is_expand;
|
|
217
|
-
if('' === apiutil.getSafeString(expand) || apiutil.compareCaseString('null', apiutil.getSafeString(expand))){
|
|
218
|
-
_is_expand = true;
|
|
219
|
-
}else if(apiutil.compareCaseString('yes', apiutil.getSafeString(expand)) || apiutil.compareCaseString('true', apiutil.getSafeString(expand))){
|
|
220
|
-
_is_expand = true;
|
|
221
|
-
}else if(apiutil.compareCaseString('no', apiutil.getSafeString(expand)) || apiutil.compareCaseString('false', apiutil.getSafeString(expand))){
|
|
222
|
-
_is_expand = false;
|
|
223
|
-
}else{
|
|
224
|
-
console.log('function expand must be empty or yes(true) or no(false) : ' + expand);
|
|
225
|
-
process.exit(0);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
//
|
|
229
|
-
// Run
|
|
230
|
-
//
|
|
231
|
-
getV1Tenant(_token, null, _is_expand);
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
}else if(apiutil.compareCaseString('head', _method)){
|
|
237
|
-
cliutil.getConsoleInput('Tenant name : ', true, false, function(isbreak, tenant)
|
|
238
|
-
{
|
|
239
|
-
if(isbreak){
|
|
240
|
-
process.exit(0);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if(!apiutil.isSafeString(tenant)){
|
|
244
|
-
console.log('method HEAD must specify tenant name');
|
|
245
|
-
process.exit(0);
|
|
246
|
-
}
|
|
247
|
-
var _tenant = apiutil.getSafeString(tenant);
|
|
248
|
-
|
|
249
|
-
//
|
|
250
|
-
// Run
|
|
251
|
-
//
|
|
252
|
-
headV1Tenant(_token, _tenant);
|
|
253
|
-
});
|
|
254
|
-
}else{
|
|
255
|
-
console.log('method must be GET or HEAD : ' + _method);
|
|
256
|
-
process.exit(0);
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
/*
|
|
262
|
-
* Local variables:
|
|
263
|
-
* tab-width: 4
|
|
264
|
-
* c-basic-offset: 4
|
|
265
|
-
* End:
|
|
266
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
267
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
268
|
-
*/
|
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* K2HR3 REST API
|
|
3
|
-
*
|
|
4
|
-
* Copyright 2023 Yahoo Japan Corporation.
|
|
5
|
-
*
|
|
6
|
-
* K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
|
|
7
|
-
* common management information for the cloud.
|
|
8
|
-
* K2HR3 can dynamically manage information as "who", "what", "operate".
|
|
9
|
-
* These are stored as roles, resources, policies in K2hdkc, and the
|
|
10
|
-
* client system can dynamically read and modify these information.
|
|
11
|
-
*
|
|
12
|
-
* For the full copyright and license information, please view
|
|
13
|
-
* the license file that was distributed with this source code.
|
|
14
|
-
*
|
|
15
|
-
* AUTHOR: Takeshi Nakatani
|
|
16
|
-
* CREATE: Mon Jun 3 2023
|
|
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 postputV1Tenant(method, token, is_create, name, desc, display, users, id)
|
|
44
|
-
{
|
|
45
|
-
var strbody = '';
|
|
46
|
-
var headers = {
|
|
47
|
-
'Content-Type': 'application/json',
|
|
48
|
-
'X-Auth-Token': token
|
|
49
|
-
};
|
|
50
|
-
var options = {
|
|
51
|
-
'host': hostname,
|
|
52
|
-
'port': hostport,
|
|
53
|
-
'path': '/v1/tenant',
|
|
54
|
-
'method': method
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
var path;
|
|
58
|
-
if(apiutil.compareCaseString('post', method)){
|
|
59
|
-
var body;
|
|
60
|
-
if(is_create){
|
|
61
|
-
body = {
|
|
62
|
-
'tenant': {
|
|
63
|
-
'name': name,
|
|
64
|
-
'desc': desc,
|
|
65
|
-
'display': display,
|
|
66
|
-
'users': users
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
path = '/v1/tenant';
|
|
70
|
-
}else{
|
|
71
|
-
body = {
|
|
72
|
-
'tenant': {
|
|
73
|
-
'id': id,
|
|
74
|
-
'desc': desc,
|
|
75
|
-
'display': display,
|
|
76
|
-
'users': users,
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
path = '/v1/tenant/' + name;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
strbody = JSON.stringify(body);
|
|
83
|
-
headers['Content-Length'] = strbody.length;
|
|
84
|
-
options.headers = headers;
|
|
85
|
-
options.path = path;
|
|
86
|
-
|
|
87
|
-
}else if(apiutil.compareCaseString('put', method)){
|
|
88
|
-
var urlarg = '';
|
|
89
|
-
var already_set = false;
|
|
90
|
-
|
|
91
|
-
if(is_create){
|
|
92
|
-
path = '/v1/tenant';
|
|
93
|
-
urlarg = '?name=' + name;
|
|
94
|
-
already_set = true;
|
|
95
|
-
}else{
|
|
96
|
-
urlarg = '?id=' + id;
|
|
97
|
-
path = '/v1/tenant/' + name;
|
|
98
|
-
}
|
|
99
|
-
if('' === desc || apiutil.isSafeString(desc)){
|
|
100
|
-
urlarg += already_set ? '&desc=' : '?desc=';
|
|
101
|
-
urlarg += desc;
|
|
102
|
-
already_set = true;
|
|
103
|
-
}
|
|
104
|
-
if('' === display || apiutil.isSafeString(display)){
|
|
105
|
-
urlarg += already_set ? '&display=' : '?display=';
|
|
106
|
-
urlarg += display;
|
|
107
|
-
already_set = true;
|
|
108
|
-
}
|
|
109
|
-
if(!apiutil.isEmptyArray(users)){
|
|
110
|
-
urlarg += already_set ? '&users=' : '?users=';
|
|
111
|
-
urlarg += JSON.stringify(users);
|
|
112
|
-
already_set = true;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
headers['Content-Length'] = 0;
|
|
116
|
-
options.headers = headers;
|
|
117
|
-
options.path = path + encodeURI(urlarg);
|
|
118
|
-
|
|
119
|
-
}else{
|
|
120
|
-
console.log('method must be POST or PUT : ' + method);
|
|
121
|
-
process.exit(0);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
r3logger.dlog('request options = ' + JSON.stringify(options));
|
|
125
|
-
r3logger.dlog('request headers = ' + JSON.stringify(headers));
|
|
126
|
-
r3logger.dlog('request body = ' + strbody);
|
|
127
|
-
|
|
128
|
-
var httpobj;
|
|
129
|
-
if(is_https){
|
|
130
|
-
if(null !== cacerts.ca){
|
|
131
|
-
options.ca = cacerts.ca;
|
|
132
|
-
}
|
|
133
|
-
options.rejectUnauthorized = false; // always insecure for this manual test
|
|
134
|
-
options.agent = new https.Agent(options);
|
|
135
|
-
httpobj = https;
|
|
136
|
-
}else{
|
|
137
|
-
options.agent = new http.Agent(options);
|
|
138
|
-
httpobj = http;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
var req = httpobj.request(options, function(res)
|
|
142
|
-
{
|
|
143
|
-
var response = '';
|
|
144
|
-
console.log('RESPONSE CODE = ' + res.statusCode);
|
|
145
|
-
r3logger.dlog('response status = ' + res.statusCode);
|
|
146
|
-
r3logger.dlog('response header = ' + JSON.stringify(res.headers));
|
|
147
|
-
res.setEncoding('utf8');
|
|
148
|
-
|
|
149
|
-
res.on('data', function (chunk)
|
|
150
|
-
{
|
|
151
|
-
r3logger.dlog('response chunk = ' + chunk);
|
|
152
|
-
response += chunk;
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
res.on('end', function(result) // eslint-disable-line no-unused-vars
|
|
156
|
-
{
|
|
157
|
-
r3logger.mlog(r3logger.dump(response)); // response is object(or not)
|
|
158
|
-
console.log('RESPONSE BODY = ' + JSON.stringify(response));
|
|
159
|
-
process.exit(0);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
req.on('error', function(e)
|
|
164
|
-
{
|
|
165
|
-
r3logger.elog('problem with request: ' + e.message);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// write data to request body
|
|
169
|
-
if('' !== strbody){
|
|
170
|
-
req.write(strbody);
|
|
171
|
-
}
|
|
172
|
-
req.end();
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
//
|
|
176
|
-
// run
|
|
177
|
-
//
|
|
178
|
-
cliutil.getConsoleInput('Method(POST/PUT) : ', true, false, function(isbreak, method)
|
|
179
|
-
{
|
|
180
|
-
if(isbreak){
|
|
181
|
-
process.exit(0);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
var _method;
|
|
185
|
-
if(apiutil.compareCaseString('post', method)){
|
|
186
|
-
_method = 'POST';
|
|
187
|
-
}else if(apiutil.compareCaseString('put', method)){
|
|
188
|
-
_method = 'PUT';
|
|
189
|
-
}else{
|
|
190
|
-
console.log('method must be POST or PUT : ' + method);
|
|
191
|
-
process.exit(0);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
cliutil.getConsoleInput('Unscoped(or Scoped) user token : ', true, false, function(isbreak, token)
|
|
195
|
-
{
|
|
196
|
-
if(isbreak){
|
|
197
|
-
process.exit(0);
|
|
198
|
-
}
|
|
199
|
-
var _token = token;
|
|
200
|
-
|
|
201
|
-
cliutil.getConsoleInput('Create or Update tenant(create(default)/update) : ', true, false, function(isbreak, mode)
|
|
202
|
-
{
|
|
203
|
-
if(isbreak){
|
|
204
|
-
process.exit(0);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
var _is_create;
|
|
208
|
-
if('' === apiutil.getSafeString(mode) || apiutil.compareCaseString('null', apiutil.getSafeString(mode))){
|
|
209
|
-
_is_create = true;
|
|
210
|
-
}else if(apiutil.compareCaseString('create', apiutil.getSafeString(mode))){
|
|
211
|
-
_is_create = true;
|
|
212
|
-
}else if(apiutil.compareCaseString('update', apiutil.getSafeString(mode))){
|
|
213
|
-
_is_create = false;
|
|
214
|
-
}else{
|
|
215
|
-
console.log('function mode must be empty or create or update : ' + mode);
|
|
216
|
-
process.exit(0);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
cliutil.getConsoleInput('tenant name(if not specify, add prefix local@) : ', true, false, function(isbreak, name)
|
|
220
|
-
{
|
|
221
|
-
if(isbreak){
|
|
222
|
-
process.exit(0);
|
|
223
|
-
}
|
|
224
|
-
var _name = name;
|
|
225
|
-
|
|
226
|
-
cliutil.getConsoleInput('tenant description(allow null) : ', true, false, function(isbreak, desc)
|
|
227
|
-
{
|
|
228
|
-
if(isbreak){
|
|
229
|
-
process.exit(0);
|
|
230
|
-
}
|
|
231
|
-
var _desc = desc;
|
|
232
|
-
|
|
233
|
-
cliutil.getConsoleInput('tenant display name(allow null) : ', true, false, function(isbreak, display)
|
|
234
|
-
{
|
|
235
|
-
if(isbreak){
|
|
236
|
-
process.exit(0);
|
|
237
|
-
}
|
|
238
|
-
var _display = display;
|
|
239
|
-
|
|
240
|
-
cliutil.getConsoleInput('tenant users(input user name separate with ,) : ', true, false, function(isbreak, users)
|
|
241
|
-
{
|
|
242
|
-
if(isbreak){
|
|
243
|
-
process.exit(0);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
var _users = Array();
|
|
247
|
-
var tmparr = apiutil.getSafeString(users).split(',');
|
|
248
|
-
for(var cnt = 0; cnt < tmparr.length; ++cnt){
|
|
249
|
-
var tmpstr = apiutil.getSafeString(tmparr[cnt].trim());
|
|
250
|
-
if('' !== tmpstr){
|
|
251
|
-
_users.push(tmpstr);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
if(apiutil.isEmptyArray(_users)){
|
|
255
|
-
_users = null;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if(_is_create){
|
|
259
|
-
//
|
|
260
|
-
// Create mode
|
|
261
|
-
//
|
|
262
|
-
postputV1Tenant(_method, _token, _is_create, _name, _desc, _display, _users, null);
|
|
263
|
-
|
|
264
|
-
}else{
|
|
265
|
-
// // Update mode
|
|
266
|
-
//
|
|
267
|
-
cliutil.getConsoleInput('tenant id : ', true, false, function(isbreak, id)
|
|
268
|
-
{
|
|
269
|
-
if(isbreak){
|
|
270
|
-
process.exit(0);
|
|
271
|
-
}
|
|
272
|
-
var _id = id;
|
|
273
|
-
|
|
274
|
-
// run
|
|
275
|
-
postputV1Tenant(_method, _token, _is_create, _name, _desc, _display, _users, _id);
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
/*
|
|
287
|
-
* Local variables:
|
|
288
|
-
* tab-width: 4
|
|
289
|
-
* c-basic-offset: 4
|
|
290
|
-
* End:
|
|
291
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
292
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
293
|
-
*/
|