Compare commits

...

2 Commits

Author SHA1 Message Date
lavenderguitar da47558566 Variablize region and limit 2 years ago
lavenderguitar 57061594ee Accommodate the change-token option 2 years ago
  1. 18
      bash/delete_wafv1_rules.sh

18
bash/delete_wafv1_rules.sh

@ -1,14 +1,23 @@
#!/bin/bash #!/bin/bash
REGION="us-east-1"
LIMIT=50
get_change_token() {
local response=$(aws waf get-change-token --region $REGION)
local change_token=$(echo "$response" | jq -r '.ChangeToken')
echo "$change_token"
}
list_waf_rules() { list_waf_rules() {
local next_token="" local next_token=""
while true; do while true; do
local response=$(aws waf list-rules --region us-west-2 --limit 50 --next-marker "$next_token") local response=$(aws waf list-rules --region $REGION --limit $LIMIT --next-marker "$next_token")
local rule_ids=($(echo "$response" | jq -r '.Rules[].RuleId')) local rule_ids=($(echo "$response" | jq -r '.Rules[].RuleId'))
for rule_id in "${rule_ids[@]}"; do for rule_id in "${rule_ids[@]}"; do
local rule_name=$(aws waf get-rule --region us-west-2 --rule-id "$rule_id" --query 'Rule.Name') local rule_name=$(aws waf get-rule --region $REGION --rule-id "$rule_id" --query 'Rule.Name')
echo "Rule ID: $rule_id, Rule Name: $rule_name" echo "Rule ID: $rule_id, Rule Name: $rule_name"
done done
@ -20,15 +29,16 @@ list_waf_rules() {
} }
delete_waf_rules() { delete_waf_rules() {
local change_token=$(get_change_token)
local next_token="" local next_token=""
while true; do while true; do
local response=$(aws waf list-rules --region us-west-2 --limit 50 --next-marker "$next_token") local response=$(aws waf list-rules --region $REGION --limit $LIMIT --next-marker "$next_token")
local rule_ids=($(echo "$response" | jq -r '.Rules[].RuleId')) local rule_ids=($(echo "$response" | jq -r '.Rules[].RuleId'))
for rule_id in "${rule_ids[@]}"; do for rule_id in "${rule_ids[@]}"; do
echo "Deleting Rule ID: $rule_id" echo "Deleting Rule ID: $rule_id"
aws waf delete-rule --region us-west-2 --rule-id "$rule_id" aws waf delete-rule --region $REGION --rule-id "$rule_id" --change-token "$change_token"
done done
local next_token=$(echo "$response" | jq -r '.NextMarker') local next_token=$(echo "$response" | jq -r '.NextMarker')

Loading…
Cancel
Save