Skip to content

Commit

Permalink
feat: pass id and arn to the updator
Browse files Browse the repository at this point in the history
  • Loading branch information
hideokamoto committed Nov 7, 2019
1 parent 246b330 commit 506c98b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
8 changes: 4 additions & 4 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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'
Expand Down
9 changes: 6 additions & 3 deletions libs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DistributionConfig | null>
export type UpdatorFunction = (dist: {id: string; arn: string}, distributionConfig: DistributionConfig) => DistributionConfig | null | Promise<DistributionConfig | null>

// Filter your distribution to find out a expected distributions
export type FilterCondition = (distribution: Distribution | DistributionSummary) => boolean | Promise<boolean>
Expand Down Expand Up @@ -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)
}
Expand All @@ -128,7 +131,7 @@ export class CloudFrontUpdator {
}
}
return {
config: await this.updator(distribution.Id, DistributionConfig),
config,
ETag
}
} catch (e) {
Expand Down

0 comments on commit 506c98b

Please sign in to comment.