U
    M8cmx                     @   s  d Z ddlZddlZddlZddlmZ eeZdddgddfdddd	d
di dfdddde	fddde	fdddddej
fdddej
fdddej
fddddej
fdddd e	fd!d"d#d$d%d&d'de	fd(Zd)d*ddej
fd+ddej
fd,ddej
fd-d.gd/dej
fd0d1gd2ddfd3d4dej
fd5Zd6d7d8ddejfd9Zd:d; Zd<d= ZG d>d? d?ZG d@dA dAZG dBdC dCZG dDdE dEZG dFdG dGZG dHdI dIeZG dJdK dKeZG dLdM dMeZG dNdO dOeZG dPdQ dQeZG dRdS dSeZdS )TzOThis module contains the inteface for controlling how configuration
is loaded.
    N)utilsZAWS_DEFAULT_PROFILEZAWS_PROFILE)regionAWS_DEFAULT_REGIONNN)	data_pathZAWS_DATA_PATHNN)NZAWS_CONFIG_FILEz~/.aws/configN)	ca_bundleZAWS_CA_BUNDLENNapi_versions)NZAWS_SHARED_CREDENTIALS_FILEz~/.aws/credentialsNmetadata_service_timeoutZAWS_METADATA_SERVICE_TIMEOUT   metadata_service_num_attemptsZ!AWS_METADATA_SERVICE_NUM_ATTEMPTS)ec2_metadata_service_endpointZ!AWS_EC2_METADATA_SERVICE_ENDPOINTNN)"ec2_metadata_service_endpoint_modeZ&AWS_EC2_METADATA_SERVICE_ENDPOINT_MODENNimds_use_ipv6ZAWS_IMDS_USE_IPV6Fuse_dualstack_endpointZAWS_USE_DUALSTACK_ENDPOINTuse_fips_endpointZAWS_USE_FIPS_ENDPOINT)parameter_validationNTNcsm_enabledZAWS_CSM_ENABLED)csm_hostZAWS_CSM_HOSTz	127.0.0.1Ncsm_portZAWS_CSM_PORTiy  )csm_client_idZAWS_CSM_CLIENT_ID N)endpoint_discovery_enabledZAWS_ENDPOINT_DISCOVERY_ENABLEDautoN)sts_regional_endpointsZAWS_STS_REGIONAL_ENDPOINTSlegacyN)
retry_modeZAWS_RETRY_MODEr   N)defaults_modeZAWS_DEFAULTS_MODEr   Nmax_attemptsZAWS_MAX_ATTEMPTS)Zprofiler   r   config_filer   r   Zcredentials_filer   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ))s3addressing_styleNNN)r   use_accelerate_endpoint)r   r   )r   payload_signing_enabledZs3_use_arn_region)r   use_arn_regionZAWS_S3_USE_ARN_REGIONZs3_us_east_1_regional_endpoint)r   us_east_1_regional_endpointZ"AWS_S3_US_EAST_1_REGIONAL_ENDPOINT)r   $s3_disable_multiregion_access_pointsZ(AWS_S3_DISABLE_MULTIREGION_ACCESS_POINTS)r   r    r   r!   r"   r#   r$   )proxy_ca_bundleNNN)proxy_client_certNNNproxy_use_forwarding_for_https)r%   r&   r'   c                 C   sD   t | d}t|t}td| t|t|d< td| t|t|d< |S )N)sessionr   Zproxies_config)ConfigChainFactory_create_config_chain_mapping!BOTOCORE_DEFAUT_SESSION_VARIABLESSectionConfigProviderDEFAULT_S3_CONFIG_VARSDEFAULT_PROXIES_CONFIG_VARS)r(   chain_builderZconfig_mapping r0   ;/tmp/pip-unpacked-wheel-ozje0y8b/botocore/configprovider.py&create_botocore_default_config_mapping   s&    
  r2   c                 C   sB   i }|  D ]0\}}| j||d |d |d |d d||< q|S )Nr	   r         )instance_nameenv_var_namesconfig_property_namesdefaultconversion_func)itemscreate_config_chain)r/   Zconfig_variablesmappinglogical_nameconfigr0   r0   r1   r*      s    r*   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
