
    Vh                    D   d Z dZdZddlZddlZddlmZ 	 ddlZddl	m
Z
 ddl	mZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ d Zd ZddZd Zd Zd Z d Z!d Z"d Z#d Z$ G d de%      Z&d Z'e(dk(  r e'        yy# e$ r Y w xY w) am  
---

version_added: 1.0.0
module: cloudfront_distribution

short_description: Create, update and delete AWS CloudFront distributions

description:
  - Allows for easy creation, updating and deletion of CloudFront distributions.

author:
  - Willem van Ketwich (@wilvk)
  - Will Thames (@willthames)

options:

    state:
      description:
        - The desired state of the distribution.
        - I(state=present) creates a new distribution or updates an existing distribution.
        - I(state=absent) deletes an existing distribution.
      choices: ['present', 'absent']
      default: 'present'
      type: str

    distribution_id:
      description:
        - The ID of the CloudFront distribution.
        - This parameter can be exchanged with I(alias) or I(caller_reference) and is used in conjunction with I(e_tag).
      type: str

    e_tag:
      description:
        - A unique identifier of a modified or existing distribution. Used in conjunction with I(distribution_id).
        - Is determined automatically if not specified.
      type: str

    caller_reference:
      description:
        - A unique identifier for creating and updating CloudFront distributions.
        - Each caller reference must be unique across all distributions. e.g. a caller reference used in a web
          distribution cannot be reused in a streaming distribution. This parameter can be used instead of I(distribution_id)
          to reference an existing distribution. If not specified, this defaults to a datetime stamp of the format
          C(YYYY-MM-DDTHH:MM:SS.ffffff).
      type: str

    alias:
      description:
        - The name of an alias (CNAME) that is used in a distribution. This is used to effectively reference a distribution by its alias as an alias can only
          be used by one distribution per AWS account. This variable avoids having to provide the I(distribution_id) as well as
          the I(e_tag), or I(caller_reference) of an existing distribution.
      type: str

    aliases:
      description:
        - A list of domain name aliases (CNAMEs) as strings to be used for the distribution.
        - Each alias must be unique across all distribution for the AWS account.
      type: list
      elements: str
      default: []

    purge_aliases:
      description:
        - Specifies whether existing aliases will be removed before adding new aliases.
        - When I(purge_aliases=true), existing aliases are removed and I(aliases) are added.
      default: false
      type: bool

    default_root_object:
      description:
        - A config element that specifies the path to request when the user requests the origin.
        - e.g. if specified as 'index.html', this maps to www.example.com/index.html when www.example.com is called by the user.
        - This prevents the entire distribution origin from being exposed at the root.
      type: str

    default_origin_domain_name:
      description:
        - The domain name to use for an origin if no I(origins) have been specified.
        - Should only be used on a first run of generating a distribution and not on
          subsequent runs.
        - Should not be used in conjunction with I(distribution_id), I(caller_reference) or I(alias).
      type: str

    default_origin_path:
      description:
        - The default origin path to specify for an origin if no I(origins) have been specified. Defaults to empty if not specified.
      type: str

    origins:
      type: list
      elements: dict
      description:
        - A config element that is a list of complex origin objects to be specified for the distribution. Used for creating and updating distributions.
      suboptions:
        id:
          description: A unique identifier for the origin or origin group. I(id) must be unique within the distribution.
          type: str
        domain_name:
          description:
            - The domain name which CloudFront will query as the origin.
            - For more information see the CloudFront documentation
              at U(https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesDomainName)
          type: str
        origin_path:
          description: Tells CloudFront to request your content from a directory in your Amazon S3 bucket or your custom origin.
          type: str
        origin_shield:
          description: Specify origin shield options for the origin.
          type: dict
          suboptions:
            enabled:
              description: Indicate whether you want the origin to have Origin Shield enabled or not.
              type: bool
            origin_shield_region:
              description: Specify which AWS region will be used for Origin Shield. Required if Origin Shield is enabled.
              type: str
          version_added: 6.0.0
        custom_headers:
          description:
            - Custom headers you wish to add to the request before passing it to the origin.
            - For more information see the CloudFront documentation
              at U(https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/forward-custom-headers.html).
          type: list
          elements: dict
          suboptions:
            header_name:
              description: The name of a header that you want CloudFront to forward to your origin.
              type: str
            header_value:
              description: The value for the header that you specified in the I(header_name) field.
              type: str
        s3_origin_access_identity_enabled:
          description:
            - Use an origin access identity to configure the origin so that viewers can only access objects in an Amazon S3 bucket through CloudFront.
            - Will automatically create an Identity for you if no I(s3_origin_config) is specified.
            - See also U(https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html).
          type: bool
        s3_origin_config:
          description: Specify origin access identity for S3 origins.
          type: dict
          suboptions:
            origin_access_identity:
              description: Existing origin access identity in the format C(origin-access-identity/cloudfront/OID_ID).
              type: str
        custom_origin_config:
          description: Connection information about the origin.
          type: dict
          suboptions:
            http_port:
              description: The HTTP port the custom origin listens on.
              type: int
            https_port:
              description: The HTTPS port the custom origin listens on.
              type: int
            origin_protocol_policy:
              description: The origin protocol policy to apply to your origin.
              type: str
            origin_ssl_protocols:
              description: A list of SSL/TLS protocols that you want CloudFront to use when communicating to the origin over HTTPS.
              type: list
              elements: str
            origin_read_timeout:
              description: A timeout (in seconds) when reading from your origin.
              type: int
            origin_keepalive_timeout:
              description: A keep-alive timeout (in seconds).
              type: int
        connection_attempts:
          description: The number of times that CloudFront attempts to connect to the origin.
                       The minimum number is C(1), the maximum is C(3).
          type: int
          default: 3
          version_added: 6.0.0
        connection_timeout:
          description: The number of seconds that CloudFront waits when trying to establish a connection to the origin.
                       The minimum timeout is C(1) second, the maximum is C(10) seconds.
          type: int
          default: 10
          version_added: 6.0.0
    purge_origins:
      description: Whether to remove any origins that aren't listed in I(origins).
      default: false
      type: bool

    default_cache_behavior:
      type: dict
      description:
        - A dict specifying the default cache behavior of the distribution.
        - If not specified, the I(target_origin_id) is defined as the I(target_origin_id) of the first valid
          cache_behavior in I(cache_behaviors) with defaults.
      suboptions:
        target_origin_id:
          description:
            - The ID of the origin that you want CloudFront to route requests to
              by default.
          type: str
        response_headers_policy_id:
          description:
            - The ID of the header policy that CloudFront adds to responses that it sends to viewers.
          type: str
        cache_policy_id:
          version_added: 7.1.0
          description:
            - The ID of the cache policy for CloudFront to use for the default cache behavior.
            - A behavior should use either a C(cache_policy_id) or a C(forwarded_values) option.
            - For more information see the CloudFront documentation
              at U(https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html)
          type: str
        origin_request_policy_id:
          version_added: 7.1.0
          description:
            - The ID of the origin request policy for CloudFront to use for the default cache behavior.
            - For more information see the CloudFront documentation
              at U(https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-origin-requests.html)
          type: str
        forwarded_values:
          description:
            - A dict that specifies how CloudFront handles query strings and cookies.
            - A behavior should use either a C(cache_policy_id) or a C(forwarded_values) option.
          type: dict
          suboptions:
            query_string:
              description:
                - Indicates whether you want CloudFront to forward query strings
                  to the origin that is associated with this cache behavior.
              type: bool
            cookies:
              description: A dict that specifies whether you want CloudFront to forward cookies to the origin and, if so, which ones.
              type: dict
              suboptions:
                forward:
                  description:
                    - Specifies which cookies to forward to the origin for this cache behavior.
                    - Valid values are C(all), C(none), or C(whitelist).
                  type: str
                whitelisted_names:
                  type: list
                  elements: str
                  description: A list of cookies to forward to the origin for this cache behavior.
            headers:
              description:
              - A list of headers to forward to the origin for this cache behavior.
              - To forward all headers use a list containing a single element '*' (C(['*']))
              type: list
              elements: str
            query_string_cache_keys:
              description:
                - A list that contains the query string parameters you want CloudFront to use as a basis for caching for a cache behavior.
              type: list
              elements: str
            trusted_signers:
              description:
                - A dict that specifies the AWS accounts that you want to allow to create signed URLs for private content.
              type: dict
              suboptions:
                enabled:
                  description: Whether you want to require viewers to use signed URLs to access the files specified by I(target_origin_id)
                  type: bool
                items:
                  description: A list of trusted signers for this cache behavior.
                  elements: str
                  type: list
            viewer_protocol_policy:
              description:
                - The protocol that viewers can use to access the files in the origin specified by I(target_origin_id).
                - Valid values are C(allow-all), C(redirect-to-https) and C(https-only).
              type: str
            default_ttl:
              description: The default amount of time that you want objects to stay in CloudFront caches.
              type: int
            max_ttl:
              description: The maximum amount of time that you want objects to stay in CloudFront caches.
              type: int
            min_ttl:
              description: The minimum amount of time that you want objects to stay in CloudFront caches.
              type: int
            allowed_methods:
              description: A dict that controls which HTTP methods CloudFront processes and forwards.
              type: dict
              suboptions:
                items:
                  description: A list of HTTP methods that you want CloudFront to process and forward.
                  type: list
                  elements: str
                cached_methods:
                  description:
                    - A list of HTTP methods that you want CloudFront to apply caching to.
                    - This can either be C([GET,HEAD]), or C([GET,HEAD,OPTIONS]).
                  type: list
                  elements: str
            smooth_streaming:
              description:
                - Whether you want to distribute media files in the Microsoft Smooth Streaming format.
              type: bool
            compress:
              description:
                - Whether you want CloudFront to automatically compress files.
              type: bool
            lambda_function_associations:
              description:
                - A list of Lambda function associations to use for this cache behavior.
              type: list
              elements: dict
              suboptions:
                lambda_function_arn:
                  description: The ARN of the Lambda function.
                  type: str
                event_type:
                  description:
                    - Specifies the event type that triggers a Lambda function invocation.
                    - This can be C(viewer-request), C(origin-request), C(origin-response) or C(viewer-response).
                  type: str
            field_level_encryption_id:
              description:
                - The field-level encryption configuration that you want CloudFront to use for encrypting specific fields of data.
              type: str

    cache_behaviors:
      type: list
      elements: dict
      description:
        - A list of dictionaries describing the cache behaviors for the distribution.
        - The order of the list is preserved across runs unless I(purge_cache_behaviors) is enabled.
      suboptions:
        path_pattern:
          description:
            - The pattern that specifies which requests to apply the behavior to.
          type: str
        target_origin_id:
          description:
            - The ID of the origin that you want CloudFront to route requests to
              by default.
          type: str
        response_headers_policy_id:
          description:
            - The ID of the header policy that CloudFront adds to responses that it sends to viewers.
          type: str
        cache_policy_id:
          version_added: 7.1.0
          description:
            - The ID of the cache policy for CloudFront to use for the cache behavior.
            - A behavior should use either a C(cache_policy_id) or a C(forwarded_values) option.
            - For more information see the CloudFront documentation
              at U(https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html)
          type: str
        origin_request_policy_id:
          version_added: 7.1.0
          description:
            - The ID of the origin request policy for CloudFront to use for the cache behavior.
            - For more information see the CloudFront documentation
              at U(https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-origin-requests.html)
          type: str
        forwarded_values:
          description:
            - A dict that specifies how CloudFront handles query strings and cookies.
            - A behavior should use either a C(cache_policy_id) or a C(forwarded_values) option.
          type: dict
          suboptions:
            query_string:
              description:
                - Indicates whether you want CloudFront to forward query strings
                  to the origin that is associated with this cache behavior.
              type: bool
            cookies:
              description: A dict that specifies whether you want CloudFront to forward cookies to the origin and, if so, which ones.
              type: dict
              suboptions:
                forward:
                  description:
                    - Specifies which cookies to forward to the origin for this cache behavior.
                    - Valid values are C(all), C(none), or C(whitelist).
                  type: str
                whitelisted_names:
                  type: list
                  elements: str
                  description: A list of cookies to forward to the origin for this cache behavior.
            headers:
              description:
              - A list of headers to forward to the origin for this cache behavior.
              - To forward all headers use a list containing a single element '*' (C(['*']))
              type: list
              elements: str
            query_string_cache_keys:
              description:
                - A list that contains the query string parameters you want CloudFront to use as a basis for caching for a cache behavior.
              type: list
              elements: str
            trusted_signers:
              description:
                - A dict that specifies the AWS accounts that you want to allow to create signed URLs for private content.
              type: dict
              suboptions:
                enabled:
                  description: Whether you want to require viewers to use signed URLs to access the files specified by I(path_pattern) and I(target_origin_id)
                  type: bool
                items:
                  description: A list of trusted signers for this cache behavior.
                  elements: str
                  type: list
            viewer_protocol_policy:
              description:
                - The protocol that viewers can use to access the files in the origin specified by I(target_origin_id) when a request matches I(path_pattern).
                - Valid values are C(allow-all), C(redirect-to-https) and C(https-only).
              type: str
            default_ttl:
              description: The default amount of time that you want objects to stay in CloudFront caches.
              type: int
            max_ttl:
              description: The maximum amount of time that you want objects to stay in CloudFront caches.
              type: int
            min_ttl:
              description: The minimum amount of time that you want objects to stay in CloudFront caches.
              type: int
            allowed_methods:
              description: A dict that controls which HTTP methods CloudFront processes and forwards.
              type: dict
              suboptions:
                items:
                  description: A list of HTTP methods that you want CloudFront to process and forward.
                  type: list
                  elements: str
                cached_methods:
                  description:
                    - A list of HTTP methods that you want CloudFront to apply caching to.
                    - This can either be C([GET,HEAD]), or C([GET,HEAD,OPTIONS]).
                  type: list
                  elements: str
            smooth_streaming:
              description:
                - Whether you want to distribute media files in the Microsoft Smooth Streaming format.
              type: bool
            compress:
              description:
                - Whether you want CloudFront to automatically compress files.
              type: bool
            lambda_function_associations:
              description:
                - A list of Lambda function associations to use for this cache behavior.
              type: list
              elements: dict
              suboptions:
                lambda_function_arn:
                  description: The ARN of the Lambda function.
                  type: str
                event_type:
                  description:
                    - Specifies the event type that triggers a Lambda function invocation.
                    - This can be C(viewer-request), C(origin-request), C(origin-response) or C(viewer-response).
                  type: str
            field_level_encryption_id:
              description:
                - The field-level encryption configuration that you want CloudFront to use for encrypting specific fields of data.
              type: str


    purge_cache_behaviors:
      description:
        - Whether to remove any cache behaviors that aren't listed in I(cache_behaviors).
        - This switch also allows the reordering of I(cache_behaviors).
      default: false
      type: bool

    custom_error_responses:
      type: list
      elements: dict
      description:
        - A config element that is a I(list[]) of complex custom error responses to be specified for the distribution.
        - This attribute configures custom http error messages returned to the user.
      suboptions:
        error_code:
          type: int
          description: The error code the custom error page is for.
        error_caching_min_ttl:
          type: int
          description: The length of time (in seconds) that CloudFront will cache status codes for.
        response_code:
          type: int
          description:
            - The HTTP status code that CloudFront should return to a user when the origin returns the HTTP status code specified by I(error_code).
        response_page_path:
          type: str
          description:
            - The path to the custom error page that you want CloudFront to return to a viewer when your origin returns
              the HTTP status code specified by I(error_code).

    purge_custom_error_responses:
      description: Whether to remove any custom error responses that aren't listed in I(custom_error_responses).
      default: false
      type: bool

    comment:
      description:
        - A comment that describes the CloudFront distribution.
        - If not specified, it defaults to a generic message that it has been created with Ansible, and a datetime stamp.
      type: str

    logging:
      description:
        - A config element that is a complex object that defines logging for the distribution.
      suboptions:
        enabled:
          description: When I(enabled=true) CloudFront will log access to an S3 bucket.
          type: bool
        include_cookies:
          description: When I(include_cookies=true) CloudFront will include cookies in the logs.
          type: bool
        bucket:
          description: The S3 bucket to store the log in.
          type: str
        prefix:
          description: A prefix to include in the S3 object names.
          type: str
      type: dict

    price_class:
      description:
        - A string that specifies the pricing class of the distribution. As per
          U(https://aws.amazon.com/cloudfront/pricing/)
        - I(price_class=PriceClass_100) consists of the areas United States, Canada and Europe.
        - I(price_class=PriceClass_200) consists of the areas United States, Canada, Europe, Japan, India,
          Hong Kong, Philippines, S. Korea, Singapore & Taiwan.
        - I(price_class=PriceClass_All) consists of the areas United States, Canada, Europe, Japan, India,
          South America, Australia, Hong Kong, Philippines, S. Korea, Singapore & Taiwan.
        - AWS defaults this to C(PriceClass_All).
        - Valid values are C(PriceClass_100), C(PriceClass_200) and C(PriceClass_All)
      type: str

    enabled:
      description:
        - A boolean value that specifies whether the distribution is enabled or disabled.
        - Defaults to C(false).
      type: bool

    viewer_certificate:
      type: dict
      description:
        - A dict that specifies the encryption details of the distribution.
      suboptions:
        cloudfront_default_certificate:
          type: bool
          description:
            - If you're using the CloudFront domain name for your distribution, such as C(123456789abcde.cloudfront.net)
              you should set I(cloudfront_default_certificate=true).
            - If I(cloudfront_default_certificate=true) do not set I(ssl_support_method).
        iam_certificate_id:
          type: str
          description:
            - The ID of a certificate stored in IAM to use for HTTPS connections.
            - If I(iam_certificate_id) is set then you must also specify I(ssl_support_method).
        acm_certificate_arn:
          type: str
          description:
            - The ID of a certificate stored in ACM to use for HTTPS connections.
            - If I(acm_certificate_id) is set then you must also specify I(ssl_support_method).
        ssl_support_method:
          type: str
          description:
            - How CloudFront should serve SSL certificates.
            - Valid values are C(sni-only) for SNI, and C(vip) if CloudFront is configured to use a dedicated IP for your content.
        minimum_protocol_version:
          type: str
          description:
            - The security policy that you want CloudFront to use for HTTPS connections.
            - See U(https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/secure-connections-supported-viewer-protocols-ciphers.html)
              for supported security policies.

    restrictions:
      type: dict
      description:
        - A config element that is a complex object that describes how a distribution should restrict it's content.
      suboptions:
        geo_restriction:
          description: Apply a restriction based on the location of the requester.
          type: dict
          suboptions:
            restriction_type:
              type: str
              description:
              - The method that you want to use to restrict distribution of your content by country.
              - Valid values are C(none), C(whitelist), C(blacklist).
            items:
              description:
              - A list of ISO 3166-1 two letter (Alpha 2) country codes that the
                restriction should apply to.
              - 'See the ISO website for a full list of codes U(https://www.iso.org/obp/ui/#search/code/).'
              type: list
              elements: str

    web_acl_id:
      description:
        - The ID of a Web Application Firewall (WAF) Access Control List (ACL).
      type: str

    http_version:
      description:
        - The version of the http protocol to use for the distribution.
        - AWS defaults this to C(http2).
        - Valid values are C(http1.1), C(http2), C(http3) and C(http2and3).
      type: str

    ipv6_enabled:
      description:
        - Determines whether IPv6 support is enabled or not.
        - Defaults to C(false).
      type: bool

    wait:
      description:
        - Specifies whether the module waits until the distribution has completed processing the creation or update.
      type: bool
      default: false

    wait_timeout:
      description:
        - Specifies the duration in seconds to wait for a timeout of a cloudfront create or update.
      default: 1800
      type: int

extends_documentation_fragment:
  - amazon.aws.common.modules
  - amazon.aws.region.modules
  - amazon.aws.tags
  - amazon.aws.boto3
a  
- name: create a basic distribution with defaults and tags
  community.aws.cloudfront_distribution:
    state: present
    default_origin_domain_name: www.my-cloudfront-origin.com
    tags:
      Name: example distribution
      Project: example project
      Priority: '1'

- name: update a distribution comment by distribution_id
  community.aws.cloudfront_distribution:
    state: present
    distribution_id: E1RP5A2MJ8073O
    comment: modified by ansible cloudfront.py

- name: update a distribution comment by caller_reference
  community.aws.cloudfront_distribution:
    state: present
    caller_reference: my cloudfront distribution 001
    comment: modified by ansible cloudfront.py

- name: update a distribution's aliases and comment using the distribution_id as a reference
  community.aws.cloudfront_distribution:
    state: present
    distribution_id: E1RP5A2MJ8073O
    comment: modified by cloudfront.py again
    aliases:
      - 'www.my-distribution-source.com'
      - 'zzz.aaa.io'

- name: update a distribution's aliases and comment using an alias as a reference
  community.aws.cloudfront_distribution:
    state: present
    caller_reference: my test distribution
    comment: modified by cloudfront.py again
    aliases:
      - www.my-distribution-source.com
      - zzz.aaa.io

- name: update a distribution's comment and aliases and tags and remove existing tags
  community.aws.cloudfront_distribution:
    state: present
    distribution_id: E15BU8SDCGSG57
    comment: modified by cloudfront.py again
    aliases:
      - tested.com
    tags:
      Project: distribution 1.2
    purge_tags: true

- name: create a distribution with an origin, logging and default cache behavior
  community.aws.cloudfront_distribution:
    state: present
    caller_reference: unique test distribution ID
    origins:
      - id: 'my test origin-000111'
        domain_name: www.example.com
        origin_path: /production
        custom_headers:
          - header_name: MyCustomHeaderName
            header_value: MyCustomHeaderValue
    default_cache_behavior:
      target_origin_id: 'my test origin-000111'
      forwarded_values:
        query_string: true
        cookies:
          forward: all
        headers:
          - '*'
      viewer_protocol_policy: allow-all
      smooth_streaming: true
      compress: true
      allowed_methods:
        items:
          - GET
          - HEAD
        cached_methods:
          - GET
          - HEAD
    logging:
      enabled: true
      include_cookies: false
      bucket: mylogbucket.s3.amazonaws.com
      prefix: myprefix/
    enabled: false
    comment: this is a CloudFront distribution with logging

- name: delete a distribution
  community.aws.cloudfront_distribution:
    state: absent
    caller_reference: replaceable distribution
adX  
active_trusted_signers:
  description: Key pair IDs that CloudFront is aware of for each trusted signer.
  returned: always
  type: complex
  contains:
    enabled:
      description: Whether trusted signers are in use.
      returned: always
      type: bool
      sample: false
    quantity:
      description: Number of trusted signers.
      returned: always
      type: int
      sample: 1
    items:
      description: Number of trusted signers.
      returned: when there are trusted signers
      type: list
      sample:
      - key_pair_id
aliases:
  description: Aliases that refer to the distribution.
  returned: always
  type: complex
  contains:
    items:
      description: List of aliases.
      returned: always
      type: list
      sample:
      - test.example.com
    quantity:
      description: Number of aliases.
      returned: always
      type: int
      sample: 1
arn:
  description: Amazon Resource Name of the distribution.
  returned: always
  type: str
  sample: arn:aws:cloudfront::123456789012:distribution/E1234ABCDEFGHI
cache_behaviors:
  description: CloudFront cache behaviors.
  returned: always
  type: complex
  contains:
    items:
      description: List of cache behaviors.
      returned: always
      type: complex
      contains:
        allowed_methods:
          description: Methods allowed by the cache behavior.
          returned: always
          type: complex
          contains:
            cached_methods:
              description: Methods cached by the cache behavior.
              returned: always
              type: complex
              contains:
                items:
                  description: List of cached methods.
                  returned: always
                  type: list
                  sample:
                  - HEAD
                  - GET
                quantity:
                  description: Count of cached methods.
                  returned: always
                  type: int
                  sample: 2
            items:
              description: List of methods allowed by the cache behavior.
              returned: always
              type: list
              sample:
              - HEAD
              - GET
            quantity:
              description: Count of methods allowed by the cache behavior.
              returned: always
              type: int
              sample: 2
        compress:
          description: Whether compression is turned on for the cache behavior.
          returned: always
          type: bool
          sample: false
        default_ttl:
          description: Default Time to Live of the cache behavior.
          returned: always
          type: int
          sample: 86400
        forwarded_values:
          description: Values forwarded to the origin for this cache behavior.
          returned: always
          type: complex
          contains:
            cookies:
              description: Cookies to forward to the origin.
              returned: always
              type: complex
              contains:
                forward:
                  description: Which cookies to forward to the origin for this cache behavior.
                  returned: always
                  type: str
                  sample: none
                whitelisted_names:
                  description: The names of the cookies to forward to the origin for this cache behavior.
                  returned: when I(forward=whitelist)
                  type: complex
                  contains:
                    quantity:
                      description: Count of cookies to forward.
                      returned: always
                      type: int
                      sample: 1
                    items:
                      description: List of cookies to forward.
                      returned: when list is not empty
                      type: list
                      sample: my_cookie
            headers:
              description: Which headers are used to vary on cache retrievals.
              returned: always
              type: complex
              contains:
                quantity:
                  description: Count of headers to vary on.
                  returned: always
                  type: int
                  sample: 1
                items:
                  description: List of headers to vary on.
                  returned: when list is not empty
                  type: list
                  sample:
                  - Host
            query_string:
              description: Whether the query string is used in cache lookups.
              returned: always
              type: bool
              sample: false
            query_string_cache_keys:
              description: Which query string keys to use in cache lookups.
              returned: always
              type: complex
              contains:
                quantity:
                  description: Count of query string cache keys to use in cache lookups.
                  returned: always
                  type: int
                  sample: 1
                items:
                  description: List of query string cache keys to use in cache lookups.
                  returned: when list is not empty
                  type: list
                  sample:
        lambda_function_associations:
          description: Lambda function associations for a cache behavior.
          returned: always
          type: complex
          contains:
            quantity:
              description: Count of lambda function associations.
              returned: always
              type: int
              sample: 1
            items:
              description: List of lambda function associations.
              returned: when list is not empty
              type: list
              sample:
              - lambda_function_arn: arn:aws:lambda:123456789012:us-east-1/lambda/lambda-function
                event_type: viewer-response
        max_ttl:
          description: Maximum Time to Live.
          returned: always
          type: int
          sample: 31536000
        min_ttl:
          description: Minimum Time to Live.
          returned: always
          type: int
          sample: 0
        path_pattern:
          description: Path pattern that determines this cache behavior.
          returned: always
          type: str
          sample: /path/to/files/*
        smooth_streaming:
          description: Whether smooth streaming is enabled.
          returned: always
          type: bool
          sample: false
        target_origin_id:
          description: ID of origin reference by this cache behavior.
          returned: always
          type: str
          sample: origin_abcd
        trusted_signers:
          description: Trusted signers.
          returned: always
          type: complex
          contains:
            enabled:
              description: Whether trusted signers are enabled for this cache behavior.
              returned: always
              type: bool
              sample: false
            quantity:
              description: Count of trusted signers.
              returned: always
              type: int
              sample: 1
        viewer_protocol_policy:
          description: Policy of how to handle http/https.
          returned: always
          type: str
          sample: redirect-to-https
    quantity:
      description: Count of cache behaviors.
      returned: always
      type: int
      sample: 1

caller_reference:
  description: Idempotency reference given when creating CloudFront distribution.
  returned: always
  type: str
  sample: '1484796016700'
comment:
  description: Any comments you want to include about the distribution.
  returned: always
  type: str
  sample: 'my first CloudFront distribution'
custom_error_responses:
  description: Custom error responses to use for error handling.
  returned: always
  type: complex
  contains:
    items:
      description: List of custom error responses.
      returned: always
      type: complex
      contains:
        error_caching_min_ttl:
          description: Minimum time to cache this error response.
          returned: always
          type: int
          sample: 300
        error_code:
          description: Origin response code that triggers this error response.
          returned: always
          type: int
          sample: 500
        response_code:
          description: Response code to return to the requester.
          returned: always
          type: str
          sample: '500'
        response_page_path:
          description: Path that contains the error page to display.
          returned: always
          type: str
          sample: /errors/5xx.html
    quantity:
      description: Count of custom error response items
      returned: always
      type: int
      sample: 1
default_cache_behavior:
  description: Default cache behavior.
  returned: always
  type: complex
  contains:
    allowed_methods:
      description: Methods allowed by the cache behavior.
      returned: always
      type: complex
      contains:
        cached_methods:
          description: Methods cached by the cache behavior.
          returned: always
          type: complex
          contains:
            items:
              description: List of cached methods.
              returned: always
              type: list
              sample:
              - HEAD
              - GET
            quantity:
              description: Count of cached methods.
              returned: always
              type: int
              sample: 2
        items:
          description: List of methods allowed by the cache behavior.
          returned: always
          type: list
          sample:
          - HEAD
          - GET
        quantity:
          description: Count of methods allowed by the cache behavior.
          returned: always
          type: int
          sample: 2
    compress:
      description: Whether compression is turned on for the cache behavior.
      returned: always
      type: bool
      sample: false
    default_ttl:
      description: Default Time to Live of the cache behavior.
      returned: always
      type: int
      sample: 86400
    forwarded_values:
      description: Values forwarded to the origin for this cache behavior.
      returned: always
      type: complex
      contains:
        cookies:
          description: Cookies to forward to the origin.
          returned: always
          type: complex
          contains:
            forward:
              description: Which cookies to forward to the origin for this cache behavior.
              returned: always
              type: str
              sample: none
            whitelisted_names:
              description: The names of the cookies to forward to the origin for this cache behavior.
              returned: when I(forward=whitelist)
              type: complex
              contains:
                quantity:
                  description: Count of cookies to forward.
                  returned: always
                  type: int
                  sample: 1
                items:
                  description: List of cookies to forward.
                  returned: when list is not empty
                  type: list
                  sample: my_cookie
        headers:
          description: Which headers are used to vary on cache retrievals.
          returned: always
          type: complex
          contains:
            quantity:
              description: Count of headers to vary on.
              returned: always
              type: int
              sample: 1
            items:
              description: List of headers to vary on.
              returned: when list is not empty
              type: list
              sample:
              - Host
        query_string:
          description: Whether the query string is used in cache lookups.
          returned: always
          type: bool
          sample: false
        query_string_cache_keys:
          description: Which query string keys to use in cache lookups.
          returned: always
          type: complex
          contains:
            quantity:
              description: Count of query string cache keys to use in cache lookups.
              returned: always
              type: int
              sample: 1
            items:
              description: List of query string cache keys to use in cache lookups.
              returned: when list is not empty
              type: list
              sample:
    lambda_function_associations:
      description: Lambda function associations for a cache behavior.
      returned: always
      type: complex
      contains:
        quantity:
          description: Count of lambda function associations.
          returned: always
          type: int
          sample: 1
        items:
          description: List of lambda function associations.
          returned: when list is not empty
          type: list
          sample:
          - lambda_function_arn: arn:aws:lambda:123456789012:us-east-1/lambda/lambda-function
            event_type: viewer-response
    max_ttl:
      description: Maximum Time to Live.
      returned: always
      type: int
      sample: 31536000
    min_ttl:
      description: Minimum Time to Live.
      returned: always
      type: int
      sample: 0
    path_pattern:
      description: Path pattern that determines this cache behavior.
      returned: always
      type: str
      sample: /path/to/files/*
    smooth_streaming:
      description: Whether smooth streaming is enabled.
      returned: always
      type: bool
      sample: false
    target_origin_id:
      description: ID of origin reference by this cache behavior.
      returned: always
      type: str
      sample: origin_abcd
    trusted_signers:
      description: Trusted signers.
      returned: always
      type: complex
      contains:
        enabled:
          description: Whether trusted signers are enabled for this cache behavior.
          returned: always
          type: bool
          sample: false
        quantity:
          description: Count of trusted signers.
          returned: always
          type: int
          sample: 1
    viewer_protocol_policy:
      description: Policy of how to handle http/https.
      returned: always
      type: str
      sample: redirect-to-https
default_root_object:
  description: The object that you want CloudFront to request from your origin (for example, index.html)
    when a viewer requests the root URL for your distribution.
  returned: always
  type: str
  sample: ''
diff:
  description: Difference between previous configuration and new configuration.
  returned: always
  type: dict
  sample: {}
domain_name:
  description: Domain name of CloudFront distribution.
  returned: always
  type: str
  sample: d1vz8pzgurxosf.cloudfront.net
enabled:
  description: Whether the CloudFront distribution is enabled or not.
  returned: always
  type: bool
  sample: true
http_version:
  description: Version of HTTP supported by the distribution.
  returned: always
  type: str
  sample: http2
id:
  description: CloudFront distribution ID.
  returned: always
  type: str
  sample: E123456ABCDEFG
in_progress_invalidation_batches:
  description: The number of invalidation batches currently in progress.
  returned: always
  type: int
  sample: 0
is_ipv6_enabled:
  description: Whether IPv6 is enabled.
  returned: always
  type: bool
  sample: true
last_modified_time:
  description: Date and time distribution was last modified.
  returned: always
  type: str
  sample: '2017-10-13T01:51:12.656000+00:00'
logging:
  description: Logging information.
  returned: always
  type: complex
  contains:
    bucket:
      description: S3 bucket logging destination.
      returned: always
      type: str
      sample: logs-example-com.s3.amazonaws.com
    enabled:
      description: Whether logging is enabled.
      returned: always
      type: bool
      sample: true
    include_cookies:
      description: Whether to log cookies.
      returned: always
      type: bool
      sample: false
    prefix:
      description: Prefix added to logging object names.
      returned: always
      type: str
      sample: cloudfront/test
origins:
  description: Origins in the CloudFront distribution.
  returned: always
  type: complex
  contains:
    items:
      description: List of origins.
      returned: always
      type: complex
      contains:
        custom_headers:
          description: Custom headers passed to the origin.
          returned: always
          type: complex
          contains:
            quantity:
              description: Count of headers.
              returned: always
              type: int
              sample: 1
        custom_origin_config:
          description: Configuration of the origin.
          returned: always
          type: complex
          contains:
            http_port:
              description: Port on which HTTP is listening.
              returned: always
              type: int
              sample: 80
            https_port:
              description: Port on which HTTPS is listening.
              returned: always
              type: int
              sample: 443
            origin_keepalive_timeout:
              description: Keep-alive timeout.
              returned: always
              type: int
              sample: 5
            origin_protocol_policy:
              description: Policy of which protocols are supported.
              returned: always
              type: str
              sample: https-only
            origin_read_timeout:
              description: Timeout for reads to the origin.
              returned: always
              type: int
              sample: 30
            origin_ssl_protocols:
              description: SSL protocols allowed by the origin.
              returned: always
              type: complex
              contains:
                items:
                  description: List of SSL protocols.
                  returned: always
                  type: list
                  sample:
                  - TLSv1
                  - TLSv1.1
                  - TLSv1.2
                quantity:
                  description: Count of SSL protocols.
                  returned: always
                  type: int
                  sample: 3
        domain_name:
          description: Domain name of the origin.
          returned: always
          type: str
          sample: test-origin.example.com
        id:
          description: ID of the origin.
          returned: always
          type: str
          sample: test-origin.example.com
        origin_path:
          description: Subdirectory to prefix the request from the S3 or HTTP origin.
          returned: always
          type: str
          sample: ''
        connection_attempts:
          description: The number of times that CloudFront attempts to connect to the origin.
          returned: always
          type: int
          sample: 3
        connection_timeout:
          description: The number of seconds that CloudFront waits when trying to establish a connection to the origin.
          returned: always
          type: int
          sample: 10
        origin_shield:
          description: Configuration of the origin Origin Shield.
          returned: always
          type: complex
          contains:
            enabled:
              description: Whether Origin Shield is enabled or not.
              returned: always
              type: bool
              sample: false
            origin_shield_region:
              description: Which region is used by Origin Shield.
              returned: when enabled is true
              type: str
              sample: us-east-1
          version_added: 6.0.0
        s3_origin_config:
          description: Origin access identity configuration for S3 Origin.
          returned: when s3_origin_access_identity_enabled is true
          type: dict
          contains:
            origin_access_identity:
              type: str
              description: The origin access id as a path.
              sample: origin-access-identity/cloudfront/EXAMPLEID
    quantity:
      description: Count of origins.
      returned: always
      type: int
      sample: 1
price_class:
  description: Price class of CloudFront distribution.
  returned: always
  type: str
  sample: PriceClass_All
restrictions:
  description: Restrictions in use by CloudFront.
  returned: always
  type: complex
  contains:
    geo_restriction:
      description: Controls the countries in which your content is distributed.
      returned: always
      type: complex
      contains:
        quantity:
          description: Count of restrictions.
          returned: always
          type: int
          sample: 1
        items:
          description: List of country codes allowed or disallowed.
          returned: always
          type: list
          sample: xy
        restriction_type:
          description: Type of restriction.
          returned: always
          type: str
          sample: blacklist
status:
  description: Status of the CloudFront distribution.
  returned: always
  type: str
  sample: InProgress
tags:
  description: Distribution tags.
  returned: always
  type: dict
  sample:
    Hello: World
viewer_certificate:
  description: Certificate used by CloudFront distribution.
  returned: always
  type: complex
  contains:
    acm_certificate_arn:
      description: ARN of ACM certificate.
      returned: when certificate comes from ACM
      type: str
      sample: arn:aws:acm:us-east-1:123456789012:certificate/abcd1234-1234-1234-abcd-123456abcdef
    certificate:
      description: Reference to certificate.
      returned: always
      type: str
      sample: arn:aws:acm:us-east-1:123456789012:certificate/abcd1234-1234-1234-abcd-123456abcdef
    certificate_source:
      description: Where certificate comes from.
      returned: always
      type: str
      sample: acm
    minimum_protocol_version:
      description: Minimum SSL/TLS protocol supported by this distribution.
      returned: always
      type: str
      sample: TLSv1
    ssl_support_method:
      description: Support for pre-SNI browsers or not.
      returned: always
      type: str
      sample: sni-only
web_acl_id:
  description: ID of Web Access Control List (from WAF service).
  returned: always
  type: str
  sample: abcd1234-1234-abcd-abcd-abcd12345678
    N)OrderedDict)	to_native)to_text)camel_dict_to_snake_dict)recursive_diff)snake_dict_to_camel_dict)CloudFrontFactsServiceManager)AWSRetry)ansible_dict_to_boto3_tag_list)boto3_tag_list_to_ansible_dict)compare_aws_tags)AnsibleCommunityAWSModulec                 Z    || v r&| j                  |      | |<   | j                  |d        | S N)getpop)
dictionaryold_keynew_keys      y/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/aws/plugins/modules/cloudfront_distribution.pychange_dict_key_namer     s1    *(nnW5
7w%    c                 J   |t        |t              rW| j                  |      }|t        |j	                               }ng }t        |t        |j	                               z         | |<   t        |t              r)t        t        | j                  |      |z               | |<   | S r   )
isinstancedictr   listitemsset)configvalidated_node	node_nameconfig_nodeconfig_node_itemss        r   merge_validation_into_configr$     s    !nd+ **Y/K&$():):)<$=!$&! $%6n>R>R>T9U%U VF9nd+ $SI)>)O%P QF9Mr   c                     | g } t        | t              s-t        dt        |       j                   dt        |              i }|rt        |       |d<   t        |       dkD  r| |d<   |S )NzExpected a list, got a z with value quantityr   r   )r   r   
ValueErrortype__name__strlen)
list_itemsinclude_quantityresults      r   ansible_list_to_cloudfront_listr/     st    
j$'24
3C3L3L2M\Z]^hZiYjkllF _z
:$wMr   c                    	 |s| j                  d|      d   S |d|id}| j                  d|      d   S # t        j                  j                  t        j                  j
                  f$ r}|j                  |d       Y d }~y d }~ww xY w)	NT)	aws_retryDistributionConfigDistributionItems)r2   Tags)r1   DistributionConfigWithTagszError creating distributionmsg)create_distributioncreate_distribution_with_tagsbotocore
exceptionsClientErrorBotoCoreErrorfail_json_aws)clientmoduler   tagsdistribution_config_with_tagses         r   r9   r9     s    	C--QW-XYghhCIT[]aSb,c)77;X 8   ++X-@-@-N-NO CQ$ABBCs   7 7 7B.BBc           	      
   	 | j                  d|d   d   |d         S # t        j                  j                  t        j                  j                  f$ r,}|j                  |dt        |d                 Y d }~y d }~ww xY w)NTr3   IdETag)r1   rF   IfMatchzError deleting distribution r7   )delete_distributionr;   r<   r=   r>   r?   r   )r@   rA   distributionrD   s       r   rI   rI     s    n))|N;DA<X^K_ * 
 	
 ++X-@-@-N-NO nQ&B9\ZhMiCjBk$lmmns    7B"A==Bc                     	 | j                  d|||      d   S # t        j                  j                  t        j                  j                  f$ r)}|j                  |dt        |              Y d }~y d }~ww xY w)NT)r1   r2   rF   rH   r3   zError updating distribution to r7   )update_distributionr;   r<   r=   r>   r?   r   )r@   rA   r   distribution_ide_tagrD   s         r   rL   rL     s    [))DVXgqv)w
 	
 ++X-@-@-N-NO [Q&EiPVFWEX$YZZ[s    7A:A55A:c                     	 | j                  d|t        |            S # t        j                  j                  t        j                  j
                  f$ r}|j                  |d       Y d }~y d }~ww xY w)NTr4   )r1   Resourcer5   zError tagging resourcer7   )tag_resourcer   r;   r<   r=   r>   r?   )r@   rA   arnrB   rD   s        r   rR   rR     si    >""TCdQUFV"WW++X-@-@-N-NO >Q$<==>     7A4A//A4c                     	 | j                  d|t        |            S # t        j                  j                  t        j                  j
                  f$ r}|j                  |d       Y d }~y d }~ww xY w)NTrP   )r1   rQ   TagKeyszError untagging resourcer7   )untag_resourcer   r;   r<   r=   r>   r?   )r@   rA   rS   tag_keysrD   s        r   rW   rW     sl    @$$tc4V^K_$``++X-@-@-N-NO @Q$>??@rT   c                 *   	 | j                  d|      }t        |j                  d      j                  d            S # t        j                  j
                  t        j                  j                  f$ r}|j                  |d       Y d }~y d }~ww xY w)NT)r1   rQ   r5   r4   zError listing tags for resourcer7   )list_tags_for_resourcer   r   r;   r<   r=   r>   r?   )r@   rA   rS   responserD   s        r   rZ   rZ     s    G004#0N-hll6.B.F.Fw.OPP++X-@-@-N-NO GQ$EFFGs   ;> 7B5BBc                     |yd}t        |||      \  }}|rt        | |||       d}|rt        | ||t        |             d}|S )NFT)r   rW   rR   r   )	r@   rA   existing_tags
valid_tags
purge_tagsrS   changedto_add	to_removes	            r   update_tagsrc     sZ    G(
JOFIvvsI6VVS*H*PQNr   c                       e Zd ZdZd Zd Zd Z	 d#dZd Zd Z	d Z
	 d#d	Zd
 Zd Zd#dZd#dZd Zd Zd Zd Zd Zd Zd Zd Zd#dZd Z	 d#dZd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#y")$CloudFrontValidationManagerz(
    Manages CloudFront validations
    c                    t        |      | _        || _        d| _        d| _        d| _        d| _        g d| _        d| _        d| _	        d| _
        t        j                  j                         j                  d	      | _        d
| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        t1        g d      | _        t1        g d      | _        t1        g d      | _        t1        g d      | _        t1        g d      | _        t1        g d      | _        t1        ddg      t1        g d      g| _        | j>                  d
   | j>                  d   | j<                  g| _         t1        g d      | _!        t1        ddg      | _"        t1        g d      | _#        t1        g d      | _$        t1        g d      | _%        tM        jN                  d      | _(        y ) NTP   i  F)TLSv1TLSv1.1TLSv1.2match-viewer      z%Y-%m-%dT%H:%M:%S.%fr   i3iQ 	allow-allnone)PriceClass_100PriceClass_200PriceClass_All)z	http-onlyrk   
https-only)SSLv3rh   ri   rj   )ro   	whitelistall)rn   rs   zredirect-to-https)GETHEADPOSTPUTPATCHOPTIONSDELETErw   rx   )rw   rx   r|      )zviewer-requestzviewer-responsezorigin-requestzorigin-responsezsni-onlyvip)rt   rh   
TLSv1_2016zTLSv1.1_2016zTLSv1.2_2018zTLSv1.2_2019zTLSv1.2_2021)
cloudfrontiamacm)zhttp1.1http2http3	http2and3z!\.s3(?:\.[^.]+)?\.amazonaws\.com$))r	   2_CloudFrontValidationManager__cloudfront_facts_mgrrA   :_CloudFrontValidationManager__default_distribution_enabled/_CloudFrontValidationManager__default_http_port0_CloudFrontValidationManager__default_https_port2_CloudFrontValidationManager__default_ipv6_enabled:_CloudFrontValidationManager__default_origin_ssl_protocolsC_CloudFrontValidationManager__default_custom_origin_protocol_policy@_CloudFrontValidationManager__default_custom_origin_read_timeoutE_CloudFrontValidationManager__default_custom_origin_keepalive_timeoutdatetimenowstrftime5_CloudFrontValidationManager__default_datetime_string<_CloudFrontValidationManager__default_cache_behavior_min_ttl<_CloudFrontValidationManager__default_cache_behavior_max_ttl@_CloudFrontValidationManager__default_cache_behavior_default_ttl=_CloudFrontValidationManager__default_cache_behavior_compressK_CloudFrontValidationManager__default_cache_behavior_viewer_protocol_policyE_CloudFrontValidationManager__default_cache_behavior_smooth_streamingU_CloudFrontValidationManager__default_cache_behavior_forwarded_values_forward_cookiesR_CloudFrontValidationManager__default_cache_behavior_forwarded_values_query_string=_CloudFrontValidationManager__default_trusted_signers_enabledr   1_CloudFrontValidationManager__valid_price_classes<_CloudFrontValidationManager__valid_origin_protocol_policies8_CloudFrontValidationManager__valid_origin_ssl_protocols5_CloudFrontValidationManager__valid_cookie_forwarding<_CloudFrontValidationManager__valid_viewer_protocol_policies+_CloudFrontValidationManager__valid_methods:_CloudFrontValidationManager__valid_methods_cached_methods;_CloudFrontValidationManager__valid_methods_allowed_methodsK_CloudFrontValidationManager__valid_lambda_function_association_event_typesJ_CloudFrontValidationManager__valid_viewer_certificate_ssl_support_methodsP_CloudFrontValidationManager__valid_viewer_certificate_minimum_protocol_versionsJ_CloudFrontValidationManager__valid_viewer_certificate_certificate_sources1_CloudFrontValidationManager__valid_http_versionsrecompile4_CloudFrontValidationManager__s3_bucket_domain_regex)selfrA   s     r   __init__z$CloudFrontValidationManager.__init__.  s!   &CF&K#.2+#% $'!&+#/
+
 8F44619:6)1):):)>)>)@)I)IJ`)a&01-08-49116.?J<9>6IOFFJC16.%(&
" 141
- -0-
) *-*
& 141
-  #
 
  /
+  //2//2  0
,
 @C@
< ?B?
; EH
E
A ?B?
; &)&
" )+

3W(X%r   c                     ||vr||||<   |S r    )r   dict_object
key_to_setvalue_to_sets       r   add_missing_keyz+CloudFrontValidationManager.add_missing_key  s    [(\-E&2K
#r   c                 :    ||vr	||||<   |S t        |||      }|S r   )r   )r   r   r   r   r   s        r   add_key_else_change_dict_keyz8CloudFrontValidationManager.add_key_else_change_dict_key  s7    +%,*B#/K   /{GWMKr   c                 j    ||v r| j                  |||       |S |rt        |      ||<   |S ||||<   |S r   )&validate_attribute_with_allowed_valuesr/   )r   r   key_nameattribute_namer   valid_valuesto_aws_lists          r   add_key_else_validatez1CloudFrontValidationManager.add_key_else_validate  s[     {"77nVbc 	 (G(UH%  )(4H%r   c                    	 |y i }|r8t        g d      j                  |      s| j                  j                  d       |j	                  d      |d<   |j	                  d      |d<   |j	                  d      |d<   |j	                  d      |d<   |S # t
        $ r'}| j                  j                  |d       Y d }~y d }~ww xY w)	N)enabledinclude_cookiesbucketprefixzUThe logging parameters enabled, include_cookies, bucket and prefix must be specified.r7   r   r   r   r   z%Error validating distribution logging)r   issubsetrA   	fail_jsonr   	Exceptionr?   )r   loggingvalid_loggingrD   s       r   validate_loggingz,CloudFrontValidationManager.validate_logging  s    	VMs#UV__`gh%%o &  07{{;L/MM+,'.{{9'=M)$&-kk(&;M(#&-kk(&;M(#   	VKK%%a-T%UU	Vs   B BB 	CB>>Cc                     t        |t              s6| j                  j                  | dt	        |      j
                   d       y y )Nz is of type z. Must be a list.r7   )r   r   rA   r   r(   r)   )r   list_to_validate	list_names      r   validate_is_listz,CloudFrontValidationManager.validate_is_list  sB    *D1KK!!<EU@V@_@_?``q&r!s 2r   c                 L    ||vr | j                   j                  | d       y y )Nz must be specified.r7   )rA   r   )r   r   full_key_namer   s       r   validate_required_keyz1CloudFrontValidationManager.validate_required_key  s,    ;&KK!!7J&K!L 'r   c           	         	 |!||s|ry t        |      S |||xs ddg}ng }| j                  |d       |s ||r| j                  j                  d       t	               }t               }	|D ]  }
|
||
j                  d      <    |D ]Q  }
| j                  ||j                  |
j                  d      i       |
|      }
|
||
d   <   |	j                  |
d          S |r&t        |j                               D ]
  }||	vs||=  t        t        |j                                     S # t        $ r'}| j                  j                  |d       Y d }~y d }~ww xY w)N )domain_nameorigin_pathoriginszcBoth origins[] and default_origin_domain_name have not been specified. Please specify at least one.r7   r   z%Error validating distribution origins)r/   r   rA   r   r   r   r   validate_originappendkeysvaluesr   r?   )r   r@   r   r   default_origin_domain_namedefault_origin_pathcreatepurge_originsall_originsnew_domainsorigindomainrD   s                r   validate_originsz,CloudFrontValidationManager.validate_origins  s    	V-5f$#>vFF-9/IZmZsqstuG G!!'959Af%%} &  &-K&K  @9?FJJ}56@! :--KOOFJJ},ErJFTg 6<F=12""6-#89: ";#3#3#56 0F[0'/0 348J8J8L3MNN 	VKK%%a-T%UU	Vs(   D( 
D( C*D( &D( (	E1EEc                 `   |j                  di       j                  d      r|d   d   S |j                  di       j                  d      r|d   d   S 	 d|j                  d       d| j                   }|j                  d       d| j                   }t        t        ||            } |j                  di |d   d	   }d S # t        j
                  j                  t        j
                  j                  f$ r-}| j                  j                  |d
|d           Y d }~dd }~ww xY w)Ns3_origin_configorigin_access_identityzaccess-identity-by-ansible-r   -)CallerReferenceComment)$CloudFrontOriginAccessIdentityConfigCloudFrontOriginAccessIdentityrF   z.Couldn't create Origin Access Identity for id idr7   z"origin-access-identity/cloudfront/r   )
r   r   r   )create_cloud_front_origin_access_identityr;   r<   r>   r=   rA   r?   )	r   r@   existing_configr   commentcaller_referencecfoai_configoairD   s	            r    validate_s3_origin_configurationz<CloudFrontValidationManager.validate_s3_origin_configuration  sP   ::("-112JK,-.FGG126::;ST"#567OPP
	n3FJJ}4M3NaPTPnPnOopG"(**]";!<Ad>\>\=]^59JZdk5lL C&BBR\RSstC
 4C599 ##1183F3F3R3RS 	nKK%%a/]^dei^j]k-l%mm	ns   A0C	 	7D- #D((D-c           	      R   	 | j                  |d|j                  d|xs d            }| j                  dd|       | j                  |d|j                  d| j                              }d|v rvt	        |j                  d            dkD  rY|j                  d      D ]'  }d|vsd|vs| j
                  j                  d	
       ) t        |j                  d            |d<   nt               |d<   d|v rb|j                  d      }|j                  d      r@|j                  d      }|| j
                  j                  d
       n|j                         }| j                  j                  |j                  d      j                               rg|j                  d      4|d   r| j                  |||      }nd }|d= |r|}	nd}	t        |	      |d<   d|v r| j
                  j                  d
       |S | j                  |d|j                  di             }|j                  d      }
| j                  |
dd| j                  | j                        }
| j                  |
d| j                         }
| j                  |
d| j"                        }
| j%                  |
dd| j&                        }
| j%                  |
dd| j(                        }
|
j                  di       j                  d      r|
d   d   |
d<   |
j                  d      r!| j+                  |
d   d| j,                         n| j.                  |
d<   t        |
d         |
d<   |S # t0        j2                  j4                  t0        j2                  j6                  f$ r'}| j
                  j9                  |d 
       Y d }~y d }~ww xY w)!Nr   r   zorigins[].origin_pathr   custom_headersr   header_nameheader_valuezfBoth origins[].custom_headers.header_name and origins[].custom_headers.header_value must be specified.r7   origin_shieldr   origin_shield_regionzlorigins[].origin_shield.origin_shield_region must be specified when origins[].origin_shield.enabled is true.r   !s3_origin_access_identity_enabled)r   r   custom_origin_configzAs3 origin domains and custom_origin_config are mutually exclusiveorigin_protocol_policyz5origins[].custom_origin_config.origin_protocol_policyorigin_read_timeoutorigin_keepalive_timeout	http_porth_t_t_p_port
https_porth_t_t_p_s_portorigin_ssl_protocolsr   zorigins[].origin_ssl_protocolsz$Error validating distribution origin)r   r   r   r   r+   rA   r   r/   lowerr   searchr   r   r   r   r   r   r   r   r   r   )validate_attribute_list_with_allowed_listr   r   r;   r<   r=   r>   r?   )r   r@   r   r   r   custom_headerr   r   r   r   r   rD   s               r   r   z+CloudFrontValidationManager.validate_origin%  s   U	U))':':=J]Jcac'dF &&}6MvV))&$8K8KDRVRpRp8qrF6)c&**=M2N.ORS.S%+ZZ0@%A M$M9^S`=`-- !I . 
 ,K6::VfKg+h'(+J+L'(&( &

? ; $$Y/+8+<+<=S+T(+3--!M . 
 0D/I/I/K,,,33FJJ}4M4S4S4UV::ABNAB+/+P+PQWYhjp+q(+/(BC'. 15S1QF-.)V3KK))_ * P MI --2O4G4GH^`b4c (.zz2H'I$'+'A'A(,K@@99($ (,';';(*?AjAj($ (,';';(*DdFtFt($ (,'H'H(+~tG_G_($ (,'H'H(,8H$JcJc($ (++,BBGKKGTCWXnCopwCx()?@'++,BCBB,-CD899 DHCfCf()?@?^()?@@$%;< M##//1D1D1R1RS 	UKK%%a-S%TT	Us&   B$M 'EM 5EM 7N&?N!!N&c                    	 |||du rt        |      S t               }|s|D ]
  }|||d   <    |D ]<  }| j                  |j                  |j                  d      i       ||      }|||d   <   > |r>t	        |j                               t	        |D 	cg c]  }	|	d   	 c}	      z
  D ]  }
||
=  t        t        |j                                     S c c}	w # t        $ r'}| j                  j                  |d       Y d }~y d }~ww xY w)NFpath_patternz-Error validating distribution cache behaviorsr7   )r/   r   validate_cache_behaviorr   r   r   r   r   r   rA   r?   )r   r   cache_behaviorsvalid_originspurge_cache_behaviorsall_cache_behaviorsbehaviorcache_behaviorvalid_cache_behaviorcbtarget_origin_idrD   s               r   validate_cache_behaviorsz4CloudFrontValidationManager.validate_cache_behaviors}  sM   	^&=+DI^bgIg6v>>"-- ) & MHDL'(@AM"1 ['+'C'C'++N,>,>~,NPRSUcer($ G[#N>$BC	[
 %(+,?,D,D,F(G#2ABBR'BK ) >$ ,,<=> 348K8R8R8T3UVV C  	^KK%%a-\%]]	^s/   C A?C C
 2C C 	D!DDc                    |r|i }|||S | j                  ||||      }|j                  d      "| j                  ||j                  d      |      }| j                  ||j                  d      |      }| j	                  ||j                  d      |      }| j                  ||j                  d      |      }| j                  ||j                  d      |      }|S )Ncache_policy_idforwarded_valuesallowed_methodslambda_function_associationstrusted_signersfield_level_encryption_id)(validate_cache_behavior_first_level_keysr   validate_forwarded_valuesvalidate_allowed_methods%validate_lambda_function_associationsvalidate_trusted_signers"validate_field_level_encryption_id)r   r   r  r
  is_default_caches        r   r  z3CloudFrontValidationManager.validate_cache_behavior  s    6N!m&?MFFNM3C
 /08!;;**+=>N 66v~?Q?QRc?dftuCCN&&'EF
 66v~?Q?QRc?dftu@@N&&'BC^
 r   c           	         |j                  d      =|j                  d      ,|rd}nd|d    }| j                  j                  | d       	 |j                  d      | j                  |dd	|j                  d	| j                              }| j                  |d
d|j                  d| j
                              }| j                  |dd|j                  d| j                              }| j                  |d|j                  d| j                              }|j                  d|j                  d            }|s| j                  |      }||j                  dg       D cg c]  }|d   	 c}vr,|rd}nd|d    }| j                  j                  | d       ||d<   | j                  |dd|j                  d| j                        | j                        }| j                  |d|j                  d| j                              }|S c c}w # t        $ r'}| j                  j                  |d       Y d }~y d }~ww xY w)Nr  r  zDefault cache behaviorzCache behavior for path r  zB cannot have both a cache_policy_id and a forwarded_values option.r7   min_ttl	min_t_t_lmax_ttl	max_t_t_ldefault_ttldefault_t_t_lcompressr  r   r   z@ has target_origin_id pointing to an origin that does not exist.viewer_protocol_policyz%cache_behavior.viewer_protocol_policysmooth_streamingz=Error validating distribution cache behavior first level keys)r   rA   r   r   r   r   r   r   r   .get_first_origin_id_for_default_cache_behaviorr   r   r   r   r   r?   )	r   r   r  r
  r   cache_behavior_namer  r   rD   s	            r   r  zDCloudFrontValidationManager.validate_cache_behavior_first_level_keys  s|   /0<ASASTfAgAs&>#(@P^A_@`&a#KK!!*++mn " 1	n!!"34<!%!B!B"JJ{D,Q,QR	" "&!B!B"JJ{D,Q,QR	" "&!B!B"!#JJ0Y0YZ	" "11
FJJz4CiCi,jN  .112DfjjQcFde##'#V#VWd#e =CTCTU\^`Ca'bt'bb#*B',D^TbEcDd*e'%%.//op &  2BN-.!77(7

3T5i5ij55N "11"

-t/]/]^N
 "!+ (c,  	nKK%%a-l%mm	ns,   DH !H
-BH 
H 	H?H::H?c                 |   	 |s
t               }|j                  di       }|j                  d|j                  di       j                  d            }|r|j                          t        |      |d<   d|vr4|j                  di       j                  d| j                        }d|i|d<   n|j                  di       j                  di       j                  d      }|j                  d      j                  d|      }|r#| j                  |d       t        |      |d   d<   |j                  d      j                  d|j                  di       j                  d            }	| j                  |	d| j                         |	|d   d<   |j                  d	|j                  d	i       j                  dg             }
| j                  |
d
       t        |
      |d	<   | j                  |d|j                  d| j                              }||d<   |S # t        $ r'}| j                  j                  |d       Y d }~y d }~ww xY w)Nr  headersr   cookiesforwardwhitelisted_namesz"forwarded_values.whitelisted_namesz/cache_behavior.forwarded_values.cookies.forwardquery_string_cache_keysz(forwarded_values.query_string_cache_keysquery_stringz!Error validating forwarded valuesr7   )r   r   sortr/   r   r   r   r   r   r   r   rA   r?   )r   r   r  r  r   r.  r0  existing_whitelistru   cookie_forwardingr2  rD   s               r   r  z5CloudFrontValidationManager.validate_forwarded_values  sZ   '	R##'6 $jj);R@O&**9o6I6I)UW6X6\6\]d6efG*I'*RY' 00)--i<@@t]] 09'.B +%4%8%8B%G%K%KL_ac%d%h%hip%q",00;??@SUgh	)))5YZGfgpGq$Y/0CD$4$8$8$C$G$G229bAEEiP%! ;;%'XZ^ZxZx :K +I6&6&:&:)?+>+>?XZ\+]+a+abikm+n'# !!"9;ef:YZq:r67#33 ##ND4o4op 
 2BN-.!! 	RKK%%a-P%QQ	Rs   HH 	H;H66H;c                    	 |b| j                  |d       |D ];  }t        |dd      }| j                  |j                  d      d| j                         = t        |      |d<   |S d|v r|j                  d      |d<   |S t        g       |d<   |S # t        $ r'}| j                  j                  |d       Y d }~y d }~ww xY w)Nr  lambda_function_arnlambda_function_a_r_n
event_typez9cache_behaviors[].lambda_function_associations.event_typez-Error validating lambda function associationsr7   )	r   r   r   r   r   r/   r   rA   r?   )r   r   r  r  associationrD   s         r   r  zACloudFrontValidationManager.validate_lambda_function_associations  s    	^+7%%&BDbc#? K"6{DY[r"sK??#5SLL Ba0B=> "!	 2V;EKZZPnEoN#AB "! FeegEhN#AB!! 	^KK%%a-\%]]	^s$   A#B &B  B 	C B;;C c                 V    |||d<   |S d|v r|j                  d      |d<   |S d|d<   |S )Nr  r   )r   )r   r   r  r  s       r   r  z>CloudFrontValidationManager.validate_field_level_encryption_id(  sU    $0:SN67
 	 )F2:@**E`:aN67  ;=N67r   c                    	 |;| j                  dd|       |j                  d      }| j                  |d       | j                  |d| j                         |j                  d      }d|v r/| j                  |d       | j                  |d| j
                         d|v r&t        |d   d         t        |      k(  r	|d   |d<   nt        |      |d<   |rWt        |      t        |j                  di       j                  di       j                  dg             k(  r|d   d   |d   d<   |S t        |      |d   d<   |S d|v r|j                  d      |d<   |S # t        $ r'}| j                  j                  |d	       Y d }~y d }~ww xY w)
Nr   z&cache_behavior.allowed_methods.items[]z$cache_behavior.allowed_methods.itemscached_methodsz-cache_behavior.allowed_methods.cached_methodsz-cache_behavior.allowed_items.cached_methods[]r  z Error validating allowed methodsr7   )r   r   r   r  r   r   r   r/   r   rA   r?   )r   r   r  r  temp_allowed_itemscached_itemsrD   s          r   r  z4CloudFrontValidationManager.validate_allowed_methods1  s   "	Q***74\^mn%4%8%8%A"%%&8:`a>>&(PRVRvRv  /223CD#6)),8ghBB$G;; %.3v>O7PQX7Y3Z^abt^u3u8>?P8QN#458WXj8kN#45C$5JJ0"599:JBOSST[]_`: % KQQbJcdtJuN#456FG "!	 KjjvJwN#456FG "! %.8>

CT8UN#45!! 	QKK%%a-O%PP	Qs$   D*E -E  E 	F
#FF
c                 z   	 |i }d|v rt        |j                  d            }n/t        |j                  dd            }d|v rt        |d         }|j                  d|j                  d| j                              |d<   ||d<   |S # t        $ r'}| j
                  j                  |d	       Y d }~y d }~ww xY w)
Nr   r&   r   )r&   )r   r   r  z Error validating trusted signersr7   )r/   r   r   r   r   rA   r?   )r   r   r  r  valid_trusted_signersrD   s         r   r  z4CloudFrontValidationManager.validate_trusted_signersV  s    	Q&"$/)(GH[H[\cHd(e%(,fjjQ6O(P%f$,0vg,G)/>/B/B6::i1W1WX0!), 1FN,-!! 	QKK%%a-O%PP	Qs   BB
 
	B:B55B:c                 `   	 |y |j                  d      r-|j                  d      | j                  j                  d       | j                  |j                  d      d| j                         | j                  |j                  d      d| j
                         | j                  |j                  d      d	| j                         t        |dd
      }t        |dd      }t        |dd      }t        |dd      }|S # t        $ r'}| j                  j                  |d       Y d }~y d }~ww xY w)Ncloudfront_default_certificatessl_support_methodzviewer_certificate.ssl_support_method should not be specified with viewer_certificate_cloudfront_default_certificate set to true.r7   z%viewer_certificate.ssl_support_methodminimum_protocol_versionz+viewer_certificate.minimum_protocol_versioncertificate_sourcez%viewer_certificate.certificate_sourcecloud_front_default_certificates_s_l_support_methodiam_certificate_idi_a_m_certificate_idacm_certificate_arna_c_m_certificate_arnz#Error validating viewer certificate)
r   rA   r   r   r   r   r   r   r   r?   )r   viewer_certificaterD   s      r   validate_viewer_certificatez7CloudFrontValidationManager.validate_viewer_certificateh  sT   $	T!)"&&'GH&**+?@L%%2 &  77"&&';<7CC
 77"&&'AB=II
 77"&&';<7CC
 "6"$DFg" "66HJ^`v!w!56HJ^`v!w!5"$9;R" &% 	TKK%%a-R%SS	Ts   C= C7C= =	D-D((D-c                    	 ||st        |      S | j                  |d       t               }t        d |D              }|D ]U  }| j	                  dd|       t        |dd      }d|v rt        |d         |d<   |d   |v r||d   = |j                  |       W |s|j                  |j                                t        |      S # t        $ r'}| j                  j                  |d	       Y d }~y d }~ww xY w)
Ncustom_error_responsesc              3   *   K   | ]  }|d    |f  yw)
error_codeNr   ).0r[   s     r   	<genexpr>zNCloudFrontValidationManager.validate_custom_error_responses.<locals>.<genexpr>  s     %pXx'=x&H%ps   rS  z#custom_error_responses[].error_codeerror_caching_min_ttlerror_caching_min_t_t_lresponse_codez'Error validating custom error responsesr7   )r/   r   r   r   r   r   r*   r   extendr   r   rA   r?   )r   r   rQ  purge_custom_error_responsesr.   existing_responsescustom_error_responserD   s           r   validate_custom_error_responsesz;CloudFrontValidationManager.validate_custom_error_responses  s   	X%-6R6v>>!!"8:RSVF!%%pYo%p!p)? 	5%**<9^`uv(<)+BD])% #&;;=@AVWfAg=h)/:(6:LL*+@+NO34	5 00779:26:: 	XKK%%a-V%WW	Xs   C B3C 	C5C00C5c                    	 ||ry |S | j                  dd|       |j                  d      }| j                  dd|       |j                  di       j                  |d   i       j                  dg       }|j                  d      }|s$|j                  |D cg c]	  }||vs| c}       t        |      }|j                  d      |d<   d|iS c c}w # t        $ r'}	| j
                  j                  |	d       Y d }	~	y d }	~	ww xY w)Ngeo_restrictionzrestrictions.geo_restrictionrestriction_typez-restrictions.geo_restriction.restriction_typer   zError validating restrictionsr7   )r   r   rY  r/   r   rA   r?   )
r   r   restrictionspurge_restrictionsr_  existing_restrictionsgeo_restriction_itemsrestvalid_restrictionsrD   s
             r   validate_restrictionsz1CloudFrontValidationManager.validate_restrictions  s1   	N#%!M&&'8:XZfg*../@AO&&"$SUd 

,b155oFX6Y[]^bbcjlno " %4$7$7$@!%%,,&;adtK`?`Ta "AAV!W5D5H5HI[5\12%'9::	 b
  	NKK%%a-L%MM	Ns:   C C BC 	C!C%)C C 	DC??Dc                    	 |xs |j                  dd      |d<   ||n|j                  d| j                        |d<   ||j                  d      r5| j                  |d| j                         |xs |j                  d      |d<   |s|j                  d      r|xs |j                  d      |d<   |S # t        $ r'}| j
                  j                  |d       Y d }~y d }~ww xY w)Ndefault_root_objectr   is_i_p_v6_enabledhttp_versionweb_a_c_l_idz/Error validating distribution config parametersr7   )r   r   r   r   r   rA   r?   )r   r   ri  ipv6_enabledrk  
web_acl_idrD   s          r   'validate_distribution_config_parameterszCCloudFrontValidationManager.validate_distribution_config_parameters  s    	`,?,h6::NcegChF()  + ZZ 3T5P5PQ &'
 '6::n+E;;L.Z^ZtZtu)5)SN9S~&VZZ7)3)Qvzz.7Q~&M 	`KK%%a-^%__	`s   B0B3 3	C#<CC#c                    	 |i }|T|sD|j                  |j                  di       j                  dg       D cg c]	  }||vs| c}       t        |      |d<   || j                  |      |d<   ||n|j                  d| j                        |d<   |"| j                  |d| j                         ||d<   |S c c}w # t        $ r'}| j                  j                  |d       Y d }~y d }~ww xY w)Naliasesr   r   r   price_classz/Error validating common distribution parametersr7   )
rY  r   r/   r   r   r   r   r   rA   r?   )	r   r   r   rq  r   rr  purge_aliasesaliasrD   s	            r   'validate_common_distribution_parameterszCCloudFrontValidationManager.validate_common_distribution_parameters  s   	`~"$NN,2JJy",E,I,I'SU,Vo5Z_gnZno %DG$Ly!"$($9$9'$By!".FJJy$JmJm4n 9 &;;KX\XrXrs(3}%M p  	`KK%%a-^%__	`s/   7C  	B;B;A3C  ;C   	C0	C++C0c                 R    |xs |j                  dd| j                  z         |d<   |S )Nr   z4Distribution created by Ansible with datetime stamp )r   r   )r   r   r   s      r   validate_commentz,CloudFrontValidationManager.validate_comment  s5    # 
vzzMPTPnPnn(
y r   c                 "    |xs | j                   S r   )r   )r   r   s     r   validate_caller_referencez5CloudFrontValidationManager.validate_caller_reference  s    A4#A#AAr   c                 D   	 |N|j                  d      }|;t        |t              r+t        |      dkD  rt	        |d   j                  d            S | j
                  j                  d       y # t        $ r'}| j
                  j                  |d       Y d }~y d }~ww xY w)Nr   r   r   zqThere are no valid origins from which to specify a target_origin_id for the default_cache_behavior configuration.r7   z8Error getting first origin_id for default cache behavior)	r   r   r   r+   r*   rA   r   r   r?   )r   r
  valid_origins_listrD   s       r   r+  zJCloudFrontValidationManager.get_first_origin_id_for_default_cache_behavior  s    	i(%2%6%6w%?"&2"#5t<./!31!488>??KK!! H "   	iKK%%a-g%hh	is   AA/ A/ /	B8BBc                    	 | j                  ||       t        |t              rt        |      |vs*t        |t              rWt        |      j	                  |      s<dj                  d |D              }| j                  j                  d| d| d       y y y # t        $ r'}| j                  j                  |d       Y d }~y d }~ww xY w)N c              3   2   K   | ]  }t        |        y wr   r*   rT  as     r   rU  zXCloudFrontValidationManager.validate_attribute_list_with_allowed_list.<locals>.<genexpr>	  s     )GQ#a&)G   zThe attribute list  must be one of []r7   z7Error validating attribute list with allowed value list)
r   r   r   r   
issupersetjoinrA   r   r   r?   )r   attribute_listattribute_list_nameallowed_listrD   s        r   r  zECloudFrontValidationManager.validate_attribute_list_with_allowed_list	  s    	h!!.2EF<.'|;lC0L)44^D!$)G,)G!G%%,?@S?TTefteuuv*w%x E 1
  	hKK%%a-f%gg	hs   BB 	C	"CC	c                     |A||vr<dj                  d |D              }| j                  j                  d| d| d       y y y )Nr}  c              3   2   K   | ]  }t        |        y wr   r  r  s     r   rU  zUCloudFrontValidationManager.validate_attribute_with_allowed_values.<locals>.<genexpr>	  s     %Cc!f%Cr  zThe attribute r  r  r7   )r  rA   r   )r   	attributer   r  r  s        r   r   zBCloudFrontValidationManager.validate_attribute_with_allowed_values	  sU     Yl%B XX%Cl%CCNKK!!~6FFWXfWggh&i!j &C r   c                    	 | j                   j                  d      }d}d}|D cg c]  }|j                  d       }}|D ]X  }| j                   j                  |      }|"||   j                  |      }	|	9|	j                  d      |k(  sN|	||   |<   |c S  y c c}w # t        $ r'}
| j
                  j                  |
d	       Y d }
~
y d }
~
ww xY w)
NFkeyedr3   r2   rF   r   r   z3Error validating distribution from caller referencer7   )r   list_distributionsr   get_distributionr   rA   r?   )r   r   distributionsdistribution_namedistribution_config_namedistdistribution_idsrM   rJ   distribution_configrD   s              r   +validate_distribution_from_caller_referencezGCloudFrontValidationManager.validate_distribution_from_caller_reference	  s    	d 77JJQVJWM .';$;HI4II#3 	,#::KKK_+*67H*I*M*MNf*g'+7/334EFJZZTg%678PQ++	,  J  	dKK%%a-b%cc	ds?   $B# B%B# $B# ;B# B# B# B# #	C,CCc                     	 || j                  |      S |r|| j                  |      }|r| j                  j                  |      S y # t        $ r'}| j
                  j                  |d       Y d }~y d }~ww xY w)Nr  zIError validating distribution_id from alias, aliases and caller referencer7   )r  #validate_distribution_id_from_aliasr   r  r   rA   r?   )r   rM   rq  r   rD   s        r   3validate_distribution_from_aliases_caller_referencezOCloudFrontValidationManager.validate_distribution_from_aliases_caller_reference,	  s    	+GGHXYY6&*&N&Nw&WO"66GG?G[[ 	KK%%b &  	s   A	 2A	 		A9A44A9c                     | j                   j                  d      }|rG|D ]B  }|j                  di       j                  dg       }t        |      t        |      z  s=|d   c S  y )NFr  Aliasesr4   rF   )r   r  r   r   )r   rq  r  rJ   distribution_aliasess        r   r  z?CloudFrontValidationManager.validate_distribution_id_from_alias;	  sp    33FFUFS - .'3'7'7	2'F'J'J7TV'W$w<#&:";;'--. r   c                    || j                  |      }|d   d   }	 |j                  d      }dt        |dz        z   }|j                  |d|i       y # t        j
                  j                  $ r4}| j                  j                  |d	t        |       d
       Y d }~y d }~wt        j
                  j                  t        j
                  j                  f$ r*}| j                  j                  |d|        Y d }~y d }~ww xY w)N)r   r3   rF   distribution_deployedr~   <   MaxAttempts)rF   WaiterConfigz2Timeout waiting for CloudFront action. Waited for z seconds before timeout.r7   zError getting distribution )r  
get_waiterintwaitr;   r<   WaiterErrorrA   r?   r   r=   r>   )	r   r@   wait_timeoutrM   r   rJ   waiterattemptsrD   s	            r   wait_until_processedz0CloudFrontValidationManager.wait_until_processedD	  s   "KK]mKnL*>:4@O	^&&'>?F3|b011HKK?-9RKS"".. 	KK%%HQ]I^H__wx &  
 ##//1D1D1R1RS 	^KK%%a/J?J[-\%]]	^s#   7A D3*B"":D DDN)F)$r)   
__module____qualname____doc__r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  rO  r]  rg  ro  ru  rw  ry  r+  r  r   r  r  r  r  r   r   r   re   re   )  s    DYL
 ^c
V"tM *VX:(VUp^0,:nx(RT^.#QJQ$%TNX0N4`( MR`0Bi hk
d(^r   re   c            
         t        dHi dt        ddgd      dt               dt               dt               dt               d	t        d
dg      dt        dd      dt               dt        dg d      dt        dd      dt               dt        dd
      dt        dd      dt        d
      dt        dd
      dt        dd      d t        dd
      d!t        dd      d"t        d
      d#t               d$t        d      d%t        d
      d&t        d
      d't               d(t               d)t        d      d*t               d+t               d,t        dd-      d.t        d/d0-      } i }d}t        | dddgd*dgd*dgg1      }|j                  d2t        j                         3      }t        |      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }	|j                  j                  d	      }
|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d       }|j                  j                  d!      }|j                  j                  d"      }|j                  j                  d#      }|j                  j                  d$      }|j                  j                  d%      }|j                  j                  d&      }|j                  j                  d4      }|j                  j                  d'      }|j                  j                  d(      }|j                  j                  d)      } |j                  j                  d*      }!|j                  j                  d+      }"|j                  j                  d,      }#|j                  j                  d.      }$|r||vr|j                  |       |j                  |||      }%|dk(  xr |%}&|dk(  xr |% }'|dk(  xr |%}(|&s|'s|(s|j                  d5       i })|&s|(r|%d6   d7   })|%d8   }	|%d6   d9   }|&rt        |)d:      })|'s|&rf|j                  |)|||||      })|j                  |)|| ||      })|j                  ||)j                  di       j                  d;g       ||!|"|'|      |)d<   |j                  |)j                  di       j                  d;g       ||)d   |      |)d<   |j!                  |)j                  di       ||)d   d      |)d<   |j#                  |)j                  d i       j                  d;g       ||      |)d <   |j%                  |)j                  d&i       ||      }*|*r|*|)d&<   |j'                  |      }+t)        |)|+d%      })|j+                  |)|      })t-        |)d<      })|'rM|j/                  |      |)d=<   t1        |||)t3        |
xs i             }t        |      }t5        |||d>         |d	<   |(r\|)d?   r7d|)d?<   t7        |||)||	      }|j9                  ||$||)j                  d=             |j                  |||      }%t;        |||%      }|&r|)|%d6   d7   k7  }|rt7        |||)||	      }n|%d6   }t5        |||d@         },|,|%d6   d7   d	<   |t=        |||,|
||d@         z  }t        |      }t5        |||d>         x|dA   d	<   |)d	<   t               |dB<   t?        |%d6   d7   |)      }-|-r|-dC   |dB   dD<   |-dE   |dB   dF<   |#r'|'s|&r#|j9                  ||$||)j                  d=             dA|v r|jA                  |dA          |dA=  |j                  dHdG|i| y )INstatepresentabsent)choicesdefaultr   r   rM   rN   rB   r   resource_tags)r(   rq  r_   boolT)r(   r  rt  rq  r   r*   )r(   r  elementsrs  Fri  r   )r(   r  r   default_cache_behavior)r(   r	  r  rQ  rZ  r   rr  r   rN  ra  rn  rk  rm  r   r   r  )r  r(   r  i  r  )argument_specsupports_check_modemutually_exclusiver   )retry_decoratorrb  )r`   r3   r2   rG   rF   )
reversibler   )capitalize_firstr   rS   EnabledARNr  diffr   beforer~   afterr`   r   )!r   AnsibleAWSModuler@   r
   jittered_backoffre   paramsr   r   r  	exit_jsonr   ru  ro  r   r  r  r]  rg  rO  r$   rw  r   ry  r9   r   rZ   rL   r  rI   rc   r   update).r  r.   r`   rA   r@   validation_mgrr  r   r   rN   rB   r_   rM   rt  rq  rs  ri  r   r   r  r	  r  rQ  rZ  r   rr  r   rN  ra  rb  rn  rk  rm  r   r   r  r  rJ   r  r   deleter   rf  valid_viewer_certificater]   r  s.                                                 r   mainr  W	  s>	    Ix0)D  	
 f v'89 VT2 f &"u= 6 !F &62 6  $0 &6:  #>!"  $&A#$ &*vu%E%& &!'( F)* &!+,  V,-. v&/0 612 V34 v&56 $(678 !F9: %f-;< $U3=MB FG#!()+<=)73
F ]]<9R9R9T]UF08NMMg&E}}(();<mm	*GMMg&E==V$D""<0Jmm''(9:OMMg&Emm	*GMM%%o6M --++,ABmm	*GMM%%o6M#]]../GHmm''(9:O"MM--.EF#]]../GH#)==#4#45S#T mm	*G--##M2Kmm	*G**+?@==$$^4L**+?@""<0J==$$^4L==$$^4L!'!2!23O!P --++,AB==V$D==$$^4Lg%u!UU"2L i0LFi4$4Fh/<Ff'Fn-.BCV$&~6t<)&TBGGGWg{M
  GG'|Z
 +;;JJy"%))'26&
y %3$K$KJJ("-11'2>9!	%
 ! ,:+Q+QJJ/46LfU^N_ae,
'( ,:+Y+YJJ/488"E"(,
'(
 ,AAJJ~r*L:L
 %7F>"#1#M#MN`#a -f6NPde00A)&4H$2$L$LM]$^ !$VVV=[\`\fdf=gh)&1/uNv) %F9(RWXF//oW]WaWabsWtu%YYW&6
 %VV\BL89MNN(RWXF!.1F.vvve}MER^$%9:6B;vv}dJPVW\P]^^)&1AWX^`fhnothuAvv$%f-vvl>:;OPRXY'+AwF6N8$&*1gF6N7#6++FL/SYS]S]^oSpq&f234()F/W//r   __main__)NT))DOCUMENTATIONEXAMPLESRETURNr   r   collectionsr   r;   ImportErroransible.module_utils._textr   r   0ansible.module_utils.common.dict_transformationsr   r   r   Dansible_collections.amazon.aws.plugins.module_utils.cloudfront_factsr	   ;ansible_collections.amazon.aws.plugins.module_utils.retriesr
   ;ansible_collections.amazon.aws.plugins.module_utils.taggingr   r   r   >ansible_collections.community.aws.plugins.module_utils.modulesr   r  r   r$   r/   r9   rI   rL   rR   rW   rZ   rc   objectre   r  r)   r   r   r   <module>r     s   p	d\|S
j  	 #	 1 . U K U n P f f X x

Cn[>@Gk^& k^\{0| zF G#  		s   B BB