@collaborne/custom-cloudformation-resources
Advanced tools
Comparing version 0.5.15 to 0.5.16
@@ -32,7 +32,6 @@ import { WAFV2 } from 'aws-sdk'; | ||
createResource(physicalResourceId: string, { Name, Description, Capacity, Rules }: SchemaType<typeof SCHEMA>): Promise<Response<ResourceAttributes>>; | ||
deleteResource(physicalResourceId: string, { Name: name }: SchemaType<typeof SCHEMA>): Promise<Response<ResourceAttributes>>; | ||
deleteResource(physicalResourceId: string, { Name }: SchemaType<typeof SCHEMA>): Promise<Response<ResourceAttributes>>; | ||
updateResource(physicalResourceId: string, { Name, Description, Rules }: SchemaType<typeof SCHEMA>): Promise<Response<ResourceAttributes>>; | ||
protected getRuleGroup(name: string): Promise<WAFV2.GetRuleGroupResponse>; | ||
protected getRuleGroupAttributes(name: string): Promise<ResourceAttributes>; | ||
} | ||
export {}; |
@@ -70,10 +70,14 @@ "use strict"; | ||
} | ||
async deleteResource(physicalResourceId, { Name: name }) { | ||
const attributes = await this.getRuleGroupAttributes(name); | ||
async deleteResource(physicalResourceId, { Name }) { | ||
var _a; | ||
const ruleGroup = await this.getRuleGroup(Name); | ||
if (!ruleGroup.RuleGroup || !ruleGroup.LockToken) { | ||
throw new Error(`Rule group is not deletable ${Name}`); | ||
} | ||
await this.wafV2 | ||
.deleteRuleGroup({ | ||
Name: name, | ||
Name, | ||
Scope: SCOPE, | ||
Id: attributes.Id, | ||
LockToken: 'delete', | ||
Id: (_a = ruleGroup.RuleGroup) === null || _a === void 0 ? void 0 : _a.Id, | ||
LockToken: ruleGroup.LockToken, | ||
}) | ||
@@ -86,11 +90,9 @@ .promise(); | ||
async updateResource(physicalResourceId, { Name, Description, Rules }) { | ||
var _a, _b, _c; | ||
const ruleGroup = await this.getRuleGroup(Name); | ||
if (!ruleGroup.RuleGroup) { | ||
throw new Error(`Rule group cannot find ${Name}`); | ||
if (!ruleGroup.RuleGroup || !ruleGroup.LockToken) { | ||
throw new Error(`Rule group is not updatable ${Name}`); | ||
} | ||
const rules = JSON.parse(Rules); | ||
await this.wafV2 | ||
.updateRuleGroup({ | ||
Id: (_a = ruleGroup.RuleGroup) === null || _a === void 0 ? void 0 : _a.Id, | ||
const updateRuleGroupParams = { | ||
Id: ruleGroup.RuleGroup.Id, | ||
Name, | ||
@@ -101,10 +103,11 @@ Description, | ||
VisibilityConfig: ruleGroup.RuleGroup.VisibilityConfig, | ||
LockToken: 'update', | ||
}) | ||
.promise(); | ||
LockToken: ruleGroup.LockToken, | ||
}; | ||
console.log(`updateRuleGroupParams: ${JSON.stringify(updateRuleGroupParams)}`); | ||
await this.wafV2.updateRuleGroup(updateRuleGroupParams).promise(); | ||
return { | ||
physicalResourceId, | ||
attributes: { | ||
Arn: (_b = ruleGroup.RuleGroup) === null || _b === void 0 ? void 0 : _b.ARN, | ||
Id: (_c = ruleGroup.RuleGroup) === null || _c === void 0 ? void 0 : _c.Id, | ||
Arn: ruleGroup.RuleGroup.ARN, | ||
Id: ruleGroup.RuleGroup.Id, | ||
}, | ||
@@ -114,21 +117,27 @@ }; | ||
async getRuleGroup(name) { | ||
const ruleGroup = await this.wafV2.getRuleGroup({ Name: name }).promise(); | ||
if (!ruleGroup) { | ||
const ruleGroups = await this.wafV2 | ||
.listRuleGroups({ Scope: SCOPE }) | ||
.promise(); | ||
if (!ruleGroups.RuleGroups || ruleGroups.RuleGroups.length < 1) { | ||
throw new Error(`There is no rule groups in your account with scope ${SCOPE}`); | ||
} | ||
const ruleGroupSummary = ruleGroups.RuleGroups.find(x => x.Name === name); | ||
if (!ruleGroupSummary) { | ||
throw new Error(`Unknown rule group name ${name}`); | ||
} | ||
const ruleGroup = await this.wafV2 | ||
.getRuleGroup({ | ||
Name: name, | ||
Id: ruleGroupSummary.Id, | ||
ARN: ruleGroupSummary.ARN, | ||
Scope: SCOPE, | ||
}) | ||
.promise(); | ||
if (!ruleGroup.RuleGroup) { | ||
throw new Error(`Rule group cannot find for ${name}`); | ||
} | ||
return ruleGroup; | ||
} | ||
async getRuleGroupAttributes(name) { | ||
var _a, _b, _c; | ||
const ruleGroup = await this.getRuleGroup(name); | ||
if (!((_a = ruleGroup.RuleGroup) === null || _a === void 0 ? void 0 : _a.ARN) || !ruleGroup.RuleGroup.Id) { | ||
throw new Error(`Missing properties for rule group ${name}`); | ||
} | ||
return { | ||
Arn: (_b = ruleGroup.RuleGroup) === null || _b === void 0 ? void 0 : _b.ARN, | ||
Id: (_c = ruleGroup.RuleGroup) === null || _c === void 0 ? void 0 : _c.Id, | ||
}; | ||
} | ||
} | ||
exports.CloudFrontWafV2RuleGroup = CloudFrontWafV2RuleGroup; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@collaborne/custom-cloudformation-resources", | ||
"version": "0.5.15", | ||
"version": "0.5.16", | ||
"description": "Custom CloudFormation resources", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -94,11 +94,16 @@ import { WAFV2 } from 'aws-sdk'; | ||
physicalResourceId: string, | ||
{ Name: name }: SchemaType<typeof SCHEMA>, | ||
{ Name }: SchemaType<typeof SCHEMA>, | ||
): Promise<Response<ResourceAttributes>> { | ||
const attributes = await this.getRuleGroupAttributes(name); | ||
const ruleGroup = await this.getRuleGroup(Name); | ||
if (!ruleGroup.RuleGroup || !ruleGroup.LockToken) { | ||
throw new Error(`Rule group is not deletable ${Name}`); | ||
} | ||
await this.wafV2 | ||
.deleteRuleGroup({ | ||
Name: name, | ||
Name, | ||
Scope: SCOPE, | ||
Id: attributes.Id, | ||
LockToken: 'delete', | ||
Id: ruleGroup.RuleGroup?.Id, | ||
LockToken: ruleGroup.LockToken, | ||
}) | ||
@@ -118,4 +123,4 @@ .promise(); | ||
if (!ruleGroup.RuleGroup) { | ||
throw new Error(`Rule group cannot find ${Name}`); | ||
if (!ruleGroup.RuleGroup || !ruleGroup.LockToken) { | ||
throw new Error(`Rule group is not updatable ${Name}`); | ||
} | ||
@@ -125,19 +130,22 @@ | ||
await this.wafV2 | ||
.updateRuleGroup({ | ||
Id: ruleGroup.RuleGroup?.Id, | ||
Name, | ||
Description, | ||
Scope: SCOPE, | ||
Rules: rules, | ||
VisibilityConfig: ruleGroup.RuleGroup.VisibilityConfig, | ||
LockToken: 'update', | ||
}) | ||
.promise(); | ||
const updateRuleGroupParams = { | ||
Id: ruleGroup.RuleGroup.Id, | ||
Name, | ||
Description, | ||
Scope: SCOPE, | ||
Rules: rules, | ||
VisibilityConfig: ruleGroup.RuleGroup.VisibilityConfig, | ||
LockToken: ruleGroup.LockToken, | ||
}; | ||
console.log( | ||
`updateRuleGroupParams: ${JSON.stringify(updateRuleGroupParams)}`, | ||
); | ||
await this.wafV2.updateRuleGroup(updateRuleGroupParams).promise(); | ||
return { | ||
physicalResourceId, | ||
attributes: { | ||
Arn: ruleGroup.RuleGroup?.ARN, | ||
Id: ruleGroup.RuleGroup?.Id, | ||
Arn: ruleGroup.RuleGroup.ARN, | ||
Id: ruleGroup.RuleGroup.Id, | ||
}, | ||
@@ -150,24 +158,33 @@ }; | ||
): Promise<WAFV2.GetRuleGroupResponse> { | ||
const ruleGroup = await this.wafV2.getRuleGroup({ Name: name }).promise(); | ||
if (!ruleGroup) { | ||
const ruleGroups = await this.wafV2 | ||
.listRuleGroups({ Scope: SCOPE }) | ||
.promise(); | ||
if (!ruleGroups.RuleGroups || ruleGroups.RuleGroups.length < 1) { | ||
throw new Error( | ||
`There is no rule groups in your account with scope ${SCOPE}`, | ||
); | ||
} | ||
const ruleGroupSummary = ruleGroups.RuleGroups.find(x => x.Name === name); | ||
if (!ruleGroupSummary) { | ||
throw new Error(`Unknown rule group name ${name}`); | ||
} | ||
return ruleGroup; | ||
} | ||
const ruleGroup = await this.wafV2 | ||
.getRuleGroup({ | ||
Name: name, | ||
Id: ruleGroupSummary.Id, | ||
ARN: ruleGroupSummary.ARN, | ||
Scope: SCOPE, | ||
}) | ||
.promise(); | ||
protected async getRuleGroupAttributes( | ||
name: string, | ||
): Promise<ResourceAttributes> { | ||
const ruleGroup = await this.getRuleGroup(name); | ||
if (!ruleGroup.RuleGroup?.ARN || !ruleGroup.RuleGroup.Id) { | ||
throw new Error(`Missing properties for rule group ${name}`); | ||
if (!ruleGroup.RuleGroup) { | ||
throw new Error(`Rule group cannot find for ${name}`); | ||
} | ||
return { | ||
Arn: ruleGroup.RuleGroup?.ARN, | ||
Id: ruleGroup.RuleGroup?.Id, | ||
}; | ||
return ruleGroup; | ||
} | ||
} |
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
197853
2684