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.
Files changed (149) hide show
  1. package/config/k2hr3-init.sh.templ +4 -4
  2. package/dist/.gitkeep +0 -0
  3. package/dist/src/app.js +262 -0
  4. package/{bin → dist/src/bin}/run.sh +1 -1
  5. package/dist/src/bin/watcher.js +113 -0
  6. package/dist/src/bin/www.js +217 -0
  7. package/dist/src/lib/basicipcheck.js +392 -0
  8. package/dist/src/lib/cacerts.js +106 -0
  9. package/dist/src/lib/dbglogging.js +190 -0
  10. package/dist/src/lib/dummyuserapi.js +719 -0
  11. package/dist/src/lib/ipwatch.js +354 -0
  12. package/dist/src/lib/k2hr3acrutil.js +532 -0
  13. package/dist/src/lib/k2hr3apiutil.js +1444 -0
  14. package/dist/src/lib/k2hr3cliutil.js +183 -0
  15. package/dist/src/lib/k2hr3config.js +832 -0
  16. package/dist/src/lib/k2hr3cryptutil.js +258 -0
  17. package/dist/src/lib/k2hr3dkc.js +12121 -0
  18. package/dist/src/lib/k2hr3extdata.js +198 -0
  19. package/dist/src/lib/k2hr3keys.js +207 -0
  20. package/dist/src/lib/k2hr3resutil.js +111 -0
  21. package/dist/src/lib/k2hr3template.js +6546 -0
  22. package/dist/src/lib/k2hr3tokens.js +2643 -0
  23. package/dist/src/lib/k2hr3userdata.js +296 -0
  24. package/dist/src/lib/k8soidc.js +1000 -0
  25. package/dist/src/lib/openstackapiv2.js +695 -0
  26. package/dist/src/lib/openstackapiv3.js +932 -0
  27. package/dist/src/lib/openstackep.js +667 -0
  28. package/{tests/auto_common.js → dist/src/lib/types.js} +4 -38
  29. package/dist/src/routes/acr.js +704 -0
  30. package/dist/src/routes/debugVerify.js +294 -0
  31. package/dist/src/routes/extdata.js +219 -0
  32. package/dist/src/routes/list.js +264 -0
  33. package/dist/src/routes/policy.js +840 -0
  34. package/dist/src/routes/resource.js +1489 -0
  35. package/dist/src/routes/role.js +2627 -0
  36. package/dist/src/routes/service.js +908 -0
  37. package/dist/src/routes/tenant.js +1141 -0
  38. package/dist/src/routes/userTokens.js +482 -0
  39. package/dist/src/routes/userdata.js +212 -0
  40. package/dist/src/routes/version.js +103 -0
  41. package/package.json +152 -121
  42. package/ChangeLog +0 -378
  43. package/app.js +0 -292
  44. package/bin/watcher +0 -122
  45. package/bin/www +0 -180
  46. package/eslint.config.mjs +0 -68
  47. package/lib/basicipcheck.js +0 -376
  48. package/lib/cacerts.js +0 -71
  49. package/lib/dbglogging.js +0 -151
  50. package/lib/dummyuserapi.js +0 -766
  51. package/lib/ipwatch.js +0 -379
  52. package/lib/k2hr3acrutil.js +0 -516
  53. package/lib/k2hr3apiutil.js +0 -1494
  54. package/lib/k2hr3cliutil.js +0 -191
  55. package/lib/k2hr3config.js +0 -826
  56. package/lib/k2hr3cryptutil.js +0 -254
  57. package/lib/k2hr3dkc.js +0 -12632
  58. package/lib/k2hr3extdata.js +0 -198
  59. package/lib/k2hr3keys.js +0 -234
  60. package/lib/k2hr3resutil.js +0 -100
  61. package/lib/k2hr3template.js +0 -6925
  62. package/lib/k2hr3tokens.js +0 -2799
  63. package/lib/k2hr3userdata.js +0 -312
  64. package/lib/k8soidc.js +0 -1012
  65. package/lib/openstackapiv2.js +0 -764
  66. package/lib/openstackapiv3.js +0 -1032
  67. package/lib/openstackep.js +0 -553
  68. package/routes/acr.js +0 -738
  69. package/routes/debugVerify.js +0 -263
  70. package/routes/extdata.js +0 -232
  71. package/routes/list.js +0 -270
  72. package/routes/policy.js +0 -869
  73. package/routes/resource.js +0 -1441
  74. package/routes/role.js +0 -2664
  75. package/routes/service.js +0 -894
  76. package/routes/tenant.js +0 -1095
  77. package/routes/userTokens.js +0 -511
  78. package/routes/userdata.js +0 -218
  79. package/routes/version.js +0 -108
  80. package/templ/Dockerfile.templ +0 -71
  81. package/tests/auto_acr.js +0 -1101
  82. package/tests/auto_acr_spec.js +0 -79
  83. package/tests/auto_all_spec.js +0 -142
  84. package/tests/auto_control_subprocess.sh +0 -243
  85. package/tests/auto_extdata.js +0 -220
  86. package/tests/auto_extdata_spec.js +0 -79
  87. package/tests/auto_init_config_json.sh +0 -275
  88. package/tests/auto_k2hdkc_server.ini +0 -109
  89. package/tests/auto_k2hdkc_slave.ini +0 -83
  90. package/tests/auto_list.js +0 -439
  91. package/tests/auto_list_spec.js +0 -79
  92. package/tests/auto_policy.js +0 -1579
  93. package/tests/auto_policy_spec.js +0 -79
  94. package/tests/auto_resource.js +0 -10956
  95. package/tests/auto_resource_spec.js +0 -79
  96. package/tests/auto_role.js +0 -6150
  97. package/tests/auto_role_spec.js +0 -79
  98. package/tests/auto_service.js +0 -770
  99. package/tests/auto_service_spec.js +0 -79
  100. package/tests/auto_subprocesses.js +0 -114
  101. package/tests/auto_template.sh +0 -126
  102. package/tests/auto_tenant.js +0 -1100
  103. package/tests/auto_tenant_spec.js +0 -79
  104. package/tests/auto_token_util.js +0 -219
  105. package/tests/auto_userdata.js +0 -292
  106. package/tests/auto_userdata_spec.js +0 -79
  107. package/tests/auto_usertokens.js +0 -565
  108. package/tests/auto_usertokens_spec.js +0 -79
  109. package/tests/auto_version.js +0 -127
  110. package/tests/auto_version_spec.js +0 -79
  111. package/tests/auto_watcher.js +0 -157
  112. package/tests/auto_watcher_spec.js +0 -79
  113. package/tests/k2hdkc_test.data +0 -986
  114. package/tests/k2hdkc_test_load.sh +0 -255
  115. package/tests/k2hr3template_test.js +0 -187
  116. package/tests/k2hr3template_test.sh +0 -339
  117. package/tests/k2hr3template_test_async.js +0 -216
  118. package/tests/k2hr3template_test_template.result +0 -7117
  119. package/tests/k2hr3template_test_template.txt +0 -3608
  120. package/tests/k2hr3template_test_vars.js +0 -194
  121. package/tests/manual_acr_delete.js +0 -143
  122. package/tests/manual_acr_get.js +0 -297
  123. package/tests/manual_acr_postput.js +0 -215
  124. package/tests/manual_allusertenant_get.js +0 -113
  125. package/tests/manual_extdata_get.js +0 -191
  126. package/tests/manual_k2hr3keys_get.js +0 -84
  127. package/tests/manual_list_gethead.js +0 -230
  128. package/tests/manual_policy_delete.js +0 -132
  129. package/tests/manual_policy_gethead.js +0 -275
  130. package/tests/manual_policy_postput.js +0 -297
  131. package/tests/manual_resource_delete.js +0 -433
  132. package/tests/manual_resource_gethead.js +0 -423
  133. package/tests/manual_resource_postput.js +0 -487
  134. package/tests/manual_role_delete.js +0 -404
  135. package/tests/manual_role_gethead.js +0 -547
  136. package/tests/manual_role_postput.js +0 -544
  137. package/tests/manual_service_delete.js +0 -153
  138. package/tests/manual_service_gethead.js +0 -178
  139. package/tests/manual_service_postput.js +0 -348
  140. package/tests/manual_tenant_delete.js +0 -186
  141. package/tests/manual_tenant_gethead.js +0 -268
  142. package/tests/manual_tenant_postput.js +0 -293
  143. package/tests/manual_test.sh +0 -352
  144. package/tests/manual_userdata_get.js +0 -173
  145. package/tests/manual_usertoken_gethead.js +0 -136
  146. package/tests/manual_usertoken_postput.js +0 -310
  147. package/tests/manual_version_get.js +0 -127
  148. package/tests/run_local_test_k2hdkc.sh +0 -174
  149. package/tests/test.sh +0 -333
