o
    !dG                     @   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ConfigureCommandZadd_command)cli r   Musr/lib/python3.10/site-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)nameZcommand_classgetsetz	add-model))r   zAWS Access Key ID)r   zAWS Secret Access Key)Z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   ZsessionZprompterZ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__)_sessionZget_scoped_configr   VALUES_TO_PROMPTr#   r(   r   ospath
expanduserget_config_variableprofile_write_out_creds_file_valuesr   r)   update_config)r   Zparsed_argsZparsed_globals
new_valuesconfigr   r   r   Z	new_valueZconfig_filenamer4   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   r-   Zcredentials_file)popr0   r1   r2   r.   r3   r)   r6   )r   r7   Zprofile_nameZcredential_file_valuesZshared_credentials_filenamer   r   r   r5   z   s(   
z-ConfigureCommand._write_out_creds_file_values)NN)r   r   r   NAMEr   Z	FROM_FILEZDESCRIPTIONZSYNOPSISZEXAMPLESr   r   r   r   ZSUBCOMMANDSr/   r'   r:   r5   __classcell__r   r   r*   r   r   3   s    	r   )r0   loggingZbotocore.exceptionsr   Zawscli.compatr   Zawscli.customizations.commandsr   Z(awscli.customizations.configure.addmodelr   Z#awscli.customizations.configure.setr   Z#awscli.customizations.configure.getr   Z$awscli.customizations.configure.listr   Z&awscli.customizations.configure.writerr	   r   r   r   	getLoggerr   loggerr   objectr   r   r   r   r   r   <module>   s   
