forked from danitseitlin/redis-cloud-api-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.ts
More file actions
501 lines (449 loc) · 21.8 KB
/
api.ts
File metadata and controls
501 lines (449 loc) · 21.8 KB
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
import {
CreateSubscriptionParameters, SubscriptionUpdateParameters, CidrUpdateParameters, VpcPeeringCreationParameters, ActiveActiveAwsVpcPeeringParameters, ActiveActiveGcpVpcPeeringParameters, ActiveActiveDeleteRegionParameters, ActiveActiveCreateRegionParameters
} from './types/parameters/subscription';
import {
DatabaseImportParameters, DatabaseCreationParameters, DatabaseUpdateParameters, RegionName
} from './types/parameters/database';
import {
CloudAccountCreationParameters, CloudAccountUpdateParameters
} from './types/parameters/cloud-account';
import {
SubscriptionCloudProvider, SubscriptionCidrWhitelist, SubscriptionStatus, SubscriptionVpcPeering,
SubscriptionVpcPeeringStatus, SubscriptionResponse, ActiveActiveVpcPeeringsResponse, ActiveActiveRegionsResponse
} from './types/responses/subscription';
import {
AccountInformation, DatabaseModule, SystemLog, PaymentMethod, Plan, Region, DataPersistence
} from './types/responses/general';
import {
CloudAccountResponse, CloudAccountStatus
} from './types/responses/cloud-account';
import {
TaskObject,
TaskResponse, TaskStatus
} from './types/task';
import { DatabaseResponse, DatabaseStatus } from './types/responses/database';
import { General } from './api/general';
import { Subscription } from './api/subscription'
import { Task } from './api/task';
import { Database } from './api/database';
import { CloudAccount } from './api/cloud-account';
import { Client } from './api/api.base';
export class CloudAPISDK extends Client {
private general: General
private subscription: Subscription
private database: Database
private cloudAccount: CloudAccount
private task: Task
/**
* Initializing the constructur with given custom parameters
* @param parameters The parameters we can pass you customize our sdk client
*/
constructor(parameters: CloudAPISDKParameters) {
super(parameters);
this.general = new General(this);
this.subscription = new Subscription(this);
this.database = new Database(this);
this.cloudAccount = new CloudAccount(this);
this.task = new Task(this);
}
/**
* Returning current account and related information
*/
async getAccountInformation(): Promise<AccountInformation & {[key: string]: any}> {
return await this.general.getAccountInformation();
}
/**
* Returning a lookup list of data persistence values
*/
async getDataPersistences(): Promise<DataPersistence[] & {[key: string]: any}> {
return await this.general.getDataPersistences();
}
/**
* Returning a lookup list of database modules supported in current account (support may differ based on subscription and database settings)
*/
async getDatabaseModules(): Promise<DatabaseModule[] & {[key: string]: any}> {
return await this.general.getDatabaseModules();
}
/**
* Returning system log information for current account
* @param limit Maximum number of items to return
* @param offset Number of items to skip
*/
async getSystemLogs(limit: number, offset: number): Promise<SystemLog[] & {[key: string]: any}> {
return await this.general.getSystemLogs(limit, offset);
}
/**
* Returning a lookup list of current account’s payment methods
*/
async getPaymentMethods(): Promise<PaymentMethod[] & {[key: string]: any}> {
return await this.general.getPaymentMethods();
}
/**
* Returning a lookup list of current account's plans
* @param provider The cloud provider of the plan
*/
async getPlans(provider: SubscriptionCloudProvider): Promise<Plan[] & {[key: string]: any}> {
return await this.general.getPlans(provider);
}
/**
* Returning a lookup list of current account's regions
* @param provider The cloud provider of the plan
*/
async getRegions(provider: SubscriptionCloudProvider): Promise<Region[] & {[key: string]: any}> {
return await this.general.getRegions(provider);
}
/* ------------------------------------------------------------------------------Subscription------------------------------------------------------------------------------*/
/**
* Returning a lookup list of current account's subscriptions
*/
async getSubscriptions(): Promise<SubscriptionResponse[] & {[key: string]: any}> {
return await this.subscription.getSubscriptions();
}
/**
* Creating a subscription
* @param createParameters The given parameters given for the subscription creation
*/
async createSubscription(createParameters: CreateSubscriptionParameters): Promise<TaskResponse & {[key: string]: any}> {
return await this.subscription.createSubscription(createParameters);
}
/**
* Returning a subscription
* @param subscriptionId The id of the subscription
*/
async getSubscription(subscriptionId: number): Promise<SubscriptionResponse & {[key: string]: any}> {
return await this.subscription.getSubscription(subscriptionId)
}
/**
* Updating a subscription
* @param subscriptionId The id of the subscription
* @param updateParameters The given update parameters to update the subscription with
*/
async updateSubscription(subscriptionId: number, updateParameters: SubscriptionUpdateParameters): Promise<TaskResponse & {[key: string]: any}> {
return await this.subscription.updateSubscription(subscriptionId, updateParameters)
}
/**
* Deleting a subscription
* @param subscriptionId The id of the subscription
*/
async deleteSubscription(subscriptionId: number): Promise<TaskResponse & {[key: string]: any}> {
return await this.subscription.deleteSubscription(subscriptionId)
}
/**
* Returning a lookup list of a subscription CIDR whitelists
* @param subscriptionId The id of the subscription
*/
async getSubscriptionCidrWhitelist(subscriptionId: number): Promise<SubscriptionCidrWhitelist & {[key: string]: any}> {
return await this.subscription.getSubscriptionCidrWhitelist(subscriptionId)
}
/**
* Updating a subscription CIDR whitelists
* @param subscriptionId The id of the subscription
* @param updateParameters The parameters to update the subscription with
*/
async updateSubscriptionCidrWhitelists(subscriptionId: number, updateParameters: CidrUpdateParameters): Promise<TaskResponse & {[key: string]: any}> {
return await this.subscription.updateSubscriptionCidrWhitelists(subscriptionId, updateParameters)
}
/**
* Returning a lookup list of the subscription VPC Peerings
* @param subscriptionId The id of the subscription
*/
async getVpcPeerings(subscriptionId: number): Promise<SubscriptionVpcPeering[]> {
return await this.subscription.getVpcPeerings(subscriptionId)
}
/**
* Retrives VPC Peering request for Active Active subscription
* @param subscriptionId The subscription ID
*/
async getActiveActiveVpcPeerings(subscriptionId: number): Promise<ActiveActiveVpcPeeringsResponse> {
return await this.subscription.getActiveActiveVpcPeerings(subscriptionId);
}
/**
* Creating a subscription VPC peering
* @param subscriptionId The id of the subscription
* @param createParameters The create parameters to create the VPC peering with
*/
async createSubscriptionVpcPeering(subscriptionId: number, createParameters: VpcPeeringCreationParameters): Promise<TaskResponse & {[key: string]: any}> {
return await this.subscription.createSubscriptionVpcPeering(subscriptionId, createParameters)
}
/**
* Creates VPC Peering request for Active Active subscription
* @param subscriptionId The subscription ID
* @param createParameters The create VPC parameters
*/
async createActiveActiveVpcPeering(subscriptionId: number, createParameters: ActiveActiveAwsVpcPeeringParameters | ActiveActiveGcpVpcPeeringParameters): Promise<TaskResponse & { [key: string]: any }> {
return await this.subscription.createActiveActiveVpcPeering(subscriptionId, createParameters)
}
/**
* Deleting a subscription VPC peering
* @param subscriptionId The id of the subscription
* @param vpcPeeringId The id of the VPC peering
*/
async deleteSubscriptionVpcPeering(subscriptionId: number, vpcPeeringId: number): Promise<TaskResponse & {[key: string]: any}> {
return await this.subscription.deleteSubscriptionVpcPeering(subscriptionId, vpcPeeringId)
}
/**
* Deletes a VPC Peering from Active Active subscription
* @param subscriptionId The Subscription ID
* @param peeringId The peering ID
*/
async deleteActiveActiveVpcPeering(subscriptionId: number, peeringId: number): Promise<TaskResponse & { [key: string]: any }> {
return await this.subscription.deleteActiveActiveVpcPeering(subscriptionId, peeringId);
}
/**
* Retrives the regions information for Active Active subscription
* @param subscriptionId The subscription ID
*/
async getActiveActiveRegions(subscriptionId: number): Promise<ActiveActiveRegionsResponse & { [key: string]: any }> {
return await this.subscription.getActiveActiveRegions(subscriptionId)
}
/**
* Creates a new region for Active Active subscription
* @param subscriptionId The subscription ID
* @param createParameters The create region parameters
*/
async createActiveActiveRegion(subscriptionId: number, createParameters: ActiveActiveCreateRegionParameters): Promise<TaskResponse & { [key: string]: any }> {
return await this.subscription.createActiveActiveRegion(subscriptionId, createParameters)
}
/**
* Deletes region/s from Active Active subscriptions
* @param subscriptionId The subscription ID
* @param deleteParameters The delete region parameters
*/
async deleteActiveActiveRegion(subscriptionId: number, deleteParameters: ActiveActiveDeleteRegionParameters): Promise<TaskResponse & { [key: string]: any }> {
return await this.subscription.deleteActiveActiveRegion(subscriptionId, deleteParameters)
}
/* ---------------------------------------------------------------------------------Database---------------------------------------------------------------------------------*/
/**
* Returning a lookup list of databases owned by the account
* @param subscriptionId The id of the subscription
*/
async getDatabases(subscriptionId: number): Promise<DatabaseResponse[] & {[key: string]: any}> {
return await this.database.getDatabases(subscriptionId);
}
/**
* Creating a database
* @param subscriptionId The id of the subscription
* @param createParameters The create parameters to create the database
*/
async createDatabase(subscriptionId: number, createParameters: DatabaseCreationParameters): Promise<TaskResponse & {[key: string]: any}> {
return this.database.createDatabase(subscriptionId, createParameters);
}
/**
* Returning a database
* @param subscriptionId The id of the subscription
* @param databaseId The id of the database
*/
async getDatabase(subscriptionId: number, databaseId: number): Promise<DatabaseResponse & {[key: string]: any}> {
return this.database.getDatabase(subscriptionId, databaseId);
}
/**
* Updating a database
* @param subscriptionId The id of the subscription
* @param databaseId The id of the database
* @param updateParameters The update parameters to update the database
*/
async updateDatabase(subscriptionId: number, databaseId: number, updateParameters: DatabaseUpdateParameters): Promise<TaskResponse & {[key: string]: any}> {
return this.database.updateDatabase(subscriptionId, databaseId, updateParameters);
}
/**
* Updates an Active Active database (CRDB)
* @param subscriptionId The subscription ID
* @param databaseid The database ID
* @param updateParameters The update parameters to update the database
*/
async updateCRDB(subscriptionId: number, databaseid: number, updateParameters: DatabaseUpdateParameters): Promise<TaskResponse & { [key: string]: any }> {
return await this.database.updateCRDB(subscriptionId, databaseid, updateParameters);
}
/**
* Deleting a database
* @param subscriptionId The id of the subscription
* @param databaseId The id of the database
*/
async deleteDatabase(subscriptionId: number, databaseId: number): Promise<TaskResponse & {[key: string]: any}> {
return this.database.deleteDatabase(subscriptionId, databaseId);
}
/**
* Backing up a database
* @param subscriptionId The id of the subscription
* @param databaseId The id of the database
* @param regionName The region name parameters (Optional)
*/
async backupDatabase(subscriptionId: number, databaseId: number, regionName?: RegionName): Promise<TaskResponse & {[key: string]: any}> {
return this.database.backupDatabase(subscriptionId, databaseId, regionName);
}
/**
* Importing a dataset into a database
* @param subscriptionId The id of the subscription
* @param databaseId The id of the database
* @param importParameters The import parameters to import into a database
*/
async importIntoDatabase(subscriptionId: number, databaseId: number, importParameters: DatabaseImportParameters): Promise<TaskResponse & {[key: string]: any}> {
return this.database.importIntoDatabase(subscriptionId, databaseId, importParameters);
}
/* ------------------------------------------------------------------------------Cloud-Account------------------------------------------------------------------------------*/
/**
* Returning a lookup list of cloud accounts owned by the account
*/
async getCloudAccounts(): Promise<CloudAccountResponse[] & {[key: string]: any}> {
return await this.cloudAccount.getCloudAccounts();
}
/**
* Returning a cloud account
* @param cloudAccountId The id of the cloud account
*/
async getCloudAccount(cloudAccountId: number): Promise<CloudAccountResponse & {[key: string]: any}> {
return await this.cloudAccount.getCloudAccount(cloudAccountId);
}
/**
* Creating a cloud account
* @param createParameters The create parameters to create a cloud account
*/
async createCloudAccount(createParameters: CloudAccountCreationParameters): Promise<TaskResponse & {[key: string]: any}> {
return await this.cloudAccount.createCloudAccount(createParameters);
}
/**
* Updating a cloud account
* @param cloudAccountId The id of the cloud account
* @param updateParameters The update parameters to update a cloud account
*/
async updateCloudAccount(cloudAccountId: number, updateParameters: CloudAccountUpdateParameters): Promise<TaskResponse & {[key: string]: any}> {
return await this.cloudAccount.updateCloudAccount(cloudAccountId, updateParameters);
}
/**
* Deleting a cloud account
* @param cloudAccountId The id of the cloud account
*/
async deleteCloudAccount(cloudAccountId: number): Promise<TaskResponse & {[key: string]: any}> {
return await this.cloudAccount.deleteCloudAccount(cloudAccountId);
}
/*------------------------------------------------------------------------------Task-------------------------------------------------------------------------------/*
/**
* Returning a lookup list of tasks owned by the account
*/
async getTasks(): Promise<TaskObject[] & {[key: string]: any}> {
return await this.task.getTasks()
}
/**
* Returning a task
* @param taskId The id of the task
*/
async getTask(taskId: number): Promise<TaskObject & {[key: string]: any}> {
return await this.task.getTask(taskId)
}
/*--------------------------------------------------------------------------------------Helper--functions-----------------------------------------------------------------------------------*/
/**
* Waiting for the subscription status to change to a given status
* @param subscriptionId The id of the subscription
* @param expectedStatus The expected status
* @param timeoutInSeconds The timeout of waiting for the status. Default: 20 minutes
* @param sleepTimeInSeconds The sleep time between requests. Default: 5 seconds
*/
async waitForSubscriptionStatus(subscriptionId: number, expectedStatus: SubscriptionStatus, timeoutInSeconds = 20 * 60, sleepTimeInSeconds = 5) {
return await this.subscription.waitForSubscriptionStatus(subscriptionId, expectedStatus, timeoutInSeconds, sleepTimeInSeconds);
}
/**
* Waiting for existing subscriptions statuses to change to a given status
* @param expectedStatus The expected status
* @param timeoutInSeconds The timeout of waiting for the status. Default: 20 minutes
* @param sleepTimeInSeconds The sleep time between requests. Default: 5 seconds
* @returns A batch of subscription responses
*/
async waitForSubscriptionsStatus(expectedStatus: SubscriptionStatus, timeoutInSeconds = 20 * 60, sleepTimeInSeconds = 5) {
return await this.subscription.waitForSubscriptionsStatus(expectedStatus, timeoutInSeconds, sleepTimeInSeconds);
}
/**
* Waiting for the subscription VPC peering status to change to a given status
* @param subscriptionId The id of the subscription
* @param vpcPeeringId The id of the subscription VPC peering
* @param expectedStatus The expected status
* @param timeoutInSeconds The timeout of waiting for the status. Default: 5 minutes
* @param sleepTimeInSeconds The sleep time between requests. Default: 5 seconds
*/
async waitForVpcPeeringStatus(subscriptionId: number, vpcPeeringId: number, expectedStatus: SubscriptionVpcPeeringStatus, timeoutInSeconds = 5 * 60, sleepTimeInSeconds = 5){
return await this.subscription.waitForVpcPeeringStatus(subscriptionId, vpcPeeringId, expectedStatus, timeoutInSeconds, sleepTimeInSeconds);
}
/**
* Waiting for database status to change to a given status
* @param subscriptionId The id of the subscription
* @param databaseId The id of the database
* @param expectedStatus The expected status
* @param timeoutInSeconds The timeout of waiting for the status. Default: 5 minutes
* @param sleepTimeInSeconds The sleep time between requests. Default: 5 seconds
*/
async waitForDatabaseStatus(subscriptionId: number, databaseId: number, expectedStatus: DatabaseStatus, timeoutInSeconds = 5 * 60, sleepTimeInSeconds = 5) {
return await this.database.waitForDatabaseStatus(subscriptionId, databaseId, expectedStatus, timeoutInSeconds, sleepTimeInSeconds);
}
/**
* Waiting for all databases status under subscription to change to the expected status
* @param subscriptionId The id of the subscription
* @param expectedStatus The expected status
* @param timeoutInSeconds The timeout of waiting for the status. Default: 5 minutes
* @param sleepTimeInSeconds The sleep time between requests. Default: 5 seconds
*/
async waitForSubscriptionDatabasesStatus(subscriptionId: number, expectedStatus: DatabaseStatus = 'active', timeoutInSeconds = 5 * 60, sleepTimeInSeconds = 5) {
return await this.database.waitForSubscriptionDatabasesStatus(subscriptionId, expectedStatus, timeoutInSeconds, sleepTimeInSeconds)
}
/**
* Waiting for cloud account status to change to a given status
* @param cloudAccountId The id of the cloud account
* @param expectedStatus The expected status
* @param timeoutInSeconds The timeout of waiting for the status. Default: 5 minutes
* @param sleepTimeInSeconds The sleep time between requests. Default: 5 seconds
*/
async waitForCloudAccountStatus(cloudAccountId: number, expectedStatus: CloudAccountStatus, timeoutInSeconds = 5 * 60, sleepTimeInSeconds = 5) {
return await this.cloudAccount.waitForCloudAccountStatus(cloudAccountId, expectedStatus, timeoutInSeconds, sleepTimeInSeconds);
}
/**
* Waiting for task status to change to a given status
* @param taskId The id of the task
* @param expectedStatus The expected status
* @param timeoutInSeconds The timeout of waiting for the status. Default: 20 minutes
* @param sleepTimeInSeconds The sleep time between requests. Default: 5 seconds
*/
async waitForTaskStatus(taskId: number, expectedStatus: TaskStatus, timeoutInSeconds = 20 * 60, sleepTimeInSeconds = 5): Promise<TaskObject & {[key: string]: any}> {
return await this.task.waitForTaskStatus(taskId, expectedStatus, timeoutInSeconds, sleepTimeInSeconds)
}
}
/**
* The parameters used to initialize the constructor
* @param accessKey Required. The Cloud API access key
* @param secretKey Required. The Cloud API secret key
* @param protocol Optional. The protocol of the API url
* @param domain Optional. The domain of the API url
* @param version Optional. The version of the API
* @param debug Optional. Ability to show extra debug logs
*/
export interface CloudAPISDKParameters {
accessKey: string,
secretKey: string,
protocol?: string,
domain?: string,
version?: string,
debug?: boolean
}
type Error = {
config: {
url: string,
method: string,
headers: {[key: string]: any},
baseURL: string,
[key: string]: any
},
request: {[key: string]: any},
response: {
status: string | number,
statusText: string,
headers: {[key: string]: any},
config: {
url: string,
method: string,
headers: {[key: string]: any},
baseURL: string,
[key: string]: any
},
request: {[key: string]: any},
data: string,
[key: string]: any
},
[key: string]: any
}