Skip to content

Commit

Permalink
fixed linting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
itsnotsagar committed May 24, 2024
1 parent ef6d817 commit dcc0d5f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.",
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down Expand Up @@ -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 []

Expand Down

0 comments on commit dcc0d5f

Please sign in to comment.