Skip to content

Commit 26aa9ac

Browse files
committed
removing unused params from kms module
1 parent 5bb3ff8 commit 26aa9ac

File tree

1 file changed

+21
-20
lines changed
  • aws_sra_examples/solutions/genai/bedrock_org/lambda/src

1 file changed

+21
-20
lines changed

aws_sra_examples/solutions/genai/bedrock_org/lambda/src/sra_kms.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ class sra_kms:
3838
LOGGER.setLevel(log_level)
3939

4040
# Global Variables
41-
RESOURCE_TYPE: str = ""
41+
# RESOURCE_TYPE: str = ""
4242
UNEXPECTED = "Unexpected!"
4343
BOTO3_CONFIG = Config(retries={"max_attempts": 10, "mode": "standard"})
44-
SRA_SOLUTION_NAME = "sra-common-prerequisites"
45-
CFN_RESOURCE_ID: str = "sra-iam-function"
46-
CFN_CUSTOM_RESOURCE: str = "Custom::LambdaCustomResource"
47-
48-
CONFIGURATION_ROLE: str = ""
49-
TARGET_ACCOUNT_ID: str = ""
50-
ORG_ID: str = ""
51-
52-
KEY_ALIAS: str = "alias/sra-secrets-key" # TODO(liamschn): parameterize this alias name
53-
KEY_DESCRIPTION: str = "SRA Secrets Key" # TODO(liamschn): parameterize this description
54-
EXECUTION_ROLE: str = "sra-execution" # TODO(liamschn): parameterize this role name
55-
SECRETS_PREFIX: str = "sra" # TODO(liamschn): parameterize this?
44+
# SRA_SOLUTION_NAME = "sra-common-prerequisites"
45+
# CFN_RESOURCE_ID: str = "sra-iam-function"
46+
# CFN_CUSTOM_RESOURCE: str = "Custom::LambdaCustomResource"
47+
48+
# CONFIGURATION_ROLE: str = ""
49+
# TARGET_ACCOUNT_ID: str = ""
50+
# ORG_ID: str = ""
51+
52+
# KEY_ALIAS: str = "alias/sra-secrets-key" # TODO(liamschn): parameterize this alias name
53+
# KEY_DESCRIPTION: str = "SRA Secrets Key" # TODO(liamschn): parameterize this description
54+
# EXECUTION_ROLE: str = "sra-execution" # TODO(liamschn): parameterize this role name
55+
# SECRETS_PREFIX: str = "sra" # TODO(liamschn): parameterize this?
5656
SECRETS_KEY_POLICY: str = ""
5757

5858
try:
@@ -176,21 +176,22 @@ def schedule_key_deletion(self, kms_client: KMSClient, key_id: str, pending_wind
176176
self.LOGGER.info(f"Schedule deletion of key: {key_id} in {pending_window_in_days} days")
177177
kms_client.schedule_key_deletion(KeyId=key_id, PendingWindowInDays=pending_window_in_days)
178178

179-
def search_key_policies(self, kms_client: KMSClient) -> tuple[bool, str]:
179+
def search_key_policies(self, kms_client: KMSClient, key_policy: str) -> tuple[bool, str]:
180180
for key in self.list_all_keys(kms_client):
181+
self.LOGGER.info(f"Examinining policies in {key} kms key...")
181182
for policy in self.list_key_policies(kms_client, key["KeyId"]):
182183
policy_body = kms_client.get_key_policy(KeyId=key["KeyId"], PolicyName=policy)["Policy"]
183184
policy_body = json.loads(policy_body)
184-
self.LOGGER.info(f"Key policy: {policy_body}")
185-
self.LOGGER.info(f"SECRETS_KEY_POLICY: {self.SECRETS_KEY_POLICY}")
186-
secrets_key_policy = json.loads(self.SECRETS_KEY_POLICY)
187-
if policy_body == secrets_key_policy:
185+
self.LOGGER.info(f"Examining policy: {policy_body}")
186+
self.LOGGER.info(f"Comparing policy to provided policy: {key_policy}")
187+
expected_key_policy = json.loads(key_policy)
188+
if policy_body == expected_key_policy:
188189
self.LOGGER.info(f"Key policy match found for key {key['KeyId']} policy {policy}: {policy_body}")
189-
self.LOGGER.info(f"Attempted to match to: {secrets_key_policy}")
190+
self.LOGGER.info(f"Attempted to match to: {expected_key_policy}")
190191
return True, key["KeyId"]
191192
else:
192193
self.LOGGER.info(f"No key policy match found for key {key['KeyId']} policy {policy}: {policy_body}")
193-
self.LOGGER.info(f"Attempted to match to: {secrets_key_policy}")
194+
self.LOGGER.info(f"Attempted to match to: {expected_key_policy}")
194195
return False, "None"
195196

196197
def list_key_policies(self, kms_client: KMSClient, key_id: str) -> list:

0 commit comments

Comments
 (0)