<commit_before>#!/usr/bin/python3

from troposphere import cloudfront, Ref, Tags, Template

from amazonia.classes.cf_distribution_unit import CFDistributionUnit
from amazonia.classes.cf_distribution_config import CFDistributionConfig
from amazonia.classes.cf_origins_config import CFOriginsConfig
from amazonia.classes.cf_cache_behavior_config import CFCacheBehavior


def main():
    template = Template()

    origins = [ CFOriginsConfig (
            domain_name='amazonia-elb-bucket.s3.amazonaws.com',
            origin_id='S3-amazonia-elb-bucket',
            origin_policy={
                'is_s3' : True,
                'origin_access_identity': 'originaccessid1'
            }
        ),
        CFOriginsConfig(
            domain_name='amazonia-myStackap-LXYP1MFWT9UC-145363293.ap-southeast-2.elb.amazonaws.com',
            origin_id='ELB-amazonia-myStackap-LXYP1MFWT9UC-145363293',
            origin_policy={
                'is_s3' : False,
                'origin_protocol_policy' : 'https-only',
                'http_port' : 80,
                'https_port' : 443,
                'origin_ssl_protocols' : ['TLSv1', 'TLSv1.1', 'TLSv1.2'],
            }
        )
    ]

    cache_behavior = [
        CFCacheBehavior(
            path_pattern='/index.html',
            allowed_methods=['GET', 'HEAD'],
            cached_methods=['GET', 'HEAD'],
            target_origin_id='S3-bucket-id',
            forward_cookies='all',
            forwarded_headers=['*'],
            viewer_protocol_policy='allow-all',
            min_ttl=0,
            default_ttl=0,
            max_ttl=0,
            trusted_signers=['self']
        ),
        CFCacheBehavior(
            path_pattern='/login.js',
            allowed_methods=['GET', 'POST', 'HEAD', 'DELETE', 'OPTIONS', 'PATCH', 'PUT'],
            cached_methods=['GET', 'HEAD'],
            target_origin_id='www-origin',
            forward_cookies='all',
            forwarded_headers=['Accept',
                               'Accept-Charset',
                               'Accept-Datetime',
                               'Accept-Language',
                               'Authorization',
                               'Content-Type',
                               'Origin',
                               'Referer',
                               'Set-Cookie'],
            viewer_protocol_policy='https-only',
            min_ttl=0,
            default_ttl=0,
            max_ttl=0,
            trusted_signers=['self']
        ),
    ]

    distribution_config = CFDistributionConfig(
        aliases=['www.test-stack.gadevs.ga','test-stack.gadevs.ga'],
        comment='SysTestCFDistribution',
        default_root_object='index.html',
        enabled=True,
        price_class='PriceClass_All',
        target_origin_id='originId',
        allowed_methods=['GET','HEAD'],
        cached_methods=['GET','HEAD'],
        trusted_signers=['self'],
        forward_cookies='all',
        forwarded_headers=['*'],
        viewer_protocol_policy='https-only',
        min_ttl=0,
        default_ttl=0,
        max_ttl=0,
        error_page_path='index.html',
        acm_cert_arn='',
        minimum_protocol_version='TLSv1',
        ssl_support_method='sni-only'
    )

    CFDistributionUnit(unit_title='cfdist',
                    template=template,
                    network_config=[],
                    cf_origins_config=origins,
                    cf_cache_behavior_config=cache_behavior,
                    cf_distribution_config=distribution_config)

    print(template.to_json(indent=2, separators=(',', ': ')))
<commit_msg>Fix forwarded headers for S3 bucket origin in systest<commit_after>#!/usr/bin/python3

from troposphere import cloudfront, Ref, Tags, Template

from amazonia.classes.cf_distribution_unit import CFDistributionUnit
from amazonia.classes.cf_distribution_config import CFDistributionConfig
from amazonia.classes.cf_origins_config import CFOriginsConfig
from amazonia.classes.cf_cache_behavior_config import CFCacheBehavior


def main():
    template = Template()

    origins = [ CFOriginsConfig (
            domain_name='amazonia-elb-bucket.s3.amazonaws.com',
            origin_id='S3-amazonia-elb-bucket',
            origin_policy={
                'is_s3' : True,
                'origin_access_identity': 'originaccessid1'
            }
        ),
        CFOriginsConfig(
            domain_name='amazonia-myStackap-LXYP1MFWT9UC-145363293.ap-southeast-2.elb.amazonaws.com',
            origin_id='ELB-amazonia-myStackap-LXYP1MFWT9UC-145363293',
            origin_policy={
                'is_s3' : False,
                'origin_protocol_policy' : 'https-only',
                'http_port' : 80,
                'https_port' : 443,
                'origin_ssl_protocols' : ['TLSv1', 'TLSv1.1', 'TLSv1.2'],
            }
        )
    ]

    cache_behavior = [
        CFCacheBehavior(
            path_pattern='/index.html',
            allowed_methods=['GET', 'HEAD'],
            cached_methods=['GET', 'HEAD'],
            target_origin_id='S3-bucket-id',
            forward_cookies='all',
            forwarded_headers=[''],
            viewer_protocol_policy='allow-all',
            min_ttl=0,
            default_ttl=0,
            max_ttl=0,
            trusted_signers=['self']
        ),
        CFCacheBehavior(
            path_pattern='/login.js',
            allowed_methods=['GET', 'POST', 'HEAD', 'DELETE', 'OPTIONS', 'PATCH', 'PUT'],
            cached_methods=['GET', 'HEAD'],
            target_origin_id='www-origin',
            forward_cookies='all',
            forwarded_headers=['Accept',
                               'Accept-Charset',
                               'Accept-Datetime',
                               'Accept-Language',
                               'Authorization',
                               'Content-Type',
                               'Origin',
                               'Referer',
                               'Set-Cookie'],
            viewer_protocol_policy='https-only',
            min_ttl=0,
            default_ttl=0,
            max_ttl=0,
            trusted_signers=['self']
        ),
    ]

    distribution_config = CFDistributionConfig(
        aliases=['www.test-stack.gadevs.ga','test-stack.gadevs.ga'],
        comment='SysTestCFDistribution',
        default_root_object='index.html',
        enabled=True,
        price_class='PriceClass_All',
        target_origin_id='originId',
        allowed_methods=['GET','HEAD'],
        cached_methods=['GET','HEAD'],
        trusted_signers=['self'],
        forward_cookies='all',
        forwarded_headers=[''],
        viewer_protocol_policy='https-only',
        min_ttl=0,
        default_ttl=0,
        max_ttl=0,
        error_page_path='index.html',
        acm_cert_arn='',
        minimum_protocol_version='TLSv1',
        ssl_support_method='sni-only'
    )

    CFDistributionUnit(unit_title='cfdist',
                    template=template,
                    network_config=[],
                    cf_origins_config=origins,
                    cf_cache_behavior_config=cache_behavior,
                    cf_distribution_config=distribution_config)

    print(template.to_json(indent=2, separators=(',', ': ')))

{'fraction_non_alphanumeric': 0.1152048391531482, 'fraction_numerical': 0.014160021996150674, 'mean_word_length': 1.8274387874076954, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2260996', 'n_tokens_mistral': 2176, 'n_tokens_neox': 2094, 'n_words': 256}