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,832 @@
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 Oct 31 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.chkipType = exports.r3ApiConfig = exports.loadedConfig = exports.chkipconfigType = void 0;
59
+ const path = __importStar(require("path"));
60
+ const rotatefs = __importStar(require("rotating-file-stream"));
61
+ const config_1 = __importDefault(require("config"));
62
+ const k2hr3apiutil_1 = __importDefault(require("./k2hr3apiutil"));
63
+ const openstackep_1 = __importDefault(require("./openstackep"));
64
+ const toIntervalNumber = (val) => {
65
+ if (/^\d+d$/.test(val)) {
66
+ return val;
67
+ }
68
+ if (/^\d+s$/.test(val)) {
69
+ return val;
70
+ }
71
+ if (/^\d+M$/.test(val)) {
72
+ return val;
73
+ }
74
+ if (/^\d+h$/.test(val)) {
75
+ return val;
76
+ }
77
+ if (/^\d+m$/.test(val)) {
78
+ return val;
79
+ }
80
+ return '1d';
81
+ };
82
+ //
83
+ // Utility: copy(overwrite) LoadedConfig
84
+ //
85
+ const setLoadedConfig = (base, data) => {
86
+ if (!k2hr3apiutil_1.default.isPlainObject(data)) {
87
+ return null;
88
+ }
89
+ // Keystone type
90
+ if (k2hr3apiutil_1.default.isPlainObject(data.keystone)) {
91
+ if (k2hr3apiutil_1.default.isSafeString(data.keystone.type)) {
92
+ base.keystone.type = data.keystone.type;
93
+ }
94
+ if (k2hr3apiutil_1.default.isSafeString(data.keystone.eptype) && k2hr3apiutil_1.default.compareCaseString('list', data.keystone.eptype)) {
95
+ if (openstackep_1.default.isValTypeKeystoneEndpointMap(data.keystone.eplist)) {
96
+ const eplist = {};
97
+ for (const region in data.keystone.eplist) {
98
+ const tmpRegion = data.keystone.eplist[region];
99
+ if (k2hr3apiutil_1.default.isString(tmpRegion)) {
100
+ if (k2hr3apiutil_1.default.isSafeUrl(tmpRegion)) {
101
+ eplist[region] = tmpRegion;
102
+ }
103
+ }
104
+ }
105
+ base.keystone.eptype = data.keystone.eptype;
106
+ base.keystone.epfile = null;
107
+ base.keystone.eplist = eplist;
108
+ }
109
+ else {
110
+ // Wrong value
111
+ }
112
+ }
113
+ else if (k2hr3apiutil_1.default.isSafeString(data.keystone.eptype) && k2hr3apiutil_1.default.compareCaseString('file', data.keystone.eptype)) {
114
+ if (k2hr3apiutil_1.default.isSafeString(data.keystone.epfile)) {
115
+ base.keystone.eptype = data.keystone.eptype;
116
+ base.keystone.epfile = data.keystone.epfile;
117
+ base.keystone.eplist = null;
118
+ }
119
+ else {
120
+ // Wrong value
121
+ }
122
+ }
123
+ else {
124
+ // Unknown value
125
+ }
126
+ }
127
+ // K2HDKC configuration
128
+ if (k2hr3apiutil_1.default.isPlainObject(data.k2hdkc)) {
129
+ if (k2hr3apiutil_1.default.isSafeString(data.k2hdkc.config)) {
130
+ base.k2hdkc.config = data.k2hdkc.config;
131
+ }
132
+ if (k2hr3apiutil_1.default.isSafeNumeric(data.k2hdkc.port)) {
133
+ const tmpPort = k2hr3apiutil_1.default.cvtToNumber(data.k2hdkc.port);
134
+ if (k2hr3apiutil_1.default.isSafeNumber(tmpPort)) {
135
+ base.k2hdkc.port = tmpPort;
136
+ }
137
+ }
138
+ if (null === data.k2hdkc.cuk || k2hr3apiutil_1.default.isString(data.k2hdkc.cuk)) {
139
+ base.k2hdkc.cuk = data.k2hdkc.cuk;
140
+ }
141
+ }
142
+ // CORS
143
+ if (k2hr3apiutil_1.default.isStringArray(data.corsips)) {
144
+ base.corsips = data.corsips;
145
+ }
146
+ // multi processes
147
+ if (k2hr3apiutil_1.default.isBoolean(data.multiproc)) {
148
+ base.multiproc = data.multiproc;
149
+ }
150
+ // scheme & port
151
+ if (k2hr3apiutil_1.default.isString(data.scheme)) {
152
+ base.scheme = k2hr3apiutil_1.default.getSafeString(data.scheme);
153
+ if (k2hr3apiutil_1.default.compareCaseString('http', data.scheme)) {
154
+ base.port = 80;
155
+ }
156
+ else if (k2hr3apiutil_1.default.compareCaseString('https', data.scheme)) {
157
+ base.port = 443;
158
+ }
159
+ }
160
+ if (k2hr3apiutil_1.default.isSafeEntity(data.port)) {
161
+ const tmpPort = k2hr3apiutil_1.default.cvtToNumber(data.port);
162
+ if (k2hr3apiutil_1.default.isSafeNumber(tmpPort)) {
163
+ base.port = tmpPort;
164
+ }
165
+ }
166
+ else if (k2hr3apiutil_1.default.isSafeNumeric(process.env.PORT)) { // Get port from environment
167
+ const tmpPort = k2hr3apiutil_1.default.cvtToNumber(process.env.PORT);
168
+ if (k2hr3apiutil_1.default.isSafeNumber(tmpPort)) {
169
+ base.port = tmpPort;
170
+ }
171
+ }
172
+ // run user
173
+ if (null === data.runuser || k2hr3apiutil_1.default.isString(data.runuser)) {
174
+ base.runuser = k2hr3apiutil_1.default.getSafeString(data.runuser);
175
+ }
176
+ // private key & cert & ca
177
+ if (null === data.privatekey || k2hr3apiutil_1.default.isString(data.privatekey)) {
178
+ base.privatekey = k2hr3apiutil_1.default.getSafeString(data.privatekey);
179
+ }
180
+ if (null === data.cert || k2hr3apiutil_1.default.isString(data.cert)) {
181
+ base.cert = k2hr3apiutil_1.default.getSafeString(data.cert);
182
+ }
183
+ if (null === data.ca || k2hr3apiutil_1.default.isString(data.ca)) {
184
+ base.ca = k2hr3apiutil_1.default.getSafeString(data.ca);
185
+ }
186
+ // log directory
187
+ if (null === data.logdir || k2hr3apiutil_1.default.isString(data.logdir)) {
188
+ base.logdir = k2hr3apiutil_1.default.getSafeString(data.logdir);
189
+ }
190
+ // access log file name
191
+ if (null === data.accesslogname || k2hr3apiutil_1.default.isString(data.accesslogname)) {
192
+ base.accesslogname = k2hr3apiutil_1.default.getSafeString(data.accesslogname);
193
+ }
194
+ if (null === data.accesslogform || k2hr3apiutil_1.default.isString(data.accesslogform)) {
195
+ base.accesslogform = k2hr3apiutil_1.default.getSafeString(data.accesslogform);
196
+ }
197
+ if (null === data.consolelogname || k2hr3apiutil_1.default.isString(data.consolelogname)) {
198
+ base.consolelogname = k2hr3apiutil_1.default.getSafeString(data.consolelogname);
199
+ }
200
+ if (null === data.watcherlogname || k2hr3apiutil_1.default.isString(data.watcherlogname)) {
201
+ base.watcherlogname = k2hr3apiutil_1.default.getSafeString(data.watcherlogname);
202
+ }
203
+ if (null === data.watchertimeform || k2hr3apiutil_1.default.isString(data.watchertimeform)) {
204
+ base.watchertimeform = k2hr3apiutil_1.default.getSafeString(data.watchertimeform);
205
+ }
206
+ if (null === data.wconsolelogname || k2hr3apiutil_1.default.isString(data.wconsolelogname)) {
207
+ base.wconsolelogname = k2hr3apiutil_1.default.getSafeString(data.wconsolelogname);
208
+ }
209
+ // log rotation option
210
+ if (k2hr3apiutil_1.default.isPlainObject(data.logrotateopt)) {
211
+ if (k2hr3apiutil_1.default.isSafeString(data.logrotateopt.compress)) {
212
+ base.logrotateopt.compress = data.logrotateopt.compress;
213
+ }
214
+ if (k2hr3apiutil_1.default.isSafeString(data.logrotateopt.interval)) {
215
+ base.logrotateopt.interval = data.logrotateopt.interval;
216
+ }
217
+ if (k2hr3apiutil_1.default.isBoolean(data.logrotateopt.initialRotation)) {
218
+ base.logrotateopt.initialRotation = data.logrotateopt.initialRotation;
219
+ }
220
+ if (k2hr3apiutil_1.default.isSafeString(data.logrotateopt.path)) {
221
+ base.logrotateopt.path = data.logrotateopt.path;
222
+ }
223
+ const _logrotateopt = data.logrotateopt;
224
+ Object.keys(_logrotateopt).forEach((key) => {
225
+ const val = _logrotateopt[key];
226
+ if (null === val || k2hr3apiutil_1.default.isSafeString(val) || k2hr3apiutil_1.default.isBoolean(val)) {
227
+ base.logrotateopt[key] = val;
228
+ }
229
+ });
230
+ }
231
+ // Userdata
232
+ if (k2hr3apiutil_1.default.isPlainObject(data.userdata)) {
233
+ if (k2hr3apiutil_1.default.isSafeString(data.userdata.baseuri)) {
234
+ base.userdata.baseuri = data.userdata.baseuri;
235
+ }
236
+ if (k2hr3apiutil_1.default.isSafeString(data.userdata.cc_templ)) {
237
+ base.userdata.cc_templ = data.userdata.cc_templ;
238
+ }
239
+ if (k2hr3apiutil_1.default.isSafeString(data.userdata.script_templ)) {
240
+ base.userdata.script_templ = data.userdata.script_templ;
241
+ }
242
+ if (k2hr3apiutil_1.default.isSafeString(data.userdata.errscript_templ)) {
243
+ base.userdata.errscript_templ = data.userdata.errscript_templ;
244
+ }
245
+ if (k2hr3apiutil_1.default.isSafeString(data.userdata.algorithm)) {
246
+ base.userdata.algorithm = data.userdata.algorithm;
247
+ }
248
+ if (k2hr3apiutil_1.default.isSafeString(data.userdata.passphrase)) {
249
+ base.userdata.passphrase = data.userdata.passphrase;
250
+ }
251
+ }
252
+ // Extdata
253
+ if (k2hr3apiutil_1.default.isPlainObject(data.extdata)) {
254
+ const _extdata = data.extdata;
255
+ Object.keys(_extdata).forEach((key) => {
256
+ const one_extdata = _extdata[key];
257
+ if (k2hr3apiutil_1.default.isPlainObject(one_extdata) && k2hr3apiutil_1.default.isSafeString(one_extdata.baseuri) && k2hr3apiutil_1.default.isSafeString(one_extdata.template)) {
258
+ base.extdata[key] = {};
259
+ base.extdata[key].baseuri = one_extdata.baseuri;
260
+ base.extdata[key].template = one_extdata.template;
261
+ base.extdata[key].useragent = k2hr3apiutil_1.default.isSafeString(one_extdata.useragent) ? k2hr3apiutil_1.default.getSafeString(one_extdata.useragent) : null;
262
+ base.extdata[key].contenttype = k2hr3apiutil_1.default.isSafeString(one_extdata.contenttype) ? k2hr3apiutil_1.default.getSafeString(one_extdata.contenttype) : 'text/plain';
263
+ }
264
+ else {
265
+ // [NOTE] Some required parameters could not be detected, then skip this.
266
+ }
267
+ });
268
+ }
269
+ // Admin
270
+ if (k2hr3apiutil_1.default.isPlainObject(data.k2hr3admin)) {
271
+ if (k2hr3apiutil_1.default.isSafeString(data.k2hr3admin.tenant)) {
272
+ base.k2hr3admin.tenant = data.k2hr3admin.tenant;
273
+ }
274
+ if (k2hr3apiutil_1.default.isSafeString(data.k2hr3admin.delhostrole)) {
275
+ base.k2hr3admin.delhostrole = data.k2hr3admin.delhostrole;
276
+ }
277
+ }
278
+ // Local tenants
279
+ if (k2hr3apiutil_1.default.isBoolean(data.localtenants)) {
280
+ base.localtenants = data.localtenants;
281
+ }
282
+ // Confirm tenant mode for adding service member
283
+ if (k2hr3apiutil_1.default.isBoolean(data.confirmtenant)) {
284
+ base.confirmtenant = data.confirmtenant;
285
+ }
286
+ // IP Addresses checker(watcher) config
287
+ if (k2hr3apiutil_1.default.isPlainObject(data.chkipconfig)) {
288
+ if (k2hr3apiutil_1.default.isSafeString(data.chkipconfig.type) &&
289
+ (exports.chkipconfigType.CHECKER_TYPE_LISTENER === data.chkipconfig.type ||
290
+ exports.chkipconfigType.CHECKER_TYPE_FUNCTION === data.chkipconfig.type ||
291
+ exports.chkipconfigType.CHECKER_TYPE_BASIC_OR === data.chkipconfig.type ||
292
+ exports.chkipconfigType.CHECKER_TYPE_BASIC_AND === data.chkipconfig.type ||
293
+ exports.chkipconfigType.CHECKER_TYPE_NOCHECK === data.chkipconfig.type)) {
294
+ base.chkipconfig.type = data.chkipconfig.type;
295
+ }
296
+ if (k2hr3apiutil_1.default.isSafeString(data.chkipconfig.funcmod)) {
297
+ base.chkipconfig.funcmod = data.chkipconfig.funcmod;
298
+ }
299
+ if (k2hr3apiutil_1.default.isSafeNumeric(data.chkipconfig.pendingsec)) {
300
+ const tmpTime = k2hr3apiutil_1.default.cvtToNumber(data.chkipconfig.pendingsec);
301
+ if (k2hr3apiutil_1.default.isSafeNumber(tmpTime)) {
302
+ base.chkipconfig.pendingsec = tmpTime;
303
+ }
304
+ }
305
+ if (k2hr3apiutil_1.default.isSafeNumeric(data.chkipconfig.intervalms)) {
306
+ const tmpTime = k2hr3apiutil_1.default.cvtToNumber(data.chkipconfig.intervalms);
307
+ if (k2hr3apiutil_1.default.isSafeNumber(tmpTime)) {
308
+ base.chkipconfig.intervalms = tmpTime;
309
+ }
310
+ }
311
+ if (k2hr3apiutil_1.default.isSafeNumeric(data.chkipconfig.parallelcnt)) {
312
+ const tmpCnt = k2hr3apiutil_1.default.cvtToNumber(data.chkipconfig.parallelcnt);
313
+ if (k2hr3apiutil_1.default.isSafeNumber(tmpCnt)) {
314
+ base.chkipconfig.parallelcnt = tmpCnt;
315
+ }
316
+ }
317
+ if (k2hr3apiutil_1.default.isSafeString(data.chkipconfig.command4)) {
318
+ base.chkipconfig.command4 = data.chkipconfig.command4;
319
+ }
320
+ if (k2hr3apiutil_1.default.isSafeString(data.chkipconfig.command6)) {
321
+ base.chkipconfig.command6 = data.chkipconfig.command6;
322
+ }
323
+ if (k2hr3apiutil_1.default.isSafeString(data.chkipconfig.params)) {
324
+ base.chkipconfig.params = data.chkipconfig.params;
325
+ }
326
+ if (k2hr3apiutil_1.default.isSafeString(data.chkipconfig.timeoutparam)) {
327
+ base.chkipconfig.timeoutparam = data.chkipconfig.timeoutparam;
328
+ }
329
+ if (k2hr3apiutil_1.default.isSafeNumeric(data.chkipconfig.timeoutms)) {
330
+ const tmpTime = k2hr3apiutil_1.default.cvtToNumber(data.chkipconfig.timeoutms);
331
+ if (k2hr3apiutil_1.default.isSafeNumber(tmpTime)) {
332
+ base.chkipconfig.timeoutms = tmpTime;
333
+ }
334
+ }
335
+ }
336
+ if (k2hr3apiutil_1.default.isBoolean(data.allowcredauth)) {
337
+ base.allowcredauth = data.allowcredauth;
338
+ }
339
+ // Expiration for Tokens
340
+ if (k2hr3apiutil_1.default.isPlainObject(data.expiration)) {
341
+ if (k2hr3apiutil_1.default.isSafeNumeric(data.expiration.roletoken)) {
342
+ const tmpNum = k2hr3apiutil_1.default.cvtToNumber(data.expiration.roletoken);
343
+ if (k2hr3apiutil_1.default.isSafeNumber(tmpNum)) {
344
+ base.expiration.roletoken = tmpNum;
345
+ }
346
+ }
347
+ if (k2hr3apiutil_1.default.isSafeNumeric(data.expiration.regroletoken)) {
348
+ const tmpNum = k2hr3apiutil_1.default.cvtToNumber(data.expiration.regroletoken);
349
+ if (k2hr3apiutil_1.default.isSafeNumber(tmpNum)) {
350
+ base.expiration.regroletoken = tmpNum;
351
+ }
352
+ }
353
+ }
354
+ // Other objects
355
+ Object.keys(config_1.default).forEach((key) => {
356
+ if (!k2hr3apiutil_1.default.findStringInArray(reserved_key_list, key)) {
357
+ // not found key in reserved key name list, then add(replace) this object to data.
358
+ base[key] = data[key];
359
+ }
360
+ });
361
+ return base;
362
+ };
363
+ //
364
+ // [NOTE]
365
+ // About type assertion
366
+ //
367
+ // The config package loads settings dynamically and does not
368
+ // guarantee type safety by default.
369
+ // To address this, we define our own LoadedConfig type for
370
+ // project-specific configuration, and use a type assertion(as
371
+ // LoadedConfig) on the config object.
372
+ // This allows us to access configuration values with type safety.
373
+ //
374
+ // Note: Type assertion does not perform runtime checks. TypeScript
375
+ // will assume the config object matches LoadedConfig,
376
+ // even if the actual config content differs. Be careful to keep
377
+ // the LoadedConfig definition in sync with the configuration file.
378
+ //
379
+ const k2hr3Config = config_1.default;
380
+ //
381
+ // For IP Addresses checker(watcher) type
382
+ //
383
+ exports.chkipconfigType = {
384
+ CHECKER_TYPE_LISTENER: 'Listener',
385
+ CHECKER_TYPE_FUNCTION: 'Function',
386
+ CHECKER_TYPE_BASIC_OR: 'BasicOr',
387
+ CHECKER_TYPE_BASIC_AND: 'BasicAnd',
388
+ CHECKER_TYPE_NOCHECK: 'NoCheck'
389
+ };
390
+ //
391
+ // Reserved key name in config
392
+ //
393
+ const reserved_key_list = [
394
+ 'keystone',
395
+ 'k2hdkc',
396
+ 'corsips',
397
+ 'multiproc',
398
+ 'scheme',
399
+ 'port',
400
+ 'runuser',
401
+ 'privatekey',
402
+ 'cert',
403
+ 'ca',
404
+ 'logdir',
405
+ 'accesslogname',
406
+ 'accesslogform',
407
+ 'consolelogname',
408
+ 'watcherlogname',
409
+ 'watchertimeform',
410
+ 'wconsolelogname',
411
+ 'logrotateopt',
412
+ 'userdata',
413
+ 'extdata',
414
+ 'k2hr3admin',
415
+ 'localtenants',
416
+ 'confirmtenant',
417
+ 'chkipconfig',
418
+ 'allowcredauth',
419
+ 'expiration'
420
+ ];
421
+ //
422
+ // LoadedConfig
423
+ //
424
+ exports.loadedConfig = (() => {
425
+ // Default values
426
+ let data = {
427
+ // [NOTE]
428
+ // Set keystone type and others for openstack keystone.
429
+ //
430
+ // Specify the keystone.type module to handle keystone authentication.
431
+ // We prepare two of keystone V2/V3 for this value by k2hr3. They are
432
+ // lib/openstackapiv2.js and lib/openstackapiv3.js.
433
+ // Please specify module name specified for keystone.type without
434
+ // extension. The matching file name is automatically searched from
435
+ // the lib directory.
436
+ // If you want to use your own module, prepare the file in the lib
437
+ // directory and specify the file name. To create your own, please
438
+ // prepare the module exporting the getKeystoneEndpoint(callback, is_v3, is_test, timeout)
439
+ // function. For details of the getKeystoneEndpoint function, please
440
+ // refer to openstackep.js.
441
+ //
442
+ // Please specify 'list' or 'file' as keystone.eptype.
443
+ // If 'list' is specified, please specify one or more {'region name': 'keystone endpoint URI'}
444
+ // in keystone.eplist.
445
+ // If you specify 'file', specify keystone.epfile with your own module
446
+ // name in the lib directory. This module specifies the file exporting
447
+ // the getDynamicKeystoneEndpoints(cbargs, callback) function.
448
+ // The getDynamicKeystoneEndpoints function takes callback(cbargs, error, endpoint_mapping)
449
+ // as a callback function as an argument. 'endpoint_mapping' argument
450
+ // of this callback function should return data of the same type as
451
+ // keystone.eplist.
452
+ // cbargs specifies the cbargs passed to the getDynamicKeystoneEndpoints
453
+ // function as is.
454
+ //
455
+ keystone: {
456
+ type: 'openstackapiv3', // module name in lib for openstack keystone access
457
+ eptype: 'list', // type of openstack keystone endpoint
458
+ epfile: null,
459
+ eplist: {
460
+ myregion: 'https://dummy.keystone.openstack/'
461
+ }
462
+ },
463
+ k2hdkc: {
464
+ config: '/etc/k2hdkc/slave.ini', // Configuration file path for k2hdkc(chmpx) slave
465
+ port: '8031', // Control port number for k2hdkc(chmpx) slave
466
+ cuk: null // CUK for k2hdkc(chmpx) slave
467
+ },
468
+ corsips: [
469
+ '::ffff:127.0.0.1',
470
+ '127.0.0.1'
471
+ ],
472
+ scheme: 'http', // Scheme
473
+ port: 80, // Port
474
+ multiproc: true, // Multi processing
475
+ runuser: '', // Username for process owner
476
+ privatekey: '', // Privatekey file path
477
+ cert: '', // Certification file path
478
+ ca: '', // CA
479
+ logdir: null, // Path for logging directory
480
+ fixedlogdir: null, // Fixed log directory
481
+ accesslogname: 'access.log', // Access log name
482
+ accesslogform: 'combined', // Access log format by morgan
483
+ consolelogname: null, // Console(Error)/Debug log name
484
+ watcherlogname: 'watcher.log', // Watcher log name
485
+ watchertimeform: 'yyyy/mm/dd HH:MM:ss', // Watcher log time format by dateformat
486
+ wconsolelogname: null, // Console(Error)/Debug log name by watcher
487
+ logrotateopt: {
488
+ compress: 'gzip', // gzip : compression method of rotated files.
489
+ interval: '6h', // 6 hour : the time interval to rotate the file.
490
+ initialRotation: true, // true : initial rotation based on not-rotated file timestamp.
491
+ path: null // null : the base path for files.(* this value is replace by 'logdir')
492
+ /*
493
+ * [NOTE] following option is not specified now.
494
+ *
495
+ rotationTime: true, // true : makes rotated file name with time of rotation.
496
+ highWaterMark: null, // null : proxy to new stream.
497
+ history: null, // null : the history filename.
498
+ immutable: null, // null : never mutates file names.
499
+ maxFiles: null, // null : the maximum number of rotated files to keep.
500
+ maxSize: null, // null : the maximum size of rotated files to keep.
501
+ mode: null, // null : proxy to fs.createWriteStream
502
+ rotate: null, // null : enables the classical UNIX logrotate behaviour.
503
+ size: null // null : the file size to rotate the file.
504
+ */
505
+ },
506
+ userdata: {
507
+ baseuri: 'https://localhost', // URI
508
+ cc_templ: 'config/k2hr3-cloud-config.txt.templ', // Template for Cloud Config part
509
+ script_templ: 'config/k2hr3-init.sh.templ', // Template for Shell part
510
+ errscript_templ: 'config/k2hr3-init-error.sh.templ', // Template for common shell if error
511
+ algorithm: 'aes-256-cbc', // Encrypt type
512
+ passphrase: 'k2hr3_regpass' // Default passphrase
513
+ },
514
+ extdata: { // Additional extra data
515
+ /*
516
+ * // [NOTE]
517
+ * // This Extra data is the data unique to the user who performs
518
+ * // the same operation as User data.
519
+ * // The data is encrypted and compressed.
520
+ * // The encryption uses the algorithm and passphrase specified
521
+ * // in userdata.
522
+ *
523
+ dummy: { // Extra data API(key=suburi) for trove k2hdkc
524
+ baseuri: 'https://localhost', // URI
525
+ template: 'config/extdata-dummy.sh.templ', // Template for Shell part
526
+ useragent: 'dummy-client' // Allowed user-agent(can be omitted: default is allowed all)
527
+ contenttype: 'text/x-shellscript; charset="us-ascii"'// Response Content-Type(can be omitted: default is 'text/plain')
528
+ }
529
+ */
530
+ },
531
+ k2hr3admin: {
532
+ tenant: 'admintenant', // Admin tenant name
533
+ delhostrole: 'delhostrole' // Admin Role name
534
+ },
535
+ localtenants: true, // Whether to allow K2HR3 cluster local tenants
536
+ confirmtenant: false, // Whichever confirm tenant when adding service member
537
+ chkipconfig: {
538
+ type: exports.chkipconfigType.CHECKER_TYPE_LISTENER, // Listener / Function / Basic{Or|And} / NoCheck
539
+ funcmod: null, // Module name(path) for Function type
540
+ pendingsec: 864000, // Limit for removing IP which is not alive : 10 * 24 * 60 * 60 = 10 days
541
+ intervalms: 4320000, // Interval ms for checking IP address : 12 * 60 * 60 * 1000 = 12 hour
542
+ parallelcnt: 32, // Parallel processing count
543
+ command4: 'ping', // Basic IP address check use this command for IPv4 : ping command
544
+ command6: 'ping6', // Basic IP address check use this command for IPv6
545
+ params: '-c 1', // Common ping command parameters
546
+ timeoutparam: '-W', // Timeout parameter name for ping command
547
+ timeoutms: 5000 // Timeout millisecond for each checking : 5000ms
548
+ },
549
+ allowcredauth: true, // allow CORS access for authorization by credential
550
+ expiration: {
551
+ roletoken: 86400, // Expire time(sec) for RoleToken : 24 * 60 * 60 = 1 day
552
+ regroletoken: 315360000 // Expire time(sec) for register host : 10 * 356 * 24 * 60 * 60 = 10 years(no expire)
553
+ }
554
+ };
555
+ // Set(overwrite) from loaded config
556
+ const mergeConfig = setLoadedConfig(data, k2hr3Config);
557
+ if (null !== mergeConfig) {
558
+ data = mergeConfig;
559
+ }
560
+ else {
561
+ console.warn('Failed loading configuration file. Please check config file.');
562
+ }
563
+ return data;
564
+ })();
565
+ //---------------------------------------------------------
566
+ // Configuration Class
567
+ //---------------------------------------------------------
568
+ class r3ApiConfig {
569
+ loadedConfig;
570
+ consolelog;
571
+ //
572
+ // Constructor
573
+ //
574
+ constructor() {
575
+ this.loadedConfig = exports.loadedConfig;
576
+ this.consolelog = null;
577
+ }
578
+ //
579
+ // Methods
580
+ //
581
+ getKeystoneConfig = () => {
582
+ return this.loadedConfig.keystone;
583
+ };
584
+ getKeystoneType = () => {
585
+ return this.loadedConfig.keystone.type;
586
+ };
587
+ getKeystoneEpType = () => {
588
+ return this.loadedConfig.keystone.eptype;
589
+ };
590
+ isKeystoneEpList = () => {
591
+ return k2hr3apiutil_1.default.compareCaseString('list', this.loadedConfig.keystone.eptype);
592
+ };
593
+ getKeystoneEpList = () => {
594
+ if (!k2hr3apiutil_1.default.compareCaseString('list', this.loadedConfig.keystone.eptype)) {
595
+ return null;
596
+ }
597
+ return this.loadedConfig.keystone.eplist ?? null;
598
+ };
599
+ isKeystoneEpFile = () => {
600
+ return k2hr3apiutil_1.default.compareCaseString('file', this.loadedConfig.keystone.eptype);
601
+ };
602
+ getKeystoneEpFile = () => {
603
+ if (!k2hr3apiutil_1.default.compareCaseString('file', this.loadedConfig.keystone.eptype)) {
604
+ return null;
605
+ }
606
+ return this.loadedConfig.keystone.epfile;
607
+ };
608
+ getK2hdkcConfig = () => {
609
+ return this.loadedConfig.k2hdkc.config;
610
+ };
611
+ getK2hdkcPort = () => {
612
+ return this.loadedConfig.k2hdkc.port;
613
+ };
614
+ getK2hdkcCuk = () => {
615
+ return this.loadedConfig.k2hdkc.cuk;
616
+ };
617
+ getCORSIPs = () => {
618
+ return this.loadedConfig.corsips;
619
+ };
620
+ isMultiProc = () => {
621
+ return this.loadedConfig.multiproc;
622
+ };
623
+ getScheme = () => {
624
+ return this.loadedConfig.scheme;
625
+ };
626
+ getPort = () => {
627
+ return this.loadedConfig.port;
628
+ };
629
+ getRunUser = () => {
630
+ return this.loadedConfig.runuser;
631
+ };
632
+ getPrivateKey = () => {
633
+ return this.loadedConfig.privatekey;
634
+ };
635
+ getCert = () => {
636
+ return this.loadedConfig.cert;
637
+ };
638
+ getCA = () => {
639
+ return this.loadedConfig.ca;
640
+ };
641
+ updateLogDir = (basepath) => {
642
+ let dirpath = null;
643
+ if (null !== this.loadedConfig.logdir) {
644
+ if (0 === this.loadedConfig.logdir.indexOf('/')) {
645
+ dirpath = path.join(this.loadedConfig.logdir); // logdir is full path
646
+ }
647
+ else {
648
+ if (null !== basepath && k2hr3apiutil_1.default.isSafeString(basepath)) {
649
+ if (null !== basepath && 0 === basepath.indexOf('/')) {
650
+ dirpath = path.join(basepath, this.loadedConfig.logdir);
651
+ }
652
+ else {
653
+ dirpath = path.join(__dirname, '../..', basepath, this.loadedConfig.logdir); // from top directory
654
+ }
655
+ }
656
+ else {
657
+ dirpath = path.join(__dirname, '../..', this.loadedConfig.logdir); // from top directory
658
+ }
659
+ }
660
+ }
661
+ else {
662
+ // logdir is null, it means not putting log to file.
663
+ }
664
+ // update log directory
665
+ this.loadedConfig.fixedlogdir = dirpath;
666
+ if (k2hr3apiutil_1.default.isSafeString(dirpath)) {
667
+ // check log directory and make it if not exists
668
+ if (null !== dirpath && !k2hr3apiutil_1.default.checkMakeDir(dirpath)) {
669
+ console.warn('Log directory(' + dirpath + ') is not existed, and could not create it.');
670
+ dirpath = null; // continue with no log directory
671
+ }
672
+ else {
673
+ // set dir path to log rotation option
674
+ this.loadedConfig.logrotateopt['path'] = dirpath;
675
+ }
676
+ }
677
+ return dirpath;
678
+ };
679
+ getAccessLogName = () => {
680
+ return this.loadedConfig.accesslogname;
681
+ };
682
+ getAccessLogFormat = () => {
683
+ return this.loadedConfig.accesslogform;
684
+ };
685
+ getConsoleLogName = () => {
686
+ return this.loadedConfig.consolelogname;
687
+ };
688
+ getWatcherLogName = () => {
689
+ return this.loadedConfig.watcherlogname;
690
+ };
691
+ getWatcherTimeFormat = () => {
692
+ return this.loadedConfig.watchertimeform;
693
+ };
694
+ getWatcherConsoleLogName = () => {
695
+ return this.loadedConfig.wconsolelogname;
696
+ };
697
+ getLogRotateOption = () => {
698
+ return this.loadedConfig.logrotateopt;
699
+ };
700
+ getRotateLogStream = (basedir, filename) => {
701
+ let logstream = null;
702
+ const logdir = this.updateLogDir(basedir);
703
+ if (null == logdir) {
704
+ return logstream;
705
+ }
706
+ if (null === filename || !k2hr3apiutil_1.default.isSafeString(filename)) {
707
+ return logstream;
708
+ }
709
+ try {
710
+ const rawopt = { ...this.loadedConfig.logrotateopt };
711
+ const opt = {
712
+ ...rawopt,
713
+ path: rawopt.path ?? undefined,
714
+ // 'true' -> true(boolean)
715
+ // 'false' -> false(boolean)
716
+ // 'gzip' -> 'gzip'(string)
717
+ // other -> false(boolean)
718
+ compress: ('true' === rawopt.compress ? true : 'false' === rawopt.compress ? false : 'gzip' === rawopt.compress ? 'gzip' : false),
719
+ interval: toIntervalNumber(rawopt.interval ?? '1d')
720
+ };
721
+ logstream = rotatefs.createStream(filename, opt);
722
+ }
723
+ catch (error) {
724
+ let msg;
725
+ if (error instanceof Error) {
726
+ msg = k2hr3apiutil_1.default.getSafeString(error.message);
727
+ }
728
+ else {
729
+ msg = String(error);
730
+ }
731
+ console.warn('Could not create log rotate option by : ' + JSON.stringify(msg));
732
+ logstream = null;
733
+ }
734
+ return logstream;
735
+ };
736
+ getMorganLoggerOption = (basedir) => {
737
+ let loggeropt = null;
738
+ const logstream = this.getRotateLogStream(basedir, this.loadedConfig.accesslogname);
739
+ if (null !== logstream) {
740
+ loggeropt = {
741
+ stream: logstream
742
+ };
743
+ }
744
+ return loggeropt;
745
+ };
746
+ getWatcherLoggingStream = (basedir) => {
747
+ let logstream = this.getRotateLogStream(basedir, this.loadedConfig.watcherlogname);
748
+ if (null == logstream) {
749
+ // [NOTE]
750
+ // Default stream is stdout
751
+ //
752
+ logstream = process.stdout;
753
+ }
754
+ return logstream;
755
+ };
756
+ setConsoleLogging = (basedir, is_watcher) => {
757
+ let logname = this.loadedConfig.consolelogname;
758
+ if (k2hr3apiutil_1.default.isBoolean(is_watcher) && is_watcher) {
759
+ logname = this.loadedConfig.wconsolelogname;
760
+ }
761
+ const logstream = this.getRotateLogStream(basedir, logname);
762
+ if (null !== logstream) {
763
+ this.consolelog = new console.Console(logstream, logstream);
764
+ global.console.error = this.consolelog.error;
765
+ global.console.warn = this.consolelog.warn;
766
+ global.console.log = this.consolelog.log;
767
+ global.console.debug = this.consolelog.debug;
768
+ global.console.info = this.consolelog.info;
769
+ }
770
+ return true;
771
+ };
772
+ getUserdataConfig = () => {
773
+ return this.loadedConfig.userdata;
774
+ };
775
+ getUserdataCryptConfig = () => {
776
+ const udCryptConfig = {
777
+ algorithm: this.loadedConfig.userdata.algorithm,
778
+ passphrase: this.loadedConfig.userdata.passphrase,
779
+ };
780
+ return udCryptConfig;
781
+ };
782
+ getExtdataConfigCount = () => {
783
+ return Object.keys(this.loadedConfig.extdata).length;
784
+ };
785
+ getAllExtdataConfig = () => {
786
+ return this.loadedConfig.extdata;
787
+ };
788
+ getK2hr3AdminConfig = () => {
789
+ return this.loadedConfig.k2hr3admin;
790
+ };
791
+ isLocalTenants = () => {
792
+ return this.loadedConfig.localtenants;
793
+ };
794
+ isConfirmTenantForService = () => {
795
+ return this.loadedConfig.confirmtenant;
796
+ };
797
+ getCheckIPConfig = () => {
798
+ return this.loadedConfig.chkipconfig;
799
+ };
800
+ isAllowedCredentialAccess = () => {
801
+ return this.loadedConfig.allowcredauth;
802
+ };
803
+ getExpireTimeRoleToken = () => {
804
+ return this.loadedConfig.expiration.roletoken;
805
+ };
806
+ getExpireTimeRegRoleToken = () => {
807
+ return this.loadedConfig.expiration.regroletoken;
808
+ };
809
+ getOtherObject = (key) => {
810
+ if (!k2hr3apiutil_1.default.isSafeString(key)) {
811
+ return null;
812
+ }
813
+ if (!k2hr3apiutil_1.default.isSafeEntity(this.loadedConfig[key])) {
814
+ return null;
815
+ }
816
+ return this.loadedConfig[key];
817
+ };
818
+ }
819
+ exports.r3ApiConfig = r3ApiConfig;
820
+ ;
821
+ //---------------------------------------------------------
822
+ // Exports
823
+ //---------------------------------------------------------
824
+ exports.chkipType = exports.chkipconfigType;
825
+ /*
826
+ * Local variables:
827
+ * tab-width: 4
828
+ * c-basic-offset: 4
829
+ * End:
830
+ * vim600: noexpandtab sw=4 ts=4 fdm=marker
831
+ * vim<600: noexpandtab sw=4 ts=4
832
+ */