o
    .&ßaG  ã                   @   s¶   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 d dlmZ d d	lmZ d
dlmZmZ e e¡Zdd„ ZG dd„ deƒZG dd„ deƒZdS )é    N)ÚProfileNotFound)Úcompat_input)ÚBasicCommand)ÚAddModelCommand)ÚConfigureSetCommand)ÚConfigureGetCommand)ÚConfigureListCommand)ÚConfigFileWriteré   )Ú
mask_valueÚprofile_to_sectionc                 C   s   |   dtj¡ d S )Nzbuilding-command-table.main)ÚregisterÚConfigureCommandÚadd_command)Úcli© r   úK/usr/lib/python3/dist-packages/awscli/customizations/configure/configure.pyÚregister_configure_cmd    s   ÿr   c                   @   s   e Zd Zddd„ZdS )ÚInteractivePrompterÚ c                 C   s,   |dv rt |ƒ}td||f ƒ}|sd }|S )N)Úaws_access_key_idÚaws_secret_access_keyz	%s [%s]: )r   r   )ÚselfÚcurrent_valueÚconfig_nameÚprompt_textÚresponser   r   r   Ú	get_value'   s   zInteractivePrompter.get_valueN)r   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   %   s    r   c                       sn   e Zd ZdZe ¡ ZdZdZde	dœde
dœdedœdedœgZg d	¢Zd‡ fdd„	Zdd„ Zdd„ Z‡  ZS )r   Ú	configurez&aws configure [--profile profile-name]a�  To create a new configuration::

    $ aws configure
    AWS Access Key ID [None]: accesskey
    AWS Secret Access Key [None]: secretkey
    Default region name [None]: us-west-2
    Default output format [None]:

To update just the region name::

    $ aws configure
    AWS Access Key ID [****]:
    AWS Secret Access Key [****]:
    Default region name [us-west-1]: us-west-2
    Default output format [None]:
Úlist)ÚnameÚcommand_classÚgetÚsetz	add-model))r   zAWS Access Key ID)r   zAWS Secret Access Key)ÚregionzDefault region name)ÚoutputzDefault output formatNc                    s<   t t| ƒ |¡ |d u rtƒ }|| _|d u rtƒ }|| _d S )N)Úsuperr   Ú__init__r   Ú	_prompterr	   Ú_config_writer)r   ÚsessionÚprompterÚconfig_writer©Ú	__class__r   r   r*   X   s   
zConfigureCommand.__init__c                 C   sÆ   i }z| j  ¡ }W n ty   i }Y nw | jD ]\}}| |¡}| j |||¡}|d ur5||kr5|||< qtj 	| j  
d¡¡}	|ra| j j}
|  ||
¡ |
d urXt|
ƒ}||d< | j ||	¡ d S d S )NÚconfig_fileÚ__section__)Ú_sessionÚget_scoped_configr   ÚVALUES_TO_PROMPTr%   r+   r   ÚosÚpathÚ
expanduserÚget_config_variableÚprofileÚ_write_out_creds_file_valuesr   r,   Úupdate_config)r   Úparsed_argsÚparsed_globalsÚ
new_valuesÚconfigr   r   r   Ú	new_valueÚconfig_filenamer;   Úsectionr   r   r   Ú	_run_maina   s2   ÿ

ÿ€
ÿúzConfigureCommand._run_mainc                 C   sn   i }d|v r|  d¡|d< d|v r|  d¡|d< |r5|d ur"||d< tj | j d¡¡}| j ||¡ d S d S )Nr   r   r3   Úcredentials_file)Úpopr7   r8   r9   r4   r:   r,   r=   )r   r@   Úprofile_nameÚcredential_file_valuesÚshared_credentials_filenamer   r   r   r<   z   s(   ÿÿ
ÿþûz-ConfigureCommand._write_out_creds_file_values)NN)r   r   r    ÚNAMEr   Ú	FROM_FILEÚDESCRIPTIONÚSYNOPSISÚEXAMPLESr   r   r   r   ÚSUBCOMMANDSr6   r*   rE   r<   Ú__classcell__r   r   r0   r   r   3   s    ÿü	r   )r7   ÚloggingÚbotocore.exceptionsr   Úawscli.compatr   Úawscli.customizations.commandsr   Ú(awscli.customizations.configure.addmodelr   Ú#awscli.customizations.configure.setr   Ú#awscli.customizations.configure.getr   Ú$awscli.customizations.configure.listr   Ú&awscli.customizations.configure.writerr	   r   r   r   Ú	getLoggerr   Úloggerr   Úobjectr   r   r   r   r   r   Ú<module>   s   
