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,544 +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 postV1Role(method, token, name, policies, alias)
|
|
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
|
-
'method': method
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
if(apiutil.compareCaseString('post', method)){
|
|
57
|
-
var body = {
|
|
58
|
-
'role': {
|
|
59
|
-
'name': name,
|
|
60
|
-
'policies': policies,
|
|
61
|
-
'alias': alias
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
strbody = JSON.stringify(body);
|
|
66
|
-
headers['Content-Length'] = strbody.length;
|
|
67
|
-
options.headers = headers;
|
|
68
|
-
options.path = '/v1/role';
|
|
69
|
-
|
|
70
|
-
}else if(apiutil.compareCaseString('put', method)){
|
|
71
|
-
// case for PUT
|
|
72
|
-
var urlarg = '';
|
|
73
|
-
var already_set = false;
|
|
74
|
-
if('' === name || apiutil.isSafeString(name)){
|
|
75
|
-
urlarg += already_set ? '&name=' : '?name=';
|
|
76
|
-
urlarg += name;
|
|
77
|
-
already_set = true;
|
|
78
|
-
}
|
|
79
|
-
if(apiutil.isSafeEntity(policies)){
|
|
80
|
-
urlarg += already_set ? '&policies=' : '?policies=';
|
|
81
|
-
urlarg += JSON.stringify(policies); // policies is converted to JSON
|
|
82
|
-
already_set = true;
|
|
83
|
-
}
|
|
84
|
-
if(apiutil.isSafeEntity(alias)){
|
|
85
|
-
urlarg += already_set ? '&alias=' : '?alias=';
|
|
86
|
-
urlarg += JSON.stringify(alias); // alias is converted to JSON
|
|
87
|
-
already_set = true;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
headers['Content-Length'] = 0;
|
|
91
|
-
options.headers = headers;
|
|
92
|
-
options.path = '/v1/role' + encodeURI(urlarg);
|
|
93
|
-
|
|
94
|
-
}else{
|
|
95
|
-
console.log('method must be POST or PUT : ' + method);
|
|
96
|
-
process.exit(0);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
r3logger.dlog('request options = ' + JSON.stringify(options));
|
|
100
|
-
r3logger.dlog('request headers = ' + JSON.stringify(headers));
|
|
101
|
-
r3logger.dlog('request body = ' + strbody);
|
|
102
|
-
|
|
103
|
-
var httpobj;
|
|
104
|
-
if(is_https){
|
|
105
|
-
if(null !== cacerts.ca){
|
|
106
|
-
options.ca = cacerts.ca;
|
|
107
|
-
}
|
|
108
|
-
options.rejectUnauthorized = false; // always insecure for this manual test
|
|
109
|
-
options.agent = new https.Agent(options);
|
|
110
|
-
httpobj = https;
|
|
111
|
-
}else{
|
|
112
|
-
options.agent = new http.Agent(options);
|
|
113
|
-
httpobj = http;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
var req = httpobj.request(options, function(res)
|
|
117
|
-
{
|
|
118
|
-
var response = '';
|
|
119
|
-
console.log('RESPONSE CODE = ' + res.statusCode);
|
|
120
|
-
r3logger.dlog('response status = ' + res.statusCode);
|
|
121
|
-
r3logger.dlog('response header = ' + JSON.stringify(res.headers));
|
|
122
|
-
res.setEncoding('utf8');
|
|
123
|
-
|
|
124
|
-
res.on('data', function (chunk)
|
|
125
|
-
{
|
|
126
|
-
r3logger.dlog('response chunk = ' + chunk);
|
|
127
|
-
response += chunk;
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
res.on('end', function(result) // eslint-disable-line no-unused-vars
|
|
131
|
-
{
|
|
132
|
-
r3logger.mlog(r3logger.dump(response)); // response is object(or not)
|
|
133
|
-
console.log('RESPONSE BODY = ' + JSON.stringify(response));
|
|
134
|
-
process.exit(0);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
req.on('error', function(e) {
|
|
138
|
-
r3logger.elog('problem with request: ' + e.message);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
// write data to request body
|
|
142
|
-
if('' !== strbody){
|
|
143
|
-
req.write(strbody);
|
|
144
|
-
}
|
|
145
|
-
req.end();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function postV1RoleHost(method, is_user_token, token, name, target_host, port, cuk, extra, tag, inboundip, outboundip)
|
|
149
|
-
{
|
|
150
|
-
var strbody = '';
|
|
151
|
-
var _token = (is_user_token ? ('U=' + token) : ('R=' + token));
|
|
152
|
-
var headers = {
|
|
153
|
-
'Content-Type': 'application/json',
|
|
154
|
-
'X-Auth-Token': _token
|
|
155
|
-
};
|
|
156
|
-
var options = {
|
|
157
|
-
'host': hostname,
|
|
158
|
-
'port': hostport,
|
|
159
|
-
'method': method
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
if(apiutil.compareCaseString('post', method)){
|
|
163
|
-
var host_info = {};
|
|
164
|
-
if(is_user_token){
|
|
165
|
-
host_info.host = target_host;
|
|
166
|
-
host_info.ip = null;
|
|
167
|
-
}
|
|
168
|
-
host_info.port = port;
|
|
169
|
-
host_info.cuk = cuk;
|
|
170
|
-
host_info.extra = extra;
|
|
171
|
-
host_info.tag = tag;
|
|
172
|
-
|
|
173
|
-
if(apiutil.isSafeString(inboundip)){ // not need to check ip address
|
|
174
|
-
host_info.inboundip = inboundip;
|
|
175
|
-
}
|
|
176
|
-
if(apiutil.isSafeString(outboundip)){ // not need to check ip address
|
|
177
|
-
host_info.outboundip = outboundip;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
var body = { 'host': host_info };
|
|
181
|
-
|
|
182
|
-
strbody = JSON.stringify(body);
|
|
183
|
-
headers['Content-Length'] = strbody.length;
|
|
184
|
-
options.headers = headers;
|
|
185
|
-
options.path = '/v1/role/' + name;
|
|
186
|
-
|
|
187
|
-
}else if(apiutil.compareCaseString('put', method)){
|
|
188
|
-
// case for PUT
|
|
189
|
-
var urlarg = '';
|
|
190
|
-
var already_set = false;
|
|
191
|
-
if(is_user_token && apiutil.isSafeString(target_host)){
|
|
192
|
-
urlarg += already_set ? '&host=' : '?host=';
|
|
193
|
-
urlarg += target_host;
|
|
194
|
-
already_set = true;
|
|
195
|
-
}
|
|
196
|
-
if(0 <= port){
|
|
197
|
-
urlarg += already_set ? '&port=' : '?port=';
|
|
198
|
-
urlarg += port;
|
|
199
|
-
already_set = true;
|
|
200
|
-
}
|
|
201
|
-
if(apiutil.isSafeString(cuk)){
|
|
202
|
-
urlarg += already_set ? '&cuk=' : '?cuk=';
|
|
203
|
-
urlarg += cuk;
|
|
204
|
-
already_set = true;
|
|
205
|
-
}
|
|
206
|
-
if(apiutil.isSafeString(extra)){
|
|
207
|
-
urlarg += already_set ? '&extra=' : '?extra=';
|
|
208
|
-
urlarg += JSON.stringify(extra); // if extra is existing, it includes control codes, so it is converted to JSON.
|
|
209
|
-
already_set = true;
|
|
210
|
-
}
|
|
211
|
-
if(apiutil.isSafeString(tag)){
|
|
212
|
-
urlarg += already_set ? '&tag=' : '?tag=';
|
|
213
|
-
urlarg += JSON.stringify(tag); // if tag is existing, it includes control codes, so it is converted to JSON.
|
|
214
|
-
already_set = true;
|
|
215
|
-
}
|
|
216
|
-
if(apiutil.isSafeString(inboundip)){ // not need to check ip address
|
|
217
|
-
urlarg += already_set ? '&inboundip=' : '?inboundip=';
|
|
218
|
-
urlarg += inboundip;
|
|
219
|
-
already_set = true;
|
|
220
|
-
}
|
|
221
|
-
if(apiutil.isSafeString(outboundip)){ // not need to check ip address
|
|
222
|
-
urlarg += already_set ? '&outboundip=' : '?outboundip=';
|
|
223
|
-
urlarg += outboundip;
|
|
224
|
-
already_set = true;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
headers['Content-Length'] = 0;
|
|
228
|
-
options.headers = headers;
|
|
229
|
-
options.path = '/v1/role/' + name + encodeURI(urlarg);
|
|
230
|
-
|
|
231
|
-
}else{
|
|
232
|
-
console.log('method must be POST or PUT : ' + method);
|
|
233
|
-
process.exit(0);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
r3logger.dlog('request options = ' + JSON.stringify(options));
|
|
237
|
-
r3logger.dlog('request headers = ' + JSON.stringify(headers));
|
|
238
|
-
r3logger.dlog('request body = ' + strbody);
|
|
239
|
-
|
|
240
|
-
var httpobj;
|
|
241
|
-
if(is_https){
|
|
242
|
-
if(null !== cacerts.ca){
|
|
243
|
-
options.ca = cacerts.ca;
|
|
244
|
-
}
|
|
245
|
-
options.rejectUnauthorized = false; // always insecure for this manual test
|
|
246
|
-
options.agent = new https.Agent(options);
|
|
247
|
-
httpobj = https;
|
|
248
|
-
}else{
|
|
249
|
-
options.agent = new http.Agent(options);
|
|
250
|
-
httpobj = http;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
var req = httpobj.request(options, function(res)
|
|
254
|
-
{
|
|
255
|
-
var response = '';
|
|
256
|
-
console.log('RESPONSE CODE = ' + res.statusCode);
|
|
257
|
-
r3logger.dlog('response status = ' + res.statusCode);
|
|
258
|
-
r3logger.dlog('response header = ' + JSON.stringify(res.headers));
|
|
259
|
-
res.setEncoding('utf8');
|
|
260
|
-
|
|
261
|
-
res.on('data', function (chunk)
|
|
262
|
-
{
|
|
263
|
-
r3logger.dlog('response chunk = ' + chunk);
|
|
264
|
-
response += chunk;
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
res.on('end', function(result) // eslint-disable-line no-unused-vars
|
|
268
|
-
{
|
|
269
|
-
r3logger.mlog(r3logger.dump(response)); // response is object(or not)
|
|
270
|
-
console.log('RESPONSE BODY = ' + JSON.stringify(response));
|
|
271
|
-
process.exit(0);
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
req.on('error', function(e) {
|
|
275
|
-
r3logger.elog('problem with request: ' + e.message);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
// write data to request body
|
|
279
|
-
if('' !== strbody){
|
|
280
|
-
req.write(strbody);
|
|
281
|
-
}
|
|
282
|
-
req.end();
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
//
|
|
286
|
-
// Run for role
|
|
287
|
-
//
|
|
288
|
-
function inputRoleType(method)
|
|
289
|
-
{
|
|
290
|
-
var _method = method;
|
|
291
|
-
|
|
292
|
-
cliutil.getConsoleInput('Scoped user token for tenant : ', true, false, function(isbreak, token)
|
|
293
|
-
{
|
|
294
|
-
if(isbreak){
|
|
295
|
-
process.exit(0);
|
|
296
|
-
}
|
|
297
|
-
var _token = token;
|
|
298
|
-
|
|
299
|
-
cliutil.getConsoleInput('Role name(path) : ', true, false, function(isbreak, name)
|
|
300
|
-
{
|
|
301
|
-
if(isbreak){
|
|
302
|
-
process.exit(0);
|
|
303
|
-
}
|
|
304
|
-
var _name = name;
|
|
305
|
-
|
|
306
|
-
cliutil.getConsoleInput(' policies(specify null/yrn with \',\' for multiple) : ', true, false, function(isbreak, policies)
|
|
307
|
-
{
|
|
308
|
-
if(isbreak){
|
|
309
|
-
process.exit(0);
|
|
310
|
-
}
|
|
311
|
-
var _policies;
|
|
312
|
-
|
|
313
|
-
if('' === apiutil.getSafeString(policies) || apiutil.compareCaseString('null', apiutil.getSafeString(policies))){
|
|
314
|
-
_policies = null;
|
|
315
|
-
}else{
|
|
316
|
-
// parse ','
|
|
317
|
-
_policies = new Array(0);
|
|
318
|
-
var strarray= policies.split(',');
|
|
319
|
-
for(var cnt = 0; cnt < strarray.length; ++cnt){
|
|
320
|
-
var strtmp = strarray[cnt].trim();
|
|
321
|
-
_policies.push(strtmp);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
cliutil.getConsoleInput(' alias(specify null/yrn with \',\' for multiple) : ', true, false, function(isbreak, alias)
|
|
326
|
-
{
|
|
327
|
-
if(isbreak){
|
|
328
|
-
process.exit(0);
|
|
329
|
-
}
|
|
330
|
-
var _alias;
|
|
331
|
-
|
|
332
|
-
if('' === apiutil.getSafeString(alias) || apiutil.compareCaseString('null', apiutil.getSafeString(alias))){
|
|
333
|
-
_alias = null;
|
|
334
|
-
}else{
|
|
335
|
-
// parse ','
|
|
336
|
-
_alias = new Array(0);
|
|
337
|
-
var strarray= alias.split(',');
|
|
338
|
-
for(var cnt = 0; cnt < strarray.length; ++cnt){
|
|
339
|
-
var strtmp = strarray[cnt].trim();
|
|
340
|
-
_alias.push(strtmp);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
// run
|
|
345
|
-
postV1Role(_method, _token, _name, _policies, _alias);
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
//
|
|
353
|
-
// Run for host
|
|
354
|
-
//
|
|
355
|
-
function inputHostType(method)
|
|
356
|
-
{
|
|
357
|
-
var _method = method;
|
|
358
|
-
|
|
359
|
-
cliutil.getConsoleInput('Token type( USER(default) / ROLE ) : ', true, false, function(isbreak, type)
|
|
360
|
-
{
|
|
361
|
-
if(isbreak){
|
|
362
|
-
process.exit(0);
|
|
363
|
-
}
|
|
364
|
-
var _is_user_token;
|
|
365
|
-
var _keyward;
|
|
366
|
-
if(!apiutil.isSafeString(type) || apiutil.compareCaseString('null', apiutil.getSafeString(type)) || apiutil.compareCaseString('user', apiutil.getSafeString(type))){
|
|
367
|
-
_is_user_token = true;
|
|
368
|
-
_keyward = 'USER';
|
|
369
|
-
}else if(apiutil.compareCaseString('role', apiutil.getSafeString(type))){
|
|
370
|
-
_is_user_token = false;
|
|
371
|
-
_keyward = 'ROLE';
|
|
372
|
-
}else{
|
|
373
|
-
process.exit(0);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
cliutil.getConsoleInput('Scoped ' + _keyward + ' token for tenant : ', true, false, function(isbreak, token)
|
|
377
|
-
{
|
|
378
|
-
if(isbreak){
|
|
379
|
-
process.exit(0);
|
|
380
|
-
}
|
|
381
|
-
var _token = token;
|
|
382
|
-
|
|
383
|
-
cliutil.getConsoleInput('Role name(path) : ', true, false, function(isbreak, name)
|
|
384
|
-
{
|
|
385
|
-
if(isbreak){
|
|
386
|
-
process.exit(0);
|
|
387
|
-
}
|
|
388
|
-
var _name = name;
|
|
389
|
-
|
|
390
|
-
cliutil.getConsoleInput(' Port number(specify 0...(0 means any port)) : ', true, false, function(isbreak, port)
|
|
391
|
-
{
|
|
392
|
-
if(isbreak){
|
|
393
|
-
process.exit(0);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
var _port;
|
|
397
|
-
if(null === port || !apiutil.isSafeString(port)){
|
|
398
|
-
_port = 0;
|
|
399
|
-
}else if(!isNaN(port)){
|
|
400
|
-
_port = parseInt(port);
|
|
401
|
-
}else{
|
|
402
|
-
console.log('port number must be decimal number: ' + JSON.stringify(port));
|
|
403
|
-
process.exit(0);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
cliutil.getConsoleInput(' CUK string(allow null) : ', true, false, function(isbreak, cuk)
|
|
407
|
-
{
|
|
408
|
-
if(isbreak){
|
|
409
|
-
process.exit(0);
|
|
410
|
-
}
|
|
411
|
-
var _cuk = null;
|
|
412
|
-
if(apiutil.isSafeString(cuk) && apiutil.isSafeString(cuk.trim())){
|
|
413
|
-
_cuk = cuk.trim();
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
cliutil.getConsoleInput(' Extra data - null/openstack(os)/kubernetes(k8s) : ', true, false, function(isbreak, extra)
|
|
417
|
-
{
|
|
418
|
-
if(isbreak){
|
|
419
|
-
process.exit(0);
|
|
420
|
-
}
|
|
421
|
-
var _extra;
|
|
422
|
-
|
|
423
|
-
if('' === apiutil.getSafeString(extra) || apiutil.compareCaseString('null', apiutil.getSafeString(extra))){
|
|
424
|
-
_extra = null;
|
|
425
|
-
}else if(apiutil.compareCaseString('os', apiutil.getSafeString(extra)) || apiutil.compareCaseString('openstack', apiutil.getSafeString(extra))){
|
|
426
|
-
_extra = 'openstack-auto-v1';
|
|
427
|
-
}else if(apiutil.compareCaseString('k8s', apiutil.getSafeString(extra)) || apiutil.compareCaseString('kubernetes', apiutil.getSafeString(extra))){
|
|
428
|
-
_extra = 'k8s-auto-v1';
|
|
429
|
-
}else{
|
|
430
|
-
_extra = extra;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
cliutil.getConsoleInput(' Tag string - null or string : ', true, false, function(isbreak, tag)
|
|
434
|
-
{
|
|
435
|
-
if(isbreak){
|
|
436
|
-
process.exit(0);
|
|
437
|
-
}
|
|
438
|
-
var _tag;
|
|
439
|
-
if('' === apiutil.getSafeString(tag) || apiutil.compareCaseString('null', apiutil.getSafeString(tag))){
|
|
440
|
-
_tag = null;
|
|
441
|
-
}else{
|
|
442
|
-
_tag = tag;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
cliutil.getConsoleInput(' Inbound IP address - null or string : ', true, false, function(isbreak, inbound)
|
|
446
|
-
{
|
|
447
|
-
if(isbreak){
|
|
448
|
-
process.exit(0);
|
|
449
|
-
}
|
|
450
|
-
var _inbound;
|
|
451
|
-
if('' === apiutil.getSafeString(inbound) || apiutil.compareCaseString('null', apiutil.getSafeString(inbound))){
|
|
452
|
-
_inbound = null;
|
|
453
|
-
}else{
|
|
454
|
-
_inbound = inbound;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
cliutil.getConsoleInput(' Outbound IP address - null or string : ', true, false, function(isbreak, outbound)
|
|
458
|
-
{
|
|
459
|
-
if(isbreak){
|
|
460
|
-
process.exit(0);
|
|
461
|
-
}
|
|
462
|
-
var _outbound;
|
|
463
|
-
if('' === apiutil.getSafeString(outbound) || apiutil.compareCaseString('null', apiutil.getSafeString(outbound))){
|
|
464
|
-
_outbound = null;
|
|
465
|
-
}else{
|
|
466
|
-
_outbound = outbound;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
if(!_is_user_token){
|
|
470
|
-
// run
|
|
471
|
-
postV1RoleHost(_method, _is_user_token, _token, _name, null, _port, _cuk, _extra, _tag, _inbound, _outbound);
|
|
472
|
-
}else{
|
|
473
|
-
|
|
474
|
-
cliutil.getConsoleInput(' Host(specify hostname or ip address) : ', true, false, function(isbreak, target_host)
|
|
475
|
-
{
|
|
476
|
-
if(isbreak){
|
|
477
|
-
process.exit(0);
|
|
478
|
-
}
|
|
479
|
-
if(!apiutil.isSafeString(target_host)){
|
|
480
|
-
process.exit(0);
|
|
481
|
-
}
|
|
482
|
-
var _target_host = target_host;
|
|
483
|
-
|
|
484
|
-
// run
|
|
485
|
-
postV1RoleHost(_method, _is_user_token, _token, _name, _target_host, _port, _cuk, _extra, _tag, _inbound, _outbound);
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
});
|
|
489
|
-
});
|
|
490
|
-
});
|
|
491
|
-
});
|
|
492
|
-
});
|
|
493
|
-
});
|
|
494
|
-
});
|
|
495
|
-
});
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
//
|
|
500
|
-
// Run
|
|
501
|
-
//
|
|
502
|
-
cliutil.getConsoleInput('Method(POST/PUT) : ', true, false, function(isbreak, method)
|
|
503
|
-
{
|
|
504
|
-
if(isbreak){
|
|
505
|
-
process.exit(0);
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
var _method;
|
|
509
|
-
if(apiutil.compareCaseString('post', method)){
|
|
510
|
-
_method = 'POST';
|
|
511
|
-
}else if(apiutil.compareCaseString('put', method)){
|
|
512
|
-
_method = 'PUT';
|
|
513
|
-
}else{
|
|
514
|
-
console.log('method must be POST or PUT : ' + method);
|
|
515
|
-
process.exit(0);
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
cliutil.getConsoleInput('Use API for Role or Host in Role(ROLE/HOST) : ', true, false, function(isbreak, apitype)
|
|
519
|
-
{
|
|
520
|
-
if(isbreak){
|
|
521
|
-
process.exit(0);
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
if(apiutil.compareCaseString('role', apitype)){
|
|
525
|
-
inputRoleType(_method);
|
|
526
|
-
|
|
527
|
-
}else if(apiutil.compareCaseString('host', apitype)){
|
|
528
|
-
inputHostType(_method);
|
|
529
|
-
|
|
530
|
-
}else{
|
|
531
|
-
console.log('API type must be ROLE or HOST : ' + apitype);
|
|
532
|
-
process.exit(0);
|
|
533
|
-
}
|
|
534
|
-
});
|
|
535
|
-
});
|
|
536
|
-
|
|
537
|
-
/*
|
|
538
|
-
* Local variables:
|
|
539
|
-
* tab-width: 4
|
|
540
|
-
* c-basic-offset: 4
|
|
541
|
-
* End:
|
|
542
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
543
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
544
|
-
*/
|
|
@@ -1,153 +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: Mon Nor 6 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 rawDeleteV1Service(token, service, tenant)
|
|
44
|
-
{
|
|
45
|
-
var basepath = '/v1/service/' + service;
|
|
46
|
-
if(apiutil.isSafeString(tenant)){
|
|
47
|
-
basepath += '?tenant=' + encodeURI(tenant);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
var headers = {
|
|
51
|
-
'Content-Type': 'application/json',
|
|
52
|
-
'X-Auth-Token': 'U=' + token
|
|
53
|
-
};
|
|
54
|
-
var options = {
|
|
55
|
-
'host': hostname,
|
|
56
|
-
'port': hostport,
|
|
57
|
-
'path': basepath,
|
|
58
|
-
'method': 'DELETE',
|
|
59
|
-
'headers': headers
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
r3logger.dlog('request options = ' + JSON.stringify(options));
|
|
63
|
-
r3logger.dlog('request headers = ' + JSON.stringify(headers));
|
|
64
|
-
|
|
65
|
-
var httpobj;
|
|
66
|
-
if(is_https){
|
|
67
|
-
if(null !== cacerts.ca){
|
|
68
|
-
options.ca = cacerts.ca;
|
|
69
|
-
}
|
|
70
|
-
options.rejectUnauthorized = false; // always insecure for this manual test
|
|
71
|
-
options.agent = new https.Agent(options);
|
|
72
|
-
httpobj = https;
|
|
73
|
-
}else{
|
|
74
|
-
options.agent = new http.Agent(options);
|
|
75
|
-
httpobj = http;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
var req = httpobj.request(options, function(res)
|
|
79
|
-
{
|
|
80
|
-
var response = '';
|
|
81
|
-
console.log('RESPONSE CODE = ' + res.statusCode);
|
|
82
|
-
r3logger.dlog('response status = ' + res.statusCode);
|
|
83
|
-
r3logger.dlog('response header = ' + JSON.stringify(res.headers));
|
|
84
|
-
res.setEncoding('utf8');
|
|
85
|
-
|
|
86
|
-
res.on('data', function (chunk)
|
|
87
|
-
{
|
|
88
|
-
r3logger.dlog('response chunk = ' + chunk);
|
|
89
|
-
response += chunk;
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
res.on('end', function(result) // eslint-disable-line no-unused-vars
|
|
93
|
-
{
|
|
94
|
-
r3logger.mlog(r3logger.dump(response)); // response is object(or not)
|
|
95
|
-
console.log('RESPONSE BODY = ' + JSON.stringify(response));
|
|
96
|
-
process.exit(0);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
req.on('error', function(e)
|
|
101
|
-
{
|
|
102
|
-
r3logger.elog('problem with request: ' + e.message);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
req.end();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
//
|
|
109
|
-
// run
|
|
110
|
-
//
|
|
111
|
-
cliutil.getConsoleInput('Scoped user token for service owner tenant : ', true, false, function(isbreak, token)
|
|
112
|
-
{
|
|
113
|
-
if(isbreak){
|
|
114
|
-
process.exit(0);
|
|
115
|
-
}
|
|
116
|
-
var _token = token;
|
|
117
|
-
|
|
118
|
-
cliutil.getConsoleInput('Service name : ', true, false, function(isbreak, service)
|
|
119
|
-
{
|
|
120
|
-
if(isbreak){
|
|
121
|
-
process.exit(0);
|
|
122
|
-
}
|
|
123
|
-
if(!apiutil.isSafeString(service)){
|
|
124
|
-
console.log('must be service name.');
|
|
125
|
-
process.exit(0);
|
|
126
|
-
}
|
|
127
|
-
var _service = service;
|
|
128
|
-
|
|
129
|
-
cliutil.getConsoleInput('Remove tenant name(empty(null)->remove service) : ', true, false, function(isbreak, tenant)
|
|
130
|
-
{
|
|
131
|
-
if(isbreak){
|
|
132
|
-
process.exit(0);
|
|
133
|
-
}
|
|
134
|
-
var _tenant = tenant;
|
|
135
|
-
if(!apiutil.isSafeString(tenant)){
|
|
136
|
-
_tenant = null;
|
|
137
|
-
}
|
|
138
|
-
//
|
|
139
|
-
// run DELETE
|
|
140
|
-
//
|
|
141
|
-
rawDeleteV1Service(_token, _service, _tenant);
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
/*
|
|
147
|
-
* Local variables:
|
|
148
|
-
* tab-width: 4
|
|
149
|
-
* c-basic-offset: 4
|
|
150
|
-
* End:
|
|
151
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
152
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
153
|
-
*/
|