DefaultConfigResolverc                 C   s   |d | _ |d | _i | _d S )Nbasemodes)_base_default_config_modes _resolved_default_configurations)selfZdefault_config_datar0   r0   r1   __init__   s    

zDefaultConfigResolver.__init__c           	      C   s   | j  }| j|}|D ]d}|| }|| }t| d }|| }|dkrX||9 }n|dkrj||7 }n|dkrv|}|||< q|S )Nr   multiplyaddoverride)rB   copyrC   getlistkeys)	rE   modeZdefault_configZmodifications
config_vardefault_valueZmodification_dictZmodificationZmodification_valuer0   r0   r1   _resolve_default_values_by_mode   s    



z5DefaultConfigResolver._resolve_default_values_by_modec                 C   s   ddg}| | j  |S )Nr   r   )extendrC   rM   )rE   Zdefault_modesr0   r0   r1   get_default_modes  s    z'DefaultConfigResolver.get_default_modesc                 C   s(   || j kr| |}|| j |< | j | S N)rD   rQ   )rE   rN   defaultsr0   r0   r1   get_default_config_values	  s    


z/DefaultConfigResolver.get_default_config_valuesN)__name__
__module____qualname__rF   rQ   rS   rV   r0   r0   r0   r1   r?      s   r?   c                   @   s4   e Zd ZdZdddZdddZdd Zd	d
 ZdS )r)   a  Factory class to create our most common configuration chain case.

    This is a convenience class to construct configuration chains that follow
    our most common pattern. This is to prevent ordering them incorrectly,
    and to make the config chain construction more readable.
    Nc                 C   s   || _ |dkrtj}|| _dS )a  Initialize a ConfigChainFactory.

        :type session: :class:`botocore.session.Session`
        :param session: This is the session that should be used to look up
            values from the config file.

        :type environ: dict
        :param environ: A mapping to use for environment variables. If this
            is not provided it will default to use os.environ.
        N)_sessionosenviron_environ)rE   r(   r\   r0   r0   r1   rF     s    zConfigChainFactory.__init__c                 C   st   g }|dk	r | t|| jd |dk	r8|| | |dk	rP|| | |dk	rh| t|d t||dS )a  Build a config chain following the standard botocore pattern.

        In botocore most of our config chains follow the the precendence:
        session_instance_variables, environment, config_file, default_value.

        This is a convenience function for creating a chain that follow
        that precendence.

        :type instance_name: str
        :param instance_name: This indicates what session instance variable
            corresponds to this config value. If it is None it will not be
            added to the chain.

        :type env_var_names: str or list of str or None
        :param env_var_names: One or more environment variable names to
            search for this value. They are searched in order. If it is None
            it will not be added to the chain.

        :type config_property_names: str/tuple or list of str/tuple or None
        :param config_property_names: One of more strings or tuples
            representing the name of the key in the config file for this
            config option. They are searched in order. If it is None it will
            not be added to the chain.

        :type default: Any
        :param default: Any constant value to be returned.

        :type conversion_func: None or callable
        :param conversion_func: If this value is None then it has no effect on
            the return type. Otherwise, it is treated as a function that will
            conversion_func our provided type.

        :rvalue: ConfigChain
        :returns: A ConfigChain that resolves in the order env_var_names ->
            config_property_name -> default. Any values that were none are
            omitted form the chain.
        N)instance_varr(   )value)	providersr9   )appendInstanceVarProviderrZ   rR   _get_env_providers_get_scoped_config_providersConstantProviderChainProvider)rE   r5   r6   r7   r8   r9   r`   r0   r0   r1   r;   (  s(    - z&ConfigChainFactory.create_config_chainc                 C   s6   g }t |ts|g}|D ]}|t|| jd q|S )N)nameenv)
isinstancerL   ra   EnvironmentProviderr]   )rE   r6   Zenv_var_providersZenv_var_namer0   r0   r1   rc   j  s    
z%ConfigChainFactory._get_env_providersc                 C   s6   g }t |ts|g}|D ]}|t|| jd q|S )N)config_var_namer(   )ri   rL   ra   ScopedConfigProviderrZ   )rE   r7   Zscoped_config_providersZconfig_property_namer0   r0   r1   rd   t  s    
z/ConfigChainFactory._get_scoped_config_providers)N)NNNNN)rW   rX   rY   __doc__rF   r;   rc   rd   r0   r0   r0   r1   r)     s   
     
B
r)   c                   @   sJ   e Zd ZdZdddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )ConfigValueStorez8The ConfigValueStore object stores configuration values.Nc                 C   s6   i | _ i | _|dk	r2| D ]\}}| || qdS )aN  Initialize a ConfigValueStore.

        :type mapping: dict
        :param mapping: The mapping parameter is a map of string to a subclass
            of BaseProvider. When a config variable is asked for via the
            get_config_variable method, the corresponding provider will be
            invoked to load the value.
        N)
_overrides_mappingr:   set_config_provider)rE   r<   r=   providerr0   r0   r1   rF     s
    	zConfigValueStore.__init__c                 C   s   t t| j|S rT   )rn   rJ   deepcopyrp   rE   memor0   r0   r1   __deepcopy__  s    zConfigValueStore.__deepcopy__c                 C   s4   || j kr| j | S || jkr"dS | j| }| S )a  
        Retrieve the value associeated with the specified logical_name
        from the corresponding provider. If no value is found None will
        be returned.

        :type logical_name: str
        :param logical_name: The logical name of the session variable
            you want to retrieve.  This name will be mapped to the
            appropriate environment variable name for this session as
            well as the appropriate config file entry.

        :returns: value of variable or None if not defined.
        N)ro   rp   providerE   r=   rr   r0   r0   r1   get_config_variable  s    



z$ConfigValueStore.get_config_variablec                 C   s&   || j ks|| jkrdS | j| }|S )a  
        Retrieve the provider associated with the specified logical_name.
        If no provider is found None will be returned.

        :type logical_name: str
        :param logical_name: The logical name of the session variable
            you want to retrieve.  This name will be mapped to the
            appropriate environment variable name for this session as
            well as the appropriate config file entry.

        :returns: configuration provider or None if not defined.
        N)ro   rp   rx   r0   r0   r1   get_config_provider  s    
z$ConfigValueStore.get_config_providerc                 C   s   || j |< dS )a  Set a configuration variable to a specific value.

        By using this method, you can override the normal lookup
        process used in ``get_config_variable`` by explicitly setting
        a value.  Subsequent calls to ``get_config_variable`` will
        use the ``value``.  This gives you per-session specific
        configuration values.

        ::
            >>> # Assume logical name 'foo' maps to env var 'FOO'
            >>> os.environ['FOO'] = 'myvalue'
            >>> s.get_config_variable('foo')
            'myvalue'
            >>> s.set_config_variable('foo', 'othervalue')
            >>> s.get_config_variable('foo')
            'othervalue'

        :type logical_name: str
        :param logical_name: The logical name of the session variable
            you want to set.  These are the keys in ``SESSION_VARIABLES``.

        :param value: The value to associate with the config variable.
        N)ro   )rE   r=   r_   r0   r0   r1   set_config_variable  s    z$ConfigValueStore.set_config_variablec                 C   s   | j |d dS )zRemove an override config variable from the session.

        :type logical_name: str
        :param logical_name: The name of the parameter to clear the override
            value from.
        N)ro   pop)rE   r=   r0   r0   r1   clear_config_variable  s    z&ConfigValueStore.clear_config_variablec                 C   s   || j |< dS )a;  Set the provider for a config value.

        This provides control over how a particular configuration value is
        loaded. This replaces the provider for ``logical_name`` with the new
        ``provider``.

        :type logical_name: str
        :param logical_name: The name of the config value to change the config
            provider for.

        :type provider: :class:`botocore.configprovider.BaseProvider`
        :param provider: The new provider that should be responsible for
            providing a value for the config named ``logical_name``.
        N)rp   rx   r0   r0   r1   rq     s    z$ConfigValueStore.set_config_provider)N)rW   rX   rY   rm   rF   rv   ry   rz   r{   r}   rq   r0   r0   r0   r1   rn     s   
	rn   c                   @   sT   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd ZdS )SmartDefaultsConfigStoreFactoryc                 C   s   || _ || _d | _d S rT   )_default_config_resolver_imds_region_provider_instance_metadata_region)rE   Zdefault_config_resolverZimds_region_providerr0   r0   r1   rF     s    z(SmartDefaultsConfigStoreFactory.__init__c                 C   sT   |dkr|  |}| j|}|D ],}|| }t| d| d }|r"||| q"d S )Nr   Z_set_)resolve_auto_moder   rV   getattr)rE   config_storerN   region_nameZdefault_configsrO   Zconfig_valuemethodr0   r0   r1   merge_smart_defaults  s    

z4SmartDefaultsConfigStoreFactory.merge_smart_defaultsc                 C   s~   d }t jdr*t jd}t jd|}|sf| jr<| j}n*z| j }|| _W n tk
rd   Y nX |rz||krvdS dS dS )NZAWS_EXECUTION_ENVr   Z
AWS_REGIONz	in-regionzcross-regionstandard)r[   r\   rK   r   r   rw   	Exception)rE   r   Zcurrent_regionZdefault_regionr0   r0   r1   r   
  s"    

z1SmartDefaultsConfigStoreFactory.resolve_auto_modec                 C   sR   | |}t|}t|tr*|| d S t|trBt||gd}||| d S N)r`   )rz   re   ri   rf   set_default_providerBaseProviderrq   )rE   r   variabler_   rr   default_providerr0   r0   r1   _update_provider   s    



