`.type` is not always set
solidsnack opened this issue · 2 comments
solidsnack commented
awacs.aws.Policy(Version='2012-10-17', Statement=[]) # No error
awacs.aws.Policy(Version='2012-10-17', statement=[]) # Try to raise on line 84, but .type is never set, so we raise on line 46
GitHub's storage layer is down but here is a patch that I presume does the right thing.
--- a/awacs/__init__.py 2015-10-18 15:35:38.000000000 -0700
+++ b/awacs/__init__.py 2015-10-18 15:40:23.000000000 -0700
@@ -20,6 +20,10 @@
self.props = props
# Cache the keys for validity checks
self.propnames = props.keys()
+ if type is None:
+ self.type = type(self).__module__ + '.' + type(self).__name__
+ else:
+ self.type = type
# unset/None is also legal
if name and not valid_names.match(name):
drcoll commented
I'm experiencing this same issue I believe:
File "..../blueprints/lambda.py", line 101, in create_role
Resource=[awacs.logs.ARN(resource="*", region="*", account="*")]
File "..../venv/local/lib/python2.7/site-packages/awacs/__init__.py", line 111, in __init__
sup.__init__(None, props=self.props, **kwargs)
File "..../venv/local/lib/python2.7/site-packages/awacs/__init__.py", line 40, in __init__
self.__setattr__(k, v)
File "..../venv/local/lib/python2.7/site-packages/awacs/__init__.py", line 84, in __setattr__
(self.type, name))
File "..../venv/local/lib/python2.7/site-packages/awacs/__init__.py", line 46, in __getattr__
raise AttributeError(name)
AttributeError: type
When trying to do this:
t.add_resource(
iam.Role(
LAMBDA_EXECUTION_ROLE,
Policies=[Policy(
PolicyName='{}-lambda-execute'.format(ns),
PolicyDocument=Policy(
Version="2012-10-17",
Statement=[
Statement(
Action=[Action('logs', '*')],
Effect="Allow",
Resource=[awacs.logs.ARN(resource="*", region="*", account="*")]
)
]
)
)],
AssumeRolePolicyDocument=Policy(
Version="2012-10-17",
Statement=[
Statement(
Action=[sts.AssumeRole],
Effect="Allow",
Principal=Principal(
"Service", ["lambda.amazonaws.com"]
)
)
]
)
)
)
michael-dickinson commented
I am receiving the same error as @drcoll above, so I tried to manually apply the patch in this issue, however, I now get:
Traceback (most recent call last):
File "<stdin>", line 8, in <module>
File "/usr/local/lib/python2.7/site-packages/awacs/__init__.py", line 115, in __init__
sup.__init__(None, props=self.props, **kwargs)
File "/usr/local/lib/python2.7/site-packages/awacs/__init__.py", line 24, in __init__
self.type = type(self).__module__ + '.' + type(self).__name__
TypeError: 'NoneType' object is not callable
when trying to do:
template = troposphere.Template()
ec2Role = template.add_resource(troposphere.iam.Role(
"ec2Role",
AssumeRolePolicyDocument=awacs.aws.Policy(
Statement=[
awacs.aws.Statement(
Effect=awacs.aws.Allow,
Action=[awacs.sts.AssumeRole],
Principal=awacs.aws.Principal("Service", ["ec2.amazonaws.com"])
)
]
),
Policies=[
awacs.aws.Policy(
PolicyDocument=awacs.aws.Policy(
Statement=[
awacs.aws.Statement(
Effect=awacs.aws.Allow,
Action=[awacs.aws.Action("ec2", "AttachNetworkInterface")],
Resource=[awacs.ec2.ARN(resource="network-interface/*", region=region, account=account_id)]
)
]
)
)
]
))