From b229c01450ead8408952540205aac8fbb0abce0f Mon Sep 17 00:00:00 2001 From: Sergio Garcia <38561120+sergargar@users.noreply.github.com> Date: Mon, 8 Aug 2022 16:26:50 -0400 Subject: [PATCH] fix(key_error): remove KeyError. (#1326) --- .../iam_disable_30_days_credentials.py | 26 ++++++++----------- .../iam_disable_90_days_credentials.py | 26 ++++++++----------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/providers/aws/services/iam/iam_disable_30_days_credentials/iam_disable_30_days_credentials.py b/providers/aws/services/iam/iam_disable_30_days_credentials/iam_disable_30_days_credentials.py index 11e13d37..e63eb820 100644 --- a/providers/aws/services/iam/iam_disable_30_days_credentials/iam_disable_30_days_credentials.py +++ b/providers/aws/services/iam/iam_disable_30_days_credentials/iam_disable_30_days_credentials.py @@ -17,22 +17,18 @@ class iam_disable_30_days_credentials(Check): report.resource_arn = user.arn report.region = iam_client.region if user.password_last_used and user.password_last_used != "": - try: - time_since_insertion = ( - datetime.datetime.now() - - datetime.datetime.strptime( - str(user.password_last_used), "%Y-%m-%d %H:%M:%S+00:00" - ) + time_since_insertion = ( + datetime.datetime.now() + - datetime.datetime.strptime( + str(user.password_last_used), "%Y-%m-%d %H:%M:%S+00:00" ) - if time_since_insertion.days > maximum_expiration_days: - report.status = "FAIL" - report.status_extended = f"User {user.name} has not logged into the console in the past 30 days." - else: - report.status = "PASS" - report.status_extended = f"User {user.name} has logged into the console in the past 30 days." - - except KeyError: - pass + ) + if time_since_insertion.days > maximum_expiration_days: + report.status = "FAIL" + report.status_extended = f"User {user.name} has not logged into the console in the past 30 days." + else: + report.status = "PASS" + report.status_extended = f"User {user.name} has logged into the console in the past 30 days." else: report.status = "PASS" report.status_extended = ( diff --git a/providers/aws/services/iam/iam_disable_90_days_credentials/iam_disable_90_days_credentials.py b/providers/aws/services/iam/iam_disable_90_days_credentials/iam_disable_90_days_credentials.py index ac023145..c3289432 100644 --- a/providers/aws/services/iam/iam_disable_90_days_credentials/iam_disable_90_days_credentials.py +++ b/providers/aws/services/iam/iam_disable_90_days_credentials/iam_disable_90_days_credentials.py @@ -17,22 +17,18 @@ class iam_disable_90_days_credentials(Check): report.resource_id = user.name report.resource_arn = user.arn if user.password_last_used and user.password_last_used != "": - try: - time_since_insertion = ( - datetime.datetime.now() - - datetime.datetime.strptime( - str(user.password_last_used), "%Y-%m-%d %H:%M:%S+00:00" - ) + time_since_insertion = ( + datetime.datetime.now() + - datetime.datetime.strptime( + str(user.password_last_used), "%Y-%m-%d %H:%M:%S+00:00" ) - if time_since_insertion.days > maximum_expiration_days: - report.status = "FAIL" - report.status_extended = f"User {user.name} has not logged into the console in the past 90 days." - else: - report.status = "PASS" - report.status_extended = f"User {user.name} has logged into the console in the past 90 days." - - except KeyError: - pass + ) + if time_since_insertion.days > maximum_expiration_days: + report.status = "FAIL" + report.status_extended = f"User {user.name} has not logged into the console in the past 90 days." + else: + report.status = "PASS" + report.status_extended = f"User {user.name} has logged into the console in the past 90 days." else: report.status = "PASS"