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,198 +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 May 13 2020
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
- // load userdata templates from config directory
34
- //---------------------------------------------------------
35
- var LoadedExtdataObjs = (function()
36
- {
37
- var extdataobjs = {
38
- configs: {},
39
- cryptconfig: null,
40
- kw_role_name: /{{= %K2HR3_ROLE_NAME% }}/g, // Role YRN full path
41
- kw_role_tenant: /{{= %K2HR3_ROLE_TENANT% }}/g, // Tenant YRN full path
42
- kw_role_token: /{{= %K2HR3_ROLE_TOKEN% }}/g, // Role Token
43
- kw_api_uri: /{{= %K2HR3_API_HOST_URI% }}/g, // K2HR3 API server URI(ex. https://localhost:3000)
44
- kw_err_msg: /{{= %K2HR3_ERROR_MSG% }}/g // Error message string when something error occured
45
- };
46
-
47
- if(0 < apiConf.getExtdataConfigCount()){
48
- extdataobjs.configs = apiConf.getAllExtdataConfig();
49
- Object.keys(extdataobjs.configs).forEach(function(key){
50
- extdataobjs.configs[key].contents = apiutil.readFileContents(extdataobjs.configs[key].template);
51
- });
52
- }
53
- extdataobjs.cryptconfig = apiConf.getUserdataCryptConfig();
54
-
55
- return extdataobjs;
56
- }());
57
-
58
- //---------------------------------------------------------
59
- // Userdata Processing Class
60
- //---------------------------------------------------------
61
- var ExtdataProcess = (function()
62
- {
63
- //
64
- // Constructor
65
- //
66
- var ExtdataProcess = function()
67
- {
68
- this._extdataObjs = LoadedExtdataObjs;
69
- };
70
-
71
- var proto = ExtdataProcess.prototype;
72
-
73
- //
74
- // Methods
75
- //
76
- proto.checkSuburi = function(key)
77
- {
78
- if(!apiutil.isSafeString(key)){
79
- r3logger.elog('key parameter is empty.');
80
- return false;
81
- }
82
- return apiutil.isSafeEntity(this._extdataObjs.configs[key]);
83
- };
84
-
85
- proto.checkUserAgent = function(agent, key)
86
- {
87
- if(!apiutil.isSafeString(agent)){
88
- r3logger.elog('agent parameter is empty.');
89
- return false;
90
- }
91
- if(!apiutil.isSafeEntity(this._extdataObjs.configs[key])){
92
- r3logger.elog('unkown key(suburi): ' + JSON.stringify(key));
93
- return false;
94
- }
95
- if(!apiutil.isSafeString(this._extdataObjs.configs[key].useragent)){
96
- // allow any useragent
97
- return true;
98
- }
99
- return apiutil.compareCaseString(agent, this._extdataObjs.configs[key].useragent);
100
- };
101
-
102
- proto.getContentType = function(key)
103
- {
104
- if(!apiutil.isSafeEntity(this._extdataObjs.configs[key])){
105
- r3logger.elog('unkown key(suburi): ' + JSON.stringify(key));
106
- return null;
107
- }
108
- if(!apiutil.isSafeString(this._extdataObjs.configs[key].contenttype)){
109
- return 'text/plain';
110
- }
111
- return apiutil.getSafeString(this._extdataObjs.configs[key].contenttype);
112
- };
113
-
114
- // [NOTE]
115
- // For the encryption of Role information, the passphrase and the
116
- // algorithm set in userdata are used in common.
117
- // Therefore, Extdata-only encryption is not required, and the
118
- // composite uses the configuratino information of userdata.
119
- //
120
- proto.decryptRoleInfo = function(str)
121
- {
122
- if(!apiutil.isSafeString(str)){
123
- r3logger.elog('string parameter is empty.');
124
- return null;
125
- }
126
- return cryptutil.r3DecryptJSON(str, this._extdataObjs.cryptconfig.passphrase, this._extdataObjs.cryptconfig.algorithm);
127
- };
128
-
129
- proto.getExtdata = function(roleobj, key)
130
- {
131
- var rolename = '';
132
- var roletenant = '';
133
- var roletoken = '';
134
- var config = null;
135
- var errorMsg = null;
136
- if(!apiutil.isSafeEntity(roleobj)){
137
- r3logger.elog('role object(role name, role token) parameter is empty.');
138
- errorMsg = 'k2hr3 role information is wrong';
139
- }else if(!apiutil.isSafeString(roleobj.role)){
140
- r3logger.elog('role name parameter is empty.');
141
- errorMsg = 'k2hr3 role name is empty';
142
- }else if(!apiutil.isSafeString(roleobj.token)){
143
- r3logger.elog('role token parameter is empty.');
144
- errorMsg = 'k2hr3 role token is empty';
145
- }else{
146
- rolename = roleobj.role;
147
- roletoken = roleobj.token;
148
-
149
- // Extract tenant yrn full path from role yrn full path
150
- var keys = r3keys();
151
- var roleptn = new RegExp('^' + keys.MATCH_ANY_TENANT_ROLE); // regex = /^yrn:yahoo:(.*)::(.*):role:(.*)/
152
- var matches = rolename.match(roleptn);
153
- if(!apiutil.isEmptyArray(matches) && 4 <= matches.length && apiutil.isSafeString(matches[2])){
154
- roletenant = keys.NO_SERVICE_KEY + apiutil.getSafeString(matches[1]) + '::' + apiutil.getSafeString(matches[2]);
155
- }
156
- }
157
- if(apiutil.isSafeEntity(this._extdataObjs.configs[key])){
158
- config = this._extdataObjs.configs[key];
159
- }
160
-
161
- //-----------------
162
- // expands templates
163
- //-----------------
164
- var result = null;
165
- if(apiutil.isSafeString(config.contents)){
166
- result = config.contents.replace(this._extdataObjs.kw_role_name, rolename);
167
- result = result.replace(this._extdataObjs.kw_role_tenant, roletenant);
168
- result = result.replace(this._extdataObjs.kw_role_token, roletoken);
169
- result = result.replace(this._extdataObjs.kw_api_uri, config.baseuri);
170
- result = result.replace(this._extdataObjs.kw_err_msg, errorMsg);
171
- }
172
- return result;
173
- };
174
-
175
- proto.getGzipExtdata = function(roleobj, key)
176
- {
177
- // get expanded data
178
- var expanded = this.getExtdata(roleobj, key);
179
-
180
- return cryptutil.r3Gzip(expanded);
181
- };
182
-
183
- return ExtdataProcess;
184
- })();
185
-
186
- //---------------------------------------------------------
187
- // Exports
188
- //---------------------------------------------------------
189
- exports.extdataProcess = ExtdataProcess;
190
-
191
- /*
192
- * Local variables:
193
- * tab-width: 4
194
- * c-basic-offset: 4
195
- * End:
196
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
197
- * vim<600: noexpandtab sw=4 ts=4
198
- */
package/lib/k2hr3keys.js DELETED
@@ -1,234 +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 apiutil = require('./k2hr3apiutil');
24
-
25
- //---------------------------------------------------------
26
- // key path/value/keywords in k2hdkc
27
- //---------------------------------------------------------
28
- //
29
- // YRN Format
30
- //
31
- // yrn:<partition or domain>:<service>:<region>:<tenant or account id>:<type>{:<paths>}>
32
- //
33
- // arn : Tag for Yahoo Resource Name
34
- // partition or domain : Partition or Domain name(ex. "yahoo")
35
- // service : Service name(ex. "myservice")
36
- // region : Region name(ex. "west-east-region")
37
- // tenant or account id : Tenant name or Account id(ex, "1234" or "myname")
38
- // type : YRN type, "user", "token", "action", "keystone", "service", "role", "policy", "resource".
39
- // paths : Path(separator is "/") under YRN type
40
- //
41
- exports.getK2hr3Keys = function(user, tenant, service)
42
- {
43
- var keywords = {
44
- // common types
45
- 'TYPE_ROLE': 'role',
46
- 'TYPE_RESOURCE': 'resource',
47
- 'TYPE_POLICY': 'policy',
48
- 'TYPE_SERVICE': 'service', // Using in list API
49
-
50
- // common values
51
- 'VALUE_WILDCARD': '*',
52
- 'VALUE_TRUE': 'true',
53
- 'VALUE_FALSE': 'false',
54
- 'VALUE_ENABLE': 'enable',
55
- 'VALUE_DISABLE': 'disable',
56
- 'VALUE_ALLOW': 'allow',
57
- 'VALUE_DENY': 'deny',
58
- 'VALUE_READ': 'read',
59
- 'VALUE_WRITE': 'write',
60
- 'VALUE_ANY_PORT': '*',
61
- 'VALUE_HOST_SEP': ' ',
62
- 'VALUE_HOST_REGSEP': ':',
63
- 'VALUE_HOST_DETAILSEP': ',',
64
- 'VALUE_ANYDATA_TYPE': 'anytype',
65
- 'VALUE_STRING_TYPE': 'string',
66
- 'VALUE_OBJECT_TYPE': 'object',
67
- 'VALUE_KEYS_TYPE': 'keys',
68
- 'VALUE_ALIAS_TYPE': 'aliases',
69
- 'VALUE_EXPIRE_TYPE': 'expire',
70
- 'VALUE_POLICIES_TYPE': 'policies',
71
- 'VALUE_HOSTS_TYPE': 'hosts',
72
- 'VALUE_HOSTNAMES_TYPE': 'hostnames',
73
- 'VALUE_IPS_TYPE': 'ips',
74
- 'VALUE_KEYSTONE_NORMAL': 'kstype_normal',
75
- 'VALUE_KEYSTONE_NOPASS': 'kstype_nopasswd',
76
- 'VALUE_KEYSTONE_SUB': 'kstype_substitute',
77
- 'VALUE_OPENSTACK_V1': 'openstack-auto-v1', // used/set from k2hr3-init.sh
78
- 'VALUE_K8S_V1': 'k8s-auto-v1', // used/set from k2hr3-kube-init.sh
79
- 'VALUE_PREFIX_LOCAL_TENANT': 'local@',
80
-
81
- // common keywords( part of keyname )
82
- 'POLICIES_KW': 'policies',
83
- 'SERVICE_KW': 'service',
84
- 'HOSTS_KW': 'hosts',
85
- 'HOSTS_NAME_KW': 'name',
86
- 'HOSTS_IP_KW': 'ip',
87
- 'KEYS_KW': 'keys',
88
- 'TYPE_KW': 'type',
89
- 'EXPIRE_KW': 'expire',
90
- 'EFFECT_KW': 'effect',
91
- 'ACTION_KW': 'action',
92
- 'RESOURCE_KW': 'resource',
93
- 'CONDITION_KW': 'condition',
94
- 'REFERENCE_KW': 'reference',
95
- 'ID_KW': 'id',
96
- 'ALIAS_KW': '@',
97
- 'URL_KW': 'url',
98
- 'STATUS_KW': 'status',
99
- 'DATE_KW': 'date',
100
- 'SEED_KW': 'seed',
101
- 'ROLE_TOKEN_KW': 'tokens',
102
-
103
- // ACR keywords
104
- 'ACR_POLICY_KW': 'acr-policy',
105
- 'ACR_ROLE_KW': 'acr-role',
106
- 'ACR_RESOURCE_NAME_KEY': 'name',
107
- 'ACR_RESOURCE_EXPIRE_KEY': 'expire',
108
- 'ACR_RESOURCE_TYPE_KEY': 'type',
109
- 'ACR_RESOURCE_DATA_KEY': 'data',
110
- 'ACR_RESOURCE_KEYS_KEY': 'keys',
111
-
112
- // kubernetes cuk keywords
113
- 'K8S_NAMESPACE_INCUK_KEY': 'k8s_namespace',
114
- 'K8S_SA_INCUK_KEY': 'k8s_service_account',
115
- 'K8S_NODENAME_INCUK_KEY': 'k8s_node_name',
116
- 'K8S_NODEIP_INCUK_KEY': 'k8s_node_ip',
117
- 'K8S_PODNAME_INCUK_KEY': 'k8s_pod_name',
118
- 'K8S_PODID_INCUK_KEY': 'k8s_pod_id',
119
- 'K8S_PODIP_INCUK_KEY': 'k8s_pod_ip',
120
- 'K8S_CONTAINERID_INCUK_KEY': 'k8s_container_id',
121
- 'K8S_RAND_INCUK_KEY': 'k8s_k2hr3_rand',
122
-
123
- // common key names
124
- 'YRN_KEY': 'yrn',
125
- 'DOMAIN_KEY': 'yrn:yahoo',
126
- 'NO_SERVICE_KEY': 'yrn:yahoo:',
127
- 'NO_SERVICE_REGION_KEY': 'yrn:yahoo::',
128
- 'NO_SERVICE_TENANT_KEY': 'yrn:yahoo:::',
129
- 'USER_TOP_KEY': 'yrn:yahoo::::user',
130
- 'TOKEN_TOP_KEY': 'yrn:yahoo::::token',
131
- 'TOKEN_USER_TOP_KEY': 'yrn:yahoo::::token:user',
132
- 'TOKEN_ROLE_TOP_KEY': 'yrn:yahoo::::token:role',
133
- 'ACTION_TOP_KEY': 'yrn:yahoo::::action',
134
- 'ACTION_READ_KEY': 'yrn:yahoo::::action:read',
135
- 'ACTION_WRITE_KEY': 'yrn:yahoo::::action:write',
136
- 'KEYSTONE_TOP_KEY': 'yrn:yahoo::::keystone',
137
- 'IAAS_TOP_KEY': 'yrn:yahoo::::iaas',
138
- 'IAAS_OS_TOP_KEY': 'yrn:yahoo::::iaas:openstack',
139
- 'IAAS_K8S_TOP_KEY': 'yrn:yahoo::::iaas:k8s',
140
- 'MASTER_SERVICE_TOP_KEY': 'yrn:yahoo::::service',
141
- 'ANYTENANT_SERVICE_TOP_KEY': 'yrn:yahoo::::service:',
142
- 'ANYTENANT_SERVICE_KEY': 'yrn:yahoo::::service::anytenant',
143
-
144
- // match regex
145
- 'MATCH_ANY_SERVICE_MASTER': 'yrn:yahoo::::service:(.*)',
146
- 'MATCH_ANY_IAAS': 'yrn:yahoo::::iaas:(.*)',
147
- 'MATCH_ANY_IAAS_OS': 'yrn:yahoo::::iaas:openstack:(.*)',
148
- 'MATCH_ANY_IAAS_K8S': 'yrn:yahoo::::iaas:k8s:(.*)',
149
- 'MATCH_ANY_SERVICE_TENANT': 'yrn:yahoo:(.*)::(.*):(.*)',
150
- 'MATCH_ANY_TENANT_MAIN': 'yrn:yahoo:(.*)::(.*)',
151
- 'MATCH_ANY_TENANT_ROLE': 'yrn:yahoo:(.*)::(.*):role:(.*)',
152
- 'MATCH_ANY_TENANT_POLICY': 'yrn:yahoo:(.*)::(.*):policy:(.*)',
153
- 'MATCH_ANY_TENANT_RESOURCE': 'yrn:yahoo:(.*)::(.*):resource:(.*)',
154
- 'MATCH_ANY_TENANT_RES_DATA': 'yrn:yahoo:(.*)::(.*):resource:(.*)', // end of resource name
155
- 'MATCH_NOT_TENANT_RES_DATA': '( |\t|\r|\n|:)', // not match resource data key name
156
- 'MATCH_ANY_TENANT_RES_KEY': 'yrn:yahoo:(.*)::(.*):resource:(.*)/keys/(.*)', // end of resource name/keys/<keyname>
157
- 'MATCH_ANY_HOSTNAME_PORT': 'yrn:yahoo:(.*)::(.*):role:(.*)/hosts/name/(.*) (.*) (.*)',
158
- 'MATCH_ANY_HOSTNAME_KEYS': 'yrn:yahoo:(.*)::(.*):role:(.*)/hosts/name',
159
- 'MATCH_ANY_IP_PORT': 'yrn:yahoo:(.*)::(.*):role:(.*)/hosts/ip/(.*) (.*) (.*)',
160
- 'MATCH_ANY_IP_KEYS': 'yrn:yahoo:(.*)::(.*):role:(.*)/hosts/ip',
161
- 'MATCH_ANY_ALLHOST_KEYS': 'yrn:yahoo:(.*)::(.*):role:(.*)/hosts/all', // This is only used in template variable names, not key name
162
- 'MATCH_ANY_KS_REGION': 'yrn:yahoo::::keystone:(.*)',
163
- 'MATCH_ANY_USER_TOKEN': 'yrn:yahoo::::user:(.*):tenant/(.*)/token/(.*)',
164
- 'MATCH_ANY_ROLE_TOKEN': 'yrn:yahoo::::token:role/(.*)',
165
- 'MATCH_URI_GET_ROLE_DATA': '^/v1/role/(.*)',
166
- 'MATCH_URI_GET_RTOKEN': '^/v1/role/token/(.*)',
167
- 'MATCH_URI_GET_RTOKEN_LIST': '^/v1/role/token/list/(.*)'
168
- };
169
-
170
- var _user = apiutil.getSafeString(user).toLowerCase();
171
- var _tenant = apiutil.getSafeString(tenant).toLowerCase();
172
- var _service= apiutil.getSafeString(service).toLowerCase();
173
-
174
- keywords.SERVICE_TOP_KEY = keywords.NO_SERVICE_KEY + _service; // "yrn:yahoo:<service>"
175
- keywords.SERVICE_NO_REGION_KEY = keywords.SERVICE_TOP_KEY + ':'; // "yrn:yahoo:<service>:"
176
- if(apiutil.isSafeString(_service)){
177
- keywords.MASTER_SERVICE_KEY = keywords.MASTER_SERVICE_TOP_KEY + ':' + _service; // "yrn:yahoo::::service:<service>"
178
- keywords.SERVICE_OWNER_KEY = keywords.MASTER_SERVICE_KEY + ':owner'; // "yrn:yahoo::::service:<service>:owner"
179
- keywords.SERVICE_TENANT_KEY = keywords.MASTER_SERVICE_KEY + ':tenant'; // "yrn:yahoo::::service:<service>:tenant"
180
- keywords.SERVICE_VERIFY_TENANT_KEY = keywords.MASTER_SERVICE_KEY + ':verify'; // "yrn:yahoo::::service:<service>:verify"
181
- }
182
-
183
- if(apiutil.isSafeString(_tenant)){
184
- // tenant key with service(allowed null)
185
- keywords.TENANT_TOP_KEY = keywords.SERVICE_NO_REGION_KEY + ':' + _tenant; // "yrn:yahoo:<service>::<tenant>"
186
-
187
- // tenant master key(service is null)
188
- keywords.MASTER_TENANT_TOP_KEY = keywords.NO_SERVICE_REGION_KEY + ':' + _tenant; // "yrn:yahoo:::<tenant>"
189
-
190
- // tenant description keys(service is null)
191
- keywords.TENANT_ID_KEY = keywords.MASTER_TENANT_TOP_KEY + ':id'; // "yrn:yahoo:::<tenant>:id"
192
- keywords.TENANT_DESC_KEY = keywords.MASTER_TENANT_TOP_KEY + ':desc'; // "yrn:yahoo:::<tenant>:desc"
193
- keywords.TENANT_DISP_KEY = keywords.MASTER_TENANT_TOP_KEY + ':display'; // "yrn:yahoo:::<tenant>:display"
194
- keywords.TENANT_USER_KEY = keywords.MASTER_TENANT_TOP_KEY + ':user'; // "yrn:yahoo:::<tenant>:user"
195
- keywords.TENANT_SERVICE_KEY = keywords.MASTER_TENANT_TOP_KEY + ':service'; // "yrn:yahoo:::<tenant>:service"
196
-
197
- // role, resource, policy under tenant with service
198
- keywords.ROLE_TOP_KEY = keywords.TENANT_TOP_KEY + ':' + 'role'; // "yrn:yahoo:<service>::<tenant>:role"
199
- keywords.POLICY_TOP_KEY = keywords.TENANT_TOP_KEY + ':' + 'policy'; // "yrn:yahoo:<service>::<tenant>:policy"
200
- keywords.RESOURCE_TOP_KEY = keywords.TENANT_TOP_KEY + ':' + 'resource'; // "yrn:yahoo:<service>::<tenant>:resource"
201
- }
202
-
203
- if(apiutil.isSafeString(_user)){
204
- keywords.USER_KEY = keywords.USER_TOP_KEY + ':' + _user; // "yrn:yahoo::::user:<user>"
205
- keywords.USER_ID_KEY = keywords.USER_KEY + ':id'; // "yrn:yahoo::::user:<user>:id"
206
- keywords.USER_TENANT_TOP_KEY = keywords.USER_KEY + ':tenant'; // "yrn:yahoo::::user:<user>:tenant"
207
- keywords.USER_TENANT_COMMON_KEY = keywords.USER_TENANT_TOP_KEY + '/'; // "yrn:yahoo::::user:<user>:tenant/"
208
- keywords.USER_TENANT_UNSCOPE_TOKEN_KEY = keywords.USER_TENANT_COMMON_KEY + '/token'; // "yrn:yahoo::::user:<user>:tenant//token"
209
-
210
- if(apiutil.isSafeString(tenant)){
211
- keywords.USER_TENANT_KEY = keywords.USER_TENANT_COMMON_KEY + _tenant; // "yrn:yahoo::::user:<user>:tenant/<tenant>"
212
- keywords.USER_TENANT_SCOPE_TOKEN_KEY = keywords.USER_TENANT_KEY + '/token'; // "yrn:yahoo::::user:<user>:tenant/<tenant>/token"
213
- // ambiguous key whether tenant exists or not
214
- keywords.USER_TENANT_AMBIGUOUS_KEY = keywords.USER_TENANT_KEY; // "yrn:yahoo::::user:<user>:tenant/<tenant>"
215
- keywords.USER_TENANT_AMBIGUOUS_TOKEN_KEY= keywords.USER_TENANT_SCOPE_TOKEN_KEY; // "yrn:yahoo::::user:<user>:tenant/<tenant>/token"
216
- }else{
217
- keywords.USER_TENANT_KEY = ''; // ""
218
- keywords.USER_TENANT_SCOPE_TOKEN_KEY = ''; // ""
219
- // ambiguous key whether tenant exists or not
220
- keywords.USER_TENANT_AMBIGUOUS_KEY = keywords.USER_TENANT_COMMON_KEY; // "yrn:yahoo::::user:<user>:tenant/"
221
- keywords.USER_TENANT_AMBIGUOUS_TOKEN_KEY= keywords.USER_TENANT_UNSCOPE_TOKEN_KEY; // "yrn:yahoo::::user:<user>:tenant//token"
222
- }
223
- }
224
- return keywords;
225
- };
226
-
227
- /*
228
- * Local variables:
229
- * tab-width: 4
230
- * c-basic-offset: 4
231
- * End:
232
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
233
- * vim<600: noexpandtab sw=4 ts=4
234
- */
@@ -1,100 +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: Fri Sep 8 2017
17
- * REVISION:
18
- *
19
- */
20
-
21
- 'use strict';
22
-
23
- var apiutil = require('./k2hr3apiutil');
24
-
25
- function rawSendErrorResponse(req, res, status, msgbody, strType)
26
- {
27
- if(!apiutil.isSafeEntity(res) || !apiutil.isSafeEntity(status) || isNaN(status)){
28
- if(!apiutil.isSafeEntity(res)){
29
- // can do nothing
30
- return false;
31
- }
32
- status = 500; // 500: Internal Error
33
- msgbody = 'Wrong parameters are got.';
34
- }
35
-
36
- // set response type
37
- if(apiutil.isSafeString(strType)){
38
- res.type(strType);
39
- }
40
-
41
- // set response status
42
- res.status(status);
43
-
44
- // body message to JSON
45
- var jsonbody;
46
- if(apiutil.isSafeEntity(msgbody)){
47
- if(!apiutil.checkSimpleJSON(msgbody)){
48
- jsonbody = JSON.stringify(msgbody);
49
- }else{
50
- jsonbody = msgbody;
51
- }
52
- }
53
-
54
- // set 'x-k2hr3-error' header
55
- if( apiutil.isSafeEntity(req) &&
56
- apiutil.isSafeEntity(req.headers) &&
57
- apiutil.isSafeEntity(req.headers['x-k2hr3-debug']) &&
58
- ( apiutil.compareCaseString('ON', req.headers['x-k2hr3-debug']) ||
59
- apiutil.compareCaseString('OK', req.headers['x-k2hr3-debug']) ||
60
- apiutil.compareCaseString('debug', req.headers['x-k2hr3-debug']) ||
61
- apiutil.compareCaseString('dbg', req.headers['x-k2hr3-debug']) ||
62
- apiutil.compareCaseString('1', String(req.headers['x-k2hr3-debug']))
63
- )
64
- ){
65
- var errheader;
66
- if(apiutil.isSafeString(jsonbody)){
67
- errheader = jsonbody;
68
- }else{
69
- errheader = JSON.stringify({ status: status });
70
- }
71
- res.header('x-k2hr3-error', errheader);
72
- }
73
-
74
- // send body
75
- res.send(jsonbody);
76
-
77
- return true;
78
- }
79
-
80
- //
81
- // <argument> <default> <note>
82
- // req request object
83
- // res response object
84
- // status status code for error, must be number
85
- // msgbody null response error body if need
86
- // strType null response type if need
87
- //
88
- exports.errResponse = function(req, res, status, msgbody, strType)
89
- {
90
- return rawSendErrorResponse(req, res, status, msgbody, strType);
91
- };
92
-
93
- /*
94
- * Local variables:
95
- * tab-width: 4
96
- * c-basic-offset: 4
97
- * End:
98
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
99
- * vim<600: noexpandtab sw=4 ts=4
100
- */