o
    !d                     @   s   d dl Z d dlZd dl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 eeZG dd	 d	eZdS )
    N)Config)Template)	yaml_dump)
exceptions)BasicCommand)
S3Uploaderc                   @   s   e Zd ZdZdZeddZddddd	dd
dddddddddddddddddddddddiddidddgZdd  Z	d!d" Z
d#d$ Zd%S )&PackageCommandzSuccessfully packaged artifacts and wrote output template to file {output_file_name}.
Execute the following command to deploy the packaged template
aws cloudformation deploy --template-file {output_file_path} --stack-name <YOUR STACK NAME>
packageZcloudformationz_package_description.rstztemplate-fileTz;The path where your AWS CloudFormation template is located.)namerequired	help_textz	s3-bucketzhThe name of the S3 bucket where this command uploads the artifacts that are referenced in your template.z	s3-prefixzA prefix name that the command adds to the artifacts' name when it uploads them to the S3 bucket. The prefix name is a path name (folder name) for the S3 bucket.)r
   r   z
kms-key-idzfThe ID of an AWS KMS key that the command uses to encrypt artifacts that are at rest in the S3 bucket.zoutput-template-filezThe path to the file where the command writes the output AWS CloudFormation template. If you don't specify a path, the command writes the template to the standard output.zuse-json
store_truezpIndicates whether to use JSON as the format for the output AWS CloudFormation template. YAML is used by default.)r
   actionr   zforce-uploadzIndicates whether to override existing files in the S3 bucket. Specify this flag to upload artifacts even if they  match existing artifacts in the S3 bucket.metadatamaptypestring)r   keyvaluezXA map of metadata to attach to *ALL* the artifacts that are referenced in your template.)r
   Zcli_type_nameZschemar   c           
      C   s   | j jdtdd|j|jd}|j}tj|st	j
|d|j}t|||j|j|j| _|j| j_|j}|j}| ||}tjd | || |r^| jj|tj|d}	tj|	 tj  dS )	NZs3Zs3v4)Zsignature_version)configZregion_nameZverify)template_path
)output_file_nameZoutput_file_pathr   )Z_sessionZcreate_clientr   ZregionZ
verify_sslZtemplate_fileospathisfiler   ZInvalidTemplatePathErrorZ	s3_bucketr   Z	s3_prefixZ
kms_key_idZforce_uploads3_uploaderr   Zartifact_metadataZoutput_template_fileuse_json_exportsysstdoutwritewrite_outputMSG_PACKAGED_TEMPLATE_WRITTENformatabspathflush)
selfZparsed_argsZparsed_globalsZ	s3_clientr   bucketoutput_filer   exported_strmsg r,   Pusr/lib/python3.10/site-packages/awscli/customizations/cloudformation/package.py	_run_main~   s@   


zPackageCommand._run_mainc                 C   s>   t |t | j}| }|rtj|ddd}|S t|}|S )N   F)indentensure_ascii)r   r   getcwdr   Zexportjsondumpsr   )r'   r   r   templateZexported_templater*   r,   r,   r-   r      s   zPackageCommand._exportc                 C   sR   |d u rt j| d S t|d}|| W d    d S 1 s"w   Y  d S )Nw)r   r    r!   open)r'   r   datafpr,   r,   r-   r"      s   "zPackageCommand.write_outputN)__name__
__module____qualname__r#   NAMEr   Z	FROM_FILEZDESCRIPTIONZ	ARG_TABLEr.   r   r"   r,   r,   r,   r-   r      sX    


	

N&r   )r   loggingr   r3   Zbotocore.clientr   Z6awscli.customizations.cloudformation.artifact_exporterr   Z/awscli.customizations.cloudformation.yamlhelperr   Z$awscli.customizations.cloudformationr   Zawscli.customizations.commandsr   Z awscli.customizations.s3uploaderr   	getLoggerr:   ZLOGr   r,   r,   r,   r-   <module>   s   