z0SmartDefaultsConfigStoreFactory._update_providerc                 C   s   | |}||t| d S rT   )rz   r   re   )rE   r   section_namer   r_   Zsection_providerr0   r0   r1   _update_section_provider,  s
    
 z8SmartDefaultsConfigStoreFactory._update_section_providerc                 C   s   |  |d| d S )Nr   r   rE   r   r_   r0   r0   r1   _set_retryMode4  s    z.SmartDefaultsConfigStoreFactory._set_retryModec                 C   s   |  |d| d S )Nr   r   r   r0   r0   r1   _set_stsRegionalEndpoints7  s    z9SmartDefaultsConfigStoreFactory._set_stsRegionalEndpointsc                 C   s   |  |dd| d S )Nr   r#   )r   r   r0   r0   r1   _set_s3UsEast1RegionalEndpoints:  s       z?SmartDefaultsConfigStoreFactory._set_s3UsEast1RegionalEndpointsc                 C   s   |  |d|d  d S )Nconnect_timeouti  r   r   r0   r0   r1   _set_connectTimeoutInMillis?  s    z;SmartDefaultsConfigStoreFactory._set_connectTimeoutInMillisN)rW   rX   rY   rF   r   r   r   r   r   r   r   r   r0   r0   r0   r1   r~     s   r~   c                   @   s   e Zd ZdZdd ZdS )r   zBase class for configuration value providers.

    A configuration provider has some method of providing a configuration
    value.
    c                 C   s   t ddS )zProvide a config value.rw   N)NotImplementedErrorrE   r0   r0   r1   rw   J  s    zBaseProvider.provideN)rW   rX   rY   rm   rw   r0   r0   r0   r1   r   C  s   r   c                   @   sB   e Zd ZdZdddZdd Zdd Zd	d
 Zdd Zdd Z	dS )rf   zThis provider wraps one or more other providers.

    Each provider in the chain is called, the first one returning a non-None
    value is then returned.
    Nc                 C   s   |dkrg }|| _ || _dS )a  Initalize a ChainProvider.

        :type providers: list
        :param providers: The initial list of providers to check for values
            when invoked.

        :type conversion_func: None or callable
        :param conversion_func: If this value is None then it has no affect on
            the return type. Otherwise, it is treated as a function that will
            transform provided value.
        N)
