File: //lib/python3/dist-packages/awscli/customizations/cloudtrail/__pycache__/validation.cpython-38.pyc
U
<�^М � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dl
m
Z
mZ d dlm
Z
mZ d dlmZ d dlZd dlmZmZ d dlmZ d dlmZ d d lmZ e�e�Zd
ZdZdd
� Z dd� Z!dd� Z"dd� Z#dd� Z$dd� Z%d,dd�Z&G dd� de'�Z(G dd� de)�Z*G dd� de*�Z+G d d!� d!e*�Z,G d"d#� d#e'�Z-G d$d%� d%e'�Z.G d&d'� d'e'�Z/G d(d)� d)e'�Z0G d*d+� d+e�Z1dS )-� N)�error)�datetime� timedelta)�tz�parser)�PyAsn1Error)�get_trail_by_arn�get_account_id_from_arn)�BasicCommand)�ClientError)�ParameterRequiredErrorz%Y%m%dT%H%M%SZz%Y-%m-%dT%H:%M:%SZc C s
| � t�S )z;Returns a formatted date string in a CloudTrail date format)�strftime�DATE_FORMAT��date� r �M/usr/lib/python3/dist-packages/awscli/customizations/cloudtrail/validation.py�format_date( s r c C s
| � t�S )z4Returns a formatted date string meant for CLI output)r
�DISPLAY_DATE_FORMATr r r r �format_display_date- s r c C s | j t�� d�S )z.Returns a normalized date using a UTC timezone)Ztzinfo)�replacer Ztzutcr r r r �normalize_date2 s r c C s | dd� S )z�Extract the timestamp portion of a manifest file.
Manifest file names take the following form:
AWSLogs/{account}/CloudTrail-Digest/{region}/{ymd}/{account}_CloudTrail -Digest_{region}_{name}_region_{date}.json.gz
i��i����r )Z
digest_s3_keyr r r �extract_digest_key_date7 s r c C s2 zt �| �W S tk
r, td| ��Y nX d S )NzUnable to parse date value: %s)r �parse�
ValueError)Zdate_stringr r r �
parse_dateA s r c C s$ t �d�}|�| �s td| ��dS )zlEnsures that the arn looks correct.
ARNs look like: arn:aws:cloudtrail:us-east-1:123456789012:trail/fooz$arn:.+:cloudtrail:.+:\d{12}:trail/.+zInvalid trail ARN provided: %sN)�re�compile�matchr )� trail_arn�patternr r r �assert_cloudtrail_arn_is_validH s
r! c C s� t |� d}|dkrft| |�}t�d|� |d }|�dd�} |d }
|
rf|
sVtd��|�� d d }|�d �d
}|�d�d }|
s�t|�}
t |
|||||d
�}t
||| |||t| �d�S )a� Creates a CloudTrail DigestTraverser and its object graph.
:type cloudtrail_client: botocore.client.CloudTrail
:param cloudtrail_client: Client used to connect to CloudTrail
:type organization_client: botocore.client.organizations
:param organization_client: Client used to connect to Organizations
:type s3_client_provider: S3ClientProvider
:param s3_client_provider: Used to create Amazon S3 client per/region.
:param trail_arn: CloudTrail trail ARN
:param trail_source_region: The scanned region of a trail.
:param on_invalid: Callback that is invoked when validating a digest fails.
:param on_gap: Callback that is invoked when a digest has no link to the
previous digest, but there are more digests to validate. This can
happen when a trail is disabled for a period of time.
:param on_missing: Callback that is invoked when a digest file has been
deleted from Amazon S3 but is supposed to be present.
:param bucket: Amazon S3 bucket of the trail if it is different than the
bucket that is currently associated with the trail.
:param prefix: bucket: Key prefix prepended to each digest and log placed
in the Amazon S3 bucket if it is different than the prefix that is
currently associated with the trail.
:param account_id: The account id for which the digest files are
validated. For normal trails this is the caller account, for
organization trails it is the member accout.
``on_gap``, ``on_invalid``, and ``on_missing`` callbacks are invoked with
the following named arguments:
- ``bucket`: The next S3 bucket.
- ``next_key``: (optional) Next digest key that was found in the bucket.
- ``next_end_date``: (optional) End date of the next found digest.
- ``last_key``: The last digest key that was found.
- ``last_start_date``: (optional) Start date of last found digest.
- ``message``: (optional) Message string about the notification.
NzLoaded trail info: %sZS3BucketNameZS3KeyPrefixZIsOrganizationTrailzAMissing required parameter for organization trail: '--account-id'ZOrganizationZId�:� �/���)�
account_id�
trail_name�s3_client_provider�trail_source_region�trail_home_region�organization_id)�digest_provider�starting_bucket�starting_prefix�
on_invalid�on_gap�
on_missing�public_key_provider)r! r �LOG�debug�getr Zdescribe_organization�splitr �DigestProvider�DigestTraverser�PublicKeyProvider)�cloudtrail_client�organization_clientr( r r) r/ r0 r1 �bucket�prefixr&