Skip to content

Commit a21bdb7

Browse files
committed
chore: flag if mtls set but domain record not enabled
1 parent 79eccac commit a21bdb7

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

packages/cdkConstructs/src/constructs/RestApiGateway.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface RestApiGatewayProps {
4242
readonly stackName: string
4343
/** Shared retention period for API and deployment-related log groups. */
4444
readonly logRetentionInDays: number
45-
/** Truststore object key to enable mTLS; leave undefined to disable mTLS. */
45+
/** Truststore object key to enable mTLS; leave undefined to disable mTLS or when enableServiceDomain is false. */
4646
readonly mutualTlsTrustStoreKey: string | undefined
4747
/** Enables creation of a second subscription filter to forward logs to CSOC. */
4848
readonly forwardCsocLogs: boolean
@@ -89,6 +89,10 @@ export class RestApiGateway extends Construct {
8989
throw new Error("csocApiGatewayDestination must be provided when forwardCsocLogs is true")
9090
}
9191

92+
if (!enableServiceDomain && props.mutualTlsTrustStoreKey) {
93+
throw new Error("mutualTlsTrustStoreKey should not be provided when enableServiceDomain is false")
94+
}
95+
9296
// Imports
9397
const cloudWatchLogsKmsKey = Key.fromKeyArn(
9498
this, "cloudWatchLogsKmsKey", ACCOUNT_RESOURCES.CloudwatchLogsKmsKeyArn)

packages/cdkConstructs/tests/constructs/RestApiGateway.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,30 @@ describe("RestApiGateway validation errors", () => {
354354
executionPolicies: [testPolicy]
355355
})).toThrow("csocApiGatewayDestination must be provided when forwardCsocLogs is true")
356356
})
357+
358+
test("throws when enableServiceDomain is false and mutualTlsTrustStoreKey is provided", () => {
359+
const app = new App()
360+
const stack = new Stack(app, "ValidationStack2")
361+
const testPolicy = new ManagedPolicy(stack, "TestPolicy", {
362+
description: "test execution policy",
363+
statements: [
364+
new PolicyStatement({
365+
actions: ["lambda:InvokeFunction"],
366+
resources: ["arn:aws:lambda:eu-west-2:123456789012:function:test-function"]
367+
})
368+
]
369+
})
370+
371+
expect(() => new RestApiGateway(stack, "TestApiGateway", {
372+
stackName: "test-stack",
373+
logRetentionInDays: 30,
374+
mutualTlsTrustStoreKey: "truststore.pem",
375+
forwardCsocLogs: false,
376+
csocApiGatewayDestination: "",
377+
executionPolicies: [testPolicy],
378+
enableServiceDomain: false
379+
})).toThrow("mutualTlsTrustStoreKey should not be provided when enableServiceDomain is false")
380+
})
357381
})
358382

359383
describe("RestApiGateway enableServiceDomain default behaviour", () => {
@@ -387,3 +411,36 @@ describe("RestApiGateway enableServiceDomain default behaviour", () => {
387411
template.resourceCountIs("AWS::Route53::RecordSet", 2)
388412
})
389413
})
414+
415+
describe("RestApiGateway with enableServiceDomain false", () => {
416+
test("does not create custom domain resources when enableServiceDomain is false", () => {
417+
const app = new App()
418+
const stack = new Stack(app, "DisableServiceDomainStack")
419+
const testPolicy = new ManagedPolicy(stack, "TestPolicy", {
420+
description: "test execution policy",
421+
statements: [
422+
new PolicyStatement({
423+
actions: ["lambda:InvokeFunction"],
424+
resources: ["arn:aws:lambda:eu-west-2:123456789012:function:test-function"]
425+
})
426+
]
427+
})
428+
429+
const apiGateway = new RestApiGateway(stack, "TestApiGateway", {
430+
stackName: "test-stack",
431+
logRetentionInDays: 30,
432+
mutualTlsTrustStoreKey: undefined,
433+
forwardCsocLogs: false,
434+
csocApiGatewayDestination: "",
435+
executionPolicies: [testPolicy],
436+
enableServiceDomain: false
437+
})
438+
439+
apiGateway.api.root.addMethod("GET")
440+
441+
const template = Template.fromStack(stack)
442+
template.resourceCountIs("AWS::CertificateManager::Certificate", 0)
443+
template.resourceCountIs("AWS::ApiGateway::DomainName", 0)
444+
template.resourceCountIs("AWS::Route53::RecordSet", 0)
445+
})
446+
})

0 commit comments

Comments
 (0)