Skip to content

Commit a399ea2

Browse files
Added option to disable blue green to deployApi
1 parent 5bee63c commit a399ea2

5 files changed

Lines changed: 111 additions & 44 deletions

File tree

packages/cdkConstructs/src/specifications/deployApi.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,20 @@ export async function deployApi(
5757
proxygenKid,
5858
hiddenPaths
5959
}: ApiConfig,
60-
dryRun: boolean
60+
blueGreen: boolean = true,
61+
dryRun: boolean = false
6162
): Promise<void> {
62-
const instance = fixSpec(
63+
const instance = fixSpec({
6364
spec,
6465
apiName,
6566
version,
6667
apigeeEnvironment,
6768
isPullRequest,
6869
awsEnvironment,
6970
stackName,
70-
mtlsSecretName
71-
)
71+
mtlsSecretName,
72+
blueGreen
73+
})
7274

7375
const exports = await getCloudFormationExports()
7476
const clientCertArn = getCFConfigValue(exports, `account-resources:${clientCertExportName}`)

packages/cdkConstructs/src/specifications/fixSpec.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
import {calculateVersionedStackName} from "../config"
22

3+
type SpecConfig = {
4+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5+
spec: any
6+
apiName: string
7+
version: string
8+
apigeeEnvironment: string
9+
isPullRequest: boolean
10+
awsEnvironment: string
11+
stackName: string
12+
mtlsSecretName: string
13+
blueGreen: boolean
14+
}
15+
316
function replaceSchemeRefs(
417
// eslint-disable-next-line @typescript-eslint/no-explicit-any
518
spec: any,
@@ -15,17 +28,17 @@ function replaceSchemeRefs(
1528
}
1629
}
1730

18-
export function fixSpec(
19-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
20-
spec: any,
21-
apiName: string,
22-
version: string,
23-
apigeeEnvironment: string,
24-
isPullRequest: boolean,
25-
awsEnvironment: string,
26-
stackName: string,
27-
mtlsSecretName: string
28-
): string {
31+
export function fixSpec({
32+
spec,
33+
apiName,
34+
version,
35+
apigeeEnvironment,
36+
isPullRequest,
37+
awsEnvironment,
38+
stackName,
39+
mtlsSecretName,
40+
blueGreen
41+
}: SpecConfig): string {
2942
let instance = apiName
3043
let stack = stackName
3144
if (isPullRequest) {
@@ -35,7 +48,9 @@ export function fixSpec(
3548
spec["x-nhsd-apim"].monitoring = false
3649
delete spec["x-nhsd-apim"].target.security.secret
3750
} else {
38-
stack = calculateVersionedStackName(stackName, version)
51+
if (blueGreen) {
52+
stack = calculateVersionedStackName(stackName, version)
53+
}
3954
spec["x-nhsd-apim"].target.security.secret = mtlsSecretName
4055
}
4156
spec.info.version = version

packages/cdkConstructs/tests/specifications/deployApi.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ describe("deployApi", () => {
112112
apigeeEnvironment: "internal-dev",
113113
stackName: "eps-stack"
114114
}),
115+
true,
115116
false
116117
)
117118

@@ -150,6 +151,7 @@ describe("deployApi", () => {
150151
stackName: "eps-pr-stack-456",
151152
proxygenKid: "kid-789"
152153
}),
154+
true,
153155
false
154156
)
155157

@@ -169,6 +171,7 @@ describe("deployApi", () => {
169171
stackName: "eps-prod-stack",
170172
proxygenKid: "kid-prod"
171173
}),
174+
true,
172175
false
173176
)
174177

@@ -185,6 +188,7 @@ describe("deployApi", () => {
185188
stackName: "eps-int-stack",
186189
proxygenKid: "kid-int"
187190
}),
191+
true,
188192
false
189193
)
190194

@@ -211,6 +215,7 @@ describe("deployApi", () => {
211215
proxygenKid: "kid-int",
212216
hiddenPaths: ["/hidden"]
213217
}),
218+
true,
214219
false
215220
)
216221
const publishPayload = payloadFromCall(2)
@@ -227,6 +232,7 @@ describe("deployApi", () => {
227232
stackName: "eps-int-stack",
228233
proxygenKid: "kid-int"
229234
}),
235+
true,
230236
true
231237
)
232238

@@ -247,6 +253,7 @@ describe("deployApi", () => {
247253
apigeeEnvironment: "int",
248254
stackName: "eps-stack"
249255
}),
256+
true,
250257
false
251258
)).rejects.toThrow("Error calling lambda lambda-resources-ProxygenProdMTLSSecretPut: \"bad\"")
252259
})

