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,312 +0,0 @@
1
- /*
2
- * K2HR3 REST API
3
- *
4
- * Copyright 2018 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 2 2018
17
- * REVISION:
18
- *
19
- */
20
-
21
- 'use strict';
22
-
23
- var apiutil = require('./k2hr3apiutil');
24
- var cryptutil = require('./k2hr3cryptutil');
25
- var r3Conf = require('./k2hr3config').r3ApiConfig;
26
- var r3keys = require('./k2hr3keys').getK2hr3Keys;
27
- var apiConf = new r3Conf();
28
-
29
- // Debug logging objects
30
- var r3logger = require('./dbglogging');
31
-
32
- //---------------------------------------------------------
33
- // Empty script for error
34
- //---------------------------------------------------------
35
- var EmptyScriptContents = [
36
- '#!/bin/sh',
37
- '#',
38
- '# K2HR3 Frontend Web Application',
39
- '#',
40
- '# Copyright(C) 2018 Yahoo Japan Corporation.',
41
- '#',
42
- '# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers',
43
- '# common management information for the cloud.',
44
- '# K2HR3 can dynamically manage information as "who", "what", "operate".',
45
- '# These are stored as roles, resources, policies in K2hdkc, and the',
46
- '# client system can dynamically read and modify these information.',
47
- '#',
48
- '# For the full copyright and license information, please view',
49
- '# the license file that was distributed with this source code.',
50
- '#',
51
- '# AUTHOR: Takeshi Nakatani',
52
- '# CREATE: Tue Oct 2 2018',
53
- '# REVISION:',
54
- '#',
55
- '',
56
- 'SCRIPTNAME="k2hr3-init"',
57
- 'LOGFILE="/var/log/${SCRIPTNAME}.log"',
58
- '',
59
- 'echo "`date "+%Y-%m-%d %H:%M:%S,%3N"` - ${SCRIPTNAME}[ERROR]: Invalid userdata for creating k2hr3-init script was specified(detail error = {{= %K2HR3_ERROR_MSG% }})" | tee -a ${LOGFILE}',
60
- 'exit 1',
61
- '',
62
- '#',
63
- '# VIM modelines',
64
- '#',
65
- '# vim:set ts=4 fenc=utf-8:',
66
- '#'
67
- ].join('\n');
68
-
69
- //---------------------------------------------------------
70
- // load userdata templates from config directory
71
- //---------------------------------------------------------
72
- var LoadedUserdataTemplates = (function()
73
- {
74
- var templates = {
75
- cloud_config: null,
76
- init_script: null,
77
- init_err_script: null,
78
- kw_role_name: /{{= %K2HR3_ROLE_NAME% }}/g, // Role YRN full path
79
- kw_role_tenant: /{{= %K2HR3_ROLE_TENANT% }}/g, // Tenant YRN full path
80
- kw_role_token: /{{= %K2HR3_ROLE_TOKEN% }}/g, // Role Token
81
- kw_api_uri: /{{= %K2HR3_API_HOST_URI% }}/g, // K2HR3 API server URI(ex. https://localhost:3000)
82
- kw_err_msg: /{{= %K2HR3_ERROR_MSG% }}/g // Error message string when something error occured
83
- };
84
-
85
- var userdatacfgobj = apiConf.getUserdataConfig();
86
-
87
- if(apiutil.isSafeEntity(userdatacfgobj)){
88
- templates.baseuri = apiutil.getSafeString(userdatacfgobj.baseuri);
89
- templates.algorithm = apiutil.getSafeString(userdatacfgobj.algorithm);
90
- templates.passphrase = apiutil.getSafeString(userdatacfgobj.passphrase);
91
- templates.cloud_config = apiutil.readFileContents(userdatacfgobj.cc_templ);
92
- templates.init_script = apiutil.readFileContents(userdatacfgobj.script_templ);
93
- templates.init_err_script = apiutil.readFileContents(userdatacfgobj.errscript_templ);
94
- }else{
95
- templates.baseuri = '';
96
- templates.algorithm = '';
97
- templates.passphrase = '';
98
- templates.cloud_config = null;
99
- templates.init_script = null;
100
- templates.init_err_script = null;
101
- }
102
- templates.default_script = EmptyScriptContents;
103
-
104
- return templates;
105
- }());
106
-
107
- //---------------------------------------------------------
108
- // Userdata Processing Class
109
- //---------------------------------------------------------
110
- var UserdataProcess = (function()
111
- {
112
- //
113
- // Constructor
114
- //
115
- var UserdataProcess = function()
116
- {
117
- this._userdataTemplates = LoadedUserdataTemplates;
118
- };
119
-
120
- var proto = UserdataProcess.prototype;
121
-
122
- //
123
- // Methods
124
- //
125
- proto.encryptRoleInfo = function(obj)
126
- {
127
- if(!apiutil.isSafeEntity(obj)){
128
- r3logger.elog('role information object parameter is empty.');
129
- return null;
130
- }
131
- return cryptutil.r3EncryptJSON(obj, this._userdataTemplates.passphrase, this._userdataTemplates.algorithm);
132
- };
133
-
134
- proto.decryptRoleInfo = function(str)
135
- {
136
- if(!apiutil.isSafeString(str)){
137
- r3logger.elog('string parameter is empty.');
138
- return null;
139
- }
140
- return cryptutil.r3DecryptJSON(str, this._userdataTemplates.passphrase, this._userdataTemplates.algorithm);
141
- };
142
-
143
- proto.getMultipartUserdata = function(roleobj, errorMsg)
144
- {
145
- var rolename = '';
146
- var roletenant = '';
147
- var roletoken = '';
148
- if(!apiutil.isSafeString(errorMsg)){
149
- errorMsg = null;
150
- }
151
- if(!apiutil.isSafeEntity(roleobj)){
152
- r3logger.elog('role object(role name, role token) parameter is empty.');
153
- if(!errorMsg){
154
- errorMsg = 'k2hr3 role information is wrong';
155
- }
156
- }else if(!apiutil.isSafeString(roleobj.role)){
157
- r3logger.elog('role name parameter is empty.');
158
- if(!errorMsg){
159
- errorMsg = 'k2hr3 role name is empty';
160
- }
161
- }else if(!apiutil.isSafeString(roleobj.token)){
162
- r3logger.elog('role token parameter is empty.');
163
- if(!errorMsg){
164
- errorMsg = 'k2hr3 role token is empty';
165
- }
166
- }else{
167
- rolename = roleobj.role;
168
- roletoken = roleobj.token;
169
- // Extract tenant yrn full path from role yrn full path
170
- var keys = r3keys();
171
- var roleptn = new RegExp('^' + keys.MATCH_ANY_TENANT_ROLE); // regex = /^yrn:yahoo:(.*)::(.*):role:(.*)/
172
- var matches = rolename.match(roleptn);
173
- if(!apiutil.isEmptyArray(matches) && 4 <= matches.length && apiutil.isSafeString(matches[2])){
174
- roletenant = keys.NO_SERVICE_KEY + apiutil.getSafeString(matches[1]) + '::' + apiutil.getSafeString(matches[2]);
175
- }
176
- }
177
-
178
- //-----------------
179
- // expands templates
180
- //-----------------
181
- var config = this._userdataTemplates.cloud_config; // cloud-config does not have keywords, then no-replacing.
182
- var script = null;
183
- var errscript = null;
184
- var defscript = this._userdataTemplates.default_script;
185
- if(this._userdataTemplates.init_script){
186
- script = this._userdataTemplates.init_script.replace(this._userdataTemplates.kw_role_name, rolename);
187
- script = script.replace(this._userdataTemplates.kw_role_tenant, roletenant);
188
- script = script.replace(this._userdataTemplates.kw_role_token, roletoken);
189
- script = script.replace(this._userdataTemplates.kw_api_uri, this._userdataTemplates.baseuri);
190
- if(errorMsg){
191
- // [NOTE]
192
- // Normally, you'll use a script for error, so this process will be wasted.
193
- // However, there are cases where this keyword is specified in the template,
194
- // so we will replace it.
195
- //
196
- script = script.replace(this._userdataTemplates.kw_err_msg, errorMsg);
197
- }else{
198
- script = script.replace(this._userdataTemplates.kw_err_msg, '');
199
- }
200
- }
201
- if(this._userdataTemplates.init_err_script){
202
- errscript = this._userdataTemplates.init_err_script.replace(this._userdataTemplates.kw_role_name, rolename);
203
- errscript = errscript.replace(this._userdataTemplates.kw_role_token, roletoken);
204
- errscript = script.replace(this._userdataTemplates.kw_role_tenant, roletenant);
205
- errscript = errscript.replace(this._userdataTemplates.kw_api_uri, this._userdataTemplates.baseuri);
206
- if(errorMsg){
207
- errscript = errscript.replace(this._userdataTemplates.kw_err_msg, errorMsg);
208
- }else{
209
- errscript = errscript.replace(this._userdataTemplates.kw_err_msg, '');
210
- }
211
- }
212
- if(!config && !script){
213
- r3logger.wlog('k2hr3-init and error script template is not specified.');
214
- if(!errorMsg){
215
- errorMsg = 'no script is set';
216
- }
217
- }
218
- if(errorMsg){
219
- defscript = defscript.replace(this._userdataTemplates.kw_err_msg, errorMsg);
220
- }
221
-
222
- //-----------------
223
- // make part type array
224
- //-----------------
225
- var parts = new Array(); // member object is {type: 'contents-type string', filename: 'filename', contents: '...'}
226
- if(errorMsg){
227
- if(!errscript){
228
- parts.push({type: 'text/x-shellscript', filename: 'k2hr3-init-empty.sh', contents: defscript});
229
- }else{
230
- parts.push({type: 'text/x-shellscript', filename: 'k2hr3-init-error.sh', contents: errscript});
231
- }
232
- }else if(config && script){
233
- parts.push({type: 'text/cloud-config', filename: 'k2hr3-cloud-config.txt', contents: config});
234
- parts.push({type: 'text/x-shellscript', filename: 'k2hr3-init.sh', contents: script});
235
- }else if(config && !script){
236
- parts.push({type: 'text/cloud-config', filename: 'k2hr3-cloud-config.txt', contents: config});
237
- }else if(!config && script){
238
- parts.push({type: 'text/x-shellscript', filename: 'k2hr3-init.sh', contents: script});
239
- }else{ // !config && !script
240
- parts.push({type: 'text/x-shellscript', filename: 'k2hr3-init-empty.sh', contents: defscript});
241
- }
242
-
243
- //-----------------
244
- // make multipart
245
- //-----------------
246
- var boundary = '================K2HR3INIT' + Date.now().toString() + '==';
247
- var result = {
248
- body: '',
249
- type: null,
250
- mimeverkey: 'MIME-Version',
251
- mimeverval: '1.0',
252
- partcntkey: 'Number-Attachments',
253
- partcntval: parts.length
254
- };
255
- result.body = '';
256
- result.type = 'multipart/mixed; boundary="' + boundary + '"';
257
-
258
- // fill parts
259
- for(var cnt = 0; cnt < parts.length; ++cnt){
260
- // part header
261
- result.body += '--' + boundary + '\r\n';
262
- result.body += 'MIME-Version: 1.0\r\n';
263
- result.body += 'Content-Type: ' + parts[cnt].type + '; charset="us-ascii"\r\n';
264
- result.body += 'Content-Transfer-Encoding: 7bit\r\n';
265
- result.body += 'Content-Disposition: attachment; filename="' + parts[cnt].filename + '"\r\n\r\n';
266
-
267
- // part contents
268
- result.body += parts[cnt].contents;
269
- result.body += '\r\n';
270
- }
271
-
272
- // make footer
273
- result.body += '--' + boundary + '--\r\n';
274
-
275
- return result;
276
- };
277
-
278
- proto.getGzipMultipartUserdata = function(roleobj, errorMsg, callback)
279
- {
280
- var _callback = null;
281
- if(apiutil.isSafeEntity(callback)){
282
- _callback = callback;
283
- }
284
- // get multipart headers and body
285
- var multipartobj= this.getMultipartUserdata(roleobj, errorMsg);
286
-
287
- // make one string
288
- var multipart = '';
289
- multipart += 'Content-Type: ' + multipartobj.type + '\r\n';
290
- multipart += multipartobj.mimeverkey + ': ' + multipartobj.mimeverval + '\r\n';
291
- multipart += multipartobj.partcntkey + ': ' + multipartobj.partcntval + '\r\n\r\n';
292
- multipart += multipartobj.body;
293
-
294
- return cryptutil.r3Gzip(multipart, _callback);
295
- };
296
-
297
- return UserdataProcess;
298
- })();
299
-
300
- //---------------------------------------------------------
301
- // Exports
302
- //---------------------------------------------------------
303
- exports.userdataProcess = UserdataProcess;
304
-
305
- /*
306
- * Local variables:
307
- * tab-width: 4
308
- * c-basic-offset: 4
309
- * End:
310
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
311
- * vim<600: noexpandtab sw=4 ts=4
312
- */