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