From 321dd1e5af2917a82517ddefb69992a613c26462 Mon Sep 17 00:00:00 2001 From: Thirumalesh Aaraveti <97395760+athiruma@users.noreply.github.com> Date: Tue, 12 Dec 2023 14:12:22 +0530 Subject: [PATCH] Added the bucket_path warning (#702) --- .../common_policies/send_aggregated_alerts.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cloud_governance/policy/common_policies/send_aggregated_alerts.py b/cloud_governance/policy/common_policies/send_aggregated_alerts.py index 741a7444..820f53e0 100644 --- a/cloud_governance/policy/common_policies/send_aggregated_alerts.py +++ b/cloud_governance/policy/common_policies/send_aggregated_alerts.py @@ -48,8 +48,9 @@ def __get_kerberos_users_for_iam_users(self): """ responses = {} users = self.__environment_variables.get('KERBEROS_USERS') - for iam_user, kerberos_user in users.items(): - responses[iam_user.lower()] = kerberos_user.lower() + if users: + for iam_user, kerberos_user in users.items(): + responses[iam_user.lower()] = kerberos_user.lower() return responses def __get_users_agg_result(self, policy_result: list, agg_users_result: dict, policy_name: str, region: str): @@ -81,11 +82,15 @@ def __get_policy_data_in_bucket(self, region: str, policy: str): try: policy_save_path = f'{self.__bucket_key}/{region}/{policy}' bucket_path_file = self.__s3_operations.get_last_objects(bucket=self.__bucket_name, key_prefix=f'{policy_save_path}/{self.TODAY_DATE}') - policy_s3_response = self.__s3_operations.get_last_s3_policy_content(s3_file_path=bucket_path_file, file_name=self.FILE_NAME) - return json.loads(policy_s3_response) if policy_s3_response else [] + if bucket_path_file: + policy_s3_response = self.__s3_operations.get_last_s3_policy_content(s3_file_path=bucket_path_file, file_name=self.FILE_NAME) + return json.loads(policy_s3_response) if policy_s3_response else [] + else: + logger.warn(f"No file_path: {policy_save_path}/{self.TODAY_DATE} exists in s3 bucket") except ClientError as err: logger.info(err) return [] + return [] @logger_time_stamp def __get_policy_users_list(self):