mirror of
https://github.com/ghndrx/prowler.git
synced 2026-02-10 14:55:00 +00:00
fix(organizations): Handle non existent policy (#3319)
This commit is contained in:
@@ -102,14 +102,13 @@ class Organizations(AWSService):
|
|||||||
)
|
)
|
||||||
for page in list_policies_paginator.paginate(Filter=policy_type):
|
for page in list_policies_paginator.paginate(Filter=policy_type):
|
||||||
for policy in page["Policies"]:
|
for policy in page["Policies"]:
|
||||||
policy_content = self.__describe_policy__(policy.get("Id"))
|
policy_id = policy.get("Id")
|
||||||
policy_targets = self.__list_targets_for_policy__(
|
policy_content = self.__describe_policy__(policy_id)
|
||||||
policy.get("Id")
|
policy_targets = self.__list_targets_for_policy__(policy_id)
|
||||||
)
|
|
||||||
self.policies.append(
|
self.policies.append(
|
||||||
Policy(
|
Policy(
|
||||||
arn=policy.get("Arn"),
|
arn=policy.get("Arn"),
|
||||||
id=policy.get("Id"),
|
id=policy_id,
|
||||||
type=policy.get("Type"),
|
type=policy.get("Type"),
|
||||||
aws_managed=policy.get("AwsManaged"),
|
aws_managed=policy.get("AwsManaged"),
|
||||||
content=policy_content,
|
content=policy_content,
|
||||||
@@ -134,23 +133,29 @@ class Organizations(AWSService):
|
|||||||
|
|
||||||
# This operation can be called only from the organization’s management account or by a member account that is a delegated administrator for an Amazon Web Services service.
|
# This operation can be called only from the organization’s management account or by a member account that is a delegated administrator for an Amazon Web Services service.
|
||||||
try:
|
try:
|
||||||
policy_desc = self.client.describe_policy(PolicyId=policy_id)["Policy"]
|
policy_content = {}
|
||||||
policy_content = policy_desc["Content"]
|
if policy_id:
|
||||||
policy_content_json = json.loads(policy_content)
|
policy_content = (
|
||||||
|
self.client.describe_policy(PolicyId=policy_id)
|
||||||
|
.get("Policy", {})
|
||||||
|
.get("Content", "")
|
||||||
|
)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
logger.error(
|
logger.error(
|
||||||
f"{self.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
|
f"{self.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
return policy_content_json
|
return json.loads(policy_content)
|
||||||
|
|
||||||
def __list_targets_for_policy__(self, policy_id):
|
def __list_targets_for_policy__(self, policy_id):
|
||||||
logger.info("Organizations - List Targets for policy: %s ...", policy_id)
|
logger.info("Organizations - List Targets for policy: %s ...", policy_id)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
targets_for_policy = self.client.list_targets_for_policy(
|
targets_for_policy = []
|
||||||
PolicyId=policy_id
|
if policy_id:
|
||||||
)["Targets"]
|
targets_for_policy = self.client.list_targets_for_policy(
|
||||||
|
PolicyId=policy_id
|
||||||
|
)["Targets"]
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
logger.error(
|
logger.error(
|
||||||
f"{self.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
|
f"{self.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
|
||||||
|
|||||||
Reference in New Issue
Block a user