Skip to content

Commit

Permalink
Tox no longer complaining
Browse files Browse the repository at this point in the history
  • Loading branch information
EC2 Default User committed Jun 13, 2024
1 parent da91c6f commit 54293e9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
DEFAULT_ADF_POLICIES_DIR = "./adf-policies"


# pylint: disable=W1201, C0209
class OrganizationPolicy:
adf_policies_dir: str

Expand Down Expand Up @@ -119,7 +120,7 @@ def apply(
organization_mapping,
supported_policies,
)

# pylint: disable=R0914
def apply_policies(
self,
Expand Down Expand Up @@ -168,7 +169,6 @@ def apply_policies(
"Parameter %s was not found in Parameter Store, continuing.",
policy,
)
pass
for _policy in _legacy_policies:
LOGGER.info("Loading policy: %s", _policy)
proposed_policy = json.loads(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PolicyTargetNotFoundException(OrganizationPolicyException):
def __init__(self, *args: object) -> None:
super().__init__(*args)


# pylint: disable=W1508. R1735, W0235, R1734, W1201, C0209
class OrganizationPolicyTarget:
existing_policy_ids: dict()
path: str
Expand Down Expand Up @@ -79,7 +79,7 @@ def attach_policy(self, policy_id, policy_name):
self.existing_policy_ids[policy_id] = policy_name
else:
LOGGER.info(
"Policy {%s} ({%s}) already attached to {%s}" %
"Policy %s (%s) already attached to %s" %
(policy_name, policy_id, self),
)

Expand Down Expand Up @@ -146,7 +146,7 @@ def get_current_targets_for_policy(self):
self.organizations_client.exceptions.AccessDeniedException
) as e:
LOGGER.critical(
"Error fetching targets for policy {%s} {%s}: Access Denied"
"Error fetching targets for policy %s %s: Access Denied"
% (self.name.self.id)
)
LOGGER.error(e)
Expand All @@ -157,7 +157,7 @@ def get_current_targets_for_policy(self):
self.organizations_client.exceptions.AWSOrganizationsNotInUseException
) as e:
LOGGER.critical(
"Error fetching targets for policy {%s} {%s}: Organizations not in use"
"Error fetching targets for policy %s %s: Organizations not in use"
% (self.name.self.id)
)
LOGGER.error(e)
Expand All @@ -168,7 +168,7 @@ def get_current_targets_for_policy(self):
self.organizations_client.exceptions.InvalidInputException
) as e:
LOGGER.critical(
"Error fetching targets for policy {%s} {%s}: Invalid Input"
"Error fetching targets for policy %s %s: Invalid Input"
% (self.name.self.id)
)
LOGGER.error(e)
Expand All @@ -177,7 +177,7 @@ def get_current_targets_for_policy(self):
) from e
except self.organizations_client.exceptions.ServiceException as e:
LOGGER.critical(
"Error fetching targets for policy {%s} {%s}: Service Exception" %
"Error fetching targets for policy %s %s: Service Exception" %
(self.name.self.id),
)
LOGGER.error(e)
Expand All @@ -188,7 +188,7 @@ def get_current_targets_for_policy(self):
self.organizations_client.exceptions.TooManyRequestsException
) as e:
LOGGER.critical(
"Error fetching targets for policy {%s} {%s}: Access Denied"
"Error fetching targets for policy %s %s: Access Denied"
% (self.name.self.id)
)
LOGGER.error(e)
Expand Down Expand Up @@ -258,7 +258,8 @@ def update_targets(self):
self.organizations_client.exceptions.AccessDeniedException
) as e:
LOGGER.critical(
f"Error detaching policy {self.name} ({self.id}) from target {target_id}: Access Denied"
"Error detaching policy %s (%s) from target %s: Access Denied" %
(self.name, self.id, target_id)
)
LOGGER.error(e)
raise OrganizationPolicyException(
Expand All @@ -268,23 +269,26 @@ def update_targets(self):
self.organizations_client.exceptions.PolicyNotAttachedException
) as e:
LOGGER.warning(
f"Error detaching policy {self.name} ({self.id}) from target {target_id}: Policy Not Attached"
"Error detaching policy %s (%s) from target %s: Policy Not Attached" %
(self.name, self.id, target_id)
)
LOGGER.info(e)
return
except (
self.organizations_client.exceptions.TargetNotFoundException
) as e:
LOGGER.critical(
f"Error detaching policy {self.name} ({self.id}) from target {target_id}: Target Not Found"
"Error detaching policy %s (%s) from target %s: Target Not Found" %
(self.name, self.id, target_id)
)
LOGGER.error(e)
raise OrganizationPolicyException(
f"Error detaching policy {self.name} {self.id}: Target {target_id} Not Found"
) from e
except Exception as e:
LOGGER.critical(
f"Error detaching policy {self.name} {self.id}: Unexpected Exception"
"Error detaching policy %s %s: Unexpected Exception" %
(self.name, self.id)
)
LOGGER.error(e)
raise e
Expand Down Expand Up @@ -516,8 +520,9 @@ def update_policy(self, policy_name, policy_body):
except self.organizations.exceptions.AccessDeniedException as e:
LOGGER.critical("Error describing existing policy: Access Denied")
LOGGER.error(e)
policy_id = self.existing_policy_lookup[policy_name]
raise OrganizationPolicyException(
f"Access Denied when fetching existing policy : {policy_name}{self.existing_policy_lookup[policy_name]} ({self.type})"
f"Access Denied when fetching policy : {policy_name}{policy_id} ({self.type})"
) from e
except (
self.organizations.exceptions.AWSOrganizationsNotInUseException
Expand Down Expand Up @@ -616,7 +621,7 @@ def apply(self):
)
if self.policies_to_be_deleted:
LOGGER.info(
"The following policies will be deleted as they are no longer defined in a file: %s",
"The following will be deleted as they are no longer defined in a file: %s",
self.policies_to_be_deleted,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1149,10 +1149,16 @@ def test_policy_detachment_error_handling_policy_not_attached(self):
policy_campaign = OrganizationPolicyApplicationCampaign(
"SERVICE_CONTROL_POLICY", org_mapping, {}, org_client
)
ex_r = (
"WARNING:organization_policy_campaign:Error detaching policy"
" MyFirstPolicy (fake-policy-3) from target 11223344556: "
"Policy Not Attached"
)

with self.assertLogs("organization_policy_campaign", "WARNING") as log:
policy_campaign.apply()
self.assertIn(
"WARNING:organization_policy_campaign:Error detaching policy MyFirstPolicy (fake-policy-3) from target 11223344556: Policy Not Attached",
ex_r,
log.output,
)

Expand Down

0 comments on commit 54293e9

Please sign in to comment.