当前位置: 首页>>代码示例>>Python>>正文


Python aws.Policy方法代码示例

本文整理汇总了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 
开发者ID:glomex,项目名称:gcdt,代码行数:26,代码来源:iam.py

示例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() 
开发者ID:bjinwright,项目名称:zops,代码行数:47,代码来源:user.py

示例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 
开发者ID:glomex,项目名称:gcdt,代码行数:53,代码来源:iam.py


注:本文中的awacs.aws.Policy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。