diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3d05c1..73a1d5e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,4 +59,15 @@ jobs: AK_ACCESS_TOKEN: '${{secrets.AK_ACCESS_TOKEN}}' AK_GROUP_ID: '${{secrets.AK_GROUP_ID}}' AK_CONTRACT_ID: '${{secrets.AK_CONTRACT_ID}}' - run: yarn ts-node scripts/createProperty.ts \ No newline at end of file + run: yarn ts-node scripts/createProperty.ts + - name: Deploy Akamai Rules + id: deploy-rules + env: + BRANCH_NAME: '${{steps.extract-branch.outputs.BRANCH_NAME}}' + AK_HOST: '${{secrets.AK_HOST}}' + AK_CLIENT_TOKEN: '${{secrets.AK_CLIENT_TOKEN}}' + AK_CLIENT_SECRET: '${{secrets.AK_CLIENT_SECRET}}' + AK_ACCESS_TOKEN: '${{secrets.AK_ACCESS_TOKEN}}' + AK_GROUP_ID: '${{secrets.AK_GROUP_ID}}' + AK_CONTRACT_ID: '${{secrets.AK_CONTRACT_ID}}' + run: yarn ts-node scripts/deployRules.ts \ No newline at end of file diff --git a/build.ts b/build.ts index f71d950..1f248ef 100644 --- a/build.ts +++ b/build.ts @@ -14,12 +14,19 @@ const args = arg({ args['--type'] = args['--type'] ? args['--type'] : 'all' -const patchBody = () => { +export interface PatchBodyArgs { + integrationPath: string, + agentPath: string, + resultPath: string, + proxySecret: string, +} + +export const patchBody = (_args?: PatchBodyArgs) => { const bodyContent = generatePatchBody({ - integrationPath: args["--integration-path"], - agentPath: args["--agent-path"], - resultPath: args["--result-path"], - proxySecret: args["--proxy-secret"], + integrationPath: args["--integration-path"] ?? _args?.integrationPath, + agentPath: args["--agent-path"] ?? _args?.agentPath, + resultPath: args["--result-path"] ?? _args?.resultPath, + proxySecret: args["--proxy-secret"] ?? _args?.proxySecret, }) fs.mkdirSync(path.relative(process.cwd(), 'dist/patch-body'), {recursive: true}) diff --git a/scripts/deployRules.ts b/scripts/deployRules.ts new file mode 100644 index 0000000..cf0043c --- /dev/null +++ b/scripts/deployRules.ts @@ -0,0 +1,33 @@ +import {patchBody} from "../build"; +import {eg} from "./utils/edgeGrid"; + +patchBody({ + integrationPath: 'worker', + agentPath: 'agent', + resultPath: 'result', + proxySecret: 'abc123', +}) + +import('../dist/patch-body/body.json').then(module => { + const content = module.default as object; + + eg.auth({ + path: `/papi/v1/properties?contractId=${process.env.AK_CONTRACT_ID}&groupId=${process.env.AK_GROUP_ID}`, + method: 'GET', + }) + + eg.send((err, response, body) => { + const {properties} = JSON.parse(body ?? '{}'); + const property = properties.items.find(t => t.propertyName === `${process.env.BRANCH_NAME}.cfi-fingerprint.com`); + + eg.auth({ + path: `/papi/v1/properties/${property.propertyId}/versions/${property.latestVersion}/rules?contractId=${process.env.AK_CONTRACT_ID}&groupId=${process.env.AK_GROUP_ID}`, + method: 'PATCH', + body: JSON.stringify(content), + }); + + eg.send((err, response, body) => { + // TODO: Deploy Successful + }); + }); +}) \ No newline at end of file