o
    .&ßa   ã                   @   sV   d dl Z d dlZd dlmZ d dlmZ dd„ Zdd„ Zddd	„ZG d
d„ deƒZ	dS )é    N)ÚServiceModel)ÚBasicCommandc                 C   s*   i }|   ¡ D ]}|  |¡}|||j< q|S ©N)Úget_available_servicesÚget_service_modelÚendpoint_prefix)ÚsessionÚprefixes_to_servicesÚservice_nameÚservice_model© r   úJ/usr/lib/python3/dist-packages/awscli/customizations/configure/addmodel.pyÚ%_get_endpoint_prefix_to_name_mappings   s
   
r   c                 C   s$   ||   ¡ v r|S t| ƒ}| ||¡S r   )r   r   Úget)r   r   Úname_mappingsr   r   r   Ú_get_service_name   s   r   c                 C   s\   t |ƒ}|du r|j}t| |ƒ}|j}|  d¡j}dtt| dd¡ƒƒ }t	j
 ||||¡S )a_  Gets the path of where a service-2.json file should go in ~/.aws/models

    :type session: botocore.session.Session
    :param session: A session object

    :type service_definition: dict
    :param service_definition: The json loaded service definition

    :type service_name: str
    :param service_name: The service name to use. If this not provided,
        this will be determined from a combination of available services
        and the service definition.

    :returns: The path to where are model should be placed based on
        the service defintion and the current services in botocore.
    NÚdata_loaderzservice-%d.jsonÚversionz2.0)r   r   r   Úapi_versionÚget_componentÚCUSTOMER_DATA_PATHÚintÚfloatr   ÚosÚpathÚjoin)r   Úservice_definitionr
   r   r   r   Ú	data_pathÚservice_model_namer   r   r   Úget_model_location0   s   
ÿÿÿr   c                   @   s2   e Zd ZdZdZddddœddd	œgZd
d„ ZdS )ÚAddModelCommandz	add-modelzÄAdds a service JSON model to the appropriate location in ~/.aws/models. Once the model gets added, CLI commands and Boto3 clients will be immediately available for the service JSON model provided.zservice-modelTz'The contents of the service JSON model.)ÚnameÚrequiredÚ	help_textzservice-namezmOverrides the default name used by the service JSON model to generate CLI service commands and Boto3 clients.)r!   r#   c                 C   s€   t  |j¡}t| j||jƒ}tj |¡}tj 	|¡st 
|¡ t|dƒ�}| |j d¡¡ W d   ƒ dS 1 s9w   Y  dS )NÚwbzutf-8r   )ÚjsonÚloadsr   r   Ú_sessionr
   r   r   ÚdirnameÚexistsÚmakedirsÚopenÚwriteÚencode)ÚselfÚparsed_argsÚparsed_globalsr   Úmodel_locationÚmodel_directoryÚfr   r   r   Ú	_run_mainf   s   
ÿ

ÿýzAddModelCommand._run_mainN)Ú__name__Ú
__module__Ú__qualname__ÚNAMEÚDESCRIPTIONÚ	ARG_TABLEr4   r   r   r   r   r    V   s    ÿÿÿýr    r   )
r%   r   Úbotocore.modelr   Úawscli.customizations.commandsr   r   r   r   r    r   r   r   r   Ú<module>   s   

&