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.
Files changed (149) hide show
  1. package/config/k2hr3-init.sh.templ +2 -2
  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 -372
  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,516 +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 Oct 27 2017
17
- * REVISION:
18
- *
19
- */
20
-
21
- 'use strict';
22
-
23
- var https = require('https');
24
- var http = require('http');
25
- var cacerts = require('../lib/cacerts');
26
- var r3token = require('./k2hr3tokens');
27
- var apiutil = require('./k2hr3apiutil');
28
-
29
- // Debug logging objects
30
- var r3logger = require('../lib/dbglogging');
31
-
32
- //---------------------------------------------------------
33
- // Common send verify request
34
- //---------------------------------------------------------
35
- //
36
- // Send and Get response from verify URL
37
- //
38
- // Inputs
39
- // scopedtoken : scoped user token
40
- // urlobj : url object built by apiutil.parseUrl()
41
- // callback(error, response) : callback function received response data
42
- //
43
- // Response : following formatted array
44
- //
45
- // Ex.) Response format from verify url
46
- //
47
- // response body = [ : undefined/null or resource array(if one element, allows only it not array)
48
- // {
49
- // name : resource name which is key name(path) for resource
50
- // expire : undefined/null or integer
51
- // type : resource data type(string or object), if date is null or '', this value must be string.
52
- // data : resource data which must be string or object or null/undefined.
53
- // keys = { : resource has keys(associative array), or null/undefined.
54
- // 'foo': bar, : any value is allowed
55
- // ... :
56
- // } :
57
- // },
58
- // ...
59
- // ]
60
- //
61
- function rawACRSendVerifyEx(scopedtoken, urlobj, callback)
62
- {
63
- if(!apiutil.isSafeEntity(callback) || 'function' !== typeof callback){
64
- r3logger.elog('callback parameter is wrong : callback=' + JSON.stringify(callback));
65
- return;
66
- }
67
- var _callback = callback;
68
-
69
- if(!apiutil.isSafeString(scopedtoken) || !apiutil.isSafeEntity(urlobj)){
70
- var error = new Error('some parameters are wrong : scopedtoken=' + JSON.stringify(scopedtoken) + ', urlobj=' + JSON.stringify(urlobj));
71
- r3logger.elog(error.message);
72
- _callback(error, null);
73
- return;
74
- }
75
-
76
- var headers = {
77
- 'Content-Type': 'application/json',
78
- 'Content-Length': 0,
79
- 'X-Auth-Token': scopedtoken // [NOTE] this token string does not have 'U=' prefix.
80
- };
81
- var options = {
82
- 'host': apiutil.getSafeString(urlobj.host),
83
- 'port': urlobj.port,
84
- 'path': apiutil.getSafeString(urlobj.path),
85
- 'method': 'GET',
86
- 'headers': headers
87
- };
88
-
89
- r3logger.dlog('request options = ' + JSON.stringify(options));
90
- r3logger.dlog('request headers = ' + JSON.stringify(headers));
91
-
92
- var agent;
93
- if(urlobj.https){
94
- if(null !== cacerts.ca){
95
- options.ca = cacerts.ca;
96
- }
97
- options.agent = new https.Agent(options);
98
- agent = https;
99
- }else{
100
- agent = http;
101
- }
102
-
103
- // send request
104
- var req = agent.request(options, function(res)
105
- {
106
- var _body = '';
107
- var _status = res.statusCode;
108
- var _headers= res.headers;
109
-
110
- r3logger.dlog('verify response status: ' + _status);
111
- r3logger.dlog('verify response header: ' + JSON.stringify(_headers));
112
- res.setEncoding('utf8');
113
-
114
- res.on('data', function(chunk)
115
- {
116
- //r3logger.dlog('verify response chunk: ' + chunk);
117
- _body += chunk;
118
- });
119
-
120
- res.on('end', function(result) // eslint-disable-line no-unused-vars
121
- {
122
- var _error = null;
123
- if(300 <= _status){
124
- _error = new Error('got error response for verify request by status=' + String(_status));
125
- r3logger.elog(_error.message);
126
- _callback(_error, null);
127
- return;
128
- }
129
- //r3logger.dlog('response body: ' + _body);
130
-
131
- // check response body
132
- var resobj = null;
133
- if(!apiutil.isSafeString(_body)){
134
- _error = new Error('verify resource is not json string : response(json) =' + JSON.stringify(_body));
135
- }else{
136
- // check response string(json)
137
- resobj = _body;
138
- if(apiutil.checkSimpleJSON(_body)){
139
- resobj = JSON.parse(_body);
140
- }
141
- if(!apiutil.isArray(resobj)){
142
- _error = new Error('verify resource is not array : response(object) =' + JSON.stringify(resobj));
143
- }else{
144
- // check each object in array
145
- var namemap = {};
146
- for(var cnt = 0; cnt < resobj.length; ++cnt){
147
- // check name field
148
- if(!apiutil.isSafeString(resobj[cnt].name)){
149
- _error = new Error('empty resource name in verify response is found : response pos=' + cnt);
150
- break;
151
- }
152
- if(apiutil.isSafeEntity(namemap[resobj[cnt].name])){
153
- _error = new Error('same resource name in verify response is found : response pos=' + cnt + ', name=' + JSON.stringify(resobj[cnt].name));
154
- break;
155
- }
156
- namemap[resobj[cnt].name] = true; // set any value.
157
-
158
- // check expire field
159
- if(!apiutil.isSafeEntity(resobj[cnt].expire) && isNaN(resobj[cnt].expire)){
160
- _error = new Error('wrong expire value in verify response is found : response pos=' + cnt + ', expire=' + JSON.stringify(resobj[cnt].expire));
161
- break;
162
- }
163
- if(!apiutil.isSafeEntity(resobj[cnt].expire)){
164
- resobj[cnt].expire = -1; // set no expire
165
- }else{
166
- resobj[cnt].expire = parseInt(resobj[cnt].expire); // overwrite integer value
167
- }
168
- }
169
- }
170
- }
171
- if(null !== _error){
172
- r3logger.elog(_error.message);
173
- _callback(_error, null);
174
- return;
175
- }
176
-
177
- // return response
178
- _callback(null, resobj);
179
- return;
180
- });
181
- });
182
- req.on('error', function(exception) {
183
- r3logger.elog('problem with verify request: ' + exception.message);
184
- _callback(exception, null);
185
- return;
186
- });
187
- req.end();
188
- }
189
-
190
- //---------------------------------------------------------
191
- // Send verify request
192
- //---------------------------------------------------------
193
- //
194
- // Send and Get response from verify URL
195
- //
196
- // Inputs
197
- // user : user name
198
- // passwd : pass phrase for user
199
- // tenant : tenant name for scoped
200
- // verifyurl : verify url(allow not url string, it means static value formatted JSON)
201
- // callback(error, response) : callback function received response data
202
- //
203
- // Response : see rawACRSendVerifyEx()
204
- //
205
- function rawACRSendVerifyByUser(user, passwd, tenant, verifyurl, callback)
206
- {
207
- if(!apiutil.isSafeEntity(callback) || 'function' !== typeof callback){
208
- r3logger.elog('callback parameter is wrong : callback=' + JSON.stringify(callback));
209
- return;
210
- }
211
- var error = null;
212
- var _callback = callback;
213
-
214
- var _user = user;
215
- var _passwd = passwd;
216
- var _tenant = tenant;
217
-
218
- if(!apiutil.isSafeEntity(verifyurl)){
219
- error = new Error('parameter is wrong : verifyurl=' + JSON.stringify(verifyurl));
220
- r3logger.elog(error.message);
221
- _callback(error, null);
222
- return;
223
- }
224
- if(apiutil.checkSimpleJSON(verifyurl)){
225
- // verifyurl is formatted by JSON, it means static value.
226
- _callback(null, JSON.parse(verifyurl));
227
- return;
228
- }
229
- var urlobj = apiutil.parseUrl(verifyurl); // parse verify url string to url obejct.
230
- if(null === urlobj){
231
- error = new Error('parameter is wrong : verifyurl=' + JSON.stringify(verifyurl));
232
- r3logger.elog(error.message);
233
- _callback(error, null);
234
- return;
235
- }
236
- if(!apiutil.isSafeStrings(_user, _tenant)){
237
- error = new Error('some parameters are wrong : user=' + JSON.stringify(_user) + ', tenant=' + JSON.stringify(_tenant));
238
- r3logger.elog(error.message);
239
- _callback(error, null);
240
- return;
241
- }
242
-
243
- // get scoped token directly.
244
- r3token.getUserToken(_user, _passwd, _tenant, function(err, token)
245
- {
246
- if(null !== err){
247
- var error = new Error('could not get scoped user token for user=' + _user + ', tenant=' + _tenant + ' by ' + err.message);
248
- r3logger.elog(error.message);
249
- _callback(error, null);
250
- }
251
- r3logger.dlog('get user token jsonres = ' + JSON.stringify(token));
252
-
253
- // call verify url
254
- rawACRSendVerifyEx(token, urlobj, _callback);
255
- });
256
- }
257
-
258
- //---------------------------------------------------------
259
- // Send verify request
260
- //---------------------------------------------------------
261
- //
262
- // Send and Get response from verify URL
263
- //
264
- // Inputs
265
- // unscopedtoken : unscoped user token
266
- // user : user name
267
- // tenant : tenant name for scoped
268
- // verifyurl : verify url(allow not url string, it means static value formatted JSON)
269
- // callback(error, response) : callback function received response data
270
- //
271
- // Response : see rawACRSendVerifyEx()
272
- //
273
- function rawACRSendVerifyByUnscopedToken(unscopedtoken, user, tenant, verifyurl, callback)
274
- {
275
- if(!apiutil.isSafeEntity(callback) || 'function' !== typeof callback){
276
- r3logger.elog('callback parameter is wrong : callback=' + JSON.stringify(callback));
277
- return;
278
- }
279
- var error = null;
280
- var _callback = callback;
281
-
282
- var _unscopedtoken = unscopedtoken;
283
- var _user = user;
284
- var _tenant = tenant;
285
-
286
- if(!apiutil.isSafeEntity(verifyurl)){
287
- error = new Error('parameter is wrong : verifyurl=' + JSON.stringify(verifyurl));
288
- r3logger.elog(error.message);
289
- _callback(error, null);
290
- return;
291
- }
292
- if(apiutil.checkSimpleJSON(verifyurl)){
293
- // verifyurl is formatted by JSON, it means static value.
294
- _callback(null, JSON.parse(verifyurl));
295
- return;
296
- }
297
- var urlobj = apiutil.parseUrl(verifyurl);
298
- if(null === urlobj){
299
- error = new Error('parameter is wrong : verifyurl=' + JSON.stringify(verifyurl));
300
- r3logger.elog(error.message);
301
- _callback(error, null);
302
- return;
303
- }
304
- if(!apiutil.isSafeStrings(_unscopedtoken, _user, _tenant)){
305
- error = new Error('some parameters are wrong : unscopedtoken=' + JSON.stringify(_unscopedtoken) + ', user=' + JSON.stringify(_user) + ', tenant=' + JSON.stringify(_tenant));
306
- r3logger.elog(error.message);
307
- _callback(error, null);
308
- return;
309
- }
310
-
311
- // get scoped token from unscoped token
312
- r3token.getScopedUserToken(_unscopedtoken, _user, _tenant, function(err, token)
313
- {
314
- if(null !== err){
315
- var error = new Error('could not get scoped user token for user=' + _user + ', tenant=' + _tenant + ' by ' + err.message);
316
- r3logger.elog(error.message);
317
- _callback(error, null);
318
- }
319
- r3logger.dlog('get user token jsonres = ' + JSON.stringify(token));
320
-
321
- // call verify url
322
- rawACRSendVerifyEx(token, urlobj, _callback);
323
- });
324
- }
325
-
326
- //---------------------------------------------------------
327
- // Send verify request
328
- //---------------------------------------------------------
329
- //
330
- // Send and Get response from verify URL
331
- //
332
- // Inputs
333
- // scopedtoken : scoped user token
334
- // verifyurl : verify url(allow not url string, it means static value formatted JSON)
335
- // callback(error, response) : callback function received response data
336
- //
337
- // Response : see rawACRSendVerifyEx()
338
- //
339
- function rawACRSendVerifyByScopedToken(scopedtoken, verifyurl, callback)
340
- {
341
- if(!apiutil.isSafeEntity(callback) || 'function' !== typeof callback){
342
- r3logger.elog('callback parameter is wrong : callback=' + JSON.stringify(callback));
343
- return;
344
- }
345
- var error = null;
346
- var _callback = callback;
347
- var _scopedtoken = scopedtoken;
348
-
349
- if(!apiutil.isSafeEntity(verifyurl)){
350
- error = new Error('parameter is wrong : verifyurl=' + JSON.stringify(verifyurl));
351
- r3logger.elog(error.message);
352
- _callback(error, null);
353
- return;
354
- }
355
- if(apiutil.checkSimpleJSON(verifyurl)){
356
- // verifyurl is formatted by JSON, it means static value.
357
- _callback(null, JSON.parse(verifyurl));
358
- return;
359
- }
360
- var urlobj = apiutil.parseUrl(verifyurl);
361
- if(null === urlobj){
362
- error = new Error('parameter is wrong : verifyurl=' + JSON.stringify(verifyurl));
363
- r3logger.elog(error.message);
364
- _callback(error, null);
365
- return;
366
- }
367
- if(!apiutil.isSafeString(_scopedtoken)){
368
- error = new Error('parameter is wrong : scopedtoken=' + JSON.stringify(_scopedtoken));
369
- r3logger.elog(error.message);
370
- _callback(error, null);
371
- return;
372
- }
373
-
374
- // parse token to get user/tenant
375
- var _token_res = r3token.checkUserToken(_scopedtoken);
376
- if( null === _token_res ||
377
- !apiutil.isSafeString(_token_res.user) ||
378
- !apiutil.isSafeString(_token_res.tenant)||
379
- !apiutil.isSafeEntity(_token_res.scoped)||
380
- 'boolean' !== typeof _token_res.scoped ||
381
- true !== _token_res.scoped )
382
- {
383
- error = new Error('parameter scopedtoken(' + _scopedtoken + ' -> ' + JSON.stringify(_token_res) + ') is something wrong by ' + apiutil.getSafeString(_token_res.message));
384
- r3logger.elog(error.message);
385
- _callback(error, null);
386
- return;
387
- }
388
-
389
- // get scoped token from unscoped token
390
- //
391
- // [NOTE]
392
- // getScopedUserToken is allowed scoped token when is has as same as tenant name specified.
393
- //
394
- r3token.getScopedUserToken(_scopedtoken, _token_res.user, _token_res.tenant, function(err, token)
395
- {
396
- if(null !== err){
397
- var error = new Error('could not get scoped user token for user=' + _token_res.user + ', tenant=' + _token_res.tenant + ' by ' + err.message);
398
- r3logger.elog(error.message);
399
- _callback(error, null);
400
- }
401
- r3logger.dlog('get user token jsonres = ' + JSON.stringify(token));
402
-
403
- // call verify url
404
- rawACRSendVerifyEx(token, urlobj, _callback);
405
- });
406
- }
407
-
408
- //---------------------------------------------------------
409
- // Send verify request for all pattern
410
- //---------------------------------------------------------
411
- //
412
- // Send and Get response from verify URL
413
- //
414
- // Inputs
415
- // unscopedtoken : unscoped user token
416
- // user : user name
417
- // passwd : pass phrase for user
418
- // token : (un)scoped user token
419
- // tenant : tenant name for scoped
420
- // verifyurl : verify url(allow not url string, it means static value formatted JSON)
421
- // callback(error, response) : callback function received response data
422
- //
423
- // Response : see rawACRSendVerifyEx()
424
- //
425
- // [NOTE]
426
- // This function automatically decides raw functions by parameters.
427
- //
428
- // 1) no token
429
- // Both user and passwd parameters must be specified, and token must be null(undefined).
430
- // 2) unscoped token
431
- // Both user and token parameters must be specified, and passwd must be null(undefined).
432
- // The token parameter should be "unscoped" user token.
433
- // 3) scoped token
434
- // token parameter must be specified, and both user and passwd must be null(undefined).
435
- // The token parameter should be "scoped" user token.
436
- //
437
- function rawACRSendVerify(token, user, passwd, tenant, verifyurl, callback)
438
- {
439
- if(!apiutil.isSafeEntity(callback) || 'function' !== typeof callback){
440
- r3logger.elog('callback parameter is wrong : callback=' + JSON.stringify(callback));
441
- return;
442
- }
443
- var error = null;
444
- var _callback = callback;
445
-
446
- // check pattern
447
- if(apiutil.isSafeString(user)){
448
- if(apiutil.isSafeString(token)){
449
- if(apiutil.isSafeEntity(passwd)){
450
- error = new Error('all parameters user(' + JSON.stringify(user) + ') and token(' + JSON.stringify(token) + ') and passwd(xxxxx) are specified.');
451
- }else{
452
- // case : user + unscoped token
453
- rawACRSendVerifyByUser(user, passwd, tenant, verifyurl, _callback);
454
- }
455
- }else{
456
- token = null;
457
- if(apiutil.isSafeEntity(passwd)){
458
- // case : user + passwd
459
- }else{
460
- // case : user + passwd(null)
461
- //
462
- // [NOTE]
463
- // This case is not error pattern, because empty passwd is allowed by some authorizing system.
464
- }
465
- rawACRSendVerifyByUnscopedToken(token, user, tenant, verifyurl, _callback);
466
- }
467
- }else{
468
- user = null;
469
- if(apiutil.isSafeString(token)){
470
- if(apiutil.isSafeEntity(passwd)){
471
- error = new Error('user parameter is empty, but passwd(xxxx) is specified.');
472
- }else{
473
- // case : scoped token
474
- rawACRSendVerifyByScopedToken(token, verifyurl, _callback);
475
- }
476
- }else{
477
- error = new Error('user parameter is empty, but scoped token is not specified.');
478
- }
479
- }
480
- if(null !== error){
481
- r3logger.elog(error.message);
482
- _callback(error, null);
483
- }
484
- }
485
-
486
- //---------------------------------------------------------
487
- // Exports
488
- //---------------------------------------------------------
489
- exports.getACRVerifyByUser = function(user, passwd, tenant, verifyurl, callback)
490
- {
491
- return rawACRSendVerifyByUser(user, passwd, tenant, verifyurl, callback);
492
- };
493
-
494
- exports.getACRVerifyByUnscopedToken = function(unscopedtoken, user, tenant, verifyurl, callback)
495
- {
496
- return rawACRSendVerifyByUnscopedToken(unscopedtoken, user, tenant, verifyurl, callback);
497
- };
498
-
499
- exports.getACRVerifyByScopedToken = function(scopedtoken, verifyurl, callback)
500
- {
501
- return rawACRSendVerifyByScopedToken(scopedtoken, verifyurl, callback);
502
- };
503
-
504
- exports.getACRSendVerify = function(token, user, passwd, tenant, verifyurl, callback)
505
- {
506
- return rawACRSendVerify(token, user, passwd, tenant, verifyurl, callback);
507
- };
508
-
509
- /*
510
- * Local variables:
511
- * tab-width: 4
512
- * c-basic-offset: 4
513
- * End:
514
- * vim600: noexpandtab sw=4 ts=4 fdm=marker
515
- * vim<600: noexpandtab sw=4 ts=4
516
- */