packages/cdkConstructs/tests/specifications/fixSpec.test.ts

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,23 @@ describe("fixSpec", () => {
3030
test("sets version, mtls secret, target url and PTL refs for internal-dev", () => {
3131
const spec = createSpec()
3232

33-
const instance = fixSpec(
33+
const instance = fixSpec({
3434
spec,
35-
"eps",
36-
"2.0.0",
37-
"internal-dev",
38-
false,
39-
"nonprod",
40-
"eps-stack",
41-
"mtls/secret"
42-
)
35+
apiName: "eps",
36+
version: "2.0.0",
37+
apigeeEnvironment: "internal-dev",
38+
isPullRequest: false,
39+
awsEnvironment: "dev",
40+
stackName: "eps-stack",
41+
mtlsSecretName: "mtls/secret",
42+
blueGreen: true
43+
})
4344

4445
expect(instance).toBe("eps")
4546
expect(spec.info.version).toBe("2.0.0")
4647
expect(spec["x-nhsd-apim"].target.security.secret).toBe("mtls/secret")
4748
expect(spec["x-nhsd-apim"].target.url)
48-
.toBe("https://eps-stack-2-0-0.nonprod.eps.national.nhs.uk")
49+
.toBe("https://eps-stack-2-0-0.dev.eps.national.nhs.uk")
4950
expect(spec.components.securitySchemes["nhs-cis2-aal3"].$ref)
5051
.toBe("https://proxygen.ptl.api.platform.nhs.uk/components/securitySchemes/nhs-cis2-aal3")
5152
expect(spec.servers[0].url)
@@ -55,16 +56,17 @@ describe("fixSpec", () => {
5556
test("handles pull request sandbox specs and removes sandbox-only fields", () => {
5657
const spec = createSpec()
5758

58-
const instance = fixSpec(
59+
const instance = fixSpec({
5960
spec,
60-
"eps",
61-
"3.1.4",
62-
"sandbox",
63-
true,
64-
"nonprod",
65-
"eps-pr-stack-456",
66-
"mtls/secret"
67-
)
61+
apiName: "eps",
62+
version: "3.1.4",
63+
apigeeEnvironment: "sandbox",
64+
isPullRequest: true,
65+
awsEnvironment: "int",
66+
stackName: "eps-pr-stack-456",
67+
mtlsSecretName: "mtls/secret",
68+
blueGreen: true
69+
})
6870

6971
expect(instance).toBe("eps-pr-456")
7072
expect(spec.info.title).toBe("[PR-456] EPS API")
@@ -85,16 +87,17 @@ describe("fixSpec", () => {
8587
}
8688
})
8789

88-
const instance = fixSpec(
90+
const instance = fixSpec({
8991
spec,
90-
"eps",
91-
"4.0.0",
92-
"prod",
93-
false,
94-
"prod",
95-
"eps-prod-stack",
96-
"mtls/secret"
97-
)
92+
apiName: "eps",
93+
version: "4.0.0",
94+
apigeeEnvironment: "prod",
95+
isPullRequest: false,
96+
awsEnvironment: "prod",
97+
stackName: "eps-prod-stack",
98+
mtlsSecretName: "mtls/secret",
99+
blueGreen: true
100+
})
98101

99102
expect(instance).toBe("eps")
100103
expect(spec.servers[0].url).toBe("https://api.service.nhs.uk/eps")
@@ -110,4 +113,24 @@ describe("fixSpec", () => {
110113
.toBe(`https://proxygen.prod.api.platform.nhs.uk/components/securitySchemes/${scheme}`)
111114
}
112115
})
116+
117+
test("does not version stack name when blueGreen is false", () => {
118+
const spec = createSpec()
119+
120+
const instance = fixSpec({
121+
spec,
122+
apiName: "eps",
123+
version: "1.2.3",
124+
apigeeEnvironment: "internal-dev",
125+
isPullRequest: false,
126+
awsEnvironment: "dev",
127+
stackName: "eps-stack",
128+
mtlsSecretName: "mtls/secret",
129+
blueGreen: false
130+
})
131+
132+
expect(instance).toBe("eps")
133+
expect(spec["x-nhsd-apim"].target.url)
134+
.toBe("https://eps-stack.dev.eps.national.nhs.uk")
135+
})
113136
})

packages/cdkConstructs/tests/specifications/writeSchemas.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,24 @@ describe("writeSchemas", () => {
135135
expect(message).toContain("failing.json")
136136
expect(err).toBeInstanceOf(Error)
137137
})
138+
139+
test("does not modify non-object schemas (collapseExamples type check)", () => {
140+
const schemas = {
141+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
142+
primitive: true as any
143+
}
144+
145+
const outputDir = "primitive-schemas"
146+
const writes: Record<string, string> = {}
147+
148+
vi.spyOn(fs, "existsSync").mockReturnValue(true)
149+
vi.spyOn(fs, "writeFileSync").mockImplementation((filePath, data) => {
150+
writes[filePath.toString()] = data.toString()
151+
})
152+
153+
writeSchemas(schemas, outputDir)
154+
155+
const writtenSchema = writes[path.join(outputDir, "primitive.json")]
156+
expect(writtenSchema).toBe("true")
157+
})
138158
})

0 commit comments

Comments
 (0)