@collaborne/custom-cloudformation-resources
Advanced tools
Comparing version 0.5.16 to 0.5.17
@@ -48,3 +48,2 @@ "use strict"; | ||
}; | ||
console.log(`ruleGroupParams: ${JSON.stringify(ruleGroupParams)}`); | ||
try { | ||
@@ -57,3 +56,3 @@ const ruleGroup = await this.wafV2 | ||
} | ||
console.log('Rule Group created successfully:', (_b = ruleGroup.Summary) === null || _b === void 0 ? void 0 : _b.ARN); | ||
console.debug('Rule Group created successfully:', (_b = ruleGroup.Summary) === null || _b === void 0 ? void 0 : _b.ARN); | ||
return { | ||
@@ -105,3 +104,2 @@ physicalResourceId, | ||
}; | ||
console.log(`updateRuleGroupParams: ${JSON.stringify(updateRuleGroupParams)}`); | ||
await this.wafV2.updateRuleGroup(updateRuleGroupParams).promise(); | ||
@@ -123,3 +121,3 @@ return { | ||
} | ||
const ruleGroupSummary = ruleGroups.RuleGroups.find(x => x.Name === name); | ||
const ruleGroupSummary = ruleGroups.RuleGroups.find(ruleGroup => ruleGroup.Name === name); | ||
if (!ruleGroupSummary) { | ||
@@ -136,5 +134,2 @@ throw new Error(`Unknown rule group name ${name}`); | ||
.promise(); | ||
if (!ruleGroup.RuleGroup) { | ||
throw new Error(`Rule group cannot find for ${name}`); | ||
} | ||
return ruleGroup; | ||
@@ -141,0 +136,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import { WAFV2 } from 'aws-sdk'; | ||
import { SchemaType } from '@collaborne/json-schema-to-type'; | ||
@@ -25,6 +26,6 @@ import { CustomResource, Response } from '../custom-resource'; | ||
createResource(physicalResourceId: string, { Name, MetricName }: SchemaType<typeof SCHEMA>): Promise<Response<ResourceAttributes>>; | ||
deleteResource(physicalResourceId: string, { Name: name }: SchemaType<typeof SCHEMA>): Promise<Response<ResourceAttributes>>; | ||
updateResource(physicalResourceId: string, { Name: name }: SchemaType<typeof SCHEMA>): Promise<Response<ResourceAttributes>>; | ||
protected getWebAclAttributes(name: string): Promise<ResourceAttributes>; | ||
deleteResource(physicalResourceId: string, { Name }: SchemaType<typeof SCHEMA>): Promise<Response<ResourceAttributes>>; | ||
updateResource(physicalResourceId: string, { Name }: SchemaType<typeof SCHEMA>): Promise<Response<ResourceAttributes>>; | ||
protected getWebAcl(name: string): Promise<WAFV2.GetWebACLResponse>; | ||
} | ||
export {}; |
@@ -46,3 +46,3 @@ "use strict"; | ||
} | ||
console.log('WebACL created successfully:', (_b = webAcl.Summary) === null || _b === void 0 ? void 0 : _b.ARN); | ||
console.debug('WebACL created successfully:', (_b = webAcl.Summary) === null || _b === void 0 ? void 0 : _b.ARN); | ||
return { | ||
@@ -61,9 +61,12 @@ physicalResourceId, | ||
} | ||
async deleteResource(physicalResourceId, { Name: name }) { | ||
const attributes = await this.getWebAclAttributes(name); | ||
async deleteResource(physicalResourceId, { Name }) { | ||
const webAcl = await this.getWebAcl(Name); | ||
if (!webAcl.WebACL || !webAcl.LockToken) { | ||
throw new Error(`WAF V2 is not deletable ${Name}`); | ||
} | ||
this.wafV2.deleteWebACL({ | ||
Name: name, | ||
Name, | ||
Scope: SCOPE, | ||
Id: attributes.Id, | ||
LockToken: 'RemoveWAF', | ||
Id: webAcl.WebACL.Id, | ||
LockToken: webAcl.LockToken, | ||
}); | ||
@@ -74,10 +77,18 @@ return { | ||
} | ||
async updateResource(physicalResourceId, { Name: name }) { | ||
const attributes = await this.getWebAclAttributes(name); | ||
async updateResource(physicalResourceId, { Name }) { | ||
var _a, _b; | ||
const webAcl = await this.getWebAcl(Name); | ||
if (!webAcl.WebACL) { | ||
throw new Error(`WAF V2 is not found ${Name}`); | ||
} | ||
console.warn(`WAF V2 is not updatable. You have to delete and create new one.`); | ||
return { | ||
physicalResourceId, | ||
attributes, | ||
attributes: { | ||
Arn: (_a = webAcl.WebACL) === null || _a === void 0 ? void 0 : _a.ARN, | ||
Id: (_b = webAcl.WebACL) === null || _b === void 0 ? void 0 : _b.Id, | ||
}, | ||
}; | ||
} | ||
async getWebAclAttributes(name) { | ||
async getWebAcl(name) { | ||
var _a; | ||
@@ -88,10 +99,14 @@ const webAcls = await this.wafV2.listWebACLs({ Scope: SCOPE }).promise(); | ||
} | ||
const webAcl = (_a = webAcls.WebACLs) === null || _a === void 0 ? void 0 : _a.find(webAcl => webAcl.Name === name); | ||
if (!webAcl || !webAcl.ARN || !webAcl.Id) { | ||
const webAclSummary = (_a = webAcls.WebACLs) === null || _a === void 0 ? void 0 : _a.find(webAcl => webAcl.Name === name); | ||
if (!webAclSummary || !webAclSummary.ARN || !webAclSummary.Id) { | ||
throw new Error(`Unknown waf name ${name}`); | ||
} | ||
return { | ||
Arn: webAcl === null || webAcl === void 0 ? void 0 : webAcl.ARN, | ||
Id: webAcl === null || webAcl === void 0 ? void 0 : webAcl.Id, | ||
}; | ||
const webAcl = await this.wafV2 | ||
.getWebACL({ | ||
Name: name, | ||
Id: webAclSummary.Id, | ||
Scope: SCOPE, | ||
}) | ||
.promise(); | ||
return webAcl; | ||
} | ||
@@ -98,0 +113,0 @@ } |
{ | ||
"name": "@collaborne/custom-cloudformation-resources", | ||
"version": "0.5.16", | ||
"version": "0.5.17", | ||
"description": "Custom CloudFormation resources", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -67,4 +67,2 @@ import { WAFV2 } from 'aws-sdk'; | ||
console.log(`ruleGroupParams: ${JSON.stringify(ruleGroupParams)}`); | ||
try { | ||
@@ -78,3 +76,3 @@ const ruleGroup = await this.wafV2 | ||
} | ||
console.log('Rule Group created successfully:', ruleGroup.Summary?.ARN); | ||
console.debug('Rule Group created successfully:', ruleGroup.Summary?.ARN); | ||
@@ -139,5 +137,2 @@ return { | ||
}; | ||
console.log( | ||
`updateRuleGroupParams: ${JSON.stringify(updateRuleGroupParams)}`, | ||
); | ||
@@ -168,3 +163,5 @@ await this.wafV2.updateRuleGroup(updateRuleGroupParams).promise(); | ||
const ruleGroupSummary = ruleGroups.RuleGroups.find(x => x.Name === name); | ||
const ruleGroupSummary = ruleGroups.RuleGroups.find( | ||
ruleGroup => ruleGroup.Name === name, | ||
); | ||
@@ -184,8 +181,4 @@ if (!ruleGroupSummary) { | ||
if (!ruleGroup.RuleGroup) { | ||
throw new Error(`Rule group cannot find for ${name}`); | ||
} | ||
return ruleGroup; | ||
} | ||
} |
@@ -65,3 +65,3 @@ import { WAFV2 } from 'aws-sdk'; | ||
} | ||
console.log('WebACL created successfully:', webAcl.Summary?.ARN); | ||
console.debug('WebACL created successfully:', webAcl.Summary?.ARN); | ||
@@ -83,10 +83,15 @@ return { | ||
physicalResourceId: string, | ||
{ Name: name }: SchemaType<typeof SCHEMA>, | ||
{ Name }: SchemaType<typeof SCHEMA>, | ||
): Promise<Response<ResourceAttributes>> { | ||
const attributes = await this.getWebAclAttributes(name); | ||
const webAcl = await this.getWebAcl(Name); | ||
if (!webAcl.WebACL || !webAcl.LockToken) { | ||
throw new Error(`WAF V2 is not deletable ${Name}`); | ||
} | ||
this.wafV2.deleteWebACL({ | ||
Name: name, | ||
Name, | ||
Scope: SCOPE, | ||
Id: attributes.Id, | ||
LockToken: 'RemoveWAF', | ||
Id: webAcl.WebACL.Id, | ||
LockToken: webAcl.LockToken, | ||
}); | ||
@@ -101,15 +106,24 @@ | ||
physicalResourceId: string, | ||
{ Name: name }: SchemaType<typeof SCHEMA>, | ||
{ Name }: SchemaType<typeof SCHEMA>, | ||
): Promise<Response<ResourceAttributes>> { | ||
const attributes = await this.getWebAclAttributes(name); | ||
const webAcl = await this.getWebAcl(Name); | ||
if (!webAcl.WebACL) { | ||
throw new Error(`WAF V2 is not found ${Name}`); | ||
} | ||
console.warn( | ||
`WAF V2 is not updatable. You have to delete and create new one.`, | ||
); | ||
return { | ||
physicalResourceId, | ||
attributes, | ||
attributes: { | ||
Arn: webAcl.WebACL?.ARN, | ||
Id: webAcl.WebACL?.Id, | ||
}, | ||
}; | ||
} | ||
protected async getWebAclAttributes( | ||
name: string, | ||
): Promise<ResourceAttributes> { | ||
protected async getWebAcl(name: string): Promise<WAFV2.GetWebACLResponse> { | ||
const webAcls = await this.wafV2.listWebACLs({ Scope: SCOPE }).promise(); | ||
@@ -120,12 +134,17 @@ if (!webAcls) { | ||
const webAcl = webAcls.WebACLs?.find(webAcl => webAcl.Name === name); | ||
if (!webAcl || !webAcl.ARN || !webAcl.Id) { | ||
const webAclSummary = webAcls.WebACLs?.find(webAcl => webAcl.Name === name); | ||
if (!webAclSummary || !webAclSummary.ARN || !webAclSummary.Id) { | ||
throw new Error(`Unknown waf name ${name}`); | ||
} | ||
return { | ||
Arn: webAcl?.ARN, | ||
Id: webAcl?.Id, | ||
}; | ||
const webAcl = await this.wafV2 | ||
.getWebACL({ | ||
Name: name, | ||
Id: webAclSummary.Id, | ||
Scope: SCOPE, | ||
}) | ||
.promise(); | ||
return webAcl; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
198480
2704