1+ import { appendFile } from 'fs/promises'
12import { akamaiRequest } from './utils/akamaiRequest'
23import { getProperty } from './utils/getProperty'
34import { CI_DOMAIN } from './utils/constants'
@@ -94,7 +95,11 @@ const findEdgeHostname = async () => {
9495}
9596
9697const 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
112137const 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