generated from szikszail/npm-package
/
advanced-template.ts
495 lines (442 loc) · 16.7 KB
/
advanced-template.ts
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
import { Stack } from "aws-cdk-lib";
import { Template } from "aws-cdk-lib/assertions";
import { CloudFrontDistribution, CloudFrontFunction } from "./cloudfront";
import { S3Bucket, S3BucketPolicy } from "./s3";
import { Route53HostedZone, Route53RecordSet } from "./route53";
import { Dict, KeyAndProps } from "./types";
import { CloudFormationCustomResource } from "./cloudformation";
import { CodeBuildProject, CodeBuildSourceCredentials } from "./codebuild";
import { CustomResource } from "./custom";
import { DynamoDBTable } from "./dynamodb";
import { SSMParameter } from "./ssm";
import { WafV2WebACL } from "./wafv2";
import { IAMPolicy, IAMRole } from "./iam";
import { LambdaFunction, LambdaPermission } from "./lambda";
import { Resource } from "./resource";
import { RemovableResource } from ".";
import { LogGroup } from "./logs";
import { ApiGatewayAccount, ApiGatewayApiKey, ApiGatewayBasePathMapping, ApiGatewayDeployment, ApiGatewayDomain, ApiGatewayMethod, ApiGatewayResource, ApiGatewayRestApi, ApiGatewayStage, ApiGatewayUsagePlan, ApiGatewayUsagePlanKey } from "./apigateway";
import { Secret } from "./secretsmanager";
/**
* CloudFormation/CDK template assertion class,
* based on {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html|AWS CDK Assertions Template}
*/
export class AdvancedTemplate {
/**
* @member The parsed template
*/
private template: Template;
/**
* @member The region of the stack
*/
public region: string;
/**
* @param template The parsed template
* @param region The region of the stack
*/
constructor(template: Template, region?: string) {
this.template = template;
this.region = region;
}
/**
* Parses a template from the CDK stack instance.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#static-fromwbrstackstack}
*
* @param stack The stack instance
* @returns
*/
public static fromStack(stack: Stack): AdvancedTemplate {
return new AdvancedTemplate(Template.fromStack(stack), stack.region);
}
/**
* Parses a template from the CloudFormation template JSON.
* @ee {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#static-fromwbrjsontemplate}
*
* @param template The CloudFormation template, formatted as a nested set of records.
* @param region The region of the stack.
* @returns
*/
public static fromJSON(template: Dict, region?: string): AdvancedTemplate {
return new AdvancedTemplate(Template.fromJSON(template), region);
}
/**
* Parses a template from the CloudFormation template.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#static-fromwbrstringtemplate}
*
* @param template The CloudFormation template.
* @param region The region of the stack
* @returns
*/
public static fromString(template: string, region?: string): AdvancedTemplate {
return new AdvancedTemplate(Template.fromString(template), region);
}
/**
* Returns the Conditions matching with the passed properties.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#findwbrconditionslogicalid-props}
*/
public findConditions(logicalId: string, props?: any): KeyAndProps {
return this.template.findConditions(logicalId, props);
}
/**
* Returns the Mapping matching with the passed properties.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#findwbrmappingslogicalid-props}
*/
public findMappings(logicalId: string, props?: any): KeyAndProps {
return this.template.findMappings(logicalId, props);
}
/**
* Returns the Outputs matching with the passed properties.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#findwbroutputslogicalid-props}
*/
public findOutputs(logicalId: string, props?: any): KeyAndProps {
return this.template.findOutputs(logicalId, props);
}
/**
* Returns the Parameters matching with the passed properties.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#findwbrparameterslogicalid-props}
*/
public findParameters(logicalId: string, props?: any): KeyAndProps {
return this.template.findParameters(logicalId, props);
}
/**
* Returns the Resources of type matching with the passed properties.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#findwbrresourcestype-props}
*/
public findResources(type: string, props?: any): KeyAndProps {
return this.template.findResources(type, props);
}
/**
* Checks if there is a Condition matching the passed properties.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#haswbrconditionlogicalid-props}
*/
public hasCondition(logicalId: string, props: any): void {
this.template.hasCondition(logicalId, props);
}
/**
* Checks if there is a Mapping matching the passed properties.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#haswbrmappinglogicalid-props}
*/
public hasMapping(logicalId: string, props: any): void {
this.template.hasMapping(logicalId, props);
}
/**
* Checks if there is an Output matching the passed properties.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#haswbroutputlogicalid-props}
*/
public hasOutput(logicalId: string, props: any): void {
this.template.hasOutput(logicalId, props);
}
/**
* Checks if there is a Parameter matching the passed properties.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#haswbrparameterlogicalid-props}
*/
public hasParameter(logicalId: string, props: any): void {
this.template.hasParameter(logicalId, props);
}
/**
* Checks if there is a Resource matching the passed definition.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#haswbrresourcetype-props}
*/
public hasResource(type: string, props: any): void {
this.template.hasResource(type, props);
}
/**
* Checks if there is a Resource matching the passed properties.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#haswbrresourcewbrpropertiestype-props}
*/
public hasResourceProperties(type: string, props: any): void {
this.template.hasResourceProperties(type, props);
}
/**
* Checks if the count of the Resources of type is the passed one.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#resourcewbrcountwbristype-count}
*/
public resourceCountIs(type: string, count: number): void {
this.template.resourceCountIs(type, count);
}
/**
* Checks if the template matches the passed CloudFormation JSON template.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#templatewbrmatchesexpected}
*/
public templateMatches(expected: AdvancedTemplate | KeyAndProps): void {
if (expected instanceof AdvancedTemplate) {
this.templateMatches(expected.toJSON());
} else {
this.template.templateMatches(expected);
}
}
/**
* Returns the CloudFormation JSON template of the current one.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.assertions.Template.html#towbrjson}
*/
public toJSON(): Dict {
return this.template.toJSON();
}
/**
* Logs the CloudFormation JSON to the console.
*/
public debug(): void {
console.log(JSON.stringify(this.toJSON(), null, 2));
}
////////////////////////////////////////////////////////////////////////////
// TEST CONSTRUCTS
////////////////////////////////////////////////////////////////////////////
/**
* Creates a general Resource test construct with the passed type and properties.
* @param type The CloudFormation resource type
* @param props The properties of the expected test construct
* @returns
*/
public resource(type: string, props?: any): Resource {
return new Resource(type, this, props);
}
/**
* Creates a general RemovableResource test construct with the passed type and properties.
* @param type The CloudFormation resource type
* @param props The properties of the expected test construct
* @returns
*/
public removableResource(type: string, props?: any): RemovableResource {
return new RemovableResource(type, this, props);
}
/**
* Creates an API Gateway Account test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public apiGatewayAccount(props?: any): ApiGatewayAccount {
return new ApiGatewayAccount(this, props);
}
/**
* Creates an API Gateway API Key test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public apiGatewayApiKey(props?: any): ApiGatewayApiKey {
return new ApiGatewayApiKey(this, props);
}
/**
* Creates an API Gateway Base Path Mapping test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public apiGatewayBasePathMapping(props?: any): ApiGatewayBasePathMapping {
return new ApiGatewayBasePathMapping(this, props);
}
/**
* Creates an API Gateway Deployment test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public apiGatewayDeployment(props?: any): ApiGatewayDeployment {
return new ApiGatewayDeployment(this, props);
}
/**
* Creates an API Gateway Domain test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public apiGatewayDomain(props?: any): ApiGatewayDomain {
return new ApiGatewayDomain(this, props);
}
/**
* Creates an API Gateway Method test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public apiGatewayMethod(props?: any): ApiGatewayMethod {
return new ApiGatewayMethod(this, props);
}
/**
* Creates an API Gateway Resource test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public apiGatewayResource(props?: any): ApiGatewayResource {
return new ApiGatewayResource(this, props);
}
/**
* Creates an API Gateway REST API test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public apiGatewayRestApi(props?: any): ApiGatewayRestApi {
return new ApiGatewayRestApi(this, props);
}
/**
* Creates an API Gateway Stage test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public apiGatewayStage(props?: any): ApiGatewayStage {
return new ApiGatewayStage(this, props);
}
/**
* Creates an API Gateway Usage Plan test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public apiGatewayUsagePlan(props?: any): ApiGatewayUsagePlan {
return new ApiGatewayUsagePlan(this, props);
}
/**
* Creates an API Gateway Usage Plan Key test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public apiGatewayUsagePlanKey(props?: any): ApiGatewayUsagePlanKey {
return new ApiGatewayUsagePlanKey(this, props);
}
/**
* Creates a CloudFormation CustomResource test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public cloudFormationCustomResource(props?: any): CloudFormationCustomResource {
return new CloudFormationCustomResource(this, props);
}
/**
* Creates a CloudFront Distribution test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public cloudFrontDistribution(props?: any): CloudFrontDistribution {
return new CloudFrontDistribution(this, props);
}
/**
* Creates a CloudFront Function test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public cloudFrontFunction(props?: any): CloudFrontFunction {
return new CloudFrontFunction(this, props);
}
/**
* Creates a CodeBuild Project test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public codeBuildProject(props?: any): CodeBuildProject {
return new CodeBuildProject(this, props);
}
/**
* Creates a CodeBuild SourceCredentials test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public codeBuildSourceCredentials(props?: any): CodeBuildSourceCredentials {
return new CodeBuildSourceCredentials(this, props);
}
/**
* Creates a CustomResource test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public customResource(props?: any): CustomResource {
return new CustomResource(this, props);
}
/**
* Creates a DynamoDB Table test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public dynamoDBTable(props?: any): DynamoDBTable {
return new DynamoDBTable(this, props);
}
/**
* Creates an IAM Role test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public iamRole(props?: any): IAMRole {
return new IAMRole(this, props);
}
/**
* Creates an IAM Policy test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public iamPolicy(props?: any): IAMPolicy {
return new IAMPolicy(this, props);
}
/**
* Creates a Lambda Function test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public lambdaFunction(props?: any): LambdaFunction {
return new LambdaFunction(this, props);
}
/**
* Creates a Lambda Permission test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public lambdaPermission(props?: any): LambdaPermission {
return new LambdaPermission(this, props);
}
/**
* Creates a LogGroup test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public logGroup(props?: any): LogGroup {
return new LogGroup(this, props);
}
/**
* Creates a Route53 HostedZone test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public route53HostedZone(props?: any): Route53HostedZone {
return new Route53HostedZone(this, props);
}
/**
* Creates a Route53 RecordSet test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public route53RecordSet(props?: any): Route53RecordSet {
return new Route53RecordSet(this, props);
}
/**
* Creates an S3 Bucket test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public s3Bucket(props?: any): S3Bucket {
return new S3Bucket(this, props);
}
/**
* Creates an S3 Bucket Policy test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public s3BucketPolicy(props?: any): S3BucketPolicy {
return new S3BucketPolicy(this, props);
}
/**
* Creates a SecretsManager Secret test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public secret(props?: any): Secret {
return new Secret(this, props);
}
/**
* Creates an SSM Parameter test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public ssmParameter(props?: any): SSMParameter {
return new SSMParameter(this, props);
}
/**
* Creates a WAF v2 WebACL test construct with the passed Properties.
* @param props The Properties of the expected test construct.
* @returns
*/
public wafV2WebACL(props?: any): WafV2WebACL {
return new WafV2WebACL(this, props);
}
}