From 506c98b1c6760febfb1d5a319b77250b6163ec5e Mon Sep 17 00:00:00 2001 From: hideokamoto Date: Thu, 7 Nov 2019 11:25:49 +0900 Subject: [PATCH] feat: pass id and arn to the updator --- README.md | 2 +- __tests__/index.test.ts | 8 ++++---- libs/index.ts | 9 ++++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1743edd..71f927d 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ import CloudFrontUpdator from 'cloudfront-updator' const client = new CloudFrontUpdator({ // You can define your expected the Distribution config - updator: (id, DistributionConfig) => { + updator: ({id, arn}, DistributionConfig) => { DistributionConfig.HttpVersion = 'http2' return DistributionConfig }, diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index defe19a..b34f621 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -44,7 +44,7 @@ class DummyClient { } describe('dummy', () => { // @ts-ignore - const updator: interfaces.UpdatorFunction = (id, conf) => conf + const updator: interfaces.UpdatorFunction = (dist, conf) => conf const filter: interfaces.FilterCondition = () => true let client = new CloudFrontUpdator({ updator, @@ -58,7 +58,7 @@ describe('dummy', () => { }) it('should update', async () => { client = new CloudFrontUpdator({ - updator: (id, conf) => { + updator: ({id}, conf) => { console.log(id) conf.HttpVersion = 'http2' return conf @@ -74,7 +74,7 @@ describe('dummy', () => { }) it('should update', async () => { client = new CloudFrontUpdator({ - updator: (id, conf) => { + updator: ({id}, conf) => { console.log(id) conf.Enabled = false conf.HttpVersion = 'http2' @@ -100,7 +100,7 @@ describe('dummy', () => { }) it('should throw error', async () => { client = new CloudFrontUpdator({ - updator: (id, conf) => { + updator: ({id}, conf) => { console.log(id) conf.Enabled = false conf.HttpVersion = 'http2' diff --git a/libs/index.ts b/libs/index.ts index eb9a458..2984658 100644 --- a/libs/index.ts +++ b/libs/index.ts @@ -14,7 +14,7 @@ const sleep = async (time = 1000) => { export namespace interfaces { // To Write any method to the new CloudFront distribution config - export type UpdatorFunction = (distributionId: string, distributionConfig: DistributionConfig) => DistributionConfig | null | Promise + export type UpdatorFunction = (dist: {id: string; arn: string}, distributionConfig: DistributionConfig) => DistributionConfig | null | Promise // Filter your distribution to find out a expected distributions export type FilterCondition = (distribution: Distribution | DistributionSummary) => boolean | Promise @@ -116,7 +116,10 @@ export class CloudFrontUpdator { if (!DistributionConfig) throw new Error('No such distribution') if (!ETag) throw new Error('no ETag') const beforeConfig = Object.assign({}, DistributionConfig) - const config = await this.updator(distribution.Id, DistributionConfig) + const config = await this.updator({ + id: distribution.Id, + arn: distribution.ARN + }, DistributionConfig) if (this.debugMode && config) { this.diff = detailedDiff(beforeConfig, config) } @@ -128,7 +131,7 @@ export class CloudFrontUpdator { } } return { - config: await this.updator(distribution.Id, DistributionConfig), + config, ETag } } catch (e) {