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
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
"use strict";
|
|
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: Tue Oct 23 2018
|
|
18
|
+
* REVISION:
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
24
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
25
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
26
|
+
}
|
|
27
|
+
Object.defineProperty(o, k2, desc);
|
|
28
|
+
}) : (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
o[k2] = m[k];
|
|
31
|
+
}));
|
|
32
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
33
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
34
|
+
}) : function(o, v) {
|
|
35
|
+
o["default"] = v;
|
|
36
|
+
});
|
|
37
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
38
|
+
var ownKeys = function(o) {
|
|
39
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
40
|
+
var ar = [];
|
|
41
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
42
|
+
return ar;
|
|
43
|
+
};
|
|
44
|
+
return ownKeys(o);
|
|
45
|
+
};
|
|
46
|
+
return function (mod) {
|
|
47
|
+
if (mod && mod.__esModule) return mod;
|
|
48
|
+
var result = {};
|
|
49
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
50
|
+
__setModuleDefault(result, mod);
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
})();
|
|
54
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
55
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
56
|
+
};
|
|
57
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
|
+
exports.ipwatch = exports.chkipconfig = void 0;
|
|
59
|
+
const util = __importStar(require("util"));
|
|
60
|
+
const dateformat_1 = __importDefault(require("dateformat"));
|
|
61
|
+
const k2hr3apiutil_1 = __importDefault(require("./k2hr3apiutil"));
|
|
62
|
+
const k2hr3dkc_1 = __importDefault(require("./k2hr3dkc"));
|
|
63
|
+
const dbglogging_1 = __importDefault(require("./dbglogging"));
|
|
64
|
+
const basicipcheck_1 = __importDefault(require("./basicipcheck"));
|
|
65
|
+
const k2hr3config_1 = require("./k2hr3config");
|
|
66
|
+
const apiConf = new k2hr3config_1.r3ApiConfig();
|
|
67
|
+
//---------------------------------------------------------
|
|
68
|
+
// Checking IP Addresses configuration
|
|
69
|
+
//---------------------------------------------------------
|
|
70
|
+
const localchkipconfig = {
|
|
71
|
+
type: k2hr3config_1.chkipType.CHECKER_TYPE_LISTENER, // Listener / Function / Basic{Or|And} / NoCheck
|
|
72
|
+
funcmod: null, // Module name(path) for Function type
|
|
73
|
+
pendingsec: 864000, // Limit for removing IP which is not alive : 10 * 24 * 60 * 60 = 10 days
|
|
74
|
+
intervalms: 4320000, // Interval ms for checking IP address : 12 * 60 * 60 * 1000 = 12 hour
|
|
75
|
+
parallelcnt: 32, // Parallel processing count
|
|
76
|
+
command4: 'ping', // Basic IP address check use this command for IPv4 : ping command
|
|
77
|
+
command6: 'ping6', // Basic IP address check use this command for IPv6
|
|
78
|
+
params: '-c 1', // Common ping command parameters
|
|
79
|
+
timeoutparam: '-W', // Timeout parameter name for ping command
|
|
80
|
+
timeoutms: 5000 // Timeout millisecond for each checking : 5000ms
|
|
81
|
+
};
|
|
82
|
+
(() => {
|
|
83
|
+
const chkipconfig = apiConf.getCheckIPConfig();
|
|
84
|
+
if (k2hr3apiutil_1.default.isSafeEntity(chkipconfig)) {
|
|
85
|
+
if (k2hr3apiutil_1.default.compareCaseString(chkipconfig.type, k2hr3config_1.chkipType.CHECKER_TYPE_LISTENER)) {
|
|
86
|
+
localchkipconfig.type = k2hr3config_1.chkipType.CHECKER_TYPE_LISTENER;
|
|
87
|
+
localchkipconfig.funcmod = null;
|
|
88
|
+
}
|
|
89
|
+
else if (k2hr3apiutil_1.default.compareCaseString(chkipconfig.type, k2hr3config_1.chkipType.CHECKER_TYPE_FUNCTION)) {
|
|
90
|
+
if (k2hr3apiutil_1.default.isSafeString(chkipconfig.funcmod)) {
|
|
91
|
+
localchkipconfig.type = k2hr3config_1.chkipType.CHECKER_TYPE_FUNCTION;
|
|
92
|
+
localchkipconfig.funcmod = chkipconfig.funcmod;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
dbglogging_1.default.elog('config : chkipconfig.funcmod value is something wrong : ' + JSON.stringify(chkipconfig.funcmod));
|
|
96
|
+
localchkipconfig.type = k2hr3config_1.chkipType.CHECKER_TYPE_NOCHECK;
|
|
97
|
+
localchkipconfig.funcmod = null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (k2hr3apiutil_1.default.compareCaseString(chkipconfig.type, k2hr3config_1.chkipType.CHECKER_TYPE_BASIC_OR) || k2hr3apiutil_1.default.compareCaseString(chkipconfig.type, k2hr3config_1.chkipType.CHECKER_TYPE_BASIC_AND)) {
|
|
101
|
+
localchkipconfig.type = k2hr3apiutil_1.default.compareCaseString(chkipconfig.type, k2hr3config_1.chkipType.CHECKER_TYPE_BASIC_OR) ? k2hr3config_1.chkipType.CHECKER_TYPE_BASIC_OR : k2hr3config_1.chkipType.CHECKER_TYPE_BASIC_AND;
|
|
102
|
+
localchkipconfig.funcmod = null;
|
|
103
|
+
if (k2hr3apiutil_1.default.isSafeString(chkipconfig.command4)) {
|
|
104
|
+
localchkipconfig.command4 = chkipconfig.command4;
|
|
105
|
+
}
|
|
106
|
+
if (k2hr3apiutil_1.default.isSafeString(chkipconfig.command6)) {
|
|
107
|
+
localchkipconfig.command6 = chkipconfig.command6;
|
|
108
|
+
}
|
|
109
|
+
if (k2hr3apiutil_1.default.isSafeString(chkipconfig.params)) {
|
|
110
|
+
localchkipconfig.params = chkipconfig.params;
|
|
111
|
+
}
|
|
112
|
+
if (k2hr3apiutil_1.default.isSafeString(chkipconfig.timeoutparam)) {
|
|
113
|
+
localchkipconfig.timeoutparam = chkipconfig.timeoutparam;
|
|
114
|
+
}
|
|
115
|
+
if (k2hr3apiutil_1.default.isSafeNumber(chkipconfig.timeoutms)) {
|
|
116
|
+
localchkipconfig.timeoutms = chkipconfig.timeoutms;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else if (k2hr3apiutil_1.default.compareCaseString(chkipconfig.type, k2hr3config_1.chkipType.CHECKER_TYPE_NOCHECK)) {
|
|
120
|
+
localchkipconfig.type = k2hr3config_1.chkipType.CHECKER_TYPE_NOCHECK;
|
|
121
|
+
localchkipconfig.funcmod = null;
|
|
122
|
+
}
|
|
123
|
+
else if (k2hr3apiutil_1.default.isSafeEntity(chkipconfig.type)) {
|
|
124
|
+
dbglogging_1.default.elog('config : chkipconfig.type value is something wrong : ' + JSON.stringify(chkipconfig.type));
|
|
125
|
+
localchkipconfig.type = k2hr3config_1.chkipType.CHECKER_TYPE_NOCHECK;
|
|
126
|
+
localchkipconfig.funcmod = null;
|
|
127
|
+
}
|
|
128
|
+
if (k2hr3apiutil_1.default.isSafeNumber(chkipconfig.pendingsec)) {
|
|
129
|
+
localchkipconfig.pendingsec = chkipconfig.pendingsec;
|
|
130
|
+
}
|
|
131
|
+
if (k2hr3apiutil_1.default.isSafeNumber(chkipconfig.intervalms)) {
|
|
132
|
+
localchkipconfig.intervalms = chkipconfig.intervalms;
|
|
133
|
+
}
|
|
134
|
+
if (k2hr3apiutil_1.default.isSafeNumber(chkipconfig.parallelcnt)) {
|
|
135
|
+
localchkipconfig.parallelcnt = chkipconfig.parallelcnt;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
})();
|
|
139
|
+
//---------------------------------------------------------
|
|
140
|
+
// Utilities: Check configuration
|
|
141
|
+
//---------------------------------------------------------
|
|
142
|
+
const rawGetType = () => {
|
|
143
|
+
return localchkipconfig.type;
|
|
144
|
+
};
|
|
145
|
+
const rawIsListenerType = () => {
|
|
146
|
+
return k2hr3apiutil_1.default.compareCaseString(localchkipconfig.type, k2hr3config_1.chkipType.CHECKER_TYPE_LISTENER);
|
|
147
|
+
};
|
|
148
|
+
const rawIsBasicType = () => {
|
|
149
|
+
return (k2hr3apiutil_1.default.compareCaseString(localchkipconfig.type, k2hr3config_1.chkipType.CHECKER_TYPE_BASIC_OR) || k2hr3apiutil_1.default.compareCaseString(localchkipconfig.type, k2hr3config_1.chkipType.CHECKER_TYPE_BASIC_AND));
|
|
150
|
+
};
|
|
151
|
+
const rawIsBasicOrType = () => {
|
|
152
|
+
return k2hr3apiutil_1.default.compareCaseString(localchkipconfig.type, k2hr3config_1.chkipType.CHECKER_TYPE_BASIC_OR);
|
|
153
|
+
};
|
|
154
|
+
const rawIsBasicAndType = () => {
|
|
155
|
+
return k2hr3apiutil_1.default.compareCaseString(localchkipconfig.type, k2hr3config_1.chkipType.CHECKER_TYPE_BASIC_AND);
|
|
156
|
+
};
|
|
157
|
+
const rawIsFunctionType = () => {
|
|
158
|
+
return k2hr3apiutil_1.default.compareCaseString(localchkipconfig.type, k2hr3config_1.chkipType.CHECKER_TYPE_FUNCTION);
|
|
159
|
+
};
|
|
160
|
+
const rawIsNocheckType = () => {
|
|
161
|
+
return k2hr3apiutil_1.default.compareCaseString(localchkipconfig.type, k2hr3config_1.chkipType.CHECKER_TYPE_NOCHECK);
|
|
162
|
+
};
|
|
163
|
+
//---------------------------------------------------------
|
|
164
|
+
// Watcher Logging
|
|
165
|
+
//---------------------------------------------------------
|
|
166
|
+
let loggingStream = null;
|
|
167
|
+
let loggingTimeForm = null;
|
|
168
|
+
(() => {
|
|
169
|
+
loggingStream = apiConf.getWatcherLoggingStream(__dirname + '/..');
|
|
170
|
+
loggingTimeForm = apiConf.getWatcherTimeFormat();
|
|
171
|
+
})();
|
|
172
|
+
const rawWatcherLogging = (...args) => {
|
|
173
|
+
const prefix = '[' + (0, dateformat_1.default)(new Date(), k2hr3apiutil_1.default.isString(loggingTimeForm) ? loggingTimeForm : undefined) + '] ';
|
|
174
|
+
if (k2hr3apiutil_1.default.isPlainObject(loggingStream)) {
|
|
175
|
+
loggingStream.write(prefix + util.format(...args) + '\n');
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
//---------------------------------------------------------
|
|
179
|
+
// Check Addresses Alive raw function
|
|
180
|
+
//---------------------------------------------------------
|
|
181
|
+
const rawWatchAddressesAliveEx = (ipchecker, callback) => {
|
|
182
|
+
if (!k2hr3apiutil_1.default.isSafeEntity(callback)) {
|
|
183
|
+
dbglogging_1.default.elog('callback is not function.');
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (!k2hr3apiutil_1.default.isSafeEntity(ipchecker)) {
|
|
187
|
+
callback(true, new Error('ipchecker is not function')); // fatal
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
//
|
|
191
|
+
// make ip addresses list depending cuk
|
|
192
|
+
//
|
|
193
|
+
const targetres = k2hr3dkc_1.default.getAllIpDatasByCuk(true); // Currently supports only openstack
|
|
194
|
+
if (k2hr3apiutil_1.default.isSafeEntity(targetres.error)) {
|
|
195
|
+
callback(false, new Error('failed getting IP addresses list depending cuk by ' + JSON.stringify(targetres.error)));
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (!k2hr3apiutil_1.default.isNotEmptyArray(targetres.data)) {
|
|
199
|
+
callback(false, new Error('There is no IP address depending cuk'));
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
//
|
|
203
|
+
// Check Addresses
|
|
204
|
+
//
|
|
205
|
+
ipchecker(targetres.data, localchkipconfig).then((res) => {
|
|
206
|
+
dbglogging_1.default.dlog('after checking IP addresses : ' + JSON.stringify(res));
|
|
207
|
+
if (k2hr3apiutil_1.default.isSafeEntity(res) && !k2hr3apiutil_1.default.isSafeEntity(res.error)) {
|
|
208
|
+
if (!k2hr3apiutil_1.default.isNotEmptyArray(res.data)) {
|
|
209
|
+
callback(false, new Error('There is no IP address depending cuk after checking, why...'));
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
// remove/clear by result of checking
|
|
213
|
+
const result = k2hr3dkc_1.default.removeIpAddressWithCuk(res.data, localchkipconfig.pendingsec, rawWatcherLogging);
|
|
214
|
+
if (null !== result) {
|
|
215
|
+
callback(false, result);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
// Succeed without error
|
|
219
|
+
callback(false, null);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
let errmsg = 'unknown';
|
|
224
|
+
if (k2hr3apiutil_1.default.isPlainObject(res) && k2hr3apiutil_1.default.isPlainObject(res.error)) {
|
|
225
|
+
errmsg = k2hr3apiutil_1.default.isString(res.error.message) ? res.error.message : 'unknown';
|
|
226
|
+
}
|
|
227
|
+
callback(false, new Error('checking IP addresses returns error : ' + errmsg));
|
|
228
|
+
}
|
|
229
|
+
}).catch((error) => {
|
|
230
|
+
callback(true, new Error('checking IP addresses returns fatal error : ' + k2hr3apiutil_1.default.getSafeString(error.message))); // fatal
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
let local_mod = null;
|
|
234
|
+
(async () => {
|
|
235
|
+
if (rawIsFunctionType() && null !== localchkipconfig.funcmod) {
|
|
236
|
+
const mod = await k2hr3apiutil_1.default.tryLoadModule(localchkipconfig.funcmod);
|
|
237
|
+
if (k2hr3apiutil_1.default.isSafeEntity(mod)) {
|
|
238
|
+
local_mod = mod;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
})();
|
|
242
|
+
const rawWatchAddressesAlive = (oneshotCB) => {
|
|
243
|
+
const _callback = oneshotCB;
|
|
244
|
+
//
|
|
245
|
+
// Load checkAddressesAlive function
|
|
246
|
+
//
|
|
247
|
+
let ipchecker = null;
|
|
248
|
+
try {
|
|
249
|
+
if (rawIsFunctionType() && null !== local_mod) {
|
|
250
|
+
ipchecker = local_mod.checkAddressesAlive;
|
|
251
|
+
}
|
|
252
|
+
else if (rawIsBasicType()) {
|
|
253
|
+
ipchecker = basicipcheck_1.default.checkAddressesAlive;
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
// Nothing to do with interval
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
if (!k2hr3apiutil_1.default.isFunction(ipchecker)) {
|
|
260
|
+
dbglogging_1.default.elog('could not load checkAddressesAlive function in : ' + (rawIsBasicType() ? './basicipcheck' : localchkipconfig.funcmod));
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
dbglogging_1.default.elog('could not load module : ' + (rawIsBasicType() ? './basicipcheck' : localchkipconfig.funcmod), JSON.stringify(error));
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
if (k2hr3apiutil_1.default.isFunction(_callback)) {
|
|
269
|
+
//
|
|
270
|
+
// one shot
|
|
271
|
+
//
|
|
272
|
+
rawWatchAddressesAliveEx(ipchecker, (is_fatal, error) => {
|
|
273
|
+
let result = true;
|
|
274
|
+
if (is_fatal) {
|
|
275
|
+
if (k2hr3apiutil_1.default.isPlainObject(error)) {
|
|
276
|
+
dbglogging_1.default.elog('Fatal error is occurred : ' + k2hr3apiutil_1.default.getSafeString(error.message));
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
dbglogging_1.default.elog('Fatal error is occurred');
|
|
280
|
+
}
|
|
281
|
+
result = false;
|
|
282
|
+
}
|
|
283
|
+
else if (error) {
|
|
284
|
+
dbglogging_1.default.wlog('Finished with messsage : ' + error.message);
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
dbglogging_1.default.dlog('Finished without any error messsage');
|
|
288
|
+
}
|
|
289
|
+
_callback(result);
|
|
290
|
+
});
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
//
|
|
294
|
+
// Set Interval
|
|
295
|
+
//
|
|
296
|
+
let isFatalError = false;
|
|
297
|
+
let isWorking = false;
|
|
298
|
+
const checkInterval = setInterval(() => {
|
|
299
|
+
if (!isFatalError && !isWorking) {
|
|
300
|
+
isWorking = true;
|
|
301
|
+
//
|
|
302
|
+
// Checking
|
|
303
|
+
//
|
|
304
|
+
rawWatchAddressesAliveEx(ipchecker, (is_fatal, error) => {
|
|
305
|
+
isWorking = false;
|
|
306
|
+
if (is_fatal) {
|
|
307
|
+
if (k2hr3apiutil_1.default.isPlainObject(error)) {
|
|
308
|
+
dbglogging_1.default.elog('Fatal error is occurred : ' + k2hr3apiutil_1.default.getSafeString(error.message));
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
dbglogging_1.default.elog('Fatal error is occurred');
|
|
312
|
+
}
|
|
313
|
+
isFatalError = true;
|
|
314
|
+
}
|
|
315
|
+
else if (error) {
|
|
316
|
+
dbglogging_1.default.dlog('Finished with messsage : ' + error.message);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
dbglogging_1.default.dlog('Finished without messsage');
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}, localchkipconfig.intervalms);
|
|
324
|
+
return checkInterval;
|
|
325
|
+
};
|
|
326
|
+
//---------------------------------------------------------
|
|
327
|
+
// Exports
|
|
328
|
+
//---------------------------------------------------------
|
|
329
|
+
//
|
|
330
|
+
// Variables
|
|
331
|
+
//
|
|
332
|
+
exports.chkipconfig = localchkipconfig;
|
|
333
|
+
//
|
|
334
|
+
// Functions
|
|
335
|
+
//
|
|
336
|
+
exports.ipwatch = {
|
|
337
|
+
getType: rawGetType,
|
|
338
|
+
isListenerType: rawIsListenerType,
|
|
339
|
+
isBasicType: rawIsBasicType,
|
|
340
|
+
isBasicOrType: rawIsBasicOrType,
|
|
341
|
+
isBasicAndType: rawIsBasicAndType,
|
|
342
|
+
isFunctionType: rawIsFunctionType,
|
|
343
|
+
isNocheckType: rawIsNocheckType,
|
|
344
|
+
watchAddressesAlive: rawWatchAddressesAlive
|
|
345
|
+
};
|
|
346
|
+
exports.default = exports.ipwatch;
|
|
347
|
+
/*
|
|
348
|
+
* Local variables:
|
|
349
|
+
* tab-width: 4
|
|
350
|
+
* c-basic-offset: 4
|
|
351
|
+
* End:
|
|
352
|
+
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
353
|
+
* vim<600: noexpandtab sw=4 ts=4
|
|
354
|
+
*/
|