_providers_conversion_func)rE   r`   r9   r0   r0   r1   rF   V  s    zChainProvider.__init__c                 C   s   t t| j|| jS rT   )rf   rJ   rs   r   r   rt   r0   r0   r1   rv   g  s     zChainProvider.__deepcopy__c                 C   s.   | j D ]"}| }|dk	r| |  S qdS )a*  Provide the value from the first provider to return non-None.

        Each provider in the chain has its provide method called. The first
        one in the chain to return a non-None value is the returned from the
        ChainProvider. When no non-None value is found, None is returned.
        N)r   rw   _convert_type)rE   rr   r_   r0   r0   r1   rw   l  s
    
zChainProvider.providec                 C   sX   | j r"t| j d tr"|| j d< n| j | tdd | j D }|dkrTtd d S )Nc                 s   s   | ]}t |tV  qd S rT   )ri   re   ).0rr   r0   r0   r1   	<genexpr>  s   z5ChainProvider.set_default_provider.<locals>.<genexpr>r	   zLChainProvider object contains multiple instances of ConstantProvider objects)r   ri   re   ra   sumloggerinfo)rE   r   Znum_of_constantsr0   r0   r1   r   y  s     z"ChainProvider.set_default_providerc                 C   s   | j d k	r|  |S |S rT   )r   rE   r_   r0   r0   r1   r     s    

zChainProvider._convert_typec                 C   s   dd dd | jD  S )Nz[%s]z, c                 S   s   g | ]}t |qS r0   )str)r   pr0   r0   r1   
<listcomp>  s     z*ChainProvider.__repr__.<locals>.<listcomp>)joinr   r   r0   r0   r1   __repr__  s    zChainProvider.__repr__)NN)
rW   rX   rY   rm   rF   rv   rw   r   r   r   r0   r0   r0   r1   rf   O  s   
rf   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )rb   z>This class loads config values from the session instance vars.c                 C   s   || _ || _dS )a>  Initialize InstanceVarProvider.

        :type instance_var: str
        :param instance_var: The instance variable to load from the session.

        :type session: :class:`botocore.session.Session`
        :param session: The botocore session to get the loaded configuration
            file variables from.
        N)_instance_varrZ   )rE   r^   r(   r0   r0   r1   rF     s    
zInstanceVarProvider.__init__c                 C   s   t t| j|| jS rT   )rb   rJ   rs   r   rZ   rt   r0   r0   r1   rv     s     z InstanceVarProvider.__deepcopy__c                 C   s   | j  }|| j}|S )z6Provide a config value from the session instance vars.)rZ   Zinstance_variablesrK   r   )rE   Zinstance_varsr_   r0   r0   r1   rw     s    
zInstanceVarProvider.providec                 C   s   d | j| jS )Nz0InstanceVarProvider(instance_var={}, session={}))formatr   rZ   r   r0   r0   r1   r     s    zInstanceVarProvider.__repr__NrW   rX   rY   rm   rF   rv   rw   r   r0   r0   r0   r1   rb     s
   rb   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
rl   c                 C   s   || _ || _dS )a2  Initialize ScopedConfigProvider.

        :type config_var_name: str or tuple
        :param config_var_name: The name of the config variable to load from
            the configuration file. If the value is a tuple, it must only
            consist of two items, where the first item represents the section
            and the second item represents the config var name in the section.

        :type session: :class:`botocore.session.Session`
        :param session: The botocore session to get the loaded configuration
            file variables from.
        N)_config_var_namerZ   )rE   rk   r(   r0   r0   r1   rF     s    zScopedConfigProvider.__init__c                 C   s   t t| j|| jS rT   )rl   rJ   rs   r   rZ   rt   r0   r0   r1   rv     s     z!ScopedConfigProvider.__deepcopy__c                 C   sP   | j  }t| jtrD|| jd }t|ts4dS || jd S || jS )z,Provide a value from a config file property.r   Nr	   )rZ   Zget_scoped_configri   r   tuplerK   dict)rE   Zscoped_configsection_configr0   r0   r1   rw     s    

zScopedConfigProvider.providec                 C   s   d | j| jS )Nz4ScopedConfigProvider(config_var_name={}, session={}))r   r   rZ   r   r0   r0   r1   r     s    zScopedConfigProvider.__repr__N)rW   rX   rY   rF   rv   rw   r   r0   r0   r0   r1   rl     s   
rl   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )rj   z:This class loads config values from environment variables.c                 C   s   || _ || _dS )a  Initialize with the keys in the dictionary to check.

        :type name: str
        :param name: The key with that name will be loaded and returned.

        :type env: dict
        :param env: Environment variables dictionary to get variables from.
        N_name_env)rE   rg   rh   r0   r0   r1   rF     s    	zEnvironmentProvider.__init__c                 C   s   t t| j|t| j|S rT   )rj   rJ   rs   r   r   rt   r0   r0   r1   rv     s     z EnvironmentProvider.__deepcopy__c                 C   s   | j | jkr| j| j  S dS )z0Provide a config value from a source dictionary.Nr   r   r0   r0   r1   rw     s    zEnvironmentProvider.providec                 C   s   d| j  d| j dS )NzEnvironmentProvider(name=z, env=)r   r   r0   r0   r1   r     s    zEnvironmentProvider.__repr__Nr   r0   r0   r0   r1   rj     s
   rj   c                   @   s:   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdS )r,   zProvides a dictionary from a section in the scoped config

    This is useful for retrieving scoped config variables (i.e. s3) that have
    their own set of config variables and resolving logic.
    Nc                 C   s6   || _ || _t| j | j| _|| _| jd kr2i | _d S rT   )_section_namerZ   rl   _scoped_config_provider_override_providers)rE   r   r(   Zoverride_providersr0   r0   r1   rF     s     
zSectionConfigProvider.__init__c                 C   s"   t t| j|| jt| j|S rT   )r,   rJ   rs   r   rZ   r   rt   r0   r0   r1   rv     s
    z"SectionConfigProvider.__deepcopy__c                 C   sh   | j  }|r,t|ts,td| j| d S | j D ],\}}| }|d k	r6|d krZi }|||< q6|S )NzEThe %s config key is not a dictionary type, ignoring its value of: %s)	r   rw   ri   r   r   debugr   r   r:   )rE   r   Zsection_config_varrr   Zprovider_valr0   r0   r1   rw     s    

zSectionConfigProvider.providec                 C   sJ   | j |}t|tr$|| d S t|tr<t||gd}|| j |< d S r   )r   rK   ri   rf   r   r   )rE   keyr   rr   r0   r0   r1   r   %  s    


z*SectionConfigProvider.set_default_providerc                 C   s   d| j  d| j d| j dS )Nz#SectionConfigProvider(section_name=z
, session=z, override_providers=r   )r   rZ   r   r   r0   r0   r1   r   0  s    zSectionConfigProvider.__repr__)N)	rW   rX   rY   rm   rF   rv   rw   r   r   r0   r0   r0   r1   r,     s   

r,   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )re   z(This provider provides a constant value.c                 C   s
   || _ d S rT   _valuer   r0   r0   r1   rF   ;  s    zConstantProvider.__init__c                 C   s   t t| j|S rT   )re   rJ   rs   r   rt   r0   r0   r1   rv   >  s    zConstantProvider.__deepcopy__c                 C   s   | j S )z7Provide the constant value given during initialization.r   r   r0   r0   r1   rw   A  s    zConstantProvider.providec                 C   s
   d| j  S )NzConstantProvider(value=%s)r   r   r0   r0   r1   r   E  s    zConstantProvider.__repr__Nr   r0   r0   r0   r1   re   8  s
   re   )rm   rJ   loggingr[   Zbotocorer   	getLoggerrW   r   intZensure_booleanr+   r-   Znormalize_booleanr.   r2   r*   r?   r)   rn   r~   r   rf   rb   rl   rj   r,   re   r0   r0   r0   r1   <module>   s   


	

b
.$rtME"'=