o
    .&ßa®  ã                   @   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 )&ÚPackageCommandzðSuccessfully 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>
ÚpackageÚ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-prefixz¡A 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-filezªThe 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-uploadz�Indicates 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   Úcli_type_nameÚ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 )	NÚs3Ús3v4)Úsignature_version)ÚconfigÚregion_nameÚverify)Útemplate_pathÚ
)Úoutput_file_nameÚoutput_file_pathr   )Ú_sessionÚcreate_clientr   ÚregionÚ
verify_sslÚtemplate_fileÚosÚpathÚisfiler   ÚInvalidTemplatePathErrorÚ	s3_bucketr   Ú	s3_prefixÚ
kms_key_idÚforce_uploadÚs3_uploaderr   Úartifact_metadataÚoutput_template_fileÚuse_jsonÚ_exportÚsysÚstdoutÚwriteÚwrite_outputÚMSG_PACKAGED_TEMPLATE_WRITTENÚformatÚabspathÚflush)
ÚselfÚparsed_argsÚparsed_globalsÚ	s3_clientr   ÚbucketÚoutput_filer2   Úexported_strÚmsg© rD   úN/usr/lib/python3/dist-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/   ÚexportÚjsonÚdumpsr   )r<   r   r2   ÚtemplateÚexported_templaterB   rD   rD   rE   r3   ¤   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)r4   r5   r6   Úopen)r<   r    ÚdataÚfprD   rD   rE   r7   ¯   s   "ÿzPackageCommand.write_outputN)Ú__name__Ú
__module__Ú__qualname__r8   ÚNAMEr   Ú	FROM_FILEÚDESCRIPTIONÚ	ARG_TABLErF   r3   r7   rD   rD   rD   rE   r      sX    ÿ
ÿü
ü
ýý	ýü
ü
ýø¿N&r   )r'   Úloggingr4   rL   Úbotocore.clientr   Ú6awscli.customizations.cloudformation.artifact_exporterr   Ú/awscli.customizations.cloudformation.yamlhelperr   Ú$awscli.customizations.cloudformationr   Úawscli.customizations.commandsr   Ú awscli.customizations.s3uploaderr   Ú	getLoggerrT   ÚLOGr   rD   rD   rD   rE   Ú<module>   s   
