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
package/lib/basicipcheck.js
DELETED
|
@@ -1,376 +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: Tue Oct 23 2018
|
|
17
|
-
* REVISION:
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
'use strict';
|
|
22
|
-
|
|
23
|
-
var dns = require('dns');
|
|
24
|
-
var childProcess= require('child_process');
|
|
25
|
-
|
|
26
|
-
var chkiptype = require('./ipwatch').chkipType;
|
|
27
|
-
var apiutil = require('./k2hr3apiutil');
|
|
28
|
-
|
|
29
|
-
// Debug logging objects
|
|
30
|
-
var r3logger = require('./dbglogging');
|
|
31
|
-
|
|
32
|
-
//---------------------------------------------------------
|
|
33
|
-
// Ping & Set result checking IP Address
|
|
34
|
-
//---------------------------------------------------------
|
|
35
|
-
// ipdata: IP address information
|
|
36
|
-
// {
|
|
37
|
-
// ip: ip, -> ip address string
|
|
38
|
-
// cuk: cuk, -> cuk string (not use)
|
|
39
|
-
// port: port, -> port number or * (not use)
|
|
40
|
-
// extra: string -> 'openstack-auto-v1' or etc (not use)
|
|
41
|
-
// tag: string -> null or string (not use)
|
|
42
|
-
// inboundip: ip, -> inbound ip address (not use)
|
|
43
|
-
// outboundip: ip, -> outbound ip address (not use)
|
|
44
|
-
// key: string -> this ip address yrn full path(not use)
|
|
45
|
-
// alive: boolean -> true or false
|
|
46
|
-
// }
|
|
47
|
-
//
|
|
48
|
-
function checkAddressAliveByPing(ipdata, chkipconfig, callback)
|
|
49
|
-
{
|
|
50
|
-
var _callback = callback;
|
|
51
|
-
var _ipdata = ipdata; // reference
|
|
52
|
-
var _chkipconfig= chkipconfig;
|
|
53
|
-
var _timeoutms = _chkipconfig.timeoutms;
|
|
54
|
-
var _command = null;
|
|
55
|
-
|
|
56
|
-
if(!apiutil.isSafeEntity(_callback) || 'function' !== typeof _callback){
|
|
57
|
-
r3logger.elog('callback parameter is wrong');
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if(!apiutil.isSafeEntity(_ipdata)){
|
|
61
|
-
_callback(new Error('IP data is wrong : ' + JSON.stringify(_ipdata)), _ipdata);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if(!apiutil.isSafeString(_ipdata.ip)){
|
|
65
|
-
_callback(new Error('IP Address is wrong : ' + JSON.stringify(_ipdata.ip)), _ipdata);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if(!apiutil.isSafeEntity(_chkipconfig)){ // already check this...
|
|
69
|
-
_callback(new Error('chkipconfig value is wrong : ' + JSON.stringify(_chkipconfig)), _ipdata);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if(!apiutil.isSafeEntity(_chkipconfig.timeoutms) || isNaN(_chkipconfig.timeoutms)){
|
|
73
|
-
r3logger.wlog('timeoutms value is wrong : ' + JSON.stringify(_timeoutms));
|
|
74
|
-
_timeoutms = 5000; // default
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
//
|
|
78
|
-
// Ping - Executing ping command with timeout
|
|
79
|
-
//
|
|
80
|
-
var _timeoutsec = (_timeoutms / 1000) + 1;
|
|
81
|
-
|
|
82
|
-
if(-1 == _ipdata.ip.indexOf(':')){
|
|
83
|
-
_command = _chkipconfig.command4;
|
|
84
|
-
}else{
|
|
85
|
-
_command = _chkipconfig.command6;
|
|
86
|
-
}
|
|
87
|
-
_command += ' ' + apiutil.getSafeString(_chkipconfig.params);
|
|
88
|
-
_command += ' ' + apiutil.getSafeString(_chkipconfig.timeoutparam);
|
|
89
|
-
_command += ' ' + _timeoutsec.toString();
|
|
90
|
-
_command += ' ' + _ipdata.ip;
|
|
91
|
-
|
|
92
|
-
childProcess.exec(_command, function(error, stdout, stderr) // eslint-disable-line no-unused-vars
|
|
93
|
-
{
|
|
94
|
-
if(error){
|
|
95
|
-
r3logger.dlog('Something error occurred pinging to ' + _ipdata.ip + ' by : ' + JSON.stringify(error));
|
|
96
|
-
_callback(error, _ipdata);
|
|
97
|
-
}else{
|
|
98
|
-
_callback(null, _ipdata);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
//---------------------------------------------------------
|
|
104
|
-
// Check DNS & Set result checking IP Address
|
|
105
|
-
//---------------------------------------------------------
|
|
106
|
-
// ipdata: IP address information
|
|
107
|
-
// {
|
|
108
|
-
// ip: ip, -> ip address string
|
|
109
|
-
// cuk: cuk, -> cuk string (not use)
|
|
110
|
-
// port: port, -> port number or * (not use)
|
|
111
|
-
// extra: string -> 'openstack-auto-v1' or etc (not use)
|
|
112
|
-
// tag: string -> null or string (not use)
|
|
113
|
-
// inboundip: ip, -> inbound ip address (not use)
|
|
114
|
-
// outboundip: ip, -> outbound ip address (not use)
|
|
115
|
-
// key: string -> this ip address yrn full path(not use)
|
|
116
|
-
// alive: boolean -> true or false
|
|
117
|
-
// }
|
|
118
|
-
//
|
|
119
|
-
function checkAddressAlive(ipdata, chkipconfig, callback)
|
|
120
|
-
{
|
|
121
|
-
var _callback = callback;
|
|
122
|
-
var _ipdata = ipdata; // reference
|
|
123
|
-
var _chkipconfig= chkipconfig;
|
|
124
|
-
var _is_and = false;
|
|
125
|
-
var _timeoutms = _chkipconfig.timeoutms;
|
|
126
|
-
|
|
127
|
-
if(!apiutil.isSafeEntity(_callback) || 'function' !== typeof _callback){
|
|
128
|
-
r3logger.elog('callback parameter is wrong');
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
if(!apiutil.isSafeEntity(_ipdata)){
|
|
132
|
-
_callback(new Error('IP data is wrong : ' + JSON.stringify(_ipdata)), _ipdata);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
if(!apiutil.isSafeString(_ipdata.ip)){
|
|
136
|
-
_callback(new Error('IP Address is wrong : ' + JSON.stringify(_ipdata.ip)), _ipdata);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
if(!apiutil.isSafeEntity(_chkipconfig)){ // already check this...
|
|
140
|
-
_callback(new Error('chkipconfig value is wrong : ' + JSON.stringify(_chkipconfig)), _ipdata);
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if(!apiutil.isSafeEntity(_chkipconfig.type) || ('BasicOr' !== _chkipconfig.type && 'BasicAnd' !== _chkipconfig.type)){
|
|
144
|
-
_callback(new Error('chkipconfig value is wrong : ' + JSON.stringify(_chkipconfig)), _ipdata);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
if(chkiptype.CHECKER_TYPE_BASIC_OR == _chkipconfig.type){
|
|
148
|
-
_is_and = false;
|
|
149
|
-
}else{
|
|
150
|
-
_is_and = true;
|
|
151
|
-
}
|
|
152
|
-
if(!apiutil.isSafeEntity(_chkipconfig.timeoutms) || isNaN(_chkipconfig.timeoutms)){
|
|
153
|
-
r3logger.wlog('timeoutms value is wrong : ' + JSON.stringify(_timeoutms));
|
|
154
|
-
_timeoutms = 5000; // default
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
//
|
|
158
|
-
// checking DNS with timeout by set timer
|
|
159
|
-
//
|
|
160
|
-
try{
|
|
161
|
-
dns.reverse(_ipdata.ip, function(error, hostnames)
|
|
162
|
-
{
|
|
163
|
-
if(error){
|
|
164
|
-
r3logger.dlog('Something error occurred in dns lookup by error: ' + JSON.stringify(error));
|
|
165
|
-
if(_is_and){
|
|
166
|
-
// [Type = AND] DNS is error, then need to check Ping
|
|
167
|
-
checkAddressAliveByPing(_ipdata, _chkipconfig, _callback);
|
|
168
|
-
}else{
|
|
169
|
-
// [Type = OR] DNS is error, then this IP is not alive
|
|
170
|
-
_callback(error, _ipdata);
|
|
171
|
-
}
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
r3logger.dlog('Success dns lookup for ip address(' + _ipdata.ip + ') to hostnames(' + JSON.stringify(hostnames) + ').');
|
|
175
|
-
|
|
176
|
-
if(_is_and){
|
|
177
|
-
// [Type = AND] DNS is success, then this IP is alive
|
|
178
|
-
_callback(null, _ipdata);
|
|
179
|
-
}else{
|
|
180
|
-
// [Type = OR] DNS is error, then need to check Ping
|
|
181
|
-
checkAddressAliveByPing(_ipdata, _chkipconfig, _callback);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
}catch(errobj){
|
|
186
|
-
r3logger.dlog('Something error occurred in dns lookup by error: ' + JSON.stringify(errobj));
|
|
187
|
-
if(_is_and){
|
|
188
|
-
// [Type = AND] DNS is error, then need to check Ping
|
|
189
|
-
checkAddressAliveByPing(_ipdata, _chkipconfig, _callback);
|
|
190
|
-
}else{
|
|
191
|
-
// [Type = OR] DNS is error, then this IP is not alive
|
|
192
|
-
_callback(errobj, _ipdata);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
//---------------------------------------------------------
|
|
198
|
-
// Check & Set result checking IP Addresses by parallel
|
|
199
|
-
//---------------------------------------------------------
|
|
200
|
-
// ipdatas: IP address information array
|
|
201
|
-
// [{
|
|
202
|
-
// ip: <string>, -> ip address string
|
|
203
|
-
// cuk: <string>, -> cuk string (not use)
|
|
204
|
-
// port: <number or *>, -> port number or * (not use)
|
|
205
|
-
// extra: <string>, -> 'openstack-auto-v1' or etc (not use)
|
|
206
|
-
// inboundip: <string>, -> inbound ip address (not use)
|
|
207
|
-
// outboundip: <string>, -> outbound ip address (not use)
|
|
208
|
-
// tag: <string>, -> null or string (not use)
|
|
209
|
-
// key: <string>, -> this ip address yrn full path (not use)
|
|
210
|
-
// alive: <boolean> -> true or false
|
|
211
|
-
// }, ...]
|
|
212
|
-
// start: start position of ipdatas array
|
|
213
|
-
// chkipconfig: Configuration for IP addresses checking
|
|
214
|
-
// {
|
|
215
|
-
// type: <string>, -> IP check type (not use)
|
|
216
|
-
// funcmod: <null or string>, -> IP check special module (not use)
|
|
217
|
-
// pendingsec: <number>, -> Limit for removing IP which is not alive (not use)
|
|
218
|
-
// intervalms: <number>, -> Interval ms for checking IP address (not use)
|
|
219
|
-
// parallelcnt: <number>, -> Parallel processing count
|
|
220
|
-
// command4: <string>, -> ping command for IPv4
|
|
221
|
-
// command6: <string>, -> ping command for IPv6
|
|
222
|
-
// params: <string>, -> Common ping command parameters
|
|
223
|
-
// timeoutparam: <string>, -> Timeout parameter name for ping command
|
|
224
|
-
// timeoutms: <number> -> Timeout millisecond for each checking
|
|
225
|
-
// }
|
|
226
|
-
//
|
|
227
|
-
// [NOTE]
|
|
228
|
-
// This function is reentrant after finishing parallel count IP address checking.
|
|
229
|
-
// If all of ip datas array are finished checking, call callback function.
|
|
230
|
-
//
|
|
231
|
-
function checkAddressesAliveParallel(ipdatas, start, chkipconfig, callback)
|
|
232
|
-
{
|
|
233
|
-
var _ipdatas = ipdatas; // reference
|
|
234
|
-
var _start = start;
|
|
235
|
-
var _chkipconfig= chkipconfig;
|
|
236
|
-
var _callback = callback;
|
|
237
|
-
|
|
238
|
-
if(!apiutil.isSafeEntity(_callback) || 'function' !== typeof _callback){
|
|
239
|
-
r3logger.elog('callback parameter is wrong');
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
if(!apiutil.isSafeEntity(_start) || isNaN(_start)){
|
|
243
|
-
_callback(new Error('start value is wrong : ' + JSON.stringify(_start)));
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
if(!apiutil.isSafeEntity(_chkipconfig)){ // already check this...
|
|
247
|
-
_callback(new Error('chkipconfig value is wrong : ' + JSON.stringify(_chkipconfig)));
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
if(!apiutil.isArray(_ipdatas)){
|
|
251
|
-
_callback(new Error('IP Addresses array is wrong : ' + JSON.stringify(_ipdatas)));
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
var _totalcount = _chkipconfig.parallelcnt;
|
|
255
|
-
if((_ipdatas.length - _start) < _totalcount){
|
|
256
|
-
_totalcount = _ipdatas.length - _start;
|
|
257
|
-
if(_totalcount <= 0){
|
|
258
|
-
_callback(new Error('No rest array for checking'));
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
for(var cnt = 0, setcnt = 0; cnt < _totalcount; ++cnt){
|
|
264
|
-
checkAddressAlive(_ipdatas[_start + cnt], _chkipconfig, function(error, ipdata)
|
|
265
|
-
{
|
|
266
|
-
if(error){
|
|
267
|
-
r3logger.dlog('IP Address(' + ipdata.ip + ') : CUK(' + ipdata.cuk + ') is not alive by ' + JSON.stringify(error));
|
|
268
|
-
ipdata.alive = false;
|
|
269
|
-
}else{
|
|
270
|
-
r3logger.dlog('IP Address(' + ipdata.ip + ') : CUK(' + ipdata.cuk + ') is alive');
|
|
271
|
-
ipdata.alive = true;
|
|
272
|
-
}
|
|
273
|
-
++setcnt;
|
|
274
|
-
if(_totalcount <= setcnt){
|
|
275
|
-
if(_ipdatas.length <= (_start + _totalcount)){
|
|
276
|
-
_callback(null);
|
|
277
|
-
}else{
|
|
278
|
-
checkAddressesAliveParallel(ipdatas, (_start + _totalcount), _chkipconfig, _callback);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
//---------------------------------------------------------
|
|
286
|
-
// Check & Set result checking IP Addresses
|
|
287
|
-
//---------------------------------------------------------
|
|
288
|
-
// ipdatas: IP address information array
|
|
289
|
-
// [{
|
|
290
|
-
// ip: <string>, -> ip address string
|
|
291
|
-
// cuk: <string>, -> cuk string (not use)
|
|
292
|
-
// port: <number or *>, -> port number or * (not use)
|
|
293
|
-
// extra: <string>, -> 'openstack-auto-v1' or etc (not use)
|
|
294
|
-
// tag: <string>, -> null or string (not use)
|
|
295
|
-
// inboundip: <string>, -> inbound ip address (not use)
|
|
296
|
-
// outboundip: <string>, -> outbound ip address (not use)
|
|
297
|
-
// key: <string>, -> this ip address yrn full path (not use)
|
|
298
|
-
// alive: <boolean> -> true or false
|
|
299
|
-
// }, ...]
|
|
300
|
-
// chkipconfig: Configuration for IP addresses checking
|
|
301
|
-
// {
|
|
302
|
-
// type: <string>, -> IP check type (not use)
|
|
303
|
-
// funcmod: <null or string>, -> IP check special module (not use)
|
|
304
|
-
// pendingsec: <number>, -> Limit for removing IP which is not alive (not use)
|
|
305
|
-
// intervalms: <number>, -> Interval ms for checking IP address (not use)
|
|
306
|
-
// parallelcnt: <number>, -> Parallel processing count
|
|
307
|
-
// command4: <string>, -> ping command for IPv4
|
|
308
|
-
// command6: <string>, -> ping command for IPv6
|
|
309
|
-
// params: <string>, -> Common ping command parameters
|
|
310
|
-
// timeoutparam: <string>, -> Timeout parameter name for ping command
|
|
311
|
-
// timeoutms: <number> -> Timeout millisecond for each checking
|
|
312
|
-
// }
|
|
313
|
-
//
|
|
314
|
-
// [NOTE]
|
|
315
|
-
// This function returns Promise object.
|
|
316
|
-
// resolve: {error: <Error object if error>, data: <reference to input ipdatas>}
|
|
317
|
-
// reject: <Error object>
|
|
318
|
-
//
|
|
319
|
-
function checkAddressesAlivePromise(ipdatas, chkipconfig)
|
|
320
|
-
{
|
|
321
|
-
var _chkipconfig= chkipconfig;
|
|
322
|
-
var _ipdatas = ipdatas; // reference
|
|
323
|
-
|
|
324
|
-
return new Promise(function(resolve, reject)
|
|
325
|
-
{
|
|
326
|
-
var _resolve= resolve;
|
|
327
|
-
var _reject = reject;
|
|
328
|
-
|
|
329
|
-
if( !apiutil.isSafeEntity(_chkipconfig) ||
|
|
330
|
-
!apiutil.isSafeEntity(_chkipconfig.parallelcnt) ||
|
|
331
|
-
isNaN(_chkipconfig.parallelcnt) ||
|
|
332
|
-
!apiutil.isSafeString(_chkipconfig.command4) ||
|
|
333
|
-
!apiutil.isSafeString(_chkipconfig.command6) ||
|
|
334
|
-
//!apiutil.isSafeString(_chkipconfig.params) || // allow null
|
|
335
|
-
//!apiutil.isSafeString(_chkipconfig.timeoutparam) || // allow null
|
|
336
|
-
!apiutil.isSafeEntity(_chkipconfig.timeoutms) ||
|
|
337
|
-
isNaN(_chkipconfig.timeoutms) )
|
|
338
|
-
{
|
|
339
|
-
_reject(new Error('chkipconfig object is wrong : ' + JSON.stringify(_chkipconfig)));
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
if(!apiutil.isArray(_ipdatas)){
|
|
344
|
-
_reject(new Error('IP Addresses array is wrong : ' + JSON.stringify(_ipdatas)));
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
checkAddressesAliveParallel(_ipdatas, 0, _chkipconfig, function(error)
|
|
349
|
-
{
|
|
350
|
-
if(error){
|
|
351
|
-
r3logger.elog('Something error is occurred : ' + JSON.stringify(error));
|
|
352
|
-
_resolve({error: error, data: _ipdatas});
|
|
353
|
-
}else{
|
|
354
|
-
r3logger.dlog('Succeed to checking all ip address');
|
|
355
|
-
_resolve({error: null, data: _ipdatas});
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
//---------------------------------------------------------
|
|
362
|
-
// Exports
|
|
363
|
-
//---------------------------------------------------------
|
|
364
|
-
exports.checkAddressesAlive = function(ipdatas, chkipconfig)
|
|
365
|
-
{
|
|
366
|
-
return checkAddressesAlivePromise(ipdatas, chkipconfig);
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
/*
|
|
370
|
-
* Local variables:
|
|
371
|
-
* tab-width: 4
|
|
372
|
-
* c-basic-offset: 4
|
|
373
|
-
* End:
|
|
374
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
375
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
376
|
-
*/
|
package/lib/cacerts.js
DELETED
|
@@ -1,71 +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 fs = require('fs');
|
|
24
|
-
|
|
25
|
-
var apiutil = require('./k2hr3apiutil');
|
|
26
|
-
|
|
27
|
-
// Debug logging objects
|
|
28
|
-
var r3logger = require('./dbglogging');
|
|
29
|
-
|
|
30
|
-
function loadCACert()
|
|
31
|
-
{
|
|
32
|
-
// load CA Path environment
|
|
33
|
-
if(apiutil.isSafeString(process.env.CAPATH)){
|
|
34
|
-
try{
|
|
35
|
-
fs.statSync(process.env.CAPATH);
|
|
36
|
-
return fs.readFileSync(process.env.CAPATH);
|
|
37
|
-
}catch(err){
|
|
38
|
-
r3logger.elog('CAPATH environment' + process.env.CAPATH + ' file does not exist, then use default ca certs.', JSON.stringify(err));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// load one of CA certs
|
|
43
|
-
var def_certs = [
|
|
44
|
-
'/etc/ssl/certs/ca-certificates.crt',
|
|
45
|
-
'/etc/pki/tls/certs/ca-bundle.crt',
|
|
46
|
-
'/etc/ssl/certs/ca-bundle.crt',
|
|
47
|
-
'/etc/ssl/certs/ca-bundle.trust.crt'
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
for(var cnt = 0; cnt < def_certs.length; ++cnt){
|
|
51
|
-
try{
|
|
52
|
-
fs.statSync(def_certs[cnt]);
|
|
53
|
-
return fs.readFileSync(def_certs[cnt]);
|
|
54
|
-
}catch(err){
|
|
55
|
-
r3logger.dlog(JSON.stringify(err));
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
exports.ca = loadCACert();
|
|
63
|
-
|
|
64
|
-
/*
|
|
65
|
-
* Local variables:
|
|
66
|
-
* tab-width: 4
|
|
67
|
-
* c-basic-offset: 4
|
|
68
|
-
* End:
|
|
69
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
70
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
71
|
-
*/
|
package/lib/dbglogging.js
DELETED
|
@@ -1,151 +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 util = require('util');
|
|
24
|
-
var apiutil = require('./k2hr3apiutil');
|
|
25
|
-
|
|
26
|
-
//---------------------------------------------------------
|
|
27
|
-
// NODE_DEBUG Environment Values
|
|
28
|
-
//---------------------------------------------------------
|
|
29
|
-
const dbgLevelMap = {
|
|
30
|
-
'LOGLEVEL_DEBUG': 4,
|
|
31
|
-
'LOGLEVEL_DBG': 4,
|
|
32
|
-
'LOGLEVEL_INFO': 3,
|
|
33
|
-
'LOGLEVEL_MESSAGE': 3,
|
|
34
|
-
'LOGLEVEL_MSG': 3,
|
|
35
|
-
'LOGLEVEL_WARNING': 2,
|
|
36
|
-
'LOGLEVEL_WARN': 2,
|
|
37
|
-
'LOGLEVEL_WAN': 2,
|
|
38
|
-
'LOGLEVEL_ERROR': 1,
|
|
39
|
-
'LOGLEVEL_ERR': 1,
|
|
40
|
-
'LOGLEVEL_SILENT': 0,
|
|
41
|
-
'LOGLEVEL_SLT': 0
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const levelDbg = 4;
|
|
45
|
-
const levelInfo = 3;
|
|
46
|
-
const levelWarn = 2;
|
|
47
|
-
const levelErr = 1;
|
|
48
|
-
const levelSilent = 0;
|
|
49
|
-
|
|
50
|
-
//---------------------------------------------------------
|
|
51
|
-
// Logging Level
|
|
52
|
-
//---------------------------------------------------------
|
|
53
|
-
var currentLevel = levelErr;
|
|
54
|
-
var customLevels = [];
|
|
55
|
-
|
|
56
|
-
(function()
|
|
57
|
-
{
|
|
58
|
-
var dbgEnvs = apiutil.getSafeString(process.env.NODE_DEBUG).split(',');
|
|
59
|
-
|
|
60
|
-
dbgEnvs.forEach(function(key)
|
|
61
|
-
{
|
|
62
|
-
var upperKey = key.toUpperCase();
|
|
63
|
-
if(apiutil.isSafeEntity(dbgLevelMap[upperKey])){
|
|
64
|
-
if(levelSilent == dbgLevelMap[upperKey]){
|
|
65
|
-
// default level is error. if specify silent, we must set silent.
|
|
66
|
-
currentLevel = levelSilent;
|
|
67
|
-
}else if(currentLevel < dbgLevelMap[upperKey]){
|
|
68
|
-
currentLevel = dbgLevelMap[upperKey];
|
|
69
|
-
}
|
|
70
|
-
}else if(!apiutil.findStringInArray(customLevels, upperKey)){
|
|
71
|
-
customLevels.push(upperKey);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}());
|
|
75
|
-
|
|
76
|
-
function getCurrentInfo()
|
|
77
|
-
{
|
|
78
|
-
try{
|
|
79
|
-
throw new Error('INTERNAL_EXCEPTION_FOR_DEBUG');
|
|
80
|
-
}catch(exception){
|
|
81
|
-
var basedir = __dirname.replace(/lib$/g, '');
|
|
82
|
-
var curstr = exception.stack.split(/[\r\n]+/).filter(function(val1)
|
|
83
|
-
{
|
|
84
|
-
return /^ *at .*:[0-9]+:[0-9]+/.test(val1);
|
|
85
|
-
})[2];
|
|
86
|
-
return curstr.replace(/^ *at /g, '').replace(new RegExp(basedir, 'g'), '').replace(/.*\(/g, '').replace(/\)$/g, '').replace(/:[0-9]+$/g, '').replace(/:/g, '(') + ')';
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
exports.dlog = function()
|
|
91
|
-
{
|
|
92
|
-
if(levelDbg <= currentLevel){
|
|
93
|
-
// [NOTE]
|
|
94
|
-
// We want to use stack trace, thus using console.warn instead of console.debug method.
|
|
95
|
-
//
|
|
96
|
-
console.warn('[DEBUG] ' + getCurrentInfo(), util.format.apply(util, arguments));
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
exports.mlog = function()
|
|
101
|
-
{
|
|
102
|
-
if(levelInfo <= currentLevel){
|
|
103
|
-
// [NOTE]
|
|
104
|
-
// We want to use stack trace, thus using console.warn instead of console.info method.
|
|
105
|
-
//
|
|
106
|
-
console.warn('[INFO] ' + getCurrentInfo(), util.format.apply(util, arguments));
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
exports.wlog = function()
|
|
111
|
-
{
|
|
112
|
-
if(levelWarn <= currentLevel){
|
|
113
|
-
console.warn('[WARN] ' + getCurrentInfo(), util.format.apply(util, arguments));
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
exports.elog = function()
|
|
118
|
-
{
|
|
119
|
-
if(levelErr <= currentLevel){
|
|
120
|
-
console.error('[ERROR] ' + getCurrentInfo(), util.format.apply(util, arguments));
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
exports.clog = function(section)
|
|
125
|
-
{
|
|
126
|
-
if(apiutil.isSafeString(section) && apiutil.findStringInArray(customLevels, section.toUpperCase())){
|
|
127
|
-
// [NOTE]
|
|
128
|
-
// We want to use stack trace, thus using console.warn instead of console.info method.
|
|
129
|
-
//
|
|
130
|
-
console.warn('[' + section.toUpperCase() + '] ' + getCurrentInfo(), util.format.apply(util, arguments));
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
exports.dump = function(obj)
|
|
135
|
-
{
|
|
136
|
-
if(levelDbg <= currentLevel){
|
|
137
|
-
if(typeof obj === 'object'){
|
|
138
|
-
return util.inspect(obj, {showHidden: true, depth: null, maxArrayLength: 1000});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return obj;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
/*
|
|
145
|
-
* Local variables:
|
|
146
|
-
* tab-width: 4
|
|
147
|
-
* c-basic-offset: 4
|
|
148
|
-
* End:
|
|
149
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
150
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
151
|
-
*/
|