k2hr3-api 1.0.41 → 2.0.0
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.
- package/config/k2hr3-init.sh.templ +2 -2
- package/dist/.gitkeep +0 -0
- package/dist/src/app.js +262 -0
- package/{bin → dist/src/bin}/run.sh +1 -1
- package/dist/src/bin/watcher.js +113 -0
- package/dist/src/bin/www.js +217 -0
- package/dist/src/lib/basicipcheck.js +392 -0
- package/dist/src/lib/cacerts.js +106 -0
- package/dist/src/lib/dbglogging.js +190 -0
- package/dist/src/lib/dummyuserapi.js +719 -0
- package/dist/src/lib/ipwatch.js +354 -0
- package/dist/src/lib/k2hr3acrutil.js +532 -0
- package/dist/src/lib/k2hr3apiutil.js +1444 -0
- package/dist/src/lib/k2hr3cliutil.js +183 -0
- package/dist/src/lib/k2hr3config.js +832 -0
- package/dist/src/lib/k2hr3cryptutil.js +258 -0
- package/dist/src/lib/k2hr3dkc.js +12121 -0
- package/dist/src/lib/k2hr3extdata.js +198 -0
- package/dist/src/lib/k2hr3keys.js +207 -0
- package/dist/src/lib/k2hr3resutil.js +111 -0
- package/dist/src/lib/k2hr3template.js +6546 -0
- package/dist/src/lib/k2hr3tokens.js +2643 -0
- package/dist/src/lib/k2hr3userdata.js +296 -0
- package/dist/src/lib/k8soidc.js +1000 -0
- package/dist/src/lib/openstackapiv2.js +695 -0
- package/dist/src/lib/openstackapiv3.js +932 -0
- package/dist/src/lib/openstackep.js +667 -0
- package/{tests/auto_common.js → dist/src/lib/types.js} +4 -38
- package/dist/src/routes/acr.js +704 -0
- package/dist/src/routes/debugVerify.js +294 -0
- package/dist/src/routes/extdata.js +219 -0
- package/dist/src/routes/list.js +264 -0
- package/dist/src/routes/policy.js +840 -0
- package/dist/src/routes/resource.js +1489 -0
- package/dist/src/routes/role.js +2627 -0
- package/dist/src/routes/service.js +908 -0
- package/dist/src/routes/tenant.js +1141 -0
- package/dist/src/routes/userTokens.js +482 -0
- package/dist/src/routes/userdata.js +212 -0
- package/dist/src/routes/version.js +103 -0
- package/package.json +152 -121
- package/ChangeLog +0 -372
- package/app.js +0 -292
- package/bin/watcher +0 -122
- package/bin/www +0 -180
- package/eslint.config.mjs +0 -68
- package/lib/basicipcheck.js +0 -376
- package/lib/cacerts.js +0 -71
- package/lib/dbglogging.js +0 -151
- package/lib/dummyuserapi.js +0 -766
- package/lib/ipwatch.js +0 -379
- package/lib/k2hr3acrutil.js +0 -516
- package/lib/k2hr3apiutil.js +0 -1494
- package/lib/k2hr3cliutil.js +0 -191
- package/lib/k2hr3config.js +0 -826
- package/lib/k2hr3cryptutil.js +0 -254
- package/lib/k2hr3dkc.js +0 -12632
- package/lib/k2hr3extdata.js +0 -198
- package/lib/k2hr3keys.js +0 -234
- package/lib/k2hr3resutil.js +0 -100
- package/lib/k2hr3template.js +0 -6925
- package/lib/k2hr3tokens.js +0 -2799
- package/lib/k2hr3userdata.js +0 -312
- package/lib/k8soidc.js +0 -1012
- package/lib/openstackapiv2.js +0 -764
- package/lib/openstackapiv3.js +0 -1032
- package/lib/openstackep.js +0 -553
- package/routes/acr.js +0 -738
- package/routes/debugVerify.js +0 -263
- package/routes/extdata.js +0 -232
- package/routes/list.js +0 -270
- package/routes/policy.js +0 -869
- package/routes/resource.js +0 -1441
- package/routes/role.js +0 -2664
- package/routes/service.js +0 -894
- package/routes/tenant.js +0 -1095
- package/routes/userTokens.js +0 -511
- package/routes/userdata.js +0 -218
- package/routes/version.js +0 -108
- package/templ/Dockerfile.templ +0 -71
- package/tests/auto_acr.js +0 -1101
- package/tests/auto_acr_spec.js +0 -79
- package/tests/auto_all_spec.js +0 -142
- package/tests/auto_control_subprocess.sh +0 -243
- package/tests/auto_extdata.js +0 -220
- package/tests/auto_extdata_spec.js +0 -79
- package/tests/auto_init_config_json.sh +0 -275
- package/tests/auto_k2hdkc_server.ini +0 -109
- package/tests/auto_k2hdkc_slave.ini +0 -83
- package/tests/auto_list.js +0 -439
- package/tests/auto_list_spec.js +0 -79
- package/tests/auto_policy.js +0 -1579
- package/tests/auto_policy_spec.js +0 -79
- package/tests/auto_resource.js +0 -10956
- package/tests/auto_resource_spec.js +0 -79
- package/tests/auto_role.js +0 -6150
- package/tests/auto_role_spec.js +0 -79
- package/tests/auto_service.js +0 -770
- package/tests/auto_service_spec.js +0 -79
- package/tests/auto_subprocesses.js +0 -114
- package/tests/auto_template.sh +0 -126
- package/tests/auto_tenant.js +0 -1100
- package/tests/auto_tenant_spec.js +0 -79
- package/tests/auto_token_util.js +0 -219
- package/tests/auto_userdata.js +0 -292
- package/tests/auto_userdata_spec.js +0 -79
- package/tests/auto_usertokens.js +0 -565
- package/tests/auto_usertokens_spec.js +0 -79
- package/tests/auto_version.js +0 -127
- package/tests/auto_version_spec.js +0 -79
- package/tests/auto_watcher.js +0 -157
- package/tests/auto_watcher_spec.js +0 -79
- package/tests/k2hdkc_test.data +0 -986
- package/tests/k2hdkc_test_load.sh +0 -255
- package/tests/k2hr3template_test.js +0 -187
- package/tests/k2hr3template_test.sh +0 -339
- package/tests/k2hr3template_test_async.js +0 -216
- package/tests/k2hr3template_test_template.result +0 -7117
- package/tests/k2hr3template_test_template.txt +0 -3608
- package/tests/k2hr3template_test_vars.js +0 -194
- package/tests/manual_acr_delete.js +0 -143
- package/tests/manual_acr_get.js +0 -297
- package/tests/manual_acr_postput.js +0 -215
- package/tests/manual_allusertenant_get.js +0 -113
- package/tests/manual_extdata_get.js +0 -191
- package/tests/manual_k2hr3keys_get.js +0 -84
- package/tests/manual_list_gethead.js +0 -230
- package/tests/manual_policy_delete.js +0 -132
- package/tests/manual_policy_gethead.js +0 -275
- package/tests/manual_policy_postput.js +0 -297
- package/tests/manual_resource_delete.js +0 -433
- package/tests/manual_resource_gethead.js +0 -423
- package/tests/manual_resource_postput.js +0 -487
- package/tests/manual_role_delete.js +0 -404
- package/tests/manual_role_gethead.js +0 -547
- package/tests/manual_role_postput.js +0 -544
- package/tests/manual_service_delete.js +0 -153
- package/tests/manual_service_gethead.js +0 -178
- package/tests/manual_service_postput.js +0 -348
- package/tests/manual_tenant_delete.js +0 -186
- package/tests/manual_tenant_gethead.js +0 -268
- package/tests/manual_tenant_postput.js +0 -293
- package/tests/manual_test.sh +0 -352
- package/tests/manual_userdata_get.js +0 -173
- package/tests/manual_usertoken_gethead.js +0 -136
- package/tests/manual_usertoken_postput.js +0 -310
- package/tests/manual_version_get.js +0 -127
- package/tests/run_local_test_k2hdkc.sh +0 -174
- package/tests/test.sh +0 -333
package/lib/openstackep.js
DELETED
|
@@ -1,553 +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 http = require('http');
|
|
24
|
-
var https = require('https');
|
|
25
|
-
|
|
26
|
-
var cacerts = require('../lib/cacerts');
|
|
27
|
-
var apiutil = require('./k2hr3apiutil');
|
|
28
|
-
var k2hr3 = require('./k2hr3dkc');
|
|
29
|
-
var r3keys = require('./k2hr3keys').getK2hr3Keys;
|
|
30
|
-
|
|
31
|
-
// Debug logging objects
|
|
32
|
-
var r3logger = require('../lib/dbglogging');
|
|
33
|
-
|
|
34
|
-
//---------------------------------------------------------
|
|
35
|
-
// Keystone api wrapper
|
|
36
|
-
//---------------------------------------------------------
|
|
37
|
-
var kseplist = null;
|
|
38
|
-
var ksepobj = null;
|
|
39
|
-
|
|
40
|
-
(function()
|
|
41
|
-
{
|
|
42
|
-
var r3Conf = require('./k2hr3config').r3ApiConfig;
|
|
43
|
-
var apiConf = new r3Conf();
|
|
44
|
-
|
|
45
|
-
if(apiConf.isKeystoneEpList()){
|
|
46
|
-
kseplist = apiConf.getKeystoneEpList();
|
|
47
|
-
}else if(apiConf.isKeystoneEpFile()){
|
|
48
|
-
var ksepobj_path= './' + apiConf.getKeystoneEpFile();
|
|
49
|
-
ksepobj = require(ksepobj_path);
|
|
50
|
-
}
|
|
51
|
-
}());
|
|
52
|
-
|
|
53
|
-
//---------------------------------------------------------
|
|
54
|
-
// Callback function for testing one keystone endpoint
|
|
55
|
-
//---------------------------------------------------------
|
|
56
|
-
// Input parameter:
|
|
57
|
-
// err : if error is occurred, error object is set(if no error, this is null).
|
|
58
|
-
// callback : specify the callback to be called when all epallmap is checked.
|
|
59
|
-
// epallmap : all of keystone endpoint
|
|
60
|
-
// region : checked region
|
|
61
|
-
// status_code : check result
|
|
62
|
-
//
|
|
63
|
-
// Result: callback(error, epallmap)
|
|
64
|
-
// error : if error is occurred, error object is set(if no error, this is null).
|
|
65
|
-
// epallmap : all endpoint mapping
|
|
66
|
-
//
|
|
67
|
-
// [NOTE]
|
|
68
|
-
// The callback function is only called when all checks of
|
|
69
|
-
// epallmap are complete.
|
|
70
|
-
// This assumes that the caller will call this function on all
|
|
71
|
-
// epallmaps.
|
|
72
|
-
//
|
|
73
|
-
var rawTestKeystoneEpCallback = function(err, callback, epallmap, region, status_code)
|
|
74
|
-
{
|
|
75
|
-
var error;
|
|
76
|
-
if(!apiutil.isSafeEntity(epallmap) || !apiutil.isSafeEntity(callback) || !apiutil.isSafeString(region) || !apiutil.isSafeEntity(epallmap[region])){
|
|
77
|
-
error = new Error('some parameters are wrong : epallmap=' + JSON.stringify(epallmap) + ', region=' + JSON.stgingify(region) + ' epallmap[region]=' + JSON.stringify(epallmap[region]));
|
|
78
|
-
r3logger.elog(error.message);
|
|
79
|
-
if(apiutil.isSafeEntity(callback)){
|
|
80
|
-
callback(error);
|
|
81
|
-
}
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
if(!apiutil.isSafeEntity(status_code) || isNaN(status_code)){
|
|
85
|
-
r3logger.elog('parameter is wrong : status_code=' + JSON.stringify(status_code) + ', but continue with status_code(500).');
|
|
86
|
-
status_code = 500; // status code = internal error
|
|
87
|
-
}
|
|
88
|
-
if(null !== err){
|
|
89
|
-
r3logger.elog('failed test about keystone endpoint(' + epallmap[region].url + ') for region(' + region + ') by ' + err.message + ', but continue with status_code(500).');
|
|
90
|
-
status_code = 500; // status code = internal error
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// set checked flag and status result
|
|
94
|
-
//
|
|
95
|
-
// [NOTE][TODO]
|
|
96
|
-
// Under control by this flag, exclusion control is not perfect.
|
|
97
|
-
// In other words, the callback function may be called multiple times.
|
|
98
|
-
// (However, the callback function will be called at least once.)
|
|
99
|
-
// Currently, exclusion control here is not performed, and the caller
|
|
100
|
-
// recognizes multiple calls. Here is the code to fix.
|
|
101
|
-
//
|
|
102
|
-
epallmap[region].checked = true;
|
|
103
|
-
epallmap[region].status = status_code;
|
|
104
|
-
|
|
105
|
-
// check for finish
|
|
106
|
-
var is_finish = true;
|
|
107
|
-
for(var test_region in epallmap){
|
|
108
|
-
if(!epallmap[test_region].checked){
|
|
109
|
-
is_finish = false;
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if(is_finish){
|
|
114
|
-
// checked all of endpoints, then call original callback.
|
|
115
|
-
//
|
|
116
|
-
// [NOTE]
|
|
117
|
-
// Perhaps this function passes here multiple times.
|
|
118
|
-
//
|
|
119
|
-
callback(null);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
//---------------------------------------------------------
|
|
124
|
-
// Test one keystone endpoint
|
|
125
|
-
//---------------------------------------------------------
|
|
126
|
-
// Input parameter
|
|
127
|
-
// epallmap : all of keystone endpoint
|
|
128
|
-
// region : target one region for checking
|
|
129
|
-
// endpoint : target one endpoint for checking
|
|
130
|
-
// is_v3 : keystone v3 or v2
|
|
131
|
-
// timeout : timeout for checking one endpoint
|
|
132
|
-
// lastest_callback : callback function which is called end of last checking endpoint.
|
|
133
|
-
//
|
|
134
|
-
// Result: lastest_callback(error, orgcb, epallmap, region, status_code, orgcb)
|
|
135
|
-
// error : error object
|
|
136
|
-
// orgcb : original callback
|
|
137
|
-
// epallmap : all endpoint mapping
|
|
138
|
-
// region : region
|
|
139
|
-
// status_code : status code for request(timeout = 504)
|
|
140
|
-
//
|
|
141
|
-
// [NOTE]
|
|
142
|
-
// The lastest_callback callback function is only called when
|
|
143
|
-
// all checks of epallmap are complete.
|
|
144
|
-
// This assumes that the caller will call this function on all
|
|
145
|
-
// epallmaps.
|
|
146
|
-
//
|
|
147
|
-
function rawTestKeystoneEndpoint(epallmap, region, endpoint, is_v3, timeout, lastest_callback)
|
|
148
|
-
{
|
|
149
|
-
var error;
|
|
150
|
-
if(!apiutil.isSafeEntity(epallmap) || !apiutil.isSafeEntity(lastest_callback) || !apiutil.isSafeStrings(region, endpoint)){
|
|
151
|
-
error = new Error('some parameters are wrong : epallmap=' + JSON.stringify(epallmap) + ', region=' + JSON.stgingify(region) + ', endpoint=' + JSON.stringify(endpoint));
|
|
152
|
-
r3logger.elog(error.message);
|
|
153
|
-
rawTestKeystoneEpCallback(error, lastest_callback, epallmap, region, 500); // return result code = 500
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if(!apiutil.isSafeEntity(timeout) || isNaN(timeout)){
|
|
157
|
-
error = new Error('parameter is wrong : timeout=' + JSON.stringify(timeout));
|
|
158
|
-
r3logger.elog(error.message);
|
|
159
|
-
rawTestKeystoneEpCallback(error, lastest_callback, epallmap, region, 500); // return result code = 500
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
if('boolean' !== typeof is_v3){
|
|
163
|
-
is_v3 = true;
|
|
164
|
-
}
|
|
165
|
-
var _epallmap = epallmap;
|
|
166
|
-
var _region = region;
|
|
167
|
-
var _endpoint = endpoint;
|
|
168
|
-
var _is_v3 = is_v3;
|
|
169
|
-
var _timeout = timeout;
|
|
170
|
-
var _lastest_cb = lastest_callback;
|
|
171
|
-
|
|
172
|
-
// Make request body data
|
|
173
|
-
// This body failed authorization.(wrong user/passwd)
|
|
174
|
-
//
|
|
175
|
-
var ep = apiutil.urlParse(_endpoint);
|
|
176
|
-
var body;
|
|
177
|
-
var strbody;
|
|
178
|
-
var headers;
|
|
179
|
-
var options;
|
|
180
|
-
if(!_is_v3){
|
|
181
|
-
body = {
|
|
182
|
-
'auth': {
|
|
183
|
-
'tenantName': '', // unscoped token for test
|
|
184
|
-
'passwordCredentials': {
|
|
185
|
-
'username': '', // user name is empty for testing
|
|
186
|
-
'password': '' // unauthorized passwd
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
strbody = JSON.stringify(body);
|
|
191
|
-
headers = {
|
|
192
|
-
'Content-Type': 'application/json',
|
|
193
|
-
'Content-Length': strbody.length
|
|
194
|
-
};
|
|
195
|
-
options = {
|
|
196
|
-
'host': ep.hostname,
|
|
197
|
-
'port': ep.port,
|
|
198
|
-
'path': '/v2.0/tokens',
|
|
199
|
-
'method': 'POST',
|
|
200
|
-
'headers': headers
|
|
201
|
-
};
|
|
202
|
-
}else{
|
|
203
|
-
body = {
|
|
204
|
-
'auth': {
|
|
205
|
-
'identity': {
|
|
206
|
-
'password': {
|
|
207
|
-
'user': {
|
|
208
|
-
'domain': {
|
|
209
|
-
'id': 'default'
|
|
210
|
-
},
|
|
211
|
-
'name': '', // user name is empty for testing
|
|
212
|
-
'password': '' // unauthorized passwd
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
'methods': ['password']
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
strbody = JSON.stringify(body);
|
|
220
|
-
headers = {
|
|
221
|
-
'Content-Type': 'application/json',
|
|
222
|
-
'Content-Length': strbody.length
|
|
223
|
-
};
|
|
224
|
-
options = {
|
|
225
|
-
'host': ep.hostname,
|
|
226
|
-
'port': ep.port,
|
|
227
|
-
'path': '/v3/auth/tokens',
|
|
228
|
-
'method': 'POST',
|
|
229
|
-
'headers': headers
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
var httpobj;
|
|
234
|
-
if(apiutil.compareCaseString('https:', ep.protocol)){
|
|
235
|
-
if(null !== cacerts.ca){
|
|
236
|
-
options.ca = cacerts.ca;
|
|
237
|
-
}
|
|
238
|
-
options.agent = new https.Agent(options);
|
|
239
|
-
httpobj = https;
|
|
240
|
-
}else{
|
|
241
|
-
options.agent = new http.Agent(options);
|
|
242
|
-
httpobj = http;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
var req = httpobj.request(options, function(res)
|
|
246
|
-
{
|
|
247
|
-
var body = ''; // eslint-disable-line no-unused-vars
|
|
248
|
-
var status = res.statusCode;
|
|
249
|
-
|
|
250
|
-
r3logger.dlog('response status: ' + res.statusCode);
|
|
251
|
-
r3logger.dlog('response header: ' + JSON.stringify(res.headers));
|
|
252
|
-
res.setEncoding('utf8');
|
|
253
|
-
|
|
254
|
-
res.on('data', function(chunk)
|
|
255
|
-
{
|
|
256
|
-
//r3logger.dlog('response chunk: ' + chunk);
|
|
257
|
-
body += chunk;
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
res.on('end', function(res) // eslint-disable-line no-unused-vars
|
|
261
|
-
{
|
|
262
|
-
rawTestKeystoneEpCallback(null, _lastest_cb, _epallmap, _region, status); // return result code
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
req.on('error', function(err)
|
|
267
|
-
{
|
|
268
|
-
rawTestKeystoneEpCallback(err, _lastest_cb, _epallmap, _region, 504); // return result code = 500
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
req.on('socket', function(socket)
|
|
272
|
-
{
|
|
273
|
-
socket.setTimeout(_timeout, function()
|
|
274
|
-
{
|
|
275
|
-
req.abort();
|
|
276
|
-
rawTestKeystoneEpCallback(null, _lastest_cb, _epallmap, _region, 504); // return result code = 504
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
// write data to request body
|
|
281
|
-
req.write(strbody);
|
|
282
|
-
req.end();
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
//---------------------------------------------------------
|
|
286
|
-
// Callback function for dynamic/static endpoint list
|
|
287
|
-
//---------------------------------------------------------
|
|
288
|
-
// Input parameter:
|
|
289
|
-
// cbargs : parent function parameter in this object
|
|
290
|
-
// timeout : rawGetKeystoneEndpoint function argument
|
|
291
|
-
// is_test : rawGetKeystoneEndpoint function argument
|
|
292
|
-
// is_v3 : rawGetKeystoneEndpoint function argument
|
|
293
|
-
// callback : rawGetKeystoneEndpoint function argument
|
|
294
|
-
// err : if error is occurred, error object is set(if no error, this is null).
|
|
295
|
-
// epmap : keystone endpoint map which is result of dynamic/static list.
|
|
296
|
-
//
|
|
297
|
-
// Result: callback(error, keystone_ep)
|
|
298
|
-
// error : error object
|
|
299
|
-
// keystone_ep : url object with region string element
|
|
300
|
-
//
|
|
301
|
-
function rawGetKeystoneEndpointsCallback(cbargs, err, epmap)
|
|
302
|
-
{
|
|
303
|
-
var _cbargs = cbargs;
|
|
304
|
-
var error;
|
|
305
|
-
|
|
306
|
-
if(null !== err){
|
|
307
|
-
error = new Error('failed to get dynamic keystone endpoints : ' + err.message);
|
|
308
|
-
r3logger.elog(error.message);
|
|
309
|
-
_cbargs.callback(error, null);
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
if(!apiutil.isSafeEntity(epmap)){
|
|
313
|
-
error = new Error('getting dynamic keystone endpoints is something wrong.');
|
|
314
|
-
r3logger.elog(error.message);
|
|
315
|
-
_cbargs.callback(error, null);
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
//
|
|
320
|
-
// check and register endpoints to k2hdkc
|
|
321
|
-
//
|
|
322
|
-
var keys = r3keys();
|
|
323
|
-
var epallmap= {};
|
|
324
|
-
for(var region in epmap){
|
|
325
|
-
if(!apiutil.isSafeString(epmap[region])){
|
|
326
|
-
// wrong data
|
|
327
|
-
r3logger.wlog('dynamic keystone endpoint for ' + region + ' is something wrong(' + JSON.stringify(epmap[region]) + '), thus skip it.');
|
|
328
|
-
continue;
|
|
329
|
-
}
|
|
330
|
-
// register only https!
|
|
331
|
-
var ep = apiutil.urlParse(epmap[region]);
|
|
332
|
-
if(!apiutil.compareCaseString('https:', ep.protocol)){
|
|
333
|
-
// not https
|
|
334
|
-
r3logger.wlog('dynamic keystone endpoint for ' + region + ' is not https(' + ep.protocol + '), it is not good endpoint.');
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// add to temporary
|
|
338
|
-
var tmpmap ={
|
|
339
|
-
'url': epmap[region],
|
|
340
|
-
'checked': false,
|
|
341
|
-
'status': 0
|
|
342
|
-
};
|
|
343
|
-
epallmap[region] = tmpmap;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
if(!_cbargs.is_test){
|
|
347
|
-
// not need to test(only updates), finish here
|
|
348
|
-
//
|
|
349
|
-
// [NOTE]
|
|
350
|
-
// keystone endpoint is null
|
|
351
|
-
//
|
|
352
|
-
_cbargs.callback(null, null);
|
|
353
|
-
return;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
// test all endpoints(asynchronous)
|
|
357
|
-
for(region in epallmap){
|
|
358
|
-
// check each endpoint
|
|
359
|
-
//
|
|
360
|
-
// [NOTE]
|
|
361
|
-
// The callback function is called only when all the elements of
|
|
362
|
-
// epallmap are checked.
|
|
363
|
-
//
|
|
364
|
-
rawTestKeystoneEndpoint(epallmap, region, epallmap[region].url, _cbargs.is_v3, _cbargs.timeout, function(err)
|
|
365
|
-
{
|
|
366
|
-
var _callback = _cbargs.callback;
|
|
367
|
-
var _epallmap = epallmap;
|
|
368
|
-
|
|
369
|
-
if(null !== err){
|
|
370
|
-
var error = new Error('failed to check keystone endpoints : ' + err.message);
|
|
371
|
-
r3logger.elog(error.message);
|
|
372
|
-
_callback(error, null);
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
// set all endpoint map
|
|
377
|
-
for(var region2 in _epallmap){
|
|
378
|
-
// register endpoint(type should be VALUE_KEYSTONE_NORMAL)
|
|
379
|
-
//
|
|
380
|
-
// [NOTE][TODO]
|
|
381
|
-
// Now, we do not distinguish v2 and v3 keystone, we are registering it into k2hdkc.
|
|
382
|
-
// This may possibly cause problems.
|
|
383
|
-
//
|
|
384
|
-
var res_ep = k2hr3.setKeystoneEndpointAll(region2, _epallmap[region2].url, keys.VALUE_KEYSTONE_NORMAL, 0);
|
|
385
|
-
if(!res_ep.result){
|
|
386
|
-
r3logger.elog('could not set keystone endpoint(' + _epallmap[region2].url + ') for region2(' + region2 + ') into k2hdkc, but continue...');
|
|
387
|
-
}else{
|
|
388
|
-
r3logger.mlog('add new keystone endpoint(' + _epallmap[region2].url + ') for region2(' + region2 + ') into k2hdkc.');
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// call ownself with not reentrant flag
|
|
393
|
-
rawGetKeystoneEndpoint(function(err, keystone_ep)
|
|
394
|
-
{
|
|
395
|
-
if(null !== err){
|
|
396
|
-
var error = new Error('failed to get keystone endpoint : ' + err.message);
|
|
397
|
-
r3logger.elog(error.message);
|
|
398
|
-
_callback(error, null);
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
//
|
|
403
|
-
// returns keystone endpoint after remaking all endpoint
|
|
404
|
-
//
|
|
405
|
-
_callback(null, keystone_ep);
|
|
406
|
-
|
|
407
|
-
}, _cbargs.is_v3, _cbargs.is_test, _cbargs.timeout, false);
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
//---------------------------------------------------------
|
|
413
|
-
// Get one of endpoint for keystone from static urls
|
|
414
|
-
//---------------------------------------------------------
|
|
415
|
-
// Input parameter
|
|
416
|
-
// callback : specify callback function
|
|
417
|
-
// is_v3 : keystone api v3 or v2(default v3)
|
|
418
|
-
// is_test : specify whether to test each keystone
|
|
419
|
-
// endpoint after unable to find a valid
|
|
420
|
-
// keystone endpoint and re-creating it.
|
|
421
|
-
// (default true)
|
|
422
|
-
// timeout : specify the timeout required to check
|
|
423
|
-
// each keystone endpoint.
|
|
424
|
-
// (default 30s)
|
|
425
|
-
// is_remake_keystone_ep : if keystone endpoint is not registered,
|
|
426
|
-
// it specifies whether to recreate it.
|
|
427
|
-
// (default false)
|
|
428
|
-
//
|
|
429
|
-
// Result: callback(error, keystone_ep)
|
|
430
|
-
// error : error object
|
|
431
|
-
// keystone_ep : url object with region string element
|
|
432
|
-
//
|
|
433
|
-
var last_region = null;
|
|
434
|
-
var last_endpoint = null;
|
|
435
|
-
|
|
436
|
-
function rawGetKeystoneEndpoint(callback, is_v3, is_test, timeout, is_remake_keystone_ep)
|
|
437
|
-
{
|
|
438
|
-
var error;
|
|
439
|
-
if(!apiutil.isSafeEntity(timeout) || isNaN(timeout)){
|
|
440
|
-
timeout = 30000; // default 30s
|
|
441
|
-
}
|
|
442
|
-
if('boolean' !== typeof is_test){
|
|
443
|
-
is_test = true; // default true
|
|
444
|
-
}
|
|
445
|
-
if('boolean' !== typeof is_v3){
|
|
446
|
-
is_v3 = true; // default v3
|
|
447
|
-
}
|
|
448
|
-
if('boolean' !== typeof is_remake_keystone_ep){
|
|
449
|
-
is_remake_keystone_ep = false;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// [NOTE]
|
|
453
|
-
// This object is inherited from getDynamicKeystoneEndpoints
|
|
454
|
-
// to rawGetKeystoneEndpointsCallback.
|
|
455
|
-
// Ultimately, this function is called recursively and receives
|
|
456
|
-
// the data of this object as an argument.
|
|
457
|
-
//
|
|
458
|
-
var cbargs = {
|
|
459
|
-
timeout: timeout,
|
|
460
|
-
is_test: is_test,
|
|
461
|
-
is_v3: is_v3,
|
|
462
|
-
callback: callback
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
var keystone_ep;
|
|
466
|
-
if(apiutil.isSafeString(last_region) && apiutil.isSafeString(last_endpoint)){
|
|
467
|
-
// there is a cache for endpoint/region
|
|
468
|
-
keystone_ep = apiutil.urlParse(last_endpoint);
|
|
469
|
-
keystone_ep.region = last_region;
|
|
470
|
-
cbargs.callback(null, keystone_ep);
|
|
471
|
-
return;
|
|
472
|
-
}
|
|
473
|
-
// there is no cache for endpoint/region
|
|
474
|
-
|
|
475
|
-
var allres = k2hr3.getKeystoneEndpointAll();
|
|
476
|
-
if(!allres.result){
|
|
477
|
-
r3logger.elog('failed to get all keystone endpoint : ' + allres.message + 'but continue for recovering.');
|
|
478
|
-
}
|
|
479
|
-
var keystones = apiutil.isSafeEntity(allres.keystones) ? allres.keystones : {};
|
|
480
|
-
|
|
481
|
-
// search OK status from all
|
|
482
|
-
var keys = r3keys();
|
|
483
|
-
for(var region in keystones){
|
|
484
|
-
if( apiutil.isSafeEntity(keystones[region]) &&
|
|
485
|
-
apiutil.isSafeString(keystones[region].url) &&
|
|
486
|
-
apiutil.isSafeString(keystones[region].type) &&
|
|
487
|
-
keys.VALUE_KEYSTONE_NORMAL === keystones[region].type &&
|
|
488
|
-
apiutil.isSafeEntity(keystones[region].status) &&
|
|
489
|
-
keystones[region].status < 500 ) // allow 0, 2xx, 3xx, 4xx
|
|
490
|
-
{
|
|
491
|
-
// found reachable endpoint, then set cache and result
|
|
492
|
-
last_region = region;
|
|
493
|
-
last_endpoint = keystones[region].url;
|
|
494
|
-
keystone_ep = apiutil.urlParse(last_endpoint);
|
|
495
|
-
keystone_ep.region = last_region;
|
|
496
|
-
|
|
497
|
-
cbargs.callback(null, keystone_ep);
|
|
498
|
-
return;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
//
|
|
503
|
-
// There are no available endpoints
|
|
504
|
-
//
|
|
505
|
-
if(!is_remake_keystone_ep){
|
|
506
|
-
error = new Error('there is no safe keystone endpoints.');
|
|
507
|
-
r3logger.elog(error.message);
|
|
508
|
-
cbargs.callback(error, null);
|
|
509
|
-
return;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
//
|
|
513
|
-
// try to remake keystone endpoint
|
|
514
|
-
//
|
|
515
|
-
if(apiutil.isSafeEntity(kseplist)){
|
|
516
|
-
//
|
|
517
|
-
// Get a static keystone endpoint.
|
|
518
|
-
//
|
|
519
|
-
rawGetKeystoneEndpointsCallback(cbargs, null, kseplist);
|
|
520
|
-
|
|
521
|
-
}else if(apiutil.isSafeEntity(ksepobj)){
|
|
522
|
-
//
|
|
523
|
-
// Get keystone endpoint list dynamically.
|
|
524
|
-
//
|
|
525
|
-
ksepobj.getDynamicKeystoneEndpoints(cbargs, rawGetKeystoneEndpointsCallback);
|
|
526
|
-
|
|
527
|
-
}else{
|
|
528
|
-
//
|
|
529
|
-
// Wrong configuration
|
|
530
|
-
//
|
|
531
|
-
error = new Error('keystone endpoint configuration is something wrong.');
|
|
532
|
-
r3logger.elog(error.message);
|
|
533
|
-
cbargs.callback(error, null);
|
|
534
|
-
return;
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
//---------------------------------------------------------
|
|
539
|
-
// Exports
|
|
540
|
-
//---------------------------------------------------------
|
|
541
|
-
exports.getKeystoneEndpoint = function(callback, is_v3, is_test, timeout)
|
|
542
|
-
{
|
|
543
|
-
return rawGetKeystoneEndpoint(callback, is_v3, is_test, timeout, true);
|
|
544
|
-
};
|
|
545
|
-
|
|
546
|
-
/*
|
|
547
|
-
* Local variables:
|
|
548
|
-
* tab-width: 4
|
|
549
|
-
* c-basic-offset: 4
|
|
550
|
-
* End:
|
|
551
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
552
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
553
|
-
*/
|