This repository was archived by the owner on Oct 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
533 lines (493 loc) · 14.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
/**
* Copyright 2016 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
module.exports = exports = {
availablePlugins: availablePlugins,
currentUserAPIOrganizations: currentUserAPIOrganizations,
currentUserAPIs: currentUserAPIs,
currentUserClientOrganizations: currentUserClientOrganizations,
currentUserClients: currentUserClients,
currentUserInfo: currentUserInfo,
currentUserPlanOrganizations: currentUserPlanOrganizations,
currentUserUpdate: currentUserUpdate,
exportData: exportData,
gateway: gateway,
gatewayAdd: gatewayAdd,
gatewayDelete: gatewayDelete,
gateways: gateways,
importData: importData,
organization: organization,
organizationAdd: organizationAdd,
organizationDelete: organizationDelete,
permissions: permissions,
permissionsUser: permissionsUser,
plugin: plugin,
pluginAdd: pluginAdd,
pluginDelete: pluginDelete,
plugins: plugins,
policyDefinition: policyDefinition,
policyDefinitionDelete: policyDefinitionDelete,
policyDefinitions: policyDefinitions,
role: role,
roleDelete: roleDelete,
roles: roles,
status: status,
user: user,
userAPIs: userAPIs,
userClients: userClients,
userOrganizations: userOrganizations,
userUpdate: userUpdate
};
const roi = require('roi');
const AVAILABLE_PLUGINS = '/apiman/plugins/availablePlugins/';
const CURRENT_USER_APIORGS = '/apiman/currentuser/apiorgs/';
const CURRENT_USER_APIS = '/apiman/currentuser/apis/';
const CURRENT_USER_CLIENTORGS = '/apiman/currentuser/clientorgs/';
const CURRENT_USER_CLIENTS = '/apiman/currentuser/clients/';
const CURRENT_USER_INFO = '/apiman/currentuser/info/';
const CURRENT_USER_PLANORGS = '/apiman/currentuser/planorgs/';
const EXPORT = '/apiman/system/export/';
const GATEWAYS = '/apiman/gateways/';
const IMPORT = '/apiman/system/import/';
const ORGANIZATIONS = '/apiman/organizations/';
const PERMISSIONS = '/apiman/permissions/';
const PLUGINS = '/apiman/plugins/';
const POLICY_DEFINITIONS = '/apiman/policyDefs/';
const ROLES = '/apiman/roles/';
const STATUS = '/apiman/system/status/';
const USERS = '/apiman/users/';
/**
* Returns the status of the apiman system.
* This is useful to use when testing a client's connection
* to the apiman API Manager REST services.
*
* @instance
* @function status
* @returns {Promise} A promise that will resolve with the status information.
*/
function status (options) {
options.endpoint = options.baseUrl + STATUS;
return roi.get(options);
}
/**
* Exports the data from the API Manager as JSON. All data in the API Manager,
* including global/admin information, will be exported.
*
* @instance
* @function exportData
* @returns {Promise} A promise that will resolve with the exported JSON data.
*/
function exportData (options) {
options.endpoint = options.baseUrl + EXPORT;
return roi.get(options);
}
/**
* Imports the backup settings into the API Manager.
*
* @instance
* @function importData
* @param {string} filePath - The full path of settings file.
* @returns {Promise} A promise that will resolve with the output messages of the imported configurations.
*/
function importData (options, filePath) {
options.endpoint = options.baseUrl + IMPORT;
options.headers = {};
options.headers.Accept = 'text/plain';
console.log(filePath);
return roi.upload(options, filePath);
}
/**
* Returns all the Gateways that have been configured.
*
* @instance
* @function gateways
* @returns {Promise} A promise that will resolve with gateways.
*/
function gateways (options) {
options.endpoint = options.baseUrl + GATEWAYS;
return roi.get(options);
}
/**
* Returns information about the Gateway.
*
* @instance
* @param {string} id - The ID of the Gateway.
* @function gateway
* @returns {Promise} A promise that will resolve with gateway.
*/
function gateway (options, id) {
options.endpoint = options.baseUrl + GATEWAYS + id;
return roi.get(options);
}
/**
* This function is used to create a new Gateway.
*
* @instance
* @param {object} gatewayRepresentation - An object representing the gateway.
* @function gatewayAdd
* @returns {Promise} A promise that will resolve with the new gateway created.
*/
function gatewayAdd (options, gatewayRepresentation) {
options.endpoint = options.baseUrl + GATEWAYS;
return roi.post(options, gatewayRepresentation);
}
/**
* This function is used to remove a Gateway.
*
* @instance
* @param {string} id - The ID of the Gateway.
* @function gatewayDelete
* @returns {Promise} A promise that will resolve with 204 No Content if the delete is successful.
*/
function gatewayDelete (options, id) {
options.endpoint = options.baseUrl + GATEWAYS + id;
return roi.del(options);
}
/**
* Returns all of the permissions assigned to the current authenticated user.
*
* @instance
* @function permissions
* @returns {Promise} A promise that will resolve with permissions.
*/
function permissions (options) {
options.endpoint = options.baseUrl + PERMISSIONS;
return roi.get(options);
}
/**
* Returns all permissions of specific user.
*
* @instance
* @param {string} id - The ID of the user.
* @function permissionsUser
* @returns {Promise} A promise that will resolve with user permissions.
*/
function permissionsUser (options, id) {
options.endpoint = options.baseUrl + PERMISSIONS + id;
return roi.get(options);
}
/**
* Returns information about the Plugin.
*
* @instance
* @param {string} id - The ID of the Plugin.
* @function plugin
* @returns {Promise} A promise that will resolve with plugin.
*/
function plugin (options, id) {
options.endpoint = options.baseUrl + PLUGINS + id;
return roi.get(options);
}
/**
* Returns all plugins that have been added to the system.
*
* @instance
* @function plugins
* @returns {Promise} A promise that will resolve with plugins.
*/
function plugins (options) {
options.endpoint = options.baseUrl + PLUGINS;
return roi.get(options);
}
/**
* This function is used to create a new Plugin.
*
* @instance
* @param {object} pluginRepresentation - An object representing the plugin.
* @function pluginAdd
* @returns {Promise} A promise that will resolve with the new plugin created.
*/
function pluginAdd (options, pluginRepresentation) {
options.endpoint = options.baseUrl + PLUGINS;
return roi.post(options, pluginRepresentation);
}
/**
* Returns all available plugins.
*
* @instance
* @function availablePlugins
* @returns {Promise} A promise that will resolve with available plugins.
*/
function availablePlugins (options) {
options.endpoint = options.baseUrl + AVAILABLE_PLUGINS;
return roi.get(options);
}
/**
* This function is used to remove a Plugin.
*
* @instance
* @param {string} id - The ID of the Plugin.
* @function pluginDelete
* @returns {Promise} A promise that will resolve with 204 No Content if the delete is successful.
*/
function pluginDelete (options, id) {
options.endpoint = options.baseUrl + PLUGINS + id;
return roi.del(options);
}
/**
* Returns all the roles currently defined in apiman.
*
* @instance
* @function roles
* @returns {Promise} A promise that will resolve with roles.
*/
function roles (options) {
options.endpoint = options.baseUrl + ROLES;
return roi.get(options);
}
/**
* Returns information about the role.
*
* @instance
* @param {string} id - The ID of the role.
* @function role
* @returns {Promise} A promise that will resolve with role.
*/
function role (options, id) {
options.endpoint = options.baseUrl + ROLES + id;
return roi.get(options);
}
/**
* This function is used to remove a Role.
*
* @instance
* @param {string} id - The ID of the Role.
* @function roleDelete
* @returns {Promise} A promise that will resolve with 204 No Content if the delete is successful.
*/
function roleDelete (options, id) {
options.endpoint = options.baseUrl + ROLES + id;
return roi.del(options);
}
/**
* Returns information about the policy definition.
*
* @instance
* @param {string} id - The ID of the policy definition.
* @function policyDefinition
* @returns {Promise} A promise that will resolve with policy definition.
*/
function policyDefinition (options, id) {
options.endpoint = options.baseUrl + POLICY_DEFINITIONS + id;
return roi.get(options);
}
/**
* Returns all the policy definitions currently defined in apiman.
*
* @instance
* @function policyDefinitions
* @returns {Promise} A promise that will resolve with policy definitions.
*/
function policyDefinitions (options) {
options.endpoint = options.baseUrl + POLICY_DEFINITIONS;
return roi.get(options);
}
/**
* This function is used to remove a policy definition.
*
* @instance
* @param {string} id - The ID of the policy definition.
* @function policyDefinitionDelete
* @returns {Promise} A promise that will resolve with 204 No Content if the delete is successful.
*/
function policyDefinitionDelete (options, id) {
options.endpoint = options.baseUrl + POLICY_DEFINITIONS + id;
return roi.del(options);
}
/**
* Returns all the organizations with APIs for the current user.
*
* @instance
* @function currentUserAPIOrganizations
* @returns {Promise} A promise that will resolve with organizations.
*/
function currentUserAPIOrganizations (options) {
options.endpoint = options.baseUrl + CURRENT_USER_APIORGS;
return roi.get(options);
}
/**
* Returns all of the APIs the current user has permission to edit.
*
* @instance
* @function currentUserAPIs
* @returns {Promise} A promise that will resolve with current user APIs.
*/
function currentUserAPIs (options) {
options.endpoint = options.baseUrl + CURRENT_USER_APIS;
return roi.get(options);
}
/**
* Returns all the organizations with clients for the current user
* has permission to edit clients.
*
* @instance
* @function currentUserClientOrganizations
* @returns {Promise} A promise that will resolve with organizations.
*/
function currentUserClientOrganizations (options) {
options.endpoint = options.baseUrl + CURRENT_USER_CLIENTORGS;
return roi.get(options);
}
/**
* Returnsall the clients for the current user
* has permission to edit clients.
*
* @instance
* @function currentUserClients
* @returns {Promise} A promise that will resolve with current user clients.
*/
function currentUserClients (options) {
options.endpoint = options.baseUrl + CURRENT_USER_CLIENTS;
return roi.get(options);
}
/**
* Returns information about the current authenticated user.
*
* @instance
* @function currentUserInfo
* @returns {Promise} A promise that will resolve with the current user information.
*/
function currentUserInfo (options) {
options.endpoint = options.baseUrl + CURRENT_USER_INFO;
return roi.get(options);
}
/**
* Updates information about the current authenticated user.
*
* @instance
* @param {string} email - User's email.
* @param {string} fullName - User's full name.
* @function currentUserUpdate
* @returns {Promise} A promise that will resolve with 204 No Content if the update is successful.
*/
function currentUserUpdate (options, email, fullName) {
options.endpoint = options.baseUrl + CURRENT_USER_INFO;
const data = { email: email, fullName: fullName };
return roi.put(options, data);
}
/**
* Returns all the organizations for which the current user
* has permission to edit plans.
*
* @instance
* @function currentUserPlanOrganizations
* @returns {Promise} A promise that will resolve with the list of organizations.
*/
function currentUserPlanOrganizations (options) {
options.endpoint = options.baseUrl + CURRENT_USER_PLANORGS;
return roi.get(options);
}
/**
* Returns information about the organization.
*
* @instance
* @param {string} id - The ID of the organization.
* @function organization
* @returns {Promise} A promise that will resolve with organization.
*/
function organization (options, id) {
options.endpoint = options.baseUrl + ORGANIZATIONS + id;
return roi.get(options);
}
/**
* This function is used to create a new Organization.
*
* @instance
* @param {string} name - Organization's name.
* @param {string} description - Organizations's description.
* @function organizationAdd
* @returns {Promise} A promise that will resolve with the new organization created.
*/
function organizationAdd (options, name, description) {
options.endpoint = options.baseUrl + ORGANIZATIONS;
const data = { name: name, description: description };
return roi.post(options, data);
}
/**
* This function is used to remove a Organization.
*
* @instance
* @param {string} id - The ID of the Organization.
* @function organizationDelete
* @returns {Promise} A promise that will resolve with 204 No Content if the delete is successful.
*/
function organizationDelete (options, id) {
options.endpoint = options.baseUrl + ORGANIZATIONS + id;
return roi.del(options);
}
/**
* Returns information about the user.
*
* @instance
* @param {string} id - The ID of the user.
* @function user
* @returns {Promise} A promise that will resolve with user.
*/
function user (options, id) {
options.endpoint = options.baseUrl + USERS + id;
return roi.get(options);
}
/**
* Updates information about the user.
*
* @instance
* @param {string} userId - User's id.
* @param {string} email - User's email.
* @param {string} fullName - User's full name.
* @function userUpdate
* @returns {Promise} A promise that will resolve with 204 No Content if the update is successful.
*/
function userUpdate (options, userId, email, fullName) {
options.endpoint = options.baseUrl + USERS + userId;
const data = { email: email, fullName: fullName };
return roi.put(options, data);
}
/**
* Returns all of the User's APIs.
*
* @instance
* @function userAPIs
* @param {string} userId - User's id.
* @returns {Promise} A promise that will resolve with user APIs.
*/
function userAPIs (options, userId) {
options.endpoint = options.baseUrl + USERS + userId + '/apis';
return roi.get(options);
}
/**
* Returns all of the User's clients.
*
* @instance
* @function userClients
* @param {string} userId - User's id.
* @returns {Promise} A promise that will resolve with user clients.
*/
function userClients (options, userId) {
options.endpoint = options.baseUrl + USERS + userId + '/clients';
return roi.get(options);
}
/**
* Returns all of the User's organizations.
*
* @instance
* @function userOrganizations
* @param {string} userId - User's id.
* @returns {Promise} A promise that will resolve with user organizations.
*/
function userOrganizations (options, userId) {
options.endpoint = options.baseUrl + USERS + userId + '/organizations';
return roi.get(options);
}