Skip to content

Commit

Permalink
fix(parameters): add a default description to parameters (#310)
Browse files Browse the repository at this point in the history
* feat!: remove unused GuS3ObjectArnParameter parameter

* chore: DRY out identity parameters by extending GuStringParameter

* fix: add a description to GuGuardianEmailSenderParameter

* fix: provide a default description for GuCertificateArnParameter and allow it to be overridden

* fix!: don't allow type of GuInstanceTypeParameter to be overridden

* fix: provide a default description for GuAmiParameter and let it be overridden
  • Loading branch information
akash1810 committed Mar 9, 2021
1 parent d1002d0 commit ae6f804
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 47 deletions.
3 changes: 2 additions & 1 deletion src/constructs/core/parameters/acm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { GuStringParameter } from "./base";
export class GuCertificateArnParameter extends GuStringParameter {
constructor(scope: GuStack, id: string = "TLSCertificate", props?: GuNoTypeParameterProps) {
super(scope, id, {
...props,
allowedPattern: RegexPattern.ACM_ARN,
constraintDescription: "Must be an ACM ARN resource",
description: "The ARN of an ACM certificate for use on a load balancer",
...props,
});
}
}
3 changes: 1 addition & 2 deletions src/constructs/core/parameters/ec2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ describe("The GuInstanceTypeParameter class", () => {
const stack = simpleGuStackForTesting();

new GuInstanceTypeParameter(stack, "Parameter", {
type: "Number",
description: "This is a test",
default: 1,
});

const json = SynthUtils.toCloudFormation(stack) as SynthedStack;

expect(json.Parameters.Parameter).toEqual({
Type: "Number",
Type: "String",
Description: "This is a test",
Default: 1,
});
Expand Down
7 changes: 4 additions & 3 deletions src/constructs/core/parameters/ec2.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { GuStack } from "../stack";
import type { GuNoTypeParameterProps, GuParameterProps } from "./base";
import type { GuNoTypeParameterProps } from "./base";
import { GuParameter } from "./base";

export class GuInstanceTypeParameter extends GuParameter {
constructor(scope: GuStack, id: string = "InstanceType", props: GuParameterProps = {}) {
constructor(scope: GuStack, id: string = "InstanceType", props?: GuNoTypeParameterProps) {
super(scope, id, {
type: "String",
description: "EC2 Instance Type",
Expand All @@ -16,8 +16,9 @@ export class GuInstanceTypeParameter extends GuParameter {
export class GuAmiParameter extends GuParameter {
constructor(scope: GuStack, id: string, props: GuNoTypeParameterProps) {
super(scope, id, {
...props,
type: "AWS::EC2::Image::Id",
description: "Amazon Machine Image ID. Use this in conjunction with AMIgo to keep AMIs up to date.",
...props,
});
}
}
8 changes: 3 additions & 5 deletions src/constructs/core/parameters/identity.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import { Stage, Stages } from "../../../constants";
import type { GuStack } from "../stack";
import { GuParameter } from "./base";
import { GuStringParameter } from "./base";

export class GuStageParameter extends GuParameter {
export class GuStageParameter extends GuStringParameter {
public static readonly defaultId = "Stage";
constructor(scope: GuStack, id: string = GuStageParameter.defaultId) {
super(scope, id, {
type: "String",
description: "Stage name",
allowedValues: Stages,
default: Stage.CODE,
});
}
}

export class GuStackParameter extends GuParameter {
export class GuStackParameter extends GuStringParameter {
public static readonly defaultId = "Stack";
constructor(scope: GuStack, id: string = GuStackParameter.defaultId) {
super(scope, id, {
type: "String",
description: "Name of this stack",
default: "deploy",
});
Expand Down
23 changes: 0 additions & 23 deletions src/constructs/core/parameters/s3.test.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/constructs/core/parameters/s3.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import { RegexPattern } from "../../../constants";
import type { GuStack } from "../stack";
import type { GuNoTypeParameterProps } from "./base";
import { GuStringParameter } from "./base";

export class GuS3ObjectArnParameter extends GuStringParameter {
constructor(scope: GuStack, id: string, props: GuNoTypeParameterProps) {
super(scope, id, {
...props,
allowedPattern: RegexPattern.S3ARN,
constraintDescription:
"Must be a valid S3 ARN, see https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html",
});
}
}

export class GuDistributionBucketParameter extends GuStringParameter {
public static parameterName = "DistributionBucketName";

Expand Down
1 change: 1 addition & 0 deletions src/constructs/core/parameters/ses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class GuGuardianEmailSenderParameter extends GuStringParameter {
...props,
allowedPattern: RegexPattern.GUARDIAN_EMAIL,
constraintDescription: "Must be an @theguardian.com email address",
description: "The sender of emails sent using SES.",
});
}
}
1 change: 1 addition & 0 deletions src/constructs/iam/policies/__snapshots__/ses.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Object {
"EmailSenderAddress": Object {
"AllowedPattern": "^[a-zA-Z]+(\\\\.[a-zA-Z]+)*@theguardian.com$",
"ConstraintDescription": "Must be an @theguardian.com email address",
"Description": "The sender of emails sent using SES.",
"Type": "String",
},
"Stage": Object {
Expand Down

0 comments on commit ae6f804

Please sign in to comment.