@@ -0,0 +1,392 @@
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.basicipcheck = void 0;
59
+ const dns = __importStar(require("dns"));
60
+ const childProcess = __importStar(require("child_process"));
61
+ const k2hr3apiutil_1 = __importDefault(require("./k2hr3apiutil"));
62
+ const dbglogging_1 = __importDefault(require("./dbglogging"));
63
+ const k2hr3config_1 = require("./k2hr3config");
64
+ //---------------------------------------------------------
65
+ // Ping & Set result checking IP Address
66
+ //---------------------------------------------------------
67
+ // ipdata: IP address information
68
+ // dkcTypeHostRawValueSet = {
69
+ // ip: ip, -> ip address string
70
+ // cuk: cuk, -> cuk string (not use)
71
+ // port: port, -> port number(0 as any) (not use)
72
+ // extra: string -> 'openstack-auto-v1' or etc (not use)
73
+ // tag: string -> null or string (not use)
74
+ // inboundip: ip, -> inbound ip address (not use)
75
+ // outboundip: ip, -> outbound ip address (not use)
76
+ // key: string -> this ip address yrn full path(not use)
77
+ // alive: boolean -> true or false
78
+ // }
79
+ //
80
+ const checkAddressAliveByPing = (ipdata, chkipconfig, callback) => {
81
+ if (!k2hr3apiutil_1.default.isFunction(callback)) {
82
+ dbglogging_1.default.elog('callback parameter is wrong');
83
+ return;
84
+ }
85
+ if (!k2hr3apiutil_1.default.isPlainObject(ipdata)) {
86
+ callback(new Error('IP data is wrong : ' + JSON.stringify(ipdata)), ipdata);
87
+ return;
88
+ }
89
+ if (!k2hr3apiutil_1.default.isSafeString(ipdata.ip)) {
90
+ callback(new Error('IP Address is wrong : ' + JSON.stringify(ipdata.ip)), ipdata);
91
+ return;
92
+ }
93
+ if (!k2hr3apiutil_1.default.isPlainObject(chkipconfig)) { // already check this...
94
+ callback(new Error('chkipconfig value is wrong : ' + JSON.stringify(chkipconfig)), ipdata);
95
+ return;
96
+ }
97
+ let _timeoutms;
98
+ if (!k2hr3apiutil_1.default.isSafeNumber(chkipconfig.timeoutms)) {
99
+ dbglogging_1.default.wlog('timeoutms value is wrong : ' + JSON.stringify(chkipconfig.timeoutms));
100
+ _timeoutms = 5000; // default
101
+ }
102
+ else {
103
+ _timeoutms = chkipconfig.timeoutms;
104
+ }
105
+ //
106
+ // Ping - Executing ping command with timeout
107
+ //
108
+ const _timeoutsec = (_timeoutms / 1000) + 1;
109
+ let _command;
110
+ if (ipdata.ip && -1 == ipdata.ip.indexOf(':')) {
111
+ _command = k2hr3apiutil_1.default.getSafeString(chkipconfig.command4);
112
+ }
113
+ else {
114
+ _command = k2hr3apiutil_1.default.getSafeString(chkipconfig.command6);
115
+ }
116
+ _command += ' ' + k2hr3apiutil_1.default.getSafeString(chkipconfig.params);
117
+ _command += ' ' + k2hr3apiutil_1.default.getSafeString(chkipconfig.timeoutparam);
118
+ _command += ' ' + _timeoutsec.toString();
119
+ _command += ' ' + ipdata.ip;
120
+ childProcess.exec(_command, (error, _stdout, _stderr) => {
121
+ if (k2hr3apiutil_1.default.isPlainObject(error)) {
122
+ dbglogging_1.default.dlog('Something error occurred pinging to ' + ipdata.ip + ' by : ' + JSON.stringify(error));
123
+ callback(error, ipdata);
124
+ }
125
+ else {
126
+ callback(null, ipdata);
127
+ }
128
+ });
129
+ };
130
+ //---------------------------------------------------------
131
+ // Check DNS & Set result checking IP Address
132
+ //---------------------------------------------------------
133
+ // ipdata: IP address information
134
+ // dkcTypeHostRawValueSet = {
135
+ // ip: ip, -> ip address string
136
+ // cuk: cuk, -> cuk string (not use)
137
+ // port: port, -> port number(0 as any) (not use)
138
+ // extra: string -> 'openstack-auto-v1' or etc (not use)
139
+ // tag: string -> null or string (not use)
140
+ // inboundip: ip, -> inbound ip address (not use)
141
+ // outboundip: ip, -> outbound ip address (not use)
142
+ // key: string -> this ip address yrn full path(not use)
143
+ // alive: boolean -> true or false
144
+ // }
145
+ //
146
+ const checkAddressAlive = (ipdata, chkipconfig, callback) => {
147
+ if (!k2hr3apiutil_1.default.isFunction(callback)) {
148
+ dbglogging_1.default.elog('callback parameter is wrong');
149
+ return;
150
+ }
151
+ if (!k2hr3apiutil_1.default.isPlainObject(ipdata)) {
152
+ callback(new Error('IP data is wrong : ' + JSON.stringify(ipdata)), ipdata);
153
+ return;
154
+ }
155
+ if (!k2hr3apiutil_1.default.isSafeString(ipdata.ip)) {
156
+ callback(new Error('IP Address is wrong : ' + JSON.stringify(ipdata.ip)), ipdata);
157
+ return;
158
+ }
159
+ if (!k2hr3apiutil_1.default.isPlainObject(chkipconfig)) { // already check this...
160
+ callback(new Error('chkipconfig value is wrong : ' + JSON.stringify(chkipconfig)), ipdata);
161
+ return;
162
+ }
163
+ if (!k2hr3apiutil_1.default.isSafeString(chkipconfig.type) || ('BasicOr' !== chkipconfig.type && 'BasicAnd' !== chkipconfig.type)) {
164
+ callback(new Error('chkipconfig value is wrong : ' + JSON.stringify(chkipconfig)), ipdata);
165
+ return;
166
+ }
167
+ let _is_and = false;
168
+ if (k2hr3config_1.chkipType.CHECKER_TYPE_BASIC_OR == chkipconfig.type) {
169
+ _is_and = false;
170
+ }
171
+ else {
172
+ _is_and = true;
173
+ }
174
+ //
175
+ // checking DNS with timeout by set timer
176
+ //
177
+ try {
178
+ dns.reverse(ipdata.ip, (error, hostnames) => {
179
+ if (k2hr3apiutil_1.default.isPlainObject(error)) {
180
+ dbglogging_1.default.dlog('Something error occurred in dns lookup by error: ' + JSON.stringify(error));
181
+ if (_is_and) {
182
+ // [Type = AND] DNS is error, then need to check Ping
183
+ checkAddressAliveByPing(ipdata, chkipconfig, callback);
184
+ }
185
+ else {
186
+ // [Type = OR] DNS is error, then this IP is not alive
187
+ callback(error, ipdata);
188
+ }
189
+ return;
190
+ }
191
+ dbglogging_1.default.dlog('Success dns lookup for ip address(' + ipdata.ip + ') to hostnames(' + JSON.stringify(hostnames) + ').');
192
+ if (_is_and) {
193
+ // [Type = AND] DNS is success, then this IP is alive
194
+ callback(null, ipdata);
195
+ }
196
+ else {
197
+ // [Type = OR] DNS is error, then need to check Ping
198
+ checkAddressAliveByPing(ipdata, chkipconfig, callback);
199
+ }
200
+ });
201
+ }
202
+ catch (errobj) {
203
+ dbglogging_1.default.dlog('Something error occurred in dns lookup by error: ' + JSON.stringify(errobj));
204
+ if (_is_and) {
205
+ // [Type = AND] DNS is error, then need to check Ping
206
+ checkAddressAliveByPing(ipdata, chkipconfig, callback);
207
+ }
208
+ else {
209
+ // [Type = OR] DNS is error, then this IP is not alive
210
+ if (errobj instanceof Error) {
211
+ callback(errobj, ipdata);
212
+ }
213
+ else {
214
+ callback(new Error(String(errobj)), ipdata);
215
+ }
216
+ }
217
+ }
218
+ };
219
+ //---------------------------------------------------------
220
+ // Check & Set result checking IP Addresses by parallel
221
+ //---------------------------------------------------------
222
+ // ipdatas: IP address information array
223
+ // dkcTypeHostRawValueSet[] = [{
224
+ // ip: <string>, -> ip address string
225
+ // cuk: <string>, -> cuk string (not use)
226
+ // port: <number>, -> port number(0 as any) (not use)
227
+ // extra: <string>, -> 'openstack-auto-v1' or etc (not use)
228
+ // inboundip: <string>, -> inbound ip address (not use)
229
+ // outboundip: <string>, -> outbound ip address (not use)
230
+ // tag: <string>, -> null or string (not use)
231
+ // key: <string>, -> this ip address yrn full path (not use)
232
+ // alive: <boolean> -> true or false
233
+ // }, ...]
234
+ // start: start position of ipdatas array
235
+ // chkipconfig: Configuration for IP addresses checking
236
+ // ipchkTypeConfig = {
237
+ // type: <string>, -> IP check type (not use)
238
+ // funcmod: <null or string>, -> IP check special module (not use)
239
+ // pendingsec: <number>, -> Limit for removing IP which is not alive (not use)
240
+ // intervalms: <number>, -> Interval ms for checking IP address (not use)
241
+ // parallelcnt: <number>, -> Parallel processing count
242
+ // command4: <string>, -> ping command for IPv4
243
+ // command6: <string>, -> ping command for IPv6
244
+ // params: <string>, -> Common ping command parameters
245
+ // timeoutparam: <string>, -> Timeout parameter name for ping command
246
+ // timeoutms: <number> -> Timeout millisecond for each checking
247
+ // }
248
+ //
249
+ // [NOTE]
250
+ // This function is reentrant after finishing parallel count IP address checking.
251
+ // If all of ip datas array are finished checking, call callback function.
252
+ //
253
+ const checkAddressesAliveParallel = (ipdatas, start, chkipconfig, callback) => {
254
+ if (!k2hr3apiutil_1.default.isFunction(callback)) {
255
+ dbglogging_1.default.elog('callback parameter is wrong');
256
+ return;
257
+ }
258
+ if (!k2hr3apiutil_1.default.isSafeNumber(start)) {
259
+ callback(new Error('start value is wrong : ' + JSON.stringify(start)));
260
+ return;
261
+ }
262
+ if (!k2hr3apiutil_1.default.isPlainObject(chkipconfig)) { // already check this...
263
+ callback(new Error('chkipconfig value is wrong : ' + JSON.stringify(chkipconfig)));
264
+ return;
265
+ }
266
+ if (!k2hr3apiutil_1.default.isArray(ipdatas) || !k2hr3apiutil_1.default.isSafeEntity(ipdatas)) {
267
+ callback(new Error('IP Addresses array is wrong : ' + JSON.stringify(ipdatas)));
268
+ return;
269
+ }
270
+ let _totalcount = chkipconfig.parallelcnt;
271
+ if (null == _totalcount) {
272
+ callback(new Error('No rest array for checking'));
273
+ return;
274
+ }
275
+ else if ((ipdatas.length - start) < _totalcount) {
276
+ _totalcount = ipdatas.length - start;
277
+ if (_totalcount <= 0) {
278
+ callback(new Error('No rest array for checking'));
279
+ return;
280
+ }
281
+ }
282
+ let setcnt = 0;
283
+ for (let cnt = 0; cnt < _totalcount; ++cnt) {
284
+ checkAddressAlive(ipdatas[start + cnt], chkipconfig, (error, ipdata) => {
285
+ if (error) {
286
+ dbglogging_1.default.dlog('IP Address and CUK (' + JSON.stringify(ipdata) + ') are not alive by ' + JSON.stringify(error));
287
+ if (k2hr3apiutil_1.default.isSafeEntity(ipdata)) {
288
+ ipdata.alive = false;
289
+ }
290
+ }
291
+ else {
292
+ dbglogging_1.default.dlog('IP Address and CUK (' + JSON.stringify(ipdata) + ') is alive');
293
+ if (k2hr3apiutil_1.default.isSafeEntity(ipdata)) {
294
+ ipdata.alive = true;
295
+ }
296
+ }
297
+ ++setcnt;
298
+ if (_totalcount <= setcnt) {
299
+ if (ipdatas.length <= (start + _totalcount)) {
300
+ callback(null);
301
+ }
302
+ else {
303
+ checkAddressesAliveParallel(ipdatas, (start + _totalcount), chkipconfig, callback);
304
+ }
305
+ }
306
+ });
307
+ }
308
+ };
309
+ //---------------------------------------------------------
310
+ // Check & Set result checking IP Addresses
311
+ //---------------------------------------------------------
312
+ // ipdatas: IP address information array
313
+ // dkcTypeHostRawValueSet[] = [{
314
+ // ip: <string>, -> ip address string
315
+ // cuk: <string>, -> cuk string (not use)
316
+ // port: <number>, -> port number(0 as any) (not use)
317
+ // extra: <string>, -> 'openstack-auto-v1' or etc (not use)
318
+ // tag: <string>, -> null or string (not use)
319
+ // inboundip: <string>, -> inbound ip address (not use)
320
+ // outboundip: <string>, -> outbound ip address (not use)
321
+ // key: <string>, -> this ip address yrn full path (not use)
322
+ // alive: <boolean> -> true or false
323
+ // }, ...]
324
+ // chkipconfig: Configuration for IP addresses checking
325
+ // ipchkTypeConfig = {
326
+ // type: <string>, -> IP check type (not use)
327
+ // funcmod: <null or string>, -> IP check special module (not use)
328
+ // pendingsec: <number>, -> Limit for removing IP which is not alive (not use)
329
+ // intervalms: <number>, -> Interval ms for checking IP address (not use)
330
+ // parallelcnt: <number>, -> Parallel processing count
331
+ // command4: <string>, -> ping command for IPv4
332
+ // command6: <string>, -> ping command for IPv6
333
+ // params: <string>, -> Common ping command parameters
334
+ // timeoutparam: <string>, -> Timeout parameter name for ping command
335
+ // timeoutms: <number> -> Timeout millisecond for each checking
336
+ // }
337
+ //
338
+ // [NOTE]
339
+ // This function returns Promise object.
340
+ // resolve: {error: <Error object if error>, data: <reference to input ipdatas>}
341
+ // reject: <Error object>
342
+ //
343
+ const checkAddressesAlivePromise = (ipdatas, chkipconfig) => {
344
+ const _chkipconfig = chkipconfig;
345
+ const _ipdatas = ipdatas; // reference
346
+ return new Promise((resolve, reject) => {
347
+ const _resolve = resolve;
348
+ const _reject = reject;
349
+ if (null == _chkipconfig ||
350
+ !k2hr3apiutil_1.default.isPlainObject(_chkipconfig) ||
351
+ !k2hr3apiutil_1.default.isSafeNumber(_chkipconfig.parallelcnt) ||
352
+ !k2hr3apiutil_1.default.isSafeString(_chkipconfig.command4) ||
353
+ !k2hr3apiutil_1.default.isSafeString(_chkipconfig.command6) ||
354
+ //!apiutil.isSafeString(_chkipconfig.params) || // allow null
355
+ //!apiutil.isSafeString(_chkipconfig.timeoutparam) || // allow null
356
+ !k2hr3apiutil_1.default.isSafeNumber(_chkipconfig.timeoutms)) {
357
+ _reject(new Error('chkipconfig object is wrong : ' + JSON.stringify(_chkipconfig)));
358
+ return;
359
+ }
360
+ if (!k2hr3apiutil_1.default.isArray(_ipdatas)) {
361
+ _reject(new Error('IP Addresses array is wrong : ' + JSON.stringify(_ipdatas)));
362
+ return;
363
+ }
364
+ checkAddressesAliveParallel(_ipdatas, 0, _chkipconfig, (error) => {
365
+ if (k2hr3apiutil_1.default.isPlainObject(error)) {
366
+ dbglogging_1.default.elog('Something error is occurred : ' + JSON.stringify(error));
367
+ _resolve({ error: error, data: _ipdatas });
368
+ }
369
+ else {
370
+ dbglogging_1.default.dlog('Succeed to checking all ip address');
371
+ _resolve({ error: null, data: _ipdatas });
372
+ }
373
+ });
374
+ });
375
+ };
376
+ //---------------------------------------------------------
377
+ // Exports
378
+ //---------------------------------------------------------
379
+ exports.basicipcheck = {
380
+ checkAddressesAlive: (ipdatas, chkipconfig) => {
381
+ return checkAddressesAlivePromise(ipdatas, chkipconfig);
382
+ }
383
+ };
384
+ exports.default = exports.basicipcheck;
385
+ /*
386
+ * Local variables:
387
+ * tab-width: 4
388
+ * c-basic-offset: 4
389
+ * End:
390
+ * vim600: noexpandtab sw=4 ts=4 fdm=marker
391
+ * vim<600: noexpandtab sw=4 ts=4
392
+ */
@@ -0,0 +1,106 @@
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: Wed Jun 8 2017
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.ca = void 0;
59
+ const fs = __importStar(require("fs"));
60
+ const k2hr3apiutil_1 = __importDefault(require("./k2hr3apiutil"));
61
+ const dbglogging_1 = __importDefault(require("./dbglogging"));
62
+ const loadCACert = () => {
63
+ const caPath = process.env.CAPATH;
64
+ // load CA Path environment
65
+ if (k2hr3apiutil_1.default.isSafeString(caPath)) {
66
+ try {
67
+ fs.statSync(caPath);
68
+ return fs.readFileSync(caPath);
69
+ }
70
+ catch (err) {
71
+ dbglogging_1.default.elog('CAPATH environment' + caPath + ' file does not exist, then use default ca certs.', JSON.stringify(err));
72
+ }
73
+ }
74
+ // load one of CA certs
75
+ const def_certs = [
76
+ '/etc/ssl/certs/ca-certificates.crt',
77
+ '/etc/pki/tls/certs/ca-bundle.crt',
78
+ '/etc/ssl/certs/ca-bundle.crt',
79
+ '/etc/ssl/certs/ca-bundle.trust.crt'
80
+ ];
81
+ for (let cnt = 0; cnt < def_certs.length; ++cnt) {
82
+ try {
83
+ fs.statSync(def_certs[cnt]);
84
+ return fs.readFileSync(def_certs[cnt]);
85
+ }
86
+ catch (err) {
87
+ dbglogging_1.default.dlog(JSON.stringify(err));
88
+ continue;
89
+ }
90
+ }
91
+ return null;
92
+ };
93
+ //---------------------------------------------------------
94
+ // Exports
95
+ //---------------------------------------------------------
96
+ const ca = () => loadCACert();
97
+ exports.ca = ca;
98
+ exports.default = exports.ca;
99
+ /*
100
+ * Local variables:
101
+ * tab-width: 4
102
+ * c-basic-offset: 4
103
+ * End:
104
+ * vim600: noexpandtab sw=4 ts=4 fdm=marker
105
+ * vim<600: noexpandtab sw=4 ts=4
106
+ */
@@ -0,0 +1,190 @@
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: Wed Jun 8 2017
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.dbglogging = exports.levelSilent = exports.levelErr = exports.levelWarn = exports.levelInfo = exports.levelDbg = exports.dbgLevelMap = exports.LogLevel = void 0;
59
+ const util = __importStar(require("util"));
60
+ const k2hr3apiutil_1 = __importDefault(require("./k2hr3apiutil"));
61
+ //---------------------------------------------------------
62
+ // NODE_DEBUG Environment Values
63
+ //---------------------------------------------------------
64
+ var LogLevel;
65
+ (function (LogLevel) {
66
+ LogLevel[LogLevel["Silent"] = 0] = "Silent";
67
+ LogLevel[LogLevel["Error"] = 1] = "Error";
68
+ LogLevel[LogLevel["Warn"] = 2] = "Warn";
69
+ LogLevel[LogLevel["Info"] = 3] = "Info";
70
+ LogLevel[LogLevel["Debug"] = 4] = "Debug";
71
+ })(LogLevel || (exports.LogLevel = LogLevel = {}));
72
+ exports.dbgLevelMap = {
73
+ 'LOGLEVEL_DEBUG': LogLevel.Debug,
74
+ 'LOGLEVEL_DBG': LogLevel.Debug,
75
+ 'LOGLEVEL_INFO': LogLevel.Info,
76
+ 'LOGLEVEL_MESSAGE': LogLevel.Info,
77
+ 'LOGLEVEL_MSG': LogLevel.Info,
78
+ 'LOGLEVEL_WARNING': LogLevel.Warn,
79
+ 'LOGLEVEL_WARN': LogLevel.Warn,
80
+ 'LOGLEVEL_WAN': LogLevel.Warn,
81
+ 'LOGLEVEL_ERROR': LogLevel.Error,
82
+ 'LOGLEVEL_ERR': LogLevel.Error,
83
+ 'LOGLEVEL_SILENT': LogLevel.Silent,
84
+ 'LOGLEVEL_SLT': LogLevel.Silent
85
+ };
86
+ exports.levelDbg = 4;
87
+ exports.levelInfo = 3;
88
+ exports.levelWarn = 2;
89
+ exports.levelErr = 1;
90
+ exports.levelSilent = 0;
91
+ //---------------------------------------------------------
92
+ // Logging Level
93
+ //---------------------------------------------------------
94
+ let currentLevel = LogLevel.Error;
95
+ const customLevels = [];
96
+ (() => {
97
+ const dbgEnvs = k2hr3apiutil_1.default.getSafeString(process.env.NODE_DEBUG).split(',');
98
+ dbgEnvs.forEach((key) => {
99
+ const upperKey = key.toUpperCase();
100
+ if (upperKey in exports.dbgLevelMap) {
101
+ if (exports.levelSilent === exports.dbgLevelMap[upperKey]) {
102
+ // default level is error. if specify silent, we must set silent.
103
+ currentLevel = LogLevel.Silent;
104
+ }
105
+ else if (currentLevel < exports.dbgLevelMap[upperKey]) {
106
+ currentLevel = exports.dbgLevelMap[upperKey];
107
+ }
108
+ }
109
+ else if (!k2hr3apiutil_1.default.findStringInArray(customLevels, upperKey)) {
110
+ customLevels.push(upperKey);
111
+ }
112
+ });
113
+ })();
114
+ const getCurrentInfo = () => {
115
+ try {
116
+ throw new Error('INTERNAL_EXCEPTION_FOR_DEBUG');
117
+ }
118
+ catch (exception) {
119
+ if (exception instanceof Error && k2hr3apiutil_1.default.isString(exception.stack)) {
120
+ const basedir = __dirname.replace(/lib$/g, '');
121
+ const stackLines = exception.stack.split(/[\r\n]+/).filter((val1) => /^ *at .*:[0-9]+:[0-9]+/.test(val1));
122
+ if (2 < stackLines.length) {
123
+ const curstr = stackLines[2];
124
+ return curstr.replace(/^ *at /g, '').replace(new RegExp(basedir, 'g'), '').replace(/.*\(/g, '').replace(/\)$/g, '').replace(/:[0-9]+$/g, '').replace(/:/g, '(') + ')';
125
+ }
126
+ }
127
+ return '';
128
+ }
129
+ };
130
+ const dlog = (...args) => {
131
+ if (exports.levelDbg <= currentLevel) {
132
+ // [NOTE]
133
+ // We want to use stack trace, thus using console.warn instead of console.debug method.
134
+ //
135
+ console.warn('[DEBUG] ' + getCurrentInfo(), util.format(...args));
136
+ }
137
+ };
138
+ const mlog = (...args) => {
139
+ if (exports.levelInfo <= currentLevel) {
140
+ // [NOTE]
141
+ // We want to use stack trace, thus using console.warn instead of console.info method.
142
+ //
143
+ console.warn('[INFO] ' + getCurrentInfo(), util.format(...args));
144
+ }
145
+ };
146
+ const wlog = (...args) => {
147
+ if (exports.levelWarn <= currentLevel) {
148
+ console.warn('[WARN] ' + getCurrentInfo(), util.format(...args));
149
+ }
150
+ };
151
+ const elog = (...args) => {
152
+ if (exports.levelErr <= currentLevel) {
153
+ console.error('[ERROR] ' + getCurrentInfo(), util.format(...args));
154
+ }
155
+ };
156
+ const clog = (section, ...args) => {
157
+ if (k2hr3apiutil_1.default.isSafeString(section)) {
158
+ if (k2hr3apiutil_1.default.findStringInArray(customLevels, section.toUpperCase())) {
159
+ // [NOTE]
160
+ // We want to use stack trace, thus using console.warn instead of console.info method.
161
+ //
162
+ console.warn('[' + section.toUpperCase() + '] ' + getCurrentInfo(), util.format(...args));
163
+ }
164
+ }
165
+ };
166
+ const dump = (obj) => {
167
+ if (exports.levelDbg <= currentLevel) {
168
+ if (k2hr3apiutil_1.default.isPlainObject(obj)) {
169
+ return util.inspect(obj, { showHidden: true, depth: null, maxArrayLength: 1000 });
170
+ }
171
+ }
172
+ return obj;
173
+ };
174
+ exports.dbglogging = {
175
+ dlog,
176
+ mlog,
177
+ wlog,
178
+ elog,
179
+ clog,
180
+ dump,
181
+ };
182
+ exports.default = exports.dbglogging;
183
+ /*
184
+ * Local variables:
185
+ * tab-width: 4
186
+ * c-basic-offset: 4
187
+ * End:
188
+ * vim600: noexpandtab sw=4 ts=4 fdm=marker
189
+ * vim<600: noexpandtab sw=4 ts=4
190
+ */