Skip to content

Commit

Permalink
Merge pull request #286 from globaldatanet/4.2.1-bugfix
Browse files Browse the repository at this point in the history
4.2.1
  • Loading branch information
daknhh authored Jan 22, 2024
2 parents e0dd8d7 + 0142676 commit d6e9080
Show file tree
Hide file tree
Showing 4 changed files with 1,824 additions and 510 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## Released

## 4.2.1
### Fixed
- [Issue285](https://github.com/globaldatanet/aws-firewall-factory/issues/285) - Resolved an issue where the redeployment of changed capacity was not functioning correctly due to inconsistencies in the writing of ProcessProperties for DeployedRuleGroups.
- Bump ts-jest from 29.1.1 to 29.1.2
- Bump @aws-sdk/client-wafv2 from 3.490.0 to 3.496.0
- Bump @aws-sdk/client-service-quotas from 3.490.0 to 3.496.0
- Bump @types/node from 20.11.4 to 20.11.5
- Bump @aws-sdk/client-pricing from 3.490.0 to 3.496.0

## 4.2.0
### Fixed
- Output of the correct ManagedRuleGroup version if the stack has already been deployed, no version has been specifically set or Enforce Update has been set
Expand Down
49 changes: 32 additions & 17 deletions lib/tools/helpers/cloudformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@ import * as cloudformation from "@aws-sdk/client-cloudformation";
import { RuntimeProperties, ProcessProperties } from "../../types/runtimeprops";
import { Config } from "../../types/config";



/** Puts specified output values into the runtimeprops - this function is needed to identify chagend WCUs of WAF RuleGroups
* @param propertyName name of the property to write to eg.: DeployedRuleGroupNames
* @param runtimeProps runtime properties, where to write stack outputs into
* @param cloudformationOutputName name of the cloudformation output to get eg.: PreProcessDeployedRuleGroupNames
* @param describeStacksCommandOutput the output of the CloudFormation describeStacksCommand
*/
// eslint-disable-next-line no-inner-declarations
function processOutputsToProcessProperties<K extends keyof ProcessProperties>(
propertyName: K,
runtimeProps: ProcessProperties,
cloudformationOutputName: string,
describeStacksCommandOutput: cloudformation.DescribeStacksCommandOutput){

const outputValue = describeStacksCommandOutput.Stacks?.[0]?.Outputs?.find(output => output.OutputKey === cloudformationOutputName)?.OutputValue || "";
if(propertyName === "DeployedRuleGroupNames" || propertyName === "DeployedRuleGroupIdentifier"){
Object.assign(runtimeProps,{ [propertyName]: outputValue.split(",", outputValue.length) as ProcessProperties[K] });
}
if(propertyName === "DeployedRuleGroupCapacities"){
Object.assign(runtimeProps,{ [propertyName]: outputValue?.split(",",outputValue?.length).map(Number) as ProcessProperties[K] });
}
}


/**
* Writes outputs from an existing stack into the specified runtime props
* @param deploymentRegion AWS region, e.g. eu-central-1
Expand All @@ -19,24 +44,14 @@ export async function setOutputsFromStack(deploymentRegion: string, runtimeProps

try {
const responseStack = await cloudformationClient.send(command);
console.log("🫗 Get Outputs from existing CloudFormation Stack.\n");

const processOutput = (outputKey: string, target: ProcessProperties) => {
const outputValue = responseStack.Stacks?.[0]?.Outputs?.find(output => output.OutputKey === outputKey)?.OutputValue || "";
target.DeployedRuleGroupNames = outputValue.split(",", outputValue.length) || [];
};

processOutput("DeployedRuleGroupNames", runtimeProps.PreProcess);
processOutput("DeployedRuleGroupIdentifier", runtimeProps.PreProcess);
processOutput("DeployedRuleGroupCapacities", runtimeProps.PreProcess);

processOutput("PreProcessDeployedRuleGroupNames", runtimeProps.PreProcess);
processOutput("PreProcessDeployedRuleGroupIdentifier", runtimeProps.PreProcess);
processOutput("PreProcessDeployedRuleGroupCapacities", runtimeProps.PreProcess);

processOutput("PostProcessDeployedRuleGroupNames", runtimeProps.PostProcess);
processOutput("PostProcessDeployedRuleGroupIdentifier", runtimeProps.PostProcess);
processOutput("PostProcessDeployedRuleGroupCapacities", runtimeProps.PostProcess);
console.log("🫗 Get Outputs from existing CloudFormation Stack.\n");
processOutputsToProcessProperties("DeployedRuleGroupNames", runtimeProps.PreProcess, "PreProcessDeployedRuleGroupNames", responseStack);
processOutputsToProcessProperties("DeployedRuleGroupIdentifier", runtimeProps.PreProcess, "PreProcessDeployedRuleGroupIdentifier", responseStack);
processOutputsToProcessProperties("DeployedRuleGroupCapacities", runtimeProps.PreProcess, "PreProcessDeployedRuleGroupCapacities", responseStack);
processOutputsToProcessProperties("DeployedRuleGroupNames", runtimeProps.PostProcess, "PostProcessDeployedRuleGroupNames", responseStack);
processOutputsToProcessProperties("DeployedRuleGroupIdentifier", runtimeProps.PostProcess,"PostProcessDeployedRuleGroupIdentifier", responseStack);
processOutputsToProcessProperties("DeployedRuleGroupCapacities", runtimeProps.PostProcess, "PostProcessDeployedRuleGroupCapacities", responseStack);

} catch (e) {
console.log("🆕 Creating new CloudFormation Stack.\n");
Expand Down
Loading

0 comments on commit d6e9080

Please sign in to comment.