From dcc0d5fc3f9757bdf7ff8c9d76adb01d2c9bd5c5 Mon Sep 17 00:00:00 2001 From: itsnotsagar Date: Fri, 24 May 2024 19:27:40 +0530 Subject: [PATCH] fixed linting issue --- .../adf-build/organization_policy.py | 21 ++++++++++++------- .../adf-build/shared/python/organizations.py | 7 +++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/organization_policy.py b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/organization_policy.py index b10aacbae..8fd3cd53e 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/organization_policy.py +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/organization_policy.py @@ -60,17 +60,16 @@ def _is_govcloud(region: str) -> bool: :return: Returns True if the region is GovCloud, False otherwise. """ return region.startswith("us-gov") - + @staticmethod def return_policy_name(policy_type, target_path, policy_filename): _type = 'scp' if policy_type == "SERVICE_CONTROL_POLICY" else 'tagging-policy' if policy_filename != f'{_type}.json': #filter the policy name to remove the .json extension policy_filename = policy_filename.split('.')[0] - return 'adf-{0}-{1}-{2}'.format(_type, target_path, policy_filename) - else: - # Added for backwards-compatibility with previous versions of ADF - return 'adf-{0}-{1}'.format(_type, target_path) + return f'adf-{_type}-{target_path}-{policy_filename}' + # Added for backwards-compatibility with previous versions of ADF + return f'adf-{_type}-{target_path}' @staticmethod def set_scp_attachment(access_identifier, organization_mapping, path, organizations): @@ -173,14 +172,16 @@ def apply( config.get("scp"), organization_mapping, path, organizations ) if stored_policy not in policy_paths: - path, policy_filename = OrganizationPolicy._trim_policy_file_name(stored_policy) + path, policy_filename = OrganizationPolicy._trim_policy_file_name( + stored_policy + ) OrganizationPolicy.clean_and_remove_policy_attachment( organization_mapping, path, policy_filename, organizations, policy_type - ) + ) except ParameterNotFoundError: LOGGER.debug( "Parameter %s was not found in Parameter Store, continuing.", @@ -189,7 +190,11 @@ def apply( for policy_path in policy_paths: path, policy_filename = OrganizationPolicy._trim_policy_file_name(policy_path) - policy_name = OrganizationPolicy.return_policy_name(policy_type, path, policy_filename) + policy_name = OrganizationPolicy.return_policy_name( + policy_type, + path, + policy_filename + ) policy_id = organizations.describe_policy_id_for_target( organization_mapping[path], policy_name, diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/organizations.py b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/organizations.py index c35d583e6..3ef837998 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/organizations.py +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/organizations.py @@ -180,7 +180,7 @@ def create_policy( policy_name, policy_type="SERVICE_CONTROL_POLICY", ): - + response = self.client.create_policy( Content=content, Description=f"ADF Managed {policy_type}", @@ -212,7 +212,10 @@ def describe_policy_id_for_target( TargetId=target_id, Filter=policy_type ) try: - return [p for p in response['Policies'] if 'ADF Managed {0}'.format(policy_type) in p['Description'] and p['Name'] == policy_name][0]['Id'] + return [ + p for p in response['Policies'] + if f'ADF Managed {policy_type}' in p['Description'] and p['Name'] == policy_name + ][0]['Id'] except IndexError: return []