-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfixSpec.ts
More file actions
66 lines (63 loc) · 1.97 KB
/
fixSpec.ts
File metadata and controls
66 lines (63 loc) · 1.97 KB
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
import {calculateVersionedStackName} from "../config/index.js"
type SpecConfig = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
spec: any
apiName: string
version: string
apigeeEnvironment: string
isPullRequest: boolean
awsEnvironment: string
stackName: string
mtlsSecretName: string
blueGreen: boolean
}
function replaceSchemeRefs(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
spec: any,
domain: string
) {
const schemes = ["nhs-cis2-aal3", "nhs-login-p9", "app-level3", "app-level0"]
for (const scheme of schemes) {
if (spec.components.securitySchemes[scheme]) {
spec.components.securitySchemes[scheme] = {
"$ref": `https://${domain}/components/securitySchemes/${scheme}`
}
}
}
}
export function fixSpec({
spec,
apiName,
version,
apigeeEnvironment,
isPullRequest,
awsEnvironment,
stackName,
mtlsSecretName,
blueGreen
}: SpecConfig): string {
let instance = apiName
let stack = stackName
if (isPullRequest) {
const pr_id = stackName.split("-").pop()
instance = `${apiName}-pr-${pr_id}`
spec.info.title = `[PR-${pr_id}] ${spec.info.title}`
spec["x-nhsd-apim"].monitoring = false
} else if (blueGreen) {
stack = calculateVersionedStackName(stackName, version)
}
spec.info.version = version
spec["x-nhsd-apim"].target.url = `https://${stack}.${awsEnvironment}.eps.national.nhs.uk`
spec["x-nhsd-apim"].target.security.secret = mtlsSecretName
if (apigeeEnvironment === "prod") {
spec.servers = [ {url: `https://api.service.nhs.uk/${instance}`} ]
replaceSchemeRefs(spec, "proxygen.prod.api.platform.nhs.uk")
} else {
spec.servers = [ {url: `https://${apigeeEnvironment}.api.service.nhs.uk/${instance}`} ]
replaceSchemeRefs(spec, "proxygen.ptl.api.platform.nhs.uk")
}
if (apigeeEnvironment.includes("sandbox")) {
delete spec["x-nhsd-apim"]["target-attributes"] // Resolve issue with sandbox trying to look up app name
}
return instance
}