# Path: stacker_blueprints/policies.py
# def s3_arn(bucket):
#     if isinstance(bucket, AWSHelperFn):
#         return Sub('arn:aws:s3:::${Bucket}', Bucket=bucket)
#     else:
#         return 'arn:aws:s3:::%s' % bucket
# 
# def read_only_s3_bucket_policy(buckets):
#     return Policy(Statement=read_only_s3_bucket_policy_statements(buckets))
# 
# def read_write_s3_bucket_policy(buckets):
#     return Policy(Statement=read_write_s3_bucket_policy_statements(buckets))
# 
# def static_website_bucket_policy(bucket):
#     """
#     Attach this policy directly to an S3 bucket to make it a static website.
#     This policy grants read access to **all unauthenticated** users.
#     """
#     return Policy(
#         Statement=[
#             Statement(
#                 Effect=Allow,
#                 Principal=Principal("*"),
#                 Action=[s3.GetObject],
#                 Resource=[s3_objects_arn(bucket)],
#             )
#         ]
#     )


from stacker.blueprints.base import Blueprint
from troposphere import (
    FindInMap,
    GetAtt,
    Output,
    Sub,
    Ref,
    Region,
    s3,
    iam,
)
from .policies import (
    s3_arn,
    read_only_s3_bucket_policy,
    read_write_s3_bucket_policy,
    static_website_bucket_policy,
)
                           "being the CFN logical resource name, the "
                           "value being a dictionary of attributes for "
                           "the troposphere s3.Bucket type.",
            "default": {}
        },
        "ReadWriteRoles": {
            "type": list,
            "description": "A list of roles that should have read/write "
                           "access to the buckets created.",
            "default": []
        },
        "ReadRoles": {
            "type": list,
            "description": "A list of roles that should have read-only "
                           "access to the buckets created.",
            "default": []
        },

    }

    def create_template(self):
        t = self.template
        variables = self.get_variables()

        bucket_ids = []

        for title, attrs in variables["Buckets"].items():
            bucket_id = Ref(title)
            t.add_resource(s3.Bucket.from_dict(title, attrs))
            t.add_output(Output(title + "BucketId", Value=bucket_id))

# Path: stacker_blueprints/policies.py
# def s3_arn(bucket):
#     if isinstance(bucket, AWSHelperFn):
#         return Sub('arn:aws:s3:::${Bucket}', Bucket=bucket)
#     else:
#         return 'arn:aws:s3:::%s' % bucket
# 
# def read_only_s3_bucket_policy(buckets):
#     return Policy(Statement=read_only_s3_bucket_policy_statements(buckets))
# 
# def read_write_s3_bucket_policy(buckets):
#     return Policy(Statement=read_write_s3_bucket_policy_statements(buckets))
# 
# def static_website_bucket_policy(bucket):
#     """
#     Attach this policy directly to an S3 bucket to make it a static website.
#     This policy grants read access to **all unauthenticated** users.
#     """
#     return Policy(
#         Statement=[
#             Statement(
#                 Effect=Allow,
#                 Principal=Principal("*"),
#                 Action=[s3.GetObject],
#                 Resource=[s3_objects_arn(bucket)],
#             )
#         ]
#     )


# Path: stacker_blueprints/s3.py
from stacker.blueprints.base import Blueprint
from troposphere import (
    FindInMap,
    GetAtt,
    Output,
    Sub,
    Ref,
    Region,
    s3,
    iam,
)
from .policies import (
    s3_arn,
    read_only_s3_bucket_policy,
    read_write_s3_bucket_policy,
    static_website_bucket_policy,
)

                           "being the CFN logical resource name, the "
                           "value being a dictionary of attributes for "
                           "the troposphere s3.Bucket type.",
            "default": {}
        },
        "ReadWriteRoles": {
            "type": list,
            "description": "A list of roles that should have read/write "
                           "access to the buckets created.",
            "default": []
        },
        "ReadRoles": {
            "type": list,
            "description": "A list of roles that should have read-only "
                           "access to the buckets created.",
            "default": []
        },

    }

    def create_template(self):
        t = self.template
        variables = self.get_variables()

        bucket_ids = []

        for title, attrs in variables["Buckets"].items():
            bucket_id = Ref(title)
            t.add_resource(s3.Bucket.from_dict(title, attrs))
            t.add_output(Output(title + "BucketId", Value=bucket_id))

            t.add_output(Output(title + "BucketArn", Value=s3_arn(bucket_id)))