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,263 +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: Mon Nov 6 2017
17
- * REVISION:
18
- *
19
- */
20
-
21
- 'use strict';
22
-
23
- var express = require('express');
24
- var router = express.Router();
25
- var http = require('http');
26
- var https = require('https');
27
-
28
- var cacerts = require('../lib/cacerts');
29
- var r3token = require('../lib/k2hr3tokens');
30
- var apiutil = require('../lib/k2hr3apiutil');
31
- var resutil = require('../lib/k2hr3resutil');
32
-
33
- // Debug logging objects
34
- var r3logger = require('../lib/dbglogging');
35
-
36
- //
37
- // Debug Verify URL
38
- //
39
- // This router is for debugging verify url for dummy service.
40
- // This is called only on development environment.
41
- //
42
- // Mountpath : '/v1/debug/verify'
43
- //
44
- // GET '/v1/debug/verify' : get verify for debug on version 1
45
- // URL argument
46
- // service : service name(default testservice)
47
- // HEADER : X-Auth-Token => Scoped User token(without 'U=' prefix)
48
- // response body = [ : undefined/null or resource array(if one element, allows only it not array)
49
- // {
50
- // name : resource name which is key name(path) for resource
51
- // expire : undefined/null or integer
52
- // type : resource data type(string or object), if date is null or '', this value must be string.
53
- // data : resource data which must be string or object or null/undefined.
54
- // keys = { : resource has keys(associative array), or null/undefined.
55
- // 'foo': bar, : any value is allowed
56
- // ... :
57
- // } :
58
- // },
59
- // ]
60
- //
61
- router.get('/', function(req, res, next)
62
- {
63
- r3logger.dlog('CALL:', req.method, req.url);
64
-
65
- var _req = req;
66
- var _res = res;
67
- var _next = next;
68
- if('GET' !== _req.method){
69
- // HEAD request comes here, so it should be routed to head function.
70
- _next();
71
- return;
72
- }
73
- _res.type('application/json; charset=utf-8');
74
-
75
- //
76
- // Check request
77
- //
78
- if( !apiutil.isSafeEntity(_req) ||
79
- !apiutil.isSafeString(_req.baseUrl) ||
80
- !apiutil.isSafeString(_req.method) ||
81
- !apiutil.isSafeString(_req.protocol) ||
82
- !apiutil.isSafeEntity(_req.query) ||
83
- (!apiutil.isSafeString(_req.host) && !apiutil.isSafeString(_req.hostname)) ||
84
- !apiutil.isSafeEntity(_req.headers) ||
85
- !apiutil.isSafeEntity(_req.headers.host) )
86
- {
87
- r3logger.elog('GET request or url or token is wrong');
88
- resutil.errResponse(_req, _res, 400); // 400: Bad Request
89
- return;
90
- }
91
-
92
- //
93
- // check token
94
- //
95
- var token_result = r3token.checkToken(req, true, true); // scoped, user token
96
- if(!token_result.result){
97
- r3logger.elog(token_result.message);
98
- var _status = token_result.status;
99
- delete token_result.status;
100
- resutil.errResponse(req, res, _status, token_result);
101
- return;
102
- }
103
- var _token_info = token_result.token_info;
104
-
105
-
106
- //
107
- // check arguments
108
- //
109
- var _service_name = 'testservice'; // [NOTE] default service name
110
- if(apiutil.isSafeString(req.query.service) && apiutil.isSafeString(req.query.service.trim())){
111
- _service_name = req.query.service.trim();
112
- }
113
-
114
- //
115
- // Check localhost information for ACR API
116
- //
117
- var urlobj = apiutil.parseUrl(_req.protocol + '://' + _req.headers.host);
118
- if(!urlobj.https){
119
- if(!apiutil.compareCaseString(_req.protocol, 'http')){
120
- r3logger.elog('Original request url method is not as same as request method');
121
- resutil.errResponse(_req, _res, 400); // 400: Bad Request
122
- return;
123
- }
124
- }else{
125
- if(!apiutil.compareCaseString(_req.protocol, 'https')){
126
- r3logger.elog('Original request url method is not as same as request method');
127
- resutil.errResponse(_req, _res, 400); // 400: Bad Request
128
- return;
129
- }
130
- }
131
- if(urlobj.host !== apiutil.getSafeString(_req.host) && urlobj.host !== apiutil.getSafeString(_req.hostname)){
132
- r3logger.elog('Original request url host is not as same as request host');
133
- resutil.errResponse(_req, _res, 400); // 400: Bad Request
134
- return;
135
- }
136
-
137
- //
138
- // Make request data
139
- //
140
- var headers = {
141
- 'Content-Type': 'application/json',
142
- 'Content-Length': 0,
143
- 'X-Auth-Token': apiutil.getSafeString(_req.headers['x-auth-token']) // Transfer
144
- };
145
- var options = {
146
- 'host': urlobj.host,
147
- 'port': urlobj.port,
148
- 'path': '/v1/acr/' + _service_name,
149
- 'method': 'GET',
150
- 'headers': headers
151
- };
152
- var agent;
153
- if(urlobj.https){
154
- if(null !== cacerts.ca){
155
- options.ca = cacerts.ca;
156
- }
157
- options.agent = new https.Agent(options);
158
- agent = https;
159
- }else{
160
- options.agent = new http.Agent(options);
161
- agent = http;
162
- }
163
- r3logger.dlog('request options = ' + JSON.stringify(options));
164
- r3logger.dlog('request headers = ' + JSON.stringify(headers));
165
-
166
- //
167
- // Send request to localhost
168
- //
169
- var subreq = agent.request(options, function(subres)
170
- {
171
- var _body = '';
172
- var _status = subres.statusCode;
173
- var _headers= subres.headers;
174
-
175
- r3logger.dlog('/v1/acr/testservice response status: ' + _status);
176
- r3logger.dlog('/v1/acr/testservice response header: ' + JSON.stringify(_headers));
177
- subres.setEncoding('utf8');
178
-
179
- subres.on('data', function(chunk)
180
- {
181
- //r3logger.dlog('/v1/acr/testservice response chunk: ' + chunk);
182
- _body += chunk;
183
- });
184
-
185
- subres.on('end', function(result) // eslint-disable-line no-unused-vars
186
- {
187
- var _error = null;
188
- if(300 <= _status){
189
- _error = new Error('got error response for verify request by status=' + String(_status));
190
- r3logger.elog(_error.message);
191
- resutil.errResponse(_req, _res, _status, _error.message); // 4xx, 5xx
192
- return;
193
- }
194
- //r3logger.dlog('/v1/acr/testservice response body: ' + _body);
195
-
196
- //
197
- // Check response body
198
- //
199
- if(apiutil.checkSimpleJSON(_body)){
200
- _body = JSON.parse(_body);
201
- }
202
- if( !apiutil.isSafeEntity(_body) ||
203
- !apiutil.isSafeEntity(_body.tokeninfo) ||
204
- !apiutil.isSafeString(_body.tokeninfo.service) ||
205
- !apiutil.compareCaseString(_body.tokeninfo.service, _service_name) ||
206
- !apiutil.isSafeString(_body.tokeninfo.user) ||
207
- !apiutil.isSafeString(_body.tokeninfo.tenant) )
208
- {
209
- _error = new Error('/v1/acr/testservice response is something wrong(' + JSON.stringify(_body) + ').');
210
- r3logger.elog(_error.message);
211
- resutil.errResponse(_req, _res, 400, _error.message); // 400: Bad Request
212
- return;
213
- }
214
- r3logger.dlog('Call Verify URL: verified user(' + _body.user + ') and tenant(' + _body.tenant + ')');
215
-
216
- //
217
- // Make response body for debug
218
- //
219
- var resobj = [
220
- {
221
- name: _service_name + '_resource', // resource name
222
- expire: null, // no expire
223
- type: 'string', // resource is string type
224
- data: _service_name + ' resource data for debug', // resource data(string)
225
- keys: {
226
- 'creator': apiutil.getSafeString(_token_info.user),
227
- 'owner_tenant': apiutil.getSafeString(_token_info.tenant),
228
- 'service_name': _service_name,
229
- 'token': 'sample_token_value',
230
- 'accesskey': 'sample_accesskey_value',
231
- 'secretkey': 'sample_secretkey_value',
232
- 'anykey': 'sample_value'
233
- }
234
- }
235
- ];
236
-
237
- //
238
- // Return response
239
- //
240
- r3logger.dlog('succeed : ' + JSON.stringify(resobj));
241
- _res.status(200); // 200: OK
242
- _res.send(JSON.stringify(resobj));
243
- });
244
- });
245
- subreq.on('error', function(exception) {
246
- r3logger.elog(exception.message);
247
- resutil.errResponse(_req, _res, exception.code, exception.message); // 4xx, 5xx
248
- return;
249
- });
250
-
251
- subreq.end();
252
- });
253
-
254
- module.exports = router;
255
-
256
- /*
257
- * Local variables:
258
- * tab-width: 4
259
- * c-basic-offset: 4
260
- * End:
261
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
262
- * vim<600: noexpandtab sw=4 ts=4
263
- */
package/routes/extdata.js DELETED
@@ -1,232 +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 express = require('express');
24
- var router = express.Router();
25
-
26
- var apiutil = require('../lib/k2hr3apiutil');
27
- var resutil = require('../lib/k2hr3resutil');
28
- var r3extdata = require('../lib/k2hr3extdata');
29
-
30
- // Debug logging objects
31
- var r3logger = require('../lib/dbglogging');
32
-
33
- //---------------------------------------------------------
34
- // Router GET
35
- //---------------------------------------------------------
36
- //
37
- // Mountpath : '/v1/extdata/*'
38
- //
39
- // GET '/v1/extdata/<exturi>/<encrypted data>' : get extra(user-defined) data on version 1
40
- // response : compressed(gzip) extdata(binary)
41
- //
42
- // This mount point is for getting compressed user defined extra data.
43
- // The user can define this extra data as a template in the configuration.
44
- // The variables can be used in templates, and those are replaced real values
45
- // as like userdata entry point.
46
- // The returned data is encrypted and compressed with the specified algorithm.
47
- //
48
- router.get('/', function(req, res, next)
49
- {
50
- r3logger.dlog('CALL:', req.method, req.url);
51
-
52
- if('GET' !== req.method){
53
- // HEAD request comes here, so it should be routed to head(not defined) function.
54
- next();
55
- return;
56
- }
57
-
58
- var result;
59
- if( !apiutil.isSafeEntity(req) ||
60
- !apiutil.isSafeEntity(req.baseUrl) ||
61
- !apiutil.isSafeEntity(req.headers) ) // Must User-Agent in header
62
- {
63
- result = {
64
- result: false,
65
- message: 'GET request or url is wrong'
66
- };
67
-
68
- r3logger.elog(result.message);
69
- res.type('application/json; charset=utf-8');
70
- resutil.errResponse(req, res, 400, result); // 400: Bad Request
71
- return;
72
- }
73
-
74
- //------------------------------
75
- // Check headers
76
- //------------------------------
77
- if(!apiutil.isSafeEntity(req.headers['user-agent'])){
78
- // 'User-Agent' Must be existed
79
- r3logger.elog('GET request does not have User-Agent header');
80
-
81
- result = {
82
- result: false,
83
- message: 'GET request does not have User-Agent header'
84
- };
85
-
86
- r3logger.elog(result.message);
87
- res.type('application/json; charset=utf-8');
88
- resutil.errResponse(req, res, 400, result); // 400: Bad Request
89
- return;
90
- }
91
- var userAgent = req.headers['user-agent'].toLowerCase();
92
-
93
- var isGzip = false;
94
- if(apiutil.isSafeEntity(req.headers['accept-encoding'])){
95
- if(apiutil.hasPartString(req.headers['accept-encoding'], ',', ['gzip', 'deflate'], true)){
96
- isGzip = true;
97
- }else if(!isGzip){
98
- // Accept-Encoding should have 'gzip' or 'deflate', but all type is allowed
99
- r3logger.dlog('Get request Accept-Encoding does not have gzip nor deflate, but continue...');
100
- }
101
- }else{
102
- //r3logger.dlog('GET request doe not have Accept-Encoding, but continue...');
103
- }
104
-
105
- if(apiutil.isSafeEntity(req.headers['content-type'])){
106
- if(!apiutil.hasPartString(req.headers['content-type'], ';', 'application/octet-stream', true)){
107
- // should be 'application/octet-stream', but all type is allowed
108
- r3logger.dlog('GET request Content-Type is not application/octet-stream, but continue...');
109
- }
110
- }else{
111
- //r3logger.dlog('GET request doe not have Content-Type, but continue...');
112
- }
113
-
114
- //------------------------------
115
- // get url paths and decode
116
- //------------------------------
117
- // check path matching
118
- var requestptn = new RegExp('^/v1/extdata/(.*)/(.*)'); // regex = /^\/v1\/extdata\/(.*)\/(.*)/
119
- var reqmatchs = decodeURI(req.baseUrl).match(requestptn);
120
- if(apiutil.isEmptyArray(reqmatchs) || reqmatchs.length < 3 || '' === apiutil.getSafeString(reqmatchs[1]) || '' === apiutil.getSafeString(reqmatchs[2])){
121
- result = {
122
- result: false,
123
- message: 'GET request url does not have extdata path parameter'
124
- };
125
-
126
- r3logger.elog(result.message);
127
- res.type('application/json; charset=utf-8');
128
- resutil.errResponse(req, res, 400, result); // 400: Bad Request
129
- return;
130
- }
131
-
132
- // decode and check extdata parameter
133
- var extdataproc = new r3extdata.extdataProcess;
134
- var suburi = apiutil.getSafeString(reqmatchs[1]);
135
- var roleinfo = extdataproc.decryptRoleInfo(reqmatchs[2]);
136
- if(!extdataproc.checkSuburi(suburi)){
137
- result = {
138
- result: false,
139
- message: 'GET request URL path(' + suburi + ') does not exist'
140
- };
141
-
142
- r3logger.elog(result.message);
143
- res.type('application/json; charset=utf-8');
144
- resutil.errResponse(req, res, 400, result); // 400: Bad Request
145
- return;
146
- }
147
- if(!extdataproc.checkUserAgent(userAgent, suburi)){
148
- result = {
149
- result: false,
150
- message: 'GET request is not allowed from your client'
151
- };
152
-
153
- r3logger.elog(result.message);
154
- res.type('application/json; charset=utf-8');
155
- resutil.errResponse(req, res, 400, result); // 400: Bad Request
156
- return;
157
- }
158
- if(!apiutil.isSafeEntity(roleinfo)){
159
- result = {
160
- result: false,
161
- message: 'GET /extdata/' + suburi + '/<path> is invalid'
162
- };
163
-
164
- r3logger.elog(result.message);
165
- res.type('application/json; charset=utf-8');
166
- resutil.errResponse(req, res, 400, result); // 400: Bad Request
167
- return;
168
- }
169
- var contype = extdataproc.getContentType(suburi);
170
-
171
- //------------------------------
172
- // Make response
173
- //------------------------------
174
- var responsebody = null;
175
- if(isGzip){
176
- // Gzip
177
- responsebody = extdataproc.getGzipExtdata(roleinfo, suburi);
178
- if(null == responsebody){
179
- result = {
180
- result: false,
181
- message: 'Could not make gzip response'
182
- };
183
-
184
- r3logger.elog(result.message);
185
- res.type('application/json; charset=utf-8');
186
- resutil.errResponse(req, res, 400, result); // 400: Bad Request
187
- return;
188
- }
189
-
190
- res.type('application/zip');
191
- res.setHeader('Content-Encoding', 'gzip');
192
- res.setHeader('Content-Transfer-Encoding', 'binary');
193
- res.setHeader('Content-Disposition', 'attachment; filename=k2hr3-extdata.gz');
194
- res.setHeader('Content-Length', responsebody.length);
195
-
196
- r3logger.dlog('succeed : (response body is gzip compressed)');
197
- res.status(200); // 200: OK
198
- res.send(responsebody.data);
199
- }else{
200
- // Text
201
- responsebody = extdataproc.getExtdata(roleinfo, suburi);
202
- if(null == responsebody){
203
- result = {
204
- result: false,
205
- message: 'Could not make response'
206
- };
207
-
208
- r3logger.elog(result.message);
209
- res.type('application/json; charset=utf-8');
210
- resutil.errResponse(req, res, 400, result); // 400: Bad Request
211
- return;
212
- }
213
-
214
- res.type(apiutil.isSafeString(contype) ? contype : 'text/plain');
215
- res.setHeader('Content-Length', responsebody.length);
216
-
217
- r3logger.dlog('succeed : (response body is not gzip compressed)');
218
- res.status(200); // 200: OK
219
- res.send(responsebody);
220
- }
221
- });
222
-
223
- module.exports = router;
224
-
225
- /*
226
- * Local variables:
227
- * tab-width: 4
228
- * c-basic-offset: 4
229
- * End:
230
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
231
- * vim<600: noexpandtab sw=4 ts=4
232
- */