forked from leopardslab/nodecloud-aws-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
163 lines (160 loc) · 3.92 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
const awsSDk = require('aws-sdk');
const EC2 = require('./compute/aws-ec2');
const ECS = require('./compute/aws-ecs');
const EBS = require('./storage/aws-ebs');
const S3 = require('./storage/aws-s3');
const ELB = require('./network/aws-elb');
const Route53 = require('./network/aws-route53');
const DirectConnect = require('./network/aws-directconnect');
const RDS = require('./database/aws-rds');
const DynamoDB = require('./database/aws-dynamodb');
const IAM = require('./security/aws-iam');
class AWS {
/**
* Expose AWS APIs
* @constructor
*/
constructor(configPath) {
this._AWS = awsSDk;
if (
!this._AWS.config.credentials ||
!this._AWS.config.credentials.accessKeyId ||
!this._AWS.config.credentials.secretAccessKey ||
!process.env.AWS_REGION
) {
if (configPath) {
this._AWS.config.loadFromPath(configPath);
} else {
throw new Error('Provide credentials <link to docs>');
}
}
return {
getSDK: () => this._AWS,
compute: this.EC2,
storage: this.EBS,
bucket: this.S3,
loadbalancer: this.ELB,
dns: this.Route53,
peering: this.DirectConnect,
container: this.ECS,
rdbms: this.RDS,
nosql: this.DynamoDB,
iam: this.IAM,
};
}
/**
* EC2 Wrapper
* @EC2
* @param {object} options - { apiVersion }
*/
EC2(options) {
this._apiVersion = options.apiVersion;
return new EC2(this.getSDK(), this._apiVersion);
}
/**
* EBS Wrapper
* @EBS
* @param {object} options - { apiVersion }
*/
EBS(options) {
this._apiVersion = options.apiVersion;
return new EBS(this.getSDK(), this._apiVersion);
}
/**
* S3 Wrapper
* @EBS
* @param {object} options - { apiVersion }
*/
S3(options) {
if (options._apiVersion) {
this._apiVersion = options.apiVersion;
return new S3(this.getSDK(), this.apiVersion);
}
return new S3(this.getSDK());
}
/**
* ELB Wrapper
* @ELB
* @param {object} options - { apiVersion }
*/
ELB(options) {
if (options._apiVersion) {
this._apiVersion = options.apiVersion;
return new ELB(this.getSDK(), this.apiVersion);
}
return new ELB(this.getSDK());
}
/**
* Route53 wrapper
* @Route53
* @param {object} options - { apiVersion }
*/
Route53(options) {
if (options._apiVersion) {
this._apiVersion = options.apiVersion;
return new Route53(this.getSDK(), this.apiVersion);
}
return new Route53(this.getSDK());
}
/**
* DirectConnect wrapper
* @DirectConnect
* @param {object} options - { apiVersion }
*/
DirectConnect(options) {
if (options._apiVersion) {
this._apiVersion = options.apiVersion;
return new DirectConnect(this.getSDK(), this.apiVersion);
}
return new DirectConnect(this.getSDK());
}
/**
* ECS wrapper
* @ECS
* @param {object} options - { apiVersion }
*/
ECS(options) {
if (options._apiVersion) {
this._apiVersion = options.apiVersion;
return new ECS(this.getSDK(), this.apiVersion);
}
return new ECS(this.getSDK());
}
/**
* RDS wrapper
* @RDS
* @param {object} options - { apiVersion }
*/
RDS(options) {
if (options._apiVersion) {
this._apiVersion = options.apiVersion;
return new RDS(this.getSDK(), this.apiVersion);
}
return new RDS(this.getSDK());
}
/**
* DynamoDB wrapper
* @RDS
* @param {object} options - { apiVersion }
*/
DynamoDB(options) {
if (options._apiVersion) {
this._apiVersion = options.apiVersion;
return new DynamoDB(this.getSDK(), this.apiVersion);
}
return new DynamoDB(this.getSDK());
}
/**
* IAM wrapper
* @IAM
* @param {object} options - { apiVersion }
*/
IAM(options) {
if (options.apiVersion) {
this._apiVersion = options.apiVersion;
return new IAM(this.getSDK(), options);
}
return new IAM(this.getSDK());
}
}
module.exports = AWS;