Skip to content

Commit

Permalink
Merge pull request #119 from globaldatanet/pricefix
Browse files Browse the repository at this point in the history
Fix Pricing Shield Advanced
  • Loading branch information
daknhh authored Jun 16, 2023
2 parents 615bf81 + fd488eb commit f29e55a
Show file tree
Hide file tree
Showing 4 changed files with 9,361 additions and 8,025 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Change Log

## Released
## 3.2.5
### Fixed
- Pricing Calculation - Check for Shield Advanced State
- All public regions & Global (Amazon CloudFront locations) - No charge per policy per Region
- AWS WAF WebACLs or Rules created by Firewall Manager - Included. No additional charge.

## 3.2.4
### Fixed
- Update TestCases for WAF Testing
Expand Down
18 changes: 17 additions & 1 deletion lib/tools/price-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { RuntimeProperties } from "../types/runtimeprops";
import { Config } from "../types/config";
import { PriceRegions } from "../types/config";
import {CloudWatchClient, ListDashboardsCommand, ListDashboardsCommandInput } from "@aws-sdk/client-cloudwatch";
import { ShieldClient, GetSubscriptionStateCommand } from "@aws-sdk/client-shield"


/**
* Amazon Web Services Price List Service API Endpoint
Expand Down Expand Up @@ -162,10 +164,15 @@ export async function isPriceCalculated(runtimeProps: RuntimeProperties): Promis
const captchacost = (runtimeProps.PostProcess.CustomCaptchaRuleCount + runtimeProps.PreProcess.CustomCaptchaRuleCount) * runtimeProps.Pricing.Captcha;
const botcontrolfixedcost = (runtimeProps.PostProcess.ManagedRuleBotControlCount + runtimeProps.PreProcess.ManagedRuleBotControlCount) * runtimeProps.Pricing.BotControl;
const atpfixedcost = (runtimeProps.PostProcess.ManagedRuleATPCount + runtimeProps.PreProcess.ManagedRuleATPCount) * runtimeProps.Pricing.AccountTakeoverPrevention;
const fixedcost = runtimeProps.Pricing.Policy + runtimeProps.Pricing.WebACL + postprocessfixedcost + preprocessfixedcost + botcontrolfixedcost + atpfixedcost + runtimeProps.Pricing.Dashboard;
let fixedcost = runtimeProps.Pricing.Policy + runtimeProps.Pricing.WebACL + postprocessfixedcost + preprocessfixedcost + botcontrolfixedcost + atpfixedcost + runtimeProps.Pricing.Dashboard;
const requestscost = runtimeProps.Pricing.Request;
const totalcost = fixedcost + (requestscost * 5) + (captchacost * 5);
const ShieldSubscriptionState = await getShieldSubscriptionState();
console.log("\n🛡️ Shield Advanced State: " + ShieldSubscriptionState?.toLowerCase())
console.log("\n💰 Cost: \n");
if(ShieldSubscriptionState === "ACTIVE"){
fixedcost = botcontrolfixedcost + atpfixedcost + runtimeProps.Pricing.Dashboard
}
console.log(" WAF Rules cost: " + fixedcost + " $ per month");
console.log(" WAF Requests: "+ requestscost + " $ pro 1 mio requests");
(captchacost > 0) ? console.log(" WAF Analysis fee:\n Captcha: " +captchacost +"$ per thousand challenge attempts analyzed") : " ";
Expand All @@ -176,7 +183,16 @@ export async function isPriceCalculated(runtimeProps: RuntimeProperties): Promis
(botcontrolfixedcost !== 0) ? console.log(" The deployed WAF includes BotControl rules this costs an extra fee of "+runtimeProps.Pricing.BotControl +" $ and " +runtimeProps.Pricing.BotControlRequest +"$ pro 1 mio requests (10 mio request Free Tier). \n These costs are already included in the price calculation.") : "";
(atpfixedcost !== 0) ? console.log(" The deployed WAF includes Account Takeover Prevention rules this costs an extra fee of "+runtimeProps.Pricing.AccountTakeoverPrevention+" $ and " + runtimeProps.Pricing.AccountTakeoverPreventionRequest +" $ per thousand login attempts analyzed (10,000 attempts analyzed Free Tier). \n These costs are already included in the price calculation.") : "";
(runtimeProps.Pricing.Dashboard !== 0) ? console.log(" The deployed WAF includes CloudWatch Dashboard and you have more than 3 Dashboards (Free tier), so you will need to pay " + runtimeProps.Pricing.Dashboard+ "$ for this CloudWatch Dashboard. \n These costs are already included in the price calculation.") : "";
(ShieldSubscriptionState === "Active") ? console.log(" AWS WAF WebACLs or Rules created by Firewall Manager - are Included in AWS Shield Advanced. More information at https://aws.amazon.com/firewall-manager/pricing/.") : "";
console.log("\n\n");
const pricecalculated = "True";
return pricecalculated;
}

async function getShieldSubscriptionState(){
const client = new ShieldClient({region: PRICING_API_ENDPOINT_REGION});
const input = {};
const command = new GetSubscriptionStateCommand(input);
const SubscriptionState = (await client.send(command)).SubscriptionState;
return SubscriptionState
}
Loading

0 comments on commit f29e55a

Please sign in to comment.