First of all, good job guys, thanks for the effort. I only used your tool for a few days but it helped me to catch some mistakes early.
I found a bug that produces a very confusing error. Essentially the bug hides a helpful message.
When an incorrect policy document format is used the validator is supposed to tell the given and the expected format(s). But instead, it throws a TypeError caused by the validator code itself.
E.g.
<class 'troposphere.iam.Policy'>: None.PolicyDocument function validator 'policytypes' threw exception:
Traceback (most recent call last):
File "/home/user/cf_project/eval.cf_policy.py", line 93, in <module>
iam.Policy(
File "/home/user/cf_project/venv/lib/python3.10/site-packages/troposphere/__init__.py", line 455, in __init__
super().__init__(title, **kwargs)
File "/home/user/cf_project/venv/lib/python3.10/site-packages/troposphere/__init__.py", line 210, in __init__
self.__setattr__(k, v)
File "/home/user/cf_project/venv/lib/python3.10/site-packages/troposphere/__init__.py", line 266, in __setattr__
value = expected_type(value)
File "/home/user/cf_project/venv/lib/python3.10/site-packages/troposphere/validators/iam.py", line 88, in policytypes
return validate_policytype(policy)
File "/home/user/cf_project/venv/lib/python3.10/site-packages/troposphere/compat.py", line 21, in validate_policytype
"Invalid policy type: is %s, expected %s" % type(policy), policytypes
TypeError: not enough arguments for format string
With the issue fixed the validator actually shows the intended message, which is actually helpful.
<class 'troposphere.iam.Policy'>: None.PolicyDocument function validator 'policytypes' threw exception:
Traceback (most recent call last):
File "/home/user/cf_project/eval.parameter_injection.py", line 123, in <module>
iam.Policy(
File "/home/user/cf_project/venv/lib/python3.10/site-packages/troposphere/__init__.py", line 455, in __init__
super().__init__(title, **kwargs)
File "/home/user/cf_project/venv/lib/python3.10/site-packages/troposphere/__init__.py", line 210, in __init__
self.__setattr__(k, v)
File "/home/user/cf_project/venv/lib/python3.10/site-packages/troposphere/__init__.py", line 266, in __setattr__
value = expected_type(value)
File "/home/user/cf_project/venv/lib/python3.10/site-packages/troposphere/validators/iam.py", line 88, in policytypes
return validate_policytype(policy)
File "/home/user/cf_project/venv/lib/python3.10/site-packages/troposphere/compat.py", line 26, in validate_policytype
raise TypeError(
TypeError: Invalid policy type: is <class 'str'>, expected (<class 'dict'>, <class 'awacs.aws.Policy'>, <class 'awacs.aws.PolicyDocument'>)
I made the changes, it's trivial, but I can't push it to the repo.
Hi,
First of all, good job guys, thanks for the effort. I only used your tool for a few days but it helped me to catch some mistakes early.
I found a bug that produces a very confusing error. Essentially the bug hides a helpful message. When an incorrect policy document format is used the validator is supposed to tell the given and the expected format(s). But instead, it throws a TypeError caused by the validator code itself. E.g.
With the issue fixed the validator actually shows the intended message, which is actually helpful.
I made the changes, it's trivial, but I can't push it to the repo.
Cheers!