o
    Ü!d  ã                   @   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_servicesZget_service_modelÚendpoint_prefix)ÚsessionZprefixes_to_servicesÚservice_nameÚservice_model© r
   úLusr/lib/python3.10/site-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   Z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 definition and the current services in botocore.
    NZdata_loaderzservice-%d.jsonÚversionz2.0)r   r   r   Úapi_versionZget_componentZCUSTOMER_DATA_PATHÚintÚfloatr   ÚosÚpathÚjoin)r   Úservice_definitionr   r	   r   r   Z	data_pathZ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   Z_sessionr   r   r   ÚdirnameÚexistsÚmakedirsÚopenÚwriteÚencode)ÚselfZparsed_argsZparsed_globalsr   Zmodel_locationZmodel_directoryÚfr
   r
   r   Ú	_run_mainf   s   
ÿ

ÿýzAddModelCommand._run_mainN)Ú__name__Ú
__module__Ú__qualname__ÚNAMEZDESCRIPTIONZ	ARG_TABLEr'   r
   r
   r
   r   r   V   s    ÿÿÿýr   r   )
r   r   Zbotocore.modelr   Zawscli.customizations.commandsr   r   r   r   r   r
   r
   r
   r   Ú<module>   s   

&