Skip to content

Commit 693f99b

Browse files
committed
ci: add Akamai domain TXT record validation
Extract domain ownership verification token from patchEdgeHostname response and output it. Add a CI step to automatically create the TXT DNS record. Related-Task: INTER-2023
1 parent 6bc5ae5 commit 693f99b

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ jobs:
7070
AK_CONTRACT_ID: '${{secrets.AK_CONTRACT_ID}}'
7171
FPJS_CI_DOMAIN: '${{secrets.FPJS_CI_DOMAIN}}'
7272
run: pnpm ts-node scripts/createProperty.ts
73+
- name: Create Cloudflare TXT Record for Domain Validation
74+
if: steps.create-akamai-property.outputs.HOSTNAME_VALIDATION_TOKEN != ''
75+
uses: fjogeleit/http-request-action@v1
76+
with:
77+
url: 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/dns_records'
78+
method: 'POST'
79+
customHeaders: '{"Authorization": "Bearer ${{ secrets.CF_AUTH_TOKEN }}"}'
80+
data: '{"content": "${{steps.create-akamai-property.outputs.HOSTNAME_VALIDATION_TOKEN}}", "name": "${{steps.create-akamai-property.outputs.TXT_RECORD_HOST}}.${{steps.extract-branch.outputs.SUBDOMAIN}}.${{secrets.FPJS_CI_DOMAIN}}", "proxied": false, "type": "TXT", "comment": "Akamai domain validation for ${{steps.extract-branch.outputs.SUBDOMAIN}}", "ttl": 3600, "tags": ["owner:akamai-integration-ci"]}'
7381
- name: Build Patch Body
7482
run: pnpm build --type patchBody --proxy-secret '${{secrets.FPJS_PROXY_SECRET}}' --integration-path ${{secrets.INTEGRATION_PATH}} --agent-path ${{secrets.AGENT_PATH}} --result-path ${{secrets.RESULT_PATH}}
7583
- name: Deploy Akamai Rules
@@ -146,6 +154,14 @@ jobs:
146154
AK_CONTRACT_ID: '${{secrets.AK_CONTRACT_ID}}'
147155
FPJS_CI_DOMAIN: '${{secrets.FPJS_CI_DOMAIN}}'
148156
run: pnpm ts-node scripts/createProperty.ts
157+
- name: Create Cloudflare TXT Record for Domain Validation
158+
if: steps.create-akamai-property.outputs.HOSTNAME_VALIDATION_TOKEN != ''
159+
uses: fjogeleit/http-request-action@v1
160+
with:
161+
url: 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/dns_records'
162+
method: 'POST'
163+
customHeaders: '{"Authorization": "Bearer ${{ secrets.CF_AUTH_TOKEN }}"}'
164+
data: '{"content": "${{steps.create-akamai-property.outputs.HOSTNAME_VALIDATION_TOKEN}}", "name": "${{steps.create-akamai-property.outputs.TXT_RECORD_HOST}}.${{steps.extract-branch.outputs.SUBDOMAIN}}.${{secrets.FPJS_CI_DOMAIN}}", "proxied": false, "type": "TXT", "comment": "Akamai domain validation for ${{steps.extract-branch.outputs.SUBDOMAIN}}", "ttl": 3600, "tags": ["owner:akamai-integration-ci"]}'
149165
- name: Build Patch Body
150166
run: pnpm build --type patchBody --proxy-secret secret --integration-path ${{secrets.INTEGRATION_PATH}} --agent-path ${{secrets.AGENT_PATH}} --result-path ${{secrets.RESULT_PATH}} --ingress-url ${{secrets.MOCK_FPCDN}}
151167
- name: Deploy Akamai Rules

scripts/createProperty.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { appendFile } from 'fs/promises'
12
import { akamaiRequest } from './utils/akamaiRequest'
23
import { getProperty } from './utils/getProperty'
34
import { CI_DOMAIN } from './utils/constants'
@@ -94,7 +95,11 @@ const findEdgeHostname = async () => {
9495
}
9596

9697
const patchEdgeHostname = async (propertyId: string) => {
97-
await akamaiRequest({
98+
const {
99+
body: {
100+
hostnames: { items: hostnames },
101+
},
102+
} = await akamaiRequest({
98103
path: `/papi/v1/properties/${propertyId}/versions/1/hostnames`,
99104
method: 'PATCH',
100105
body: JSON.stringify({
@@ -107,6 +112,26 @@ const patchEdgeHostname = async (propertyId: string) => {
107112
],
108113
}),
109114
})
115+
116+
const hostname = hostnames.find((h) => h.cnameFrom === CI_DOMAIN)
117+
return hostname?.domainOwnershipVerification?.validationTxt
118+
}
119+
120+
const outputValidationTxt = async (validationTxt: { hostname: string; challengeToken: string }) => {
121+
const txtRecord = `${validationTxt.hostname}. TXT ${validationTxt.challengeToken}`
122+
const txtRecordHost = validationTxt.hostname.replace(`.${CI_DOMAIN}`, '')
123+
if (process.env.GITHUB_OUTPUT) {
124+
await appendFile(
125+
process.env.GITHUB_OUTPUT,
126+
`TXT_RECORD=${txtRecord}\nTXT_RECORD_HOST=${txtRecordHost}\nHOSTNAME_VALIDATION_TOKEN=${validationTxt.challengeToken}\n`
127+
)
128+
} else {
129+
console.log('=== Domain Ownership Verification ===')
130+
console.log(`Host: ${validationTxt.hostname}`)
131+
console.log(`Type: TXT`)
132+
console.log(`Value: ${txtRecord}`)
133+
console.log('=====================================')
134+
}
110135
}
111136

112137
const patchDefaultRuleOrigin = async (propertyId: string) =>
@@ -155,7 +180,10 @@ const handler = async () => {
155180
if (!hostname) {
156181
await createEdgeHostname()
157182
}
158-
await patchEdgeHostname(propertyId)
183+
const validationTxt = await patchEdgeHostname(propertyId)
184+
if (validationTxt) {
185+
await outputValidationTxt(validationTxt)
186+
}
159187
const cpcodeId = await createCPCode()
160188
await patchCpcode(propertyId, cpcodeId)
161189
await patchDefaultRuleOrigin(propertyId)

0 commit comments

Comments
 (0)