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,310 +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 postV1UserTokens(method, token, othertoken, user, passwd, tenant)
|
|
44
|
-
{
|
|
45
|
-
var headers = {
|
|
46
|
-
'Content-Type': 'application/json'
|
|
47
|
-
};
|
|
48
|
-
var options = {
|
|
49
|
-
'host': hostname,
|
|
50
|
-
'port': hostport,
|
|
51
|
-
'method': method
|
|
52
|
-
};
|
|
53
|
-
var strbody = '';
|
|
54
|
-
|
|
55
|
-
// set token if exists
|
|
56
|
-
var is_user_cred_type = true;
|
|
57
|
-
if(apiutil.isSafeString(token)){
|
|
58
|
-
headers['x-auth-token'] = 'U=' + token;
|
|
59
|
-
is_user_cred_type = false;
|
|
60
|
-
}else if(apiutil.isSafeString(othertoken)){
|
|
61
|
-
headers['x-auth-token'] = 'U=' + othertoken;
|
|
62
|
-
is_user_cred_type = false;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if(apiutil.compareCaseString('post', method)){
|
|
66
|
-
// case for POST
|
|
67
|
-
|
|
68
|
-
var body;
|
|
69
|
-
if(is_user_cred_type){
|
|
70
|
-
body = {
|
|
71
|
-
'auth': {
|
|
72
|
-
'tenantName': apiutil.isSafeString(tenant) ? tenant : '',
|
|
73
|
-
'passwordCredentials': {
|
|
74
|
-
'username': user,
|
|
75
|
-
'password': passwd
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
}else{
|
|
80
|
-
body = {
|
|
81
|
-
'auth': {
|
|
82
|
-
'tenantName': apiutil.isSafeString(tenant) ? tenant : ''
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
strbody = JSON.stringify(body);
|
|
88
|
-
headers['Content-Length'] = strbody.length;
|
|
89
|
-
options.headers = headers;
|
|
90
|
-
options.path = '/v1/user/tokens';
|
|
91
|
-
|
|
92
|
-
}else if(apiutil.compareCaseString('put', method)){
|
|
93
|
-
// case for PUT
|
|
94
|
-
var urlarg = '';
|
|
95
|
-
var already_set = false;
|
|
96
|
-
if('' === tenant || apiutil.isSafeString(tenant)){
|
|
97
|
-
urlarg += already_set ? '&tenantname=' : '?tenantname=';
|
|
98
|
-
urlarg += tenant;
|
|
99
|
-
already_set = true;
|
|
100
|
-
}
|
|
101
|
-
if(is_user_cred_type){
|
|
102
|
-
if('' === user || apiutil.isSafeString(user)){
|
|
103
|
-
urlarg += already_set ? '&username=' : '?username=';
|
|
104
|
-
urlarg += user;
|
|
105
|
-
already_set = true;
|
|
106
|
-
}
|
|
107
|
-
if('' === passwd || apiutil.isSafeString(passwd)){
|
|
108
|
-
urlarg += already_set ? '&password=' : '?password=';
|
|
109
|
-
urlarg += encodeURIComponent(passwd); // NOTICE: encoding passwd
|
|
110
|
-
already_set = true;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
headers['Content-Length'] = 0;
|
|
114
|
-
options.headers = headers;
|
|
115
|
-
options.path = '/v1/user/tokens' + encodeURI(urlarg);
|
|
116
|
-
|
|
117
|
-
}else{
|
|
118
|
-
console.log('method must be POST or PUT : ' + method);
|
|
119
|
-
process.exit(0);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
r3logger.dlog('request options = ' + JSON.stringify(options));
|
|
123
|
-
r3logger.dlog('request headers = ' + JSON.stringify(headers));
|
|
124
|
-
r3logger.dlog('request body = ' + strbody);
|
|
125
|
-
|
|
126
|
-
var httpobj;
|
|
127
|
-
if(is_https){
|
|
128
|
-
if(null !== cacerts.ca){
|
|
129
|
-
options.ca = cacerts.ca;
|
|
130
|
-
}
|
|
131
|
-
options.rejectUnauthorized = false; // always insecure for this manual test
|
|
132
|
-
options.agent = new https.Agent(options);
|
|
133
|
-
httpobj = https;
|
|
134
|
-
}else{
|
|
135
|
-
options.agent = new http.Agent(options);
|
|
136
|
-
httpobj = http;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
var req = httpobj.request(options, function(res)
|
|
140
|
-
{
|
|
141
|
-
var response = '';
|
|
142
|
-
console.log('RESPONSE CODE = ' + res.statusCode);
|
|
143
|
-
r3logger.dlog('response status = ' + res.statusCode);
|
|
144
|
-
r3logger.dlog('response header = ' + JSON.stringify(res.headers));
|
|
145
|
-
res.setEncoding('utf8');
|
|
146
|
-
|
|
147
|
-
res.on('data', function (chunk) {
|
|
148
|
-
r3logger.dlog('response chunk = ' + chunk);
|
|
149
|
-
response += chunk;
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
res.on('end', function(result) // eslint-disable-line no-unused-vars
|
|
153
|
-
{
|
|
154
|
-
r3logger.mlog(r3logger.dump(response)); // response is object(or not)
|
|
155
|
-
console.log('RESPONSE BODY = ' + JSON.stringify(response));
|
|
156
|
-
process.exit(0);
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
req.on('error', function(e) {
|
|
160
|
-
r3logger.elog('problem with request: ' + e.message);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
// write data to request body
|
|
164
|
-
if('' !== strbody){
|
|
165
|
-
req.write(strbody);
|
|
166
|
-
}
|
|
167
|
-
req.end();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
cliutil.getConsoleInput('Method(POST/PUT) : ', true, false, function(isbreak, method)
|
|
171
|
-
{
|
|
172
|
-
if(isbreak){
|
|
173
|
-
process.exit(0);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
var _method;
|
|
177
|
-
if(apiutil.compareCaseString('post', method)){
|
|
178
|
-
_method = 'POST';
|
|
179
|
-
}else if(apiutil.compareCaseString('put', method)){
|
|
180
|
-
_method = 'PUT';
|
|
181
|
-
}else{
|
|
182
|
-
console.log('method must be POST or PUT : ' + method);
|
|
183
|
-
process.exit(0);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
cliutil.getConsoleInput('Type(CRED/TOKEN/OTHER) : ', true, false, function(isbreak, type)
|
|
187
|
-
{
|
|
188
|
-
if(isbreak){
|
|
189
|
-
process.exit(0);
|
|
190
|
-
}
|
|
191
|
-
var _type = type;
|
|
192
|
-
|
|
193
|
-
if('' === apiutil.getSafeString(_type) || apiutil.compareCaseString('cred', apiutil.getSafeString(_type))){
|
|
194
|
-
//
|
|
195
|
-
// User credentials
|
|
196
|
-
//
|
|
197
|
-
cliutil.getConsoleInput('Username : ', true, false, function(isbreak, username)
|
|
198
|
-
{
|
|
199
|
-
if(isbreak){
|
|
200
|
-
process.exit(0);
|
|
201
|
-
}
|
|
202
|
-
var _username = username;
|
|
203
|
-
|
|
204
|
-
// if not jpopsdb api for keystone, we must set passwd.
|
|
205
|
-
//
|
|
206
|
-
cliutil.getConsoleInput('Password(null for not using pw): ', false, false, function(isbreak, passwd)
|
|
207
|
-
{
|
|
208
|
-
if(isbreak){
|
|
209
|
-
process.exit(0);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
var _passwd = passwd;
|
|
213
|
-
if('' === apiutil.getSafeString(_passwd)){
|
|
214
|
-
// [NOTE]
|
|
215
|
-
// If passwd is empty, we set null for passwd.
|
|
216
|
-
// You can specify your keystone which does not need to set passwd for getting credential.
|
|
217
|
-
//
|
|
218
|
-
_passwd = null;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
cliutil.getConsoleInput('Tenant : ', true, false, function(isbreak, tenant)
|
|
222
|
-
{
|
|
223
|
-
if(isbreak){
|
|
224
|
-
process.exit(0);
|
|
225
|
-
}
|
|
226
|
-
var _tenant = null;
|
|
227
|
-
|
|
228
|
-
if('' === apiutil.getSafeString(tenant) || apiutil.compareCaseString('null', apiutil.getSafeString(tenant))){
|
|
229
|
-
_tenant = null;
|
|
230
|
-
}else{
|
|
231
|
-
_tenant = tenant;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// run
|
|
235
|
-
postV1UserTokens(_method, null, null, _username, _passwd, _tenant);
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
}else if('' === apiutil.getSafeString(_type) || apiutil.compareCaseString('token', apiutil.getSafeString(_type))){
|
|
241
|
-
//
|
|
242
|
-
// Unscoped user token registered in k2hr3
|
|
243
|
-
//
|
|
244
|
-
cliutil.getConsoleInput('Unscoped user token : ', true, false, function(isbreak, token)
|
|
245
|
-
{
|
|
246
|
-
if(isbreak){
|
|
247
|
-
process.exit(0);
|
|
248
|
-
}
|
|
249
|
-
var _token = token;
|
|
250
|
-
|
|
251
|
-
cliutil.getConsoleInput('Tenant : ', true, false, function(isbreak, tenant)
|
|
252
|
-
{
|
|
253
|
-
if(isbreak){
|
|
254
|
-
process.exit(0);
|
|
255
|
-
}
|
|
256
|
-
if('' === apiutil.getSafeString(tenant) || apiutil.compareCaseString('null', apiutil.getSafeString(tenant))){
|
|
257
|
-
console.log('using unscoped token, need tenant name.');
|
|
258
|
-
process.exit(0);
|
|
259
|
-
}
|
|
260
|
-
var _tenant = tenant;
|
|
261
|
-
|
|
262
|
-
// run
|
|
263
|
-
postV1UserTokens(_method, _token, null, null, null, _tenant);
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
}else if('' === apiutil.getSafeString(_type) || apiutil.compareCaseString('other', apiutil.getSafeString(_type))){
|
|
269
|
-
//
|
|
270
|
-
// other token from other(openstack) authorization system
|
|
271
|
-
//
|
|
272
|
-
cliutil.getConsoleInput('Other system token : ', true, false, function(isbreak, token)
|
|
273
|
-
{
|
|
274
|
-
if(isbreak){
|
|
275
|
-
process.exit(0);
|
|
276
|
-
}
|
|
277
|
-
var _token = token;
|
|
278
|
-
|
|
279
|
-
cliutil.getConsoleInput('Tenant(allow null/skip) : ', true, false, function(isbreak, tenant)
|
|
280
|
-
{
|
|
281
|
-
if(isbreak){
|
|
282
|
-
process.exit(0);
|
|
283
|
-
}
|
|
284
|
-
var _tenant = tenant;
|
|
285
|
-
if('' === apiutil.getSafeString(tenant) || apiutil.compareCaseString('null', apiutil.getSafeString(tenant))){
|
|
286
|
-
_tenant = null;
|
|
287
|
-
}else{
|
|
288
|
-
_tenant = tenant;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// run
|
|
292
|
-
postV1UserTokens(_method, null, _token, null, null, _tenant);
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
}else{
|
|
297
|
-
console.log('type must be CRED or TOKEN or OTHER(unregistered token by openstack) : ' + _type);
|
|
298
|
-
process.exit(0);
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
/*
|
|
304
|
-
* Local variables:
|
|
305
|
-
* tab-width: 4
|
|
306
|
-
* c-basic-offset: 4
|
|
307
|
-
* End:
|
|
308
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
309
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
310
|
-
*/
|
|
@@ -1,127 +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 getV1Version(is_top)
|
|
44
|
-
{
|
|
45
|
-
var ver_path = is_top ? '/' : '/v1';
|
|
46
|
-
var headers = {
|
|
47
|
-
'Content-Type': 'application/json',
|
|
48
|
-
'Content-Length': 0
|
|
49
|
-
};
|
|
50
|
-
var options = {
|
|
51
|
-
'host': hostname,
|
|
52
|
-
'port': hostport,
|
|
53
|
-
'path': ver_path,
|
|
54
|
-
'method': 'GET',
|
|
55
|
-
'headers': headers
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
r3logger.dlog('request options = ' + JSON.stringify(options));
|
|
59
|
-
r3logger.dlog('request headers = ' + JSON.stringify(headers));
|
|
60
|
-
|
|
61
|
-
var httpobj;
|
|
62
|
-
if(is_https){
|
|
63
|
-
if(null !== cacerts.ca){
|
|
64
|
-
options.ca = cacerts.ca;
|
|
65
|
-
}
|
|
66
|
-
options.rejectUnauthorized = false; // always insecure for this manual test
|
|
67
|
-
options.agent = new https.Agent(options);
|
|
68
|
-
httpobj = https;
|
|
69
|
-
}else{
|
|
70
|
-
options.agent = new http.Agent(options);
|
|
71
|
-
httpobj = http;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
var req = httpobj.request(options, function(res)
|
|
75
|
-
{
|
|
76
|
-
var response = '';
|
|
77
|
-
console.log('RESPONSE CODE = ' + res.statusCode);
|
|
78
|
-
r3logger.dlog('response status = ' + res.statusCode);
|
|
79
|
-
r3logger.dlog('response header = ' + JSON.stringify(res.headers));
|
|
80
|
-
res.setEncoding('utf8');
|
|
81
|
-
|
|
82
|
-
res.on('data', function (chunk) {
|
|
83
|
-
r3logger.dlog('response chunk = ' + chunk);
|
|
84
|
-
response += chunk;
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
res.on('end', function(result) // eslint-disable-line no-unused-vars
|
|
88
|
-
{
|
|
89
|
-
r3logger.mlog(r3logger.dump(response)); // response is object(or not)
|
|
90
|
-
console.log('RESPONSE BODY = ' + JSON.stringify(response));
|
|
91
|
-
process.exit(0);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
req.on('error', function(e) {
|
|
95
|
-
r3logger.elog('problem with request: ' + e.message);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// send request
|
|
99
|
-
req.end();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
//
|
|
103
|
-
// run
|
|
104
|
-
//
|
|
105
|
-
cliutil.getConsoleInput('path(\'/\' or \'/v1\') : ', true, false, function(isbreak, path)
|
|
106
|
-
{
|
|
107
|
-
if(isbreak){
|
|
108
|
-
process.exit(0);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if('/' === path){
|
|
112
|
-
getV1Version(true);
|
|
113
|
-
}else if('/v1' === path){
|
|
114
|
-
getV1Version(false);
|
|
115
|
-
}else{
|
|
116
|
-
console.log('Path parameter(' + path + ') must be / or /v1\n');
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
/*
|
|
121
|
-
* Local variables:
|
|
122
|
-
* tab-width: 4
|
|
123
|
-
* c-basic-offset: 4
|
|
124
|
-
* End:
|
|
125
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
126
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
127
|
-
*/
|
|
@@ -1,174 +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 Dec 27 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
|
-
TESTDIR=$(cd "${SRCTOP}/tests" || exit 1; pwd)
|
|
29
|
-
|
|
30
|
-
#
|
|
31
|
-
# Variables
|
|
32
|
-
#
|
|
33
|
-
AUTO_CTRL_SH="${TESTDIR}/auto_control_subprocess.sh"
|
|
34
|
-
TEST_LOAD_SH="${TESTDIR}/k2hdkc_test_load.sh"
|
|
35
|
-
|
|
36
|
-
#==============================================================
|
|
37
|
-
# Utility functions
|
|
38
|
-
#==============================================================
|
|
39
|
-
#
|
|
40
|
-
# Usage
|
|
41
|
-
#
|
|
42
|
-
PrintUsage()
|
|
43
|
-
{
|
|
44
|
-
echo ""
|
|
45
|
-
echo "Usage: $1 [--key(-k) keyword(group name for control)] [start | stop]"
|
|
46
|
-
echo ""
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
#==========================================================
|
|
50
|
-
# Parse options
|
|
51
|
-
#==========================================================
|
|
52
|
-
SCRIPT_MODE=""
|
|
53
|
-
KEY_SUFFIX=""
|
|
54
|
-
|
|
55
|
-
while [ $# -ne 0 ]; do
|
|
56
|
-
if [ -z "$1" ]; then
|
|
57
|
-
break
|
|
58
|
-
|
|
59
|
-
elif echo "$1" | grep -q -i -e "^-h$" -e "^--help$"; then
|
|
60
|
-
PrintUsage "${PRGNAME}"
|
|
61
|
-
exit 0
|
|
62
|
-
|
|
63
|
-
elif echo "$1" | grep -q -i -e "^-k$" -e "^--key$"; then
|
|
64
|
-
if [ -n "${KEY_SUFFIX}" ]; then
|
|
65
|
-
echo "[ERROR] already set --key(-k) option"
|
|
66
|
-
exit 1
|
|
67
|
-
fi
|
|
68
|
-
shift
|
|
69
|
-
if [ $# -eq 0 ]; then
|
|
70
|
-
echo "[ERROR] --key(-k) option needs parameter"
|
|
71
|
-
exit 1
|
|
72
|
-
fi
|
|
73
|
-
KEY_SUFFIX="_$1"
|
|
74
|
-
|
|
75
|
-
elif echo "$1" | grep -q -i "^start$"; then
|
|
76
|
-
if [ -n "${SCRIPT_MODE}" ]; then
|
|
77
|
-
echo "[ERROR] already specified start or stop"
|
|
78
|
-
exit 1
|
|
79
|
-
fi
|
|
80
|
-
SCRIPT_MODE="start"
|
|
81
|
-
|
|
82
|
-
elif echo "$1" | grep -q -i "^stop$"; then
|
|
83
|
-
if [ -n "${SCRIPT_MODE}" ]; then
|
|
84
|
-
echo "[ERROR] already specified start or stop"
|
|
85
|
-
exit 1
|
|
86
|
-
fi
|
|
87
|
-
SCRIPT_MODE="stop"
|
|
88
|
-
|
|
89
|
-
else
|
|
90
|
-
echo "[ERROR] Unknown option $1"
|
|
91
|
-
exit 1
|
|
92
|
-
fi
|
|
93
|
-
shift
|
|
94
|
-
done
|
|
95
|
-
|
|
96
|
-
#
|
|
97
|
-
# Check option
|
|
98
|
-
#
|
|
99
|
-
if [ -z "${SCRIPT_MODE}" ]; then
|
|
100
|
-
echo "[ERROR] You must specify start or stop"
|
|
101
|
-
exit 1
|
|
102
|
-
fi
|
|
103
|
-
|
|
104
|
-
#==========================================================
|
|
105
|
-
# Do work
|
|
106
|
-
#==========================================================
|
|
107
|
-
if [ "${SCRIPT_MODE}" = "start" ]; then
|
|
108
|
-
#
|
|
109
|
-
# Start
|
|
110
|
-
#
|
|
111
|
-
echo "*** Start : chmpx server node for k2hdkc"
|
|
112
|
-
printf " "
|
|
113
|
-
if ! "${AUTO_CTRL_SH}" --start --key "server${KEY_SUFFIX}" --interval 3 -- chmpx -conf "${TESTDIR}"/auto_k2hdkc_server.ini -ctlport 18021 -d msg; then
|
|
114
|
-
echo "[ERROR] could not run chmpx server node for k2hdkc"
|
|
115
|
-
exit 1
|
|
116
|
-
fi
|
|
117
|
-
|
|
118
|
-
echo "*** Start : one k2hdkc process"
|
|
119
|
-
printf " "
|
|
120
|
-
if ! "${AUTO_CTRL_SH}" --start --key "server${KEY_SUFFIX}" --interval 3 -- k2hdkc -conf "${TESTDIR}"/auto_k2hdkc_server.ini -ctlport 18021 -d msg; then
|
|
121
|
-
echo "[ERROR] one k2hdkc process"
|
|
122
|
-
exit 1
|
|
123
|
-
fi
|
|
124
|
-
|
|
125
|
-
echo "*** Start : chmpx slave node for k2hdkc"
|
|
126
|
-
printf " "
|
|
127
|
-
if ! "${AUTO_CTRL_SH}" --start --key "slave${KEY_SUFFIX}" --interval 3 -- chmpx -conf "${TESTDIR}"/auto_k2hdkc_slave.ini -ctlport 18031 -d msg; then
|
|
128
|
-
echo "[ERROR] chmpx slave node for k2hdkc"
|
|
129
|
-
exit 1
|
|
130
|
-
fi
|
|
131
|
-
|
|
132
|
-
echo "*** Start : load default test data to k2hdkc"
|
|
133
|
-
printf " "
|
|
134
|
-
if ! "${TEST_LOAD_SH}" --for_auto_test; then
|
|
135
|
-
echo "[ERROR] load default test data to k2hdkc"
|
|
136
|
-
exit 1
|
|
137
|
-
fi
|
|
138
|
-
else
|
|
139
|
-
#
|
|
140
|
-
# Stop
|
|
141
|
-
#
|
|
142
|
-
echo "*** Stop : chmpx slave node for k2hdkc"
|
|
143
|
-
printf " "
|
|
144
|
-
if ! "${AUTO_CTRL_SH}" --stop --key "slave${KEY_SUFFIX}" --interval 3 -- chmpx; then
|
|
145
|
-
echo "[ERROR] chmpx slave node for k2hdkc"
|
|
146
|
-
exit 1
|
|
147
|
-
fi
|
|
148
|
-
|
|
149
|
-
echo "*** Stop : one k2hdkc process"
|
|
150
|
-
printf " "
|
|
151
|
-
if ! "${AUTO_CTRL_SH}" --stop --key "server${KEY_SUFFIX}" --interval 3 -- k2hdkc; then
|
|
152
|
-
echo "[ERROR] one k2hdkc process"
|
|
153
|
-
exit 1
|
|
154
|
-
fi
|
|
155
|
-
|
|
156
|
-
echo "*** Stop : chmpx server node for k2hdkc"
|
|
157
|
-
printf " "
|
|
158
|
-
if ! "${AUTO_CTRL_SH}" --stop --key "server${KEY_SUFFIX}" --interval 3 -- chmpx; then
|
|
159
|
-
echo "[ERROR] could not run chmpx server node for k2hdkc"
|
|
160
|
-
exit 1
|
|
161
|
-
fi
|
|
162
|
-
fi
|
|
163
|
-
echo "[SUCCEED] Finished"
|
|
164
|
-
|
|
165
|
-
exit 0
|
|
166
|
-
|
|
167
|
-
#
|
|
168
|
-
# Local variables:
|
|
169
|
-
# tab-width: 4
|
|
170
|
-
# c-basic-offset: 4
|
|
171
|
-
# End:
|
|
172
|
-
# vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
173
|
-
# vim<600: noexpandtab sw=4 ts=4
|
|
174
|
-
#
|