# Path: stacker_blueprints/s3.py
# class Buckets(Blueprint):
#     VARIABLES = {
#         "Buckets": {
#             "type": dict,
#             "description": "A dictionary of buckets to create. The key "
#                            "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)))
#             t.add_output(
#                 Output(
#                     title + "BucketDomainName",
#                     Value=GetAtt(title, "DomainName")
#                 )
#             )
#             if "WebsiteConfiguration" in attrs:
#                 t.add_mapping("WebsiteEndpoints", S3_WEBSITE_ENDPOINTS)
# 
#                 t.add_resource(
#                     s3.BucketPolicy(
#                         title + "BucketPolicy",
#                         Bucket=bucket_id,
#                         PolicyDocument=static_website_bucket_policy(bucket_id),
#                     )
#                 )
#                 t.add_output(
#                     Output(
#                         title + "WebsiteUrl",
#                         Value=GetAtt(title, "WebsiteURL")
#                     )
#                 )
#                 t.add_output(
#                     Output(
#                         title + "WebsiteEndpoint",
#                         Value=FindInMap(
#                             "WebsiteEndpoints", Region, "endpoint"
#                         )
#                     )
#                 )
# 
#             bucket_ids.append(bucket_id)
# 
#         read_write_roles = variables["ReadWriteRoles"]
#         if read_write_roles:
#             t.add_resource(
#                 iam.PolicyType(
#                     "ReadWritePolicy",
#                     PolicyName=Sub("${AWS::StackName}ReadWritePolicy"),
#                     PolicyDocument=read_write_s3_bucket_policy(
#                         bucket_ids
#                     ),
#                     Roles=read_write_roles,
#                 )
#             )
# 
#         read_only_roles = variables["ReadRoles"]
#         if read_only_roles:
#             t.add_resource(
#                 iam.PolicyType(
#                     "ReadPolicy",
#                     PolicyName=Sub("${AWS::StackName}ReadPolicy"),
#                     PolicyDocument=read_only_s3_bucket_policy(
#                         bucket_ids
#                     ),
#                     Roles=read_only_roles,
#                 )
#             )


import unittest
from stacker.context import Context, Config
from stacker.variables import Variable
from stacker_blueprints.s3 import Buckets
from stacker.blueprints.testutil import BlueprintTestCase
                'Simple': {},
                'Cycle': {
                    'LifecycleConfiguration': {
                        'Rules': [{
                            'Status': 'Enabled',
                            'ExpirationInDays': 40,
                        }],
                    },
                }
            }),
            Variable('ReadRoles', [
                'Role1',
                'Role2',
            ]),
            Variable('ReadWriteRoles', [
                'Role3',
                'Role4',
            ]),
        ]

    def test_s3(self):
        ctx = Context(config=Config({'namespace': 'test'}))
        blueprint = Buckets('buckets', ctx)
        blueprint.resolve_variables(self.variables)
        blueprint.create_template()
        self.assertRenderedBlueprint(blueprint)

    def test_s3_static_website(self):
        """Test a static website blog bucket."""
        ctx = Context(config=Config({'namespace': 'test'}))

# Path: stacker_blueprints/s3.py
# class Buckets(Blueprint):
#     VARIABLES = {
#         "Buckets": {
#             "type": dict,
#             "description": "A dictionary of buckets to create. The key "
#                            "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)))
#             t.add_output(
#                 Output(
#                     title + "BucketDomainName",
#                     Value=GetAtt(title, "DomainName")
#                 )
#             )
#             if "WebsiteConfiguration" in attrs:
#                 t.add_mapping("WebsiteEndpoints", S3_WEBSITE_ENDPOINTS)
# 
#                 t.add_resource(
#                     s3.BucketPolicy(
#                         title + "BucketPolicy",
#                         Bucket=bucket_id,
#                         PolicyDocument=static_website_bucket_policy(bucket_id),
#                     )
#                 )
#                 t.add_output(
#                     Output(
#                         title + "WebsiteUrl",
#                         Value=GetAtt(title, "WebsiteURL")
#                     )
#                 )
#                 t.add_output(
#                     Output(
#                         title + "WebsiteEndpoint",
#                         Value=FindInMap(
#                             "WebsiteEndpoints", Region, "endpoint"
#                         )
#                     )
#                 )
# 
#             bucket_ids.append(bucket_id)
# 
#         read_write_roles = variables["ReadWriteRoles"]
#         if read_write_roles:
#             t.add_resource(
#                 iam.PolicyType(
#                     "ReadWritePolicy",
#                     PolicyName=Sub("${AWS::StackName}ReadWritePolicy"),
#                     PolicyDocument=read_write_s3_bucket_policy(
#                         bucket_ids
#                     ),
#                     Roles=read_write_roles,
#                 )
#             )
# 
#         read_only_roles = variables["ReadRoles"]
#         if read_only_roles:
#             t.add_resource(
#                 iam.PolicyType(
#                     "ReadPolicy",
#                     PolicyName=Sub("${AWS::StackName}ReadPolicy"),
#                     PolicyDocument=read_only_s3_bucket_policy(
#                         bucket_ids
#                     ),
#                     Roles=read_only_roles,
#                 )
#             )


# Path: tests/test_s3.py
import unittest
from stacker.context import Context, Config
from stacker.variables import Variable
from stacker_blueprints.s3 import Buckets
from stacker.blueprints.testutil import BlueprintTestCase

                'Simple': {},
                'Cycle': {
                    'LifecycleConfiguration': {
                        'Rules': [{
                            'Status': 'Enabled',
                            'ExpirationInDays': 40,
                        }],
                    },
                }
            }),
            Variable('ReadRoles', [
                'Role1',
                'Role2',
            ]),
            Variable('ReadWriteRoles', [
                'Role3',
                'Role4',
            ]),
        ]

    def test_s3(self):
        ctx = Context(config=Config({'namespace': 'test'}))
        blueprint = Buckets('buckets', ctx)
        blueprint.resolve_variables(self.variables)
        blueprint.create_template()
        self.assertRenderedBlueprint(blueprint)

    def test_s3_static_website(self):
        """Test a static website blog bucket."""
        ctx = Context(config=Config({'namespace': 'test'}))

        blueprint = Buckets('s3_static_website', ctx)