@webda/aws 4.0.0-beta.1 → 4.0.0-beta.3
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/README.md +64 -7
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js.map +1 -1
- package/lib/services/aws-parameters.d.ts +33 -0
- package/lib/services/aws-parameters.d.ts.map +1 -0
- package/lib/services/aws-parameters.js +18 -0
- package/lib/services/aws-parameters.js.map +1 -0
- package/lib/services/awscommands.service.d.ts +39 -0
- package/lib/services/awscommands.service.d.ts.map +1 -0
- package/lib/services/awscommands.service.js +127 -0
- package/lib/services/awscommands.service.js.map +1 -0
- package/lib/services/cloudwatchlogger.service.d.ts +131 -0
- package/lib/services/cloudwatchlogger.service.d.ts.map +1 -0
- package/lib/services/{cloudwatchlogger.js → cloudwatchlogger.service.js} +66 -34
- package/lib/services/cloudwatchlogger.service.js.map +1 -0
- package/lib/services/contributors.d.ts +37 -0
- package/lib/services/contributors.d.ts.map +1 -0
- package/lib/services/contributors.js +2 -0
- package/lib/services/contributors.js.map +1 -0
- package/lib/services/dynamodb.service.d.ts +297 -0
- package/lib/services/dynamodb.service.d.ts.map +1 -0
- package/lib/services/dynamodb.service.js +985 -0
- package/lib/services/dynamodb.service.js.map +1 -0
- package/lib/services/index.d.ts +12 -31
- package/lib/services/index.d.ts.map +1 -0
- package/lib/services/index.js +11 -8
- package/lib/services/index.js.map +1 -1
- package/lib/services/lambdacaller.service.d.ts +81 -0
- package/lib/services/lambdacaller.service.d.ts.map +1 -0
- package/lib/services/lambdacaller.service.js +75 -0
- package/lib/services/lambdacaller.service.js.map +1 -0
- package/lib/services/lambdaserver.service.d.ts +127 -0
- package/lib/services/lambdaserver.service.d.ts.map +1 -0
- package/lib/services/lambdaserver.service.js +294 -0
- package/lib/services/lambdaserver.service.js.map +1 -0
- package/lib/services/{route53.d.ts → route53.service.d.ts} +21 -11
- package/lib/services/route53.service.d.ts.map +1 -0
- package/lib/services/{route53.js → route53.service.js} +35 -38
- package/lib/services/route53.service.js.map +1 -0
- package/lib/services/s3binary.service.d.ts +215 -0
- package/lib/services/s3binary.service.d.ts.map +1 -0
- package/lib/services/{s3binary.js → s3binary.service.js} +113 -74
- package/lib/services/s3binary.service.js.map +1 -0
- package/lib/services/secretsmanager.service.d.ts +102 -0
- package/lib/services/secretsmanager.service.d.ts.map +1 -0
- package/lib/services/{secretsmanager.js → secretsmanager.service.js} +42 -24
- package/lib/services/secretsmanager.service.js.map +1 -0
- package/lib/services/{sqsqueue.d.ts → sqsqueue.service.d.ts} +60 -34
- package/lib/services/sqsqueue.service.d.ts.map +1 -0
- package/lib/services/{sqsqueue.js → sqsqueue.service.js} +60 -35
- package/lib/services/sqsqueue.service.js.map +1 -0
- package/package.json +59 -65
- package/webda.module.json +738 -377
- package/lib/deployers/cloudformation.d.ts +0 -316
- package/lib/deployers/cloudformation.js +0 -837
- package/lib/deployers/cloudformation.js.map +0 -1
- package/lib/deployers/cloudformation.spec.d.ts +0 -1
- package/lib/deployers/cloudformation.spec.js +0 -530
- package/lib/deployers/cloudformation.spec.js.map +0 -1
- package/lib/deployers/index.d.ts +0 -254
- package/lib/deployers/index.js +0 -543
- package/lib/deployers/index.js.map +0 -1
- package/lib/deployers/index.spec.d.ts +0 -8
- package/lib/deployers/index.spec.js +0 -595
- package/lib/deployers/index.spec.js.map +0 -1
- package/lib/deployers/lambda-entrypoint.d.ts +0 -1
- package/lib/deployers/lambda-entrypoint.js +0 -11
- package/lib/deployers/lambda-entrypoint.js.map +0 -1
- package/lib/deployers/lambdapackager.d.ts +0 -27
- package/lib/deployers/lambdapackager.js +0 -26
- package/lib/deployers/lambdapackager.js.map +0 -1
- package/lib/deployers/lambdapackager.spec.d.ts +0 -1
- package/lib/deployers/lambdapackager.spec.js +0 -44
- package/lib/deployers/lambdapackager.spec.js.map +0 -1
- package/lib/index.spec.d.ts +0 -10
- package/lib/index.spec.js +0 -42
- package/lib/index.spec.js.map +0 -1
- package/lib/services/aws-mixin.d.ts +0 -24
- package/lib/services/aws-mixin.js +0 -18
- package/lib/services/aws-mixin.js.map +0 -1
- package/lib/services/cloudwatchlogger.d.ts +0 -81
- package/lib/services/cloudwatchlogger.js.map +0 -1
- package/lib/services/cloudwatchlogger.spec.d.ts +0 -1
- package/lib/services/cloudwatchlogger.spec.js +0 -104
- package/lib/services/cloudwatchlogger.spec.js.map +0 -1
- package/lib/services/dynamodb.d.ts +0 -173
- package/lib/services/dynamodb.js +0 -711
- package/lib/services/dynamodb.js.map +0 -1
- package/lib/services/dynamodb.spec.d.ts +0 -23
- package/lib/services/dynamodb.spec.js +0 -339
- package/lib/services/dynamodb.spec.js.map +0 -1
- package/lib/services/lambdacaller.d.ts +0 -68
- package/lib/services/lambdacaller.js +0 -63
- package/lib/services/lambdacaller.js.map +0 -1
- package/lib/services/lambdacaller.spec.d.ts +0 -1
- package/lib/services/lambdacaller.spec.js +0 -70
- package/lib/services/lambdacaller.spec.js.map +0 -1
- package/lib/services/lambdaserver.d.ts +0 -86
- package/lib/services/lambdaserver.js +0 -264
- package/lib/services/lambdaserver.js.map +0 -1
- package/lib/services/lambdaserver.spec.d.ts +0 -1
- package/lib/services/lambdaserver.spec.js +0 -417
- package/lib/services/lambdaserver.spec.js.map +0 -1
- package/lib/services/route53.js.map +0 -1
- package/lib/services/route53.spec.d.ts +0 -1
- package/lib/services/route53.spec.js +0 -102
- package/lib/services/route53.spec.js.map +0 -1
- package/lib/services/s3binary.d.ts +0 -162
- package/lib/services/s3binary.js.map +0 -1
- package/lib/services/s3binary.spec.d.ts +0 -1
- package/lib/services/s3binary.spec.js +0 -269
- package/lib/services/s3binary.spec.js.map +0 -1
- package/lib/services/secretsmanager.d.ts +0 -80
- package/lib/services/secretsmanager.js.map +0 -1
- package/lib/services/secretsmanager.spec.d.ts +0 -1
- package/lib/services/secretsmanager.spec.js +0 -66
- package/lib/services/secretsmanager.spec.js.map +0 -1
- package/lib/services/sqsqueue.js.map +0 -1
- package/lib/services/sqsqueue.spec.d.ts +0 -1
- package/lib/services/sqsqueue.spec.js +0 -152
- package/lib/services/sqsqueue.spec.js.map +0 -1
- package/lib/shell.d.ts +0 -12
- package/lib/shell.js +0 -42
- package/lib/shell.js.map +0 -1
- package/webda.shell.json +0 -11
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { emitCoreEvent, HttpContext, runWithContext, Service, ServiceParameters, useCore, useRouter, WebContext, WebdaError } from "@webda/core";
|
|
2
|
+
import { serialize as cookieSerialize } from "cookie";
|
|
3
|
+
/**
|
|
4
|
+
* LambdaServer parameters
|
|
5
|
+
*/
|
|
6
|
+
export class LambdaServerParameters extends ServiceParameters {
|
|
7
|
+
/**
|
|
8
|
+
* @override
|
|
9
|
+
* @param params - raw parameters
|
|
10
|
+
* @returns this
|
|
11
|
+
*/
|
|
12
|
+
load(params = {}) {
|
|
13
|
+
super.load(params);
|
|
14
|
+
this.waitForEmptyEventLoop ?? (this.waitForEmptyEventLoop = false);
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The Lambda entrypoint for Webda
|
|
20
|
+
*
|
|
21
|
+
* This take the input coming from the API Gateway to transform it and analyse it with Webda
|
|
22
|
+
* Once execution is done, it will format the result in a way that the API Gateway will output the result
|
|
23
|
+
*
|
|
24
|
+
* Other AWS events are dispatched to the services implementing {@link AWSEventsHandler}
|
|
25
|
+
*
|
|
26
|
+
* @WebdaModda
|
|
27
|
+
*/
|
|
28
|
+
export class LambdaServer extends Service {
|
|
29
|
+
constructor() {
|
|
30
|
+
super(...arguments);
|
|
31
|
+
/**
|
|
32
|
+
* Handlers registered manually
|
|
33
|
+
*/
|
|
34
|
+
this._awsEventsHandlers = [];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Register a service to handle AWS Events
|
|
38
|
+
*
|
|
39
|
+
* Services implementing {@link AWSEventsHandler} are discovered automatically
|
|
40
|
+
* @param service - the handler
|
|
41
|
+
*/
|
|
42
|
+
registerAWSEventsHandler(service) {
|
|
43
|
+
if (this._awsEventsHandlers.indexOf(service) < 0) {
|
|
44
|
+
this._awsEventsHandlers.push(service);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Return all the AWS events handlers: the registered ones and the services implementing the interface
|
|
49
|
+
* @returns the handlers
|
|
50
|
+
*/
|
|
51
|
+
getAWSEventsHandlers() {
|
|
52
|
+
const handlers = [...this._awsEventsHandlers];
|
|
53
|
+
for (const service of Object.values(useCore()?.getServices() ?? {})) {
|
|
54
|
+
const handler = service;
|
|
55
|
+
if (typeof handler?.isAWSEventHandled === "function" &&
|
|
56
|
+
typeof handler?.handleAWSEvent === "function" &&
|
|
57
|
+
!handlers.includes(handler)) {
|
|
58
|
+
handlers.push(handler);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return handlers;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Dispatch an event to the handlers
|
|
65
|
+
* @param source - the event source
|
|
66
|
+
* @param events - the raw event
|
|
67
|
+
*/
|
|
68
|
+
async handleAWSEvent(source, events) {
|
|
69
|
+
for (const handler of this.getAWSEventsHandlers()) {
|
|
70
|
+
if (handler.isAWSEventHandled(source, events)) {
|
|
71
|
+
await handler.handleAWSEvent(source, events);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Analyse events to try to find its type
|
|
77
|
+
* @param events - the raw event
|
|
78
|
+
* @returns true if the event was an AWS event
|
|
79
|
+
*/
|
|
80
|
+
async handleAWSEvents(events) {
|
|
81
|
+
if (events.Records) {
|
|
82
|
+
await this.handleAWSEvent(events.Records[0].eventSource || events.Records[0].EventSource, events);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
else if (events.invocationId && events.records) {
|
|
86
|
+
await this.handleAWSEvent("aws:kinesis", events);
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
else if (events["detail-type"] && events.detail && events.resources) {
|
|
90
|
+
await this.handleAWSEvent("aws:scheduled-event", events);
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
else if (events.awslogs) {
|
|
94
|
+
await this.handleAWSEvent("aws:cloudwatch-logs", events);
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
else if (events["CodePipeline.job"]) {
|
|
98
|
+
await this.handleAWSEvent("aws:codepipeline", events);
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
else if (events.identityPoolId) {
|
|
102
|
+
await this.handleAWSEvent("aws:cognito", events);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
else if (events.configRuleId) {
|
|
106
|
+
await this.handleAWSEvent("aws:config", events);
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
else if (events.jobDefinition || events.jobId) {
|
|
110
|
+
await this.handleAWSEvent("aws:batch", events);
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Execute a `launch` command: call a method on a service
|
|
117
|
+
* @param commandEvent - the command
|
|
118
|
+
*/
|
|
119
|
+
async handleLaunch(commandEvent) {
|
|
120
|
+
const args = commandEvent.args || [];
|
|
121
|
+
this.log("INFO", "Executing", commandEvent.method, "on", commandEvent.service, "with", args);
|
|
122
|
+
const service = useCore().getServices()[commandEvent.service];
|
|
123
|
+
if (!service) {
|
|
124
|
+
this.log("ERROR", "Cannot find", commandEvent.service);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (typeof service[commandEvent.method] !== "function") {
|
|
128
|
+
this.log("ERROR", "Cannot find method", commandEvent.method, "on", commandEvent.service);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
await service[commandEvent.method](...args);
|
|
132
|
+
this.log("INFO", "Finished");
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Handle a Lambda invocation
|
|
136
|
+
*
|
|
137
|
+
* Dispatch AWS events, `launch` commands or API Gateway requests
|
|
138
|
+
*
|
|
139
|
+
* @param sourceEvent - the Lambda event
|
|
140
|
+
* @param context - the Lambda context
|
|
141
|
+
* @returns the API Gateway result for HTTP requests
|
|
142
|
+
*/
|
|
143
|
+
async handleRequest(sourceEvent, context) {
|
|
144
|
+
// Handle AWS event
|
|
145
|
+
if (await this.handleAWSEvents(sourceEvent)) {
|
|
146
|
+
this.log("INFO", "Handled AWS event", sourceEvent);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
// Manual launch of webda
|
|
150
|
+
if (sourceEvent.command === "launch" && sourceEvent.service && sourceEvent.method) {
|
|
151
|
+
await this.handleLaunch(sourceEvent);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const event = sourceEvent;
|
|
155
|
+
if (context) {
|
|
156
|
+
context.callbackWaitsForEmptyEventLoop = this.parameters.waitForEmptyEventLoop;
|
|
157
|
+
}
|
|
158
|
+
const headers = event.headers || {};
|
|
159
|
+
const vhost = headers.Host || headers.host;
|
|
160
|
+
const method = event.httpMethod || "GET";
|
|
161
|
+
const protocol = headers["CloudFront-Forwarded-Proto"] || "https";
|
|
162
|
+
let port = headers["X-Forwarded-Port"] || 443;
|
|
163
|
+
if (typeof port === "string") {
|
|
164
|
+
port = Number(port);
|
|
165
|
+
if (isNaN(port)) {
|
|
166
|
+
port = 443;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
let resourcePath = event.path || "/";
|
|
170
|
+
// Rebuild query string
|
|
171
|
+
if (event.queryStringParameters) {
|
|
172
|
+
let sep = "?";
|
|
173
|
+
for (const i in event.queryStringParameters) {
|
|
174
|
+
// If additional error code it will be contained so need to check for &
|
|
175
|
+
// May need to add urlencode
|
|
176
|
+
resourcePath += sep + i + "=" + event.queryStringParameters[i];
|
|
177
|
+
sep = "&";
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
this.log("INFO", method, event.path);
|
|
181
|
+
const httpContext = new HttpContext(vhost, method, resourcePath, protocol, port, headers).setClientIp(headers["X-Real-Ip"]); // Might use identity.sourceIp
|
|
182
|
+
// API Gateway stage or custom domain base path: the router matches on the uri relative to it
|
|
183
|
+
this.computePrefix(event, httpContext);
|
|
184
|
+
if (["PUT", "PATCH", "POST", "DELETE"].includes(method)) {
|
|
185
|
+
httpContext.setBody(event.body);
|
|
186
|
+
}
|
|
187
|
+
const ctx = new WebContext(httpContext);
|
|
188
|
+
await ctx.init();
|
|
189
|
+
await emitCoreEvent("Webda.NewContext", { context: ctx, info: { http: httpContext } });
|
|
190
|
+
await runWithContext(ctx, async () => {
|
|
191
|
+
emitCoreEvent("Webda.Request", { context: ctx });
|
|
192
|
+
if (this.parameters.lambdaRequestHeader && context?.awsRequestId) {
|
|
193
|
+
ctx.setHeader(this.parameters.lambdaRequestHeader, context.awsRequestId);
|
|
194
|
+
}
|
|
195
|
+
const origin = headers.Origin || headers.origin;
|
|
196
|
+
try {
|
|
197
|
+
// Set predefined headers for CORS
|
|
198
|
+
if (origin) {
|
|
199
|
+
if (!(await useRouter()["checkCORSRequest"](ctx))) {
|
|
200
|
+
// Prevent CSRF
|
|
201
|
+
this.log("INFO", "CSRF denied from", origin);
|
|
202
|
+
ctx.statusCode = 401;
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
ctx.setHeader("Access-Control-Allow-Origin", origin);
|
|
206
|
+
ctx.setHeader("Access-Control-Allow-Credentials", "true");
|
|
207
|
+
}
|
|
208
|
+
if (protocol === "https") {
|
|
209
|
+
// Add the HSTS header
|
|
210
|
+
ctx.setHeader("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload");
|
|
211
|
+
}
|
|
212
|
+
if (method === "OPTIONS") {
|
|
213
|
+
// Might want to customize this one
|
|
214
|
+
ctx.setHeader("Access-Control-Max-Age", 3600);
|
|
215
|
+
ctx.setHeader("Access-Control-Allow-Headers", headers["access-control-request-headers"] || headers["Access-Control-Request-Headers"] || "content-type");
|
|
216
|
+
}
|
|
217
|
+
await useRouter().execute(ctx);
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
if (typeof err === "number") {
|
|
221
|
+
ctx.statusCode = err;
|
|
222
|
+
}
|
|
223
|
+
else if (err instanceof WebdaError.HttpError) {
|
|
224
|
+
this.log("DEBUG", "Sending error", err.message);
|
|
225
|
+
ctx.statusCode = err.getResponseCode();
|
|
226
|
+
// Handle redirect
|
|
227
|
+
if (err instanceof WebdaError.Redirect) {
|
|
228
|
+
ctx.setHeader("Location", err.location);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
this.log("ERROR", err);
|
|
233
|
+
ctx.statusCode = 500;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
emitCoreEvent("Webda.Result", { context: ctx });
|
|
237
|
+
});
|
|
238
|
+
return this.handleLambdaReturn(ctx);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Based on API Gateway event compute the prefix if any
|
|
242
|
+
* @param event - the API Gateway event
|
|
243
|
+
* @returns the prefix or an empty string
|
|
244
|
+
*/
|
|
245
|
+
getPrefix(event) {
|
|
246
|
+
if (event.resource && event.path !== event.resource) {
|
|
247
|
+
let relativeUri = event.resource;
|
|
248
|
+
for (const j in event.pathParameters) {
|
|
249
|
+
relativeUri = relativeUri.replace(new RegExp(`\\{${j}\\+?\\}`), event.pathParameters[j]);
|
|
250
|
+
}
|
|
251
|
+
if (relativeUri !== event.path && event.path.endsWith(relativeUri)) {
|
|
252
|
+
return event.path.substring(0, event.path.length - relativeUri.length);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return "";
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Based on API Gateway event set the prefix on the http context if any
|
|
259
|
+
* @param event - the API Gateway event
|
|
260
|
+
* @param httpContext - the context to update
|
|
261
|
+
*/
|
|
262
|
+
computePrefix(event, httpContext) {
|
|
263
|
+
const prefix = this.getPrefix(event);
|
|
264
|
+
if (prefix) {
|
|
265
|
+
httpContext.setPrefix(prefix);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* End the context and build the API Gateway result from it
|
|
270
|
+
* @param context - the web context
|
|
271
|
+
* @returns the API Gateway result
|
|
272
|
+
*/
|
|
273
|
+
async handleLambdaReturn(context) {
|
|
274
|
+
// Ending the context flushes (and resets) the headers
|
|
275
|
+
const headers = { ...(context.getResponseHeaders() || {}) };
|
|
276
|
+
await context.end();
|
|
277
|
+
const result = {
|
|
278
|
+
headers: { ...headers, ...(context.getResponseHeaders() || {}) },
|
|
279
|
+
statusCode: context.getResponseCode(),
|
|
280
|
+
multiValueHeaders: { "Set-Cookie": [] }
|
|
281
|
+
};
|
|
282
|
+
const cookies = context.getResponseCookies();
|
|
283
|
+
for (const i in cookies) {
|
|
284
|
+
result.multiValueHeaders["Set-Cookie"].push(cookieSerialize(cookies[i].name, cookies[i].value, cookies[i].options || {}));
|
|
285
|
+
}
|
|
286
|
+
const body = context.getResponseBody();
|
|
287
|
+
if (body !== undefined && body !== false && body !== "") {
|
|
288
|
+
result.body = body.toString();
|
|
289
|
+
}
|
|
290
|
+
return result;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
export default LambdaServer;
|
|
294
|
+
//# sourceMappingURL=lambdaserver.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambdaserver.service.js","sourceRoot":"","sources":["../../src/services/lambdaserver.service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,WAAW,EAEX,cAAc,EACd,OAAO,EACP,iBAAiB,EACjB,OAAO,EACP,SAAS,EACT,UAAU,EACV,UAAU,EACX,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,QAAQ,CAAC;AAkCtD;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,iBAAiB;I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AAC;QACvC,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;YACxD,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import { HostedZone, RRType } from "@aws-sdk/client-route-53";
|
|
2
2
|
import { Service } from "@webda/core";
|
|
3
|
+
/**
|
|
4
|
+
* Route53 helpers to manage zones and records
|
|
5
|
+
*/
|
|
3
6
|
export declare class Route53Service extends Service {
|
|
4
7
|
/**
|
|
5
8
|
* Get the closest zone to the domain
|
|
6
9
|
*
|
|
7
10
|
* @param domain to get zone for
|
|
11
|
+
* @returns the closest hosted zone or undefined
|
|
12
|
+
*/
|
|
13
|
+
static getZoneForDomainName(domain: string): Promise<HostedZone>;
|
|
14
|
+
/**
|
|
15
|
+
* Ensure the domain ends with a dot
|
|
16
|
+
* @param domain - the domain
|
|
17
|
+
* @returns the fully qualified domain
|
|
8
18
|
*/
|
|
9
|
-
static getZoneForDomainName(domain: any): Promise<HostedZone>;
|
|
10
19
|
static completeDomain(domain: string): string;
|
|
11
20
|
/**
|
|
12
21
|
* Create DNS entry
|
|
@@ -14,24 +23,30 @@ export declare class Route53Service extends Service {
|
|
|
14
23
|
* @param domain to create
|
|
15
24
|
* @param type of DNS
|
|
16
25
|
* @param value the value of the record
|
|
17
|
-
* @param targetZone
|
|
26
|
+
* @param targetZone - zone to use, default to the closest zone
|
|
27
|
+
* @param Comment - comment of the change
|
|
18
28
|
*/
|
|
19
29
|
static createDNSEntry(domain: string, type: RRType, value: string, targetZone?: HostedZone, Comment?: string): Promise<void>;
|
|
20
30
|
/**
|
|
21
31
|
* Return all entries of a zone in AWS
|
|
22
32
|
*
|
|
23
33
|
* @param domain to retrieve from
|
|
34
|
+
* @returns the record sets
|
|
24
35
|
*/
|
|
25
36
|
static getEntries(domain: string): Promise<any[]>;
|
|
26
37
|
/**
|
|
27
38
|
* Import all records to Route53
|
|
28
|
-
* @param
|
|
39
|
+
* @param options - import options
|
|
40
|
+
* @param options.file - the exported file to import
|
|
41
|
+
* @param options.pretend - only display the records that would be deleted
|
|
42
|
+
* @param options.sync - delete the records not present in the file
|
|
43
|
+
* @param log - logger to use
|
|
29
44
|
*/
|
|
30
45
|
static import(options: {
|
|
31
46
|
file: string;
|
|
32
47
|
pretend?: boolean;
|
|
33
48
|
sync?: boolean;
|
|
34
|
-
},
|
|
49
|
+
}, log?: (level: "INFO" | "ERROR", ...args: any[]) => void): Promise<void>;
|
|
35
50
|
/**
|
|
36
51
|
* Export all records from Route53 into a file
|
|
37
52
|
*
|
|
@@ -39,11 +54,6 @@ export declare class Route53Service extends Service {
|
|
|
39
54
|
* @param file to export to (can be .json or .yml)
|
|
40
55
|
*/
|
|
41
56
|
static export(domain: string, file: string): Promise<void>;
|
|
42
|
-
/**
|
|
43
|
-
* Manage the shell command
|
|
44
|
-
*
|
|
45
|
-
* @param Console
|
|
46
|
-
* @param args
|
|
47
|
-
*/
|
|
48
|
-
static shell(Console: any, args: any): Promise<void>;
|
|
49
57
|
}
|
|
58
|
+
export default Route53Service;
|
|
59
|
+
//# sourceMappingURL=route53.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route53.service.d.ts","sourceRoot":"","sources":["../../src/services/route53.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmD,MAAM,EAAW,MAAM,0BAA0B,CAAC;AACxH,OAAO,EAAE,OAAO,EAAU,MAAM,aAAa,CAAC;AAG9C;;GAEG;AACH,qBAAa,cAAe,SAAQ,OAAO;IACzC;;;;;OAKG;IACH,OAAa,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAuBrE;IAED;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,UAKnC;IAED;;;;;;;;OAQG;IACH,OAAa,cAAc,CACzB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,UAAU,GAAE,UAAsB,EAClC,OAAO,GAAE,MAA6B,GACrC,OAAO,CAAC,IAAI,CAAC,CA8Bf;IAED;;;;;OAKG;IACH,OAAa,UAAU,CAAC,MAAM,EAAE,MAAM,kBAgBrC;IAED;;;;;;;OAOG;IACH,OAAa,MAAM,CACjB,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,IAAI,CAAC,EAAE,OAAO,CAAC;KAChB,EACD,GAAG,GAAE,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAa,iBA8DhE;IAED;;;;;OAKG;IACH,OAAa,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAQ/C;CACF;eAEc,cAAc"}
|
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
import { Route53 } from "@aws-sdk/client-route-53";
|
|
2
|
-
import {
|
|
2
|
+
import { Service, useLog } from "@webda/core";
|
|
3
|
+
import { JSONUtils } from "@webda/utils";
|
|
4
|
+
/**
|
|
5
|
+
* Route53 helpers to manage zones and records
|
|
6
|
+
*/
|
|
3
7
|
export class Route53Service extends Service {
|
|
4
8
|
/**
|
|
5
9
|
* Get the closest zone to the domain
|
|
6
10
|
*
|
|
7
11
|
* @param domain to get zone for
|
|
12
|
+
* @returns the closest hosted zone or undefined
|
|
8
13
|
*/
|
|
9
14
|
static async getZoneForDomainName(domain) {
|
|
10
15
|
domain = this.completeDomain(domain);
|
|
11
16
|
let targetZone;
|
|
12
17
|
// Find the right zone
|
|
13
|
-
|
|
18
|
+
const r53 = new Route53({});
|
|
14
19
|
let res;
|
|
15
|
-
|
|
20
|
+
const params = {};
|
|
16
21
|
// Identify the right zone first
|
|
17
22
|
do {
|
|
18
23
|
res = await r53.listHostedZones(params);
|
|
19
|
-
for (
|
|
20
|
-
|
|
24
|
+
for (const i in res.HostedZones) {
|
|
25
|
+
const zone = res.HostedZones[i];
|
|
21
26
|
if (domain.endsWith(zone.Name)) {
|
|
22
27
|
if (targetZone && targetZone.Name.length > zone.Name.length) {
|
|
23
28
|
// The previous target zone is closer to the domain
|
|
@@ -30,6 +35,11 @@ export class Route53Service extends Service {
|
|
|
30
35
|
} while (!targetZone && res.NextMarker);
|
|
31
36
|
return targetZone;
|
|
32
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Ensure the domain ends with a dot
|
|
40
|
+
* @param domain - the domain
|
|
41
|
+
* @returns the fully qualified domain
|
|
42
|
+
*/
|
|
33
43
|
static completeDomain(domain) {
|
|
34
44
|
if (!domain.endsWith(".")) {
|
|
35
45
|
domain = domain + ".";
|
|
@@ -42,10 +52,11 @@ export class Route53Service extends Service {
|
|
|
42
52
|
* @param domain to create
|
|
43
53
|
* @param type of DNS
|
|
44
54
|
* @param value the value of the record
|
|
45
|
-
* @param targetZone
|
|
55
|
+
* @param targetZone - zone to use, default to the closest zone
|
|
56
|
+
* @param Comment - comment of the change
|
|
46
57
|
*/
|
|
47
58
|
static async createDNSEntry(domain, type, value, targetZone = undefined, Comment = "@webda/aws-created") {
|
|
48
|
-
|
|
59
|
+
const r53 = new Route53({});
|
|
49
60
|
domain = this.completeDomain(domain);
|
|
50
61
|
if (!targetZone) {
|
|
51
62
|
targetZone = await this.getZoneForDomainName(domain);
|
|
@@ -79,9 +90,10 @@ export class Route53Service extends Service {
|
|
|
79
90
|
* Return all entries of a zone in AWS
|
|
80
91
|
*
|
|
81
92
|
* @param domain to retrieve from
|
|
93
|
+
* @returns the record sets
|
|
82
94
|
*/
|
|
83
95
|
static async getEntries(domain) {
|
|
84
|
-
|
|
96
|
+
const r53 = new Route53({});
|
|
85
97
|
const zone = await Route53Service.getZoneForDomainName(domain);
|
|
86
98
|
if (!zone) {
|
|
87
99
|
throw new Error(`Domain '${domain}' is not handled on AWS`);
|
|
@@ -99,10 +111,14 @@ export class Route53Service extends Service {
|
|
|
99
111
|
}
|
|
100
112
|
/**
|
|
101
113
|
* Import all records to Route53
|
|
102
|
-
* @param
|
|
114
|
+
* @param options - import options
|
|
115
|
+
* @param options.file - the exported file to import
|
|
116
|
+
* @param options.pretend - only display the records that would be deleted
|
|
117
|
+
* @param options.sync - delete the records not present in the file
|
|
118
|
+
* @param log - logger to use
|
|
103
119
|
*/
|
|
104
|
-
static async import(options,
|
|
105
|
-
|
|
120
|
+
static async import(options, log = useLog) {
|
|
121
|
+
const data = JSONUtils.loadFile(options.file);
|
|
106
122
|
const targetZone = await this.getZoneForDomainName(data.domain);
|
|
107
123
|
const r53 = new Route53({});
|
|
108
124
|
if (!targetZone) {
|
|
@@ -130,9 +146,9 @@ export class Route53Service extends Service {
|
|
|
130
146
|
return;
|
|
131
147
|
}
|
|
132
148
|
let continuationToken;
|
|
133
|
-
|
|
149
|
+
const toDelete = [];
|
|
134
150
|
do {
|
|
135
|
-
|
|
151
|
+
const records = await r53.listResourceRecordSets({
|
|
136
152
|
HostedZoneId: targetZone.Id,
|
|
137
153
|
StartRecordIdentifier: continuationToken
|
|
138
154
|
});
|
|
@@ -141,13 +157,13 @@ export class Route53Service extends Service {
|
|
|
141
157
|
}));
|
|
142
158
|
continuationToken = records.NextRecordIdentifier;
|
|
143
159
|
} while (continuationToken);
|
|
144
|
-
|
|
160
|
+
log("INFO", `Deleting ${toDelete.length} records`);
|
|
145
161
|
if (options.pretend) {
|
|
146
162
|
toDelete.forEach(r => {
|
|
147
|
-
|
|
163
|
+
log("INFO", "Deleting entry\n", JSON.stringify(r, undefined, 2));
|
|
148
164
|
});
|
|
149
165
|
}
|
|
150
|
-
else {
|
|
166
|
+
else if (toDelete.length) {
|
|
151
167
|
await r53.changeResourceRecordSets({
|
|
152
168
|
HostedZoneId: targetZone.Id,
|
|
153
169
|
ChangeBatch: {
|
|
@@ -160,7 +176,7 @@ export class Route53Service extends Service {
|
|
|
160
176
|
}
|
|
161
177
|
}
|
|
162
178
|
catch (err) {
|
|
163
|
-
|
|
179
|
+
log("ERROR", err);
|
|
164
180
|
}
|
|
165
181
|
}
|
|
166
182
|
/**
|
|
@@ -175,25 +191,6 @@ export class Route53Service extends Service {
|
|
|
175
191
|
entries: await Route53Service.getEntries(domain)
|
|
176
192
|
}, file);
|
|
177
193
|
}
|
|
178
|
-
/**
|
|
179
|
-
* Manage the shell command
|
|
180
|
-
*
|
|
181
|
-
* @param Console
|
|
182
|
-
* @param args
|
|
183
|
-
*/
|
|
184
|
-
static async shell(Console, args) {
|
|
185
|
-
const command = args._.shift();
|
|
186
|
-
switch (command) {
|
|
187
|
-
case "import":
|
|
188
|
-
await this.import(args, Console);
|
|
189
|
-
break;
|
|
190
|
-
case "sync":
|
|
191
|
-
await this.import({ ...args, sync: true }, Console);
|
|
192
|
-
break;
|
|
193
|
-
case "export":
|
|
194
|
-
await this.export(args.domain, args.file);
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
194
|
}
|
|
199
|
-
|
|
195
|
+
export default Route53Service;
|
|
196
|
+
//# sourceMappingURL=route53.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route53.service.js","sourceRoot":"","sources":["../../src/services/route53.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,OAAO;IACzC;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,MAAc;QAC9C,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,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