Skip to content

Commit 7318195

Browse files
author
Justin
committed
removed prints, updated contact logic
1 parent 5451ab1 commit 7318195

File tree

2 files changed

+6
-19
lines changed
  • aws_sra_examples/solutions/shield_advanced/shield_advanced/lambda/src

2 files changed

+6
-19
lines changed

aws_sra_examples/solutions/shield_advanced/shield_advanced/lambda/src/app.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"""
1010
from __future__ import annotations
1111

12-
import json
1312
import logging
1413
import os
1514
import re
@@ -521,15 +520,12 @@ def setup_shield_global(params: dict, accounts: list) -> None:
521520
if params["SHIELD_ACCOUNTS_TO_PROTECT"] == "ALL":
522521
LOGGER.info("Protect all accounts")
523522
else:
524-
LOGGER.info("")
525523
accounts = []
526-
print(f'SHIELD_ACCOUNTS_TO_PROTECT {params["SHIELD_ACCOUNTS_TO_PROTECT"]}')
527524
for account in params["SHIELD_ACCOUNTS_TO_PROTECT"].split(","):
528-
print(f"Adding AccountId: {account} to accounts")
529525
accounts.append({"AccountId": account})
530526
for account in accounts:
531527
account_id = account["AccountId"]
532-
print(account_id)
528+
LOGGER.info(f"Configuring account {account_id}")
533529
shield.check_if_key_in_object(account_id, shield.RESOURCES_BY_ACCOUNT, "dict")
534530

535531
account_session: boto3.Session = common.assume_role(params["CONFIGURATION_ROLE_NAME"], "sra-configure-shield", account_id)
@@ -554,7 +550,7 @@ def teardown_shield(account_session: boto3.Session, account_id: str, params: dic
554550
LOGGER.info(f"Teardown shield in for account {account_id} in ")
555551
shield.build_resources_by_account(account_session, params, account_id)
556552
shield_client = account_session.client("shield")
557-
shield.disable_proactive_engagement(shield_client) #
553+
shield.disable_proactive_engagement(shield_client)
558554

559555
while len(shield.RESOURCES_BY_ACCOUNT[account_id]["buckets"]) > 0:
560556
bucket = shield.RESOURCES_BY_ACCOUNT[account_id]["buckets"].pop()
@@ -563,11 +559,8 @@ def teardown_shield(account_session: boto3.Session, account_id: str, params: dic
563559
while len(shield.RESOURCES_BY_ACCOUNT[account_id]["resources_to_protect"]) > 0:
564560
resource = shield.RESOURCES_BY_ACCOUNT[account_id]["resources_to_protect"].pop()
565561
if resource not in resources_processed:
566-
# if "::" in resource or region in resource and resource:
567562
shield.delete_protection(shield_client, resource)
568563
resources_processed.append(resource)
569-
# else:
570-
# shield.RESOURCES_BY_ACCOUNT[account_id]["resources_to_protect"].append(resource)
571564
shield.delete_protection_group(shield_client, params, account_id)
572565
shield.update_emergency_contacts(shield_client, params, True)
573566

aws_sra_examples/solutions/shield_advanced/shield_advanced/lambda/src/shield.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from typing import TYPE_CHECKING, Any, Literal, Sequence
1616

1717
import boto3
18-
import common
1918
from botocore.exceptions import ClientError
2019

2120
if TYPE_CHECKING:
@@ -51,9 +50,6 @@
5150

5251

5352
UNEXPECTED = "Unexpected!"
54-
# shield_THROTTLE_PERIOD: float = 0.2
55-
ENABLE_RETRY_ATTEMPTS: int = 10
56-
ENABLE_RETRY_SLEEP_INTERVAL: int = 10
5753
RESOURCES_BY_ACCOUNT: dict = {}
5854

5955
try:
@@ -644,7 +640,6 @@ def create_protection_group(shield_client: ShieldClient, params: dict, account_i
644640
account_id: AWS account id
645641
"""
646642
for i in range(0, 5):
647-
print(i)
648643
pg_id: str = params[f"PROTECTION_GROUP_{i}_ID"]
649644
pg_account_id: str = params[f"PROTECTION_GROUP_{i}_ACCOUNT_ID"]
650645
pg_aggregation: Literal["SUM", "MEAN", "MAX"] = params[f"PROTECTION_GROUP_{i}_AGGREGATION"]
@@ -657,10 +652,7 @@ def create_protection_group(shield_client: ShieldClient, params: dict, account_i
657652
"APPLICATION_LOAD_BALANCER",
658653
"GLOBAL_ACCELERATOR",
659654
] = params[f"PROTECTION_GROUP_{i}_RESOURCE_TYPE"]
660-
print(f" pg_account_id {pg_account_id}")
661655
pg_members: list = params[f"PROTECTION_GROUP_{i}_MEMBERS"]
662-
print(f"pg_members{pg_members}")
663-
print(f"i {i}")
664656
if pg_id != "" and pg_account_id == account_id:
665657
if check_if_protection_group_exists(shield_client, pg_id):
666658
LOGGER.info(f"Protection_Group_{i} already exists in {account_id}")
@@ -695,7 +687,10 @@ def check_emergency_contacts(shield_client: ShieldClient) -> bool:
695687
emergency_contacts_response: DescribeEmergencyContactSettingsResponseTypeDef = shield_client.describe_emergency_contact_settings()
696688
api_call_details = {"API_Call": "shield:DescribeEmergencyContactSettings", "API_Response": emergency_contacts_response}
697689
LOGGER.info(api_call_details)
698-
return True
690+
if len(emergency_contacts_response) > 0:
691+
return True
692+
else:
693+
return False
699694
except shield_client.exceptions.ResourceNotFoundException:
700695
return False
701696

@@ -707,7 +702,6 @@ def enable_proactive_engagement(shield_client: ShieldClient, params: dict) -> No
707702
shield_client: shield client
708703
params: environment variables
709704
"""
710-
print(f"Before IF SHIELD_ENABLE_PROACTIVE_ENGAGEMENT is set to {params['SHIELD_ENABLE_PROACTIVE_ENGAGEMENT']}")
711705
if params["SHIELD_ENABLE_PROACTIVE_ENGAGEMENT"] == "true":
712706
if check_proactive_engagement_enabled(shield_client, params):
713707
update_emergency_contacts(shield_client, params)

0 commit comments

Comments
 (0)