# 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 write_to_cloudwatch_logs_stream_statements(log_group_name,
#                                                log_stream_name):
#     return [
#         Statement(
#             Effect=Allow,
#             Action=[logs.PutLogEvents],
#             Resource=[log_stream_arn(log_group_name, log_stream_name)]
#         )
#     ]
# 
# Path: stacker_blueprints/cloudwatch_logs.py
# LOG_RETENTION_STRINGS = [str(x) for x in LOG_RETENTION_VALUES]
# 
# def validate_cloudwatch_log_retention(value):
#     if value not in LOG_RETENTION_VALUES:
#         raise ValueError(
#             "%d is not a valid retention period. Must be one of: %s" % (
#                 value,
#                 ', '.join(LOG_RETENTION_STRINGS)
#             )
#         )
#     return value


from awacs.aws import (
    Allow,
    Condition,
    Policy,
    Statement,
    StringEquals,
    StringLike,
)
from awacs.helpers.trust import make_simple_assume_statement
from stacker.blueprints.base import Blueprint
from troposphere import (
    iam,
    logs,
    firehose,
    Join,
    GetAtt,
    Output,
    Ref,
    Sub,
)
from ..policies import (
    s3_arn,
    write_to_cloudwatch_logs_stream_statements,
)
from ..cloudwatch_logs import (
    LOG_RETENTION_STRINGS,
    validate_cloudwatch_log_retention,
)
import awacs.logs
import awacs.s3
import awacs.firehose
import awacs.kms
                           "values: %s. Default 0 - retain forever." % (
                               ', '.join(LOG_RETENTION_STRINGS)),
            "default": 0,
            "validator": validate_cloudwatch_log_retention,
        }
    }

    def buffering_hints(self):
        hints_config = self.get_variables()["BufferingHints"]
        return firehose.BufferingHints(**hints_config)

    def encryption_config(self):
        key_arn = self.get_variables()["EncryptionKeyArn"]
        if key_arn:
            return firehose.EncryptionConfiguration(
                KMSEncryptionConfig=firehose.KMSEncryptionConfig(
                    AWSKMSKeyARN=key_arn
                )
            )
        else:
            return NOVALUE

    def s3_bucket_arn(self):
        bucket_name = self.get_variables()["BucketName"]
        return s3_arn(bucket_name)

    def cloudwatch_logging_options(self, log_group, log_stream):
        return firehose.CloudWatchLoggingOptions(
            Enabled=True,
            LogGroupName=Ref(log_group),

# 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 write_to_cloudwatch_logs_stream_statements(log_group_name,
#                                                log_stream_name):
#     return [
#         Statement(
#             Effect=Allow,
#             Action=[logs.PutLogEvents],
#             Resource=[log_stream_arn(log_group_name, log_stream_name)]
#         )
#     ]
# 
# Path: stacker_blueprints/cloudwatch_logs.py
# LOG_RETENTION_STRINGS = [str(x) for x in LOG_RETENTION_VALUES]
# 
# def validate_cloudwatch_log_retention(value):
#     if value not in LOG_RETENTION_VALUES:
#         raise ValueError(
#             "%d is not a valid retention period. Must be one of: %s" % (
#                 value,
#                 ', '.join(LOG_RETENTION_STRINGS)
#             )
#         )
#     return value


# Path: stacker_blueprints/firehose/base.py
from awacs.aws import (
    Allow,
    Condition,
    Policy,
    Statement,
    StringEquals,
    StringLike,
)
from awacs.helpers.trust import make_simple_assume_statement
from stacker.blueprints.base import Blueprint
from troposphere import (
    iam,
    logs,
    firehose,
    Join,
    GetAtt,
    Output,
    Ref,
    Sub,
)
from ..policies import (
    s3_arn,
    write_to_cloudwatch_logs_stream_statements,
)
from ..cloudwatch_logs import (
    LOG_RETENTION_STRINGS,
    validate_cloudwatch_log_retention,
)
import awacs.logs
import awacs.s3
import awacs.firehose
import awacs.kms

                           "values: %s. Default 0 - retain forever." % (
                               ', '.join(LOG_RETENTION_STRINGS)),
            "default": 0,
            "validator": validate_cloudwatch_log_retention,
        }
    }

    def buffering_hints(self):
        hints_config = self.get_variables()["BufferingHints"]
        return firehose.BufferingHints(**hints_config)

    def encryption_config(self):
        key_arn = self.get_variables()["EncryptionKeyArn"]
        if key_arn:
            return firehose.EncryptionConfiguration(
                KMSEncryptionConfig=firehose.KMSEncryptionConfig(
                    AWSKMSKeyARN=key_arn
                )
            )
        else:
            return NOVALUE

    def s3_bucket_arn(self):
        bucket_name = self.get_variables()["BucketName"]
        return s3_arn(bucket_name)

    def cloudwatch_logging_options(self, log_group, log_stream):
        return firehose.CloudWatchLoggingOptions(
            Enabled=True,
            LogGroupName=Ref(log_group),

            LogStreamName=Ref(log_stream),