本文整理汇总了Python中awacs.aws.Policy方法的典型用法代码示例。如果您正苦于以下问题:Python aws.Policy方法的具体用法?Python aws.Policy怎么用?Python aws.Policy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类awacs.aws
的用法示例。
在下文中一共展示了aws.Policy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_policy_bucket
# 需要导入模块: from awacs import aws [as 别名]
# 或者: from awacs.aws import Policy [as 别名]
def build_policy_bucket(self, bucket, name, statements):
"""
Generate bucket policy for S3 bucket
:param bucket: The bucket to attach policy to
:param name: The name of the bucket (to generate policy name from it)
:param statements: The "rules" the policy should have
:return: Ref to new policy
"""
policy = self.__template.add_resource(
BucketPolicy(
self.name_strip(name, True, False),
Bucket=troposphere.Ref(bucket),
DependsOn=[
troposphere.Name(bucket)
],
PolicyDocument=Policy(
Version=self.VERSION_IAM,
Statement=statements
)
)
)
return policy
示例2: render
# 需要导入模块: from awacs import aws [as 别名]
# 或者: from awacs.aws import Policy [as 别名]
def render(self,app_name=None,stage_name=None,username=None,function_bucket=None,
static_bucket=None,aws_region_name='us-east-1'):
self.app_name = app_name
self.stage_name = stage_name
self.username = username
self.function_bucket = function_bucket
self.static_bucket = static_bucket
self.aws_region_name = aws_region_name
self.t = Template()
self.t.add_description(
"Zappa Template for {app_name}-{stage_name} ".format(
app_name=self.app_name, stage_name=self.stage_name))
zappa_user = self.t.add_resource(User(self.username))
zappa_user_keys = self.t.add_resource(AccessKey(
"ZappaUserKeys",
Status="Active",
UserName=Ref(zappa_user))
)
self.t.add_resource(
PolicyType(
alpha_num_pattern.sub('',"{app_name}{stage_name}".format(
app_name=self.app_name,
stage_name=self.stage_name)),
Users=[Ref(zappa_user)],
PolicyName="zappa-{app_name}-{stage_name}".format(
app_name=self.app_name,
stage_name=self.stage_name),
PolicyDocument=Policy(
Version="2012-10-17",
Statement=self.get_statement_list(),
),
)
)
self.t.add_output(Output(
"AccessKey",
Value=Ref(zappa_user_keys),
Description="AWSAccessKeyId of new user",
))
self.t.add_output(Output(
"SecretKey",
Value=GetAtt(zappa_user_keys, "SecretAccessKey"),
Description="AWSSecretKey of new user",
))
return self.t.to_json()
示例3: build_role
# 需要导入模块: from awacs import aws [as 别名]
# 或者: from awacs.aws import Policy [as 别名]
def build_role(self, name, policies=False):
"""
Generate role for IAM cloudformation template
:param name: Name of role
:param policies: List of policies to attach to this role (False = none)
:return: Ref to new role
"""
# Build role template
if policies:
role = self.__template.add_resource(
Role(
self.name_strip(name),
AssumeRolePolicyDocument=Policy(
Version=self.VERSION_IAM,
Statement=[
Statement(
Effect=Allow,
Principal=Principal(
"Service", self.__role_principals
),
Action=[AssumeRole],
)
]
),
Path=self.__role_path,
ManagedPolicyArns=policies,
))
# Add role to list for default policy
self.__roles_list.append(troposphere.Ref(role))
else:
role = self.__template.add_resource(
Role(
self.name_strip(name),
AssumeRolePolicyDocument=Policy(
Version=self.VERSION_IAM,
Statement=[
Statement(
Effect=Allow,
Principal=Principal(
"Service", self.__role_principals
),
Action=[AssumeRole],
)
]
),
Path=self.__role_path,
))
# Add role to list for default policy
self.__roles_list.append(troposphere.Ref(role))
return role