Fixed resource exist validation and implemented actions exist validation.
This commit is contained in:
parent
55f9040296
commit
50745fc5c0
@ -35,9 +35,9 @@ ALLOWED_EFFECTS = [
|
|||||||
|
|
||||||
class IAMPolicyDocumentValidator:
|
class IAMPolicyDocumentValidator:
|
||||||
|
|
||||||
def __init__(self, policy_document):
|
def __init__(self, policy_document: str):
|
||||||
self._policy_document = policy_document
|
self._policy_document: str = policy_document
|
||||||
self._policy_json = {}
|
self._policy_json: dict = {}
|
||||||
self._statements = []
|
self._statements = []
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
@ -49,6 +49,10 @@ class IAMPolicyDocumentValidator:
|
|||||||
self._validate_version()
|
self._validate_version()
|
||||||
except Exception:
|
except Exception:
|
||||||
raise MalformedPolicyDocument("Policy document must be version 2012-10-17 or greater.")
|
raise MalformedPolicyDocument("Policy document must be version 2012-10-17 or greater.")
|
||||||
|
try:
|
||||||
|
self._validate_action_exist()
|
||||||
|
except Exception:
|
||||||
|
raise MalformedPolicyDocument("Policy statement must contain actions.")
|
||||||
try:
|
try:
|
||||||
self._validate_resource_exist()
|
self._validate_resource_exist()
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -139,10 +143,16 @@ class IAMPolicyDocumentValidator:
|
|||||||
assert isinstance(statement["Sid"], string_types)
|
assert isinstance(statement["Sid"], string_types)
|
||||||
|
|
||||||
def _validate_id_syntax(self):
|
def _validate_id_syntax(self):
|
||||||
if "Id" in self._policy_document:
|
if "Id" in self._policy_json:
|
||||||
assert isinstance(self._policy_document["Id"], string_types)
|
assert isinstance(self._policy_json["Id"], string_types)
|
||||||
|
|
||||||
def _validate_resource_exist(self):
|
def _validate_resource_exist(self):
|
||||||
for statement in self._statements:
|
for statement in self._statements:
|
||||||
assert "Resource" in statement
|
assert "Resource" in statement
|
||||||
|
if isinstance(statement["Resource"], list):
|
||||||
|
assert statement["Resource"]
|
||||||
|
|
||||||
|
def _validate_action_exist(self):
|
||||||
|
for statement in self._statements:
|
||||||
|
assert "Action" in statement
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user