U m^R@s~dZddlZddlZddlmZeeZdddgddfdddd d didfd d d defdddefddddej fddddefddddej fddZ ddddej fd ddej fd!ddej fd"d#gd$dej fd%d&gd'ddfd(Z d)d*Z d+d,Z Gd-d.d.eZGd/d0d0eZGd1d2d2eZGd3d4d4eZGd5d6d6eZGd7d8d8eZGd9d:d:eZGd;d<dd>eZdS)?zOThis module contains the inteface for controlling how configuration is loaded. N)utilsZAWS_DEFAULT_PROFILEZ AWS_PROFILE)regionZAWS_DEFAULT_REGIONNN) data_pathZ AWS_DATA_PATHNN)NZAWS_CONFIG_FILEz ~/.aws/configN) ca_bundleZ AWS_CA_BUNDLENN api_versions)NZAWS_SHARED_CREDENTIALS_FILEz~/.aws/credentialsNmetadata_service_timeoutZAWS_METADATA_SERVICE_TIMEOUTmetadata_service_num_attemptsZ!AWS_METADATA_SERVICE_NUM_ATTEMPTS)parameter_validationNTN csm_enabledZAWS_CSM_ENABLEDF)csm_hostZ AWS_CSM_HOSTz 127.0.0.1Ncsm_portZ AWS_CSM_PORTiy) csm_client_idZAWS_CSM_CLIENT_IDNendpoint_discovery_enabledZAWS_ENDPOINT_DISCOVERY_ENABLED)sts_regional_endpointsZAWS_STS_REGIONAL_ENDPOINTSlegacyN)Zprofilerr config_filerrZcredentials_filerr r r r r rrr))s3addressing_styleNNN)ruse_accelerate_endpoint)ruse_dualstack_endpoint)rpayload_signing_enabledZs3_use_arn_region)ruse_arn_regionZAWS_S3_USE_ARN_REGIONZs3_us_east_1_regional_endpoint)rus_east_1_regional_endpointZ"AWS_S3_US_EAST_1_REGIONAL_ENDPOINT)rrrrrrcCs.t|d}t|t}td|t|t|d<|S)N)sessionr)ConfigChainFactory_create_config_chain_mapping!BOTOCORE_DEFAUT_SESSION_VARIABLESSectionConfigProviderDEFAULT_S3_CONFIG_VARS)r chain_builderZconfig_mappingr"q/private/var/folders/sd/whlwsn6x1_qgglc0mjv25_695qk2gl/T/pip-install-4zq3fp6i/botocore/botocore/configprovider.py&create_botocore_default_config_mappingys r$cCsBi}|D]0\}}|j||d|d|d|dd||<q |S)Nrr) instance_name env_var_namesconfig_property_namesdefaultconversion_func)itemscreate_config_chain)r!Zconfig_variablesmapping logical_nameconfigr"r"r#rs rc@s4eZdZdZd ddZd ddZddZd d ZdS) raFactory 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. NcCs||_|dkrtj}||_dS)aInitialize 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)_sessionosenviron_environ)selfrr3r"r"r#__init__s zConfigChainFactory.__init__cCstg}|dk r |t||jd|dk r8||||dk rP||||dk rh|t|dt||dS)aBuild 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) providersr+)appendInstanceVarProviderr1extend_get_env_providers_get_scoped_config_providersConstantProvider ChainProvider)r5r'r(r)r*r+r9r"r"r#r-s((z&ConfigChainFactory.create_config_chaincCs6g}t|ts|g}|D]}|t||jdq|S)N)nameenv) isinstancelistr:EnvironmentProviderr4)r5r(Zenv_var_providersZ env_var_namer"r"r#r=s  z%ConfigChainFactory._get_env_providerscCs6g}t|ts|g}|D]}|t||jdq|S)N)config_var_namer)rCrDr:ScopedConfigProviderr1)r5r)Zscoped_config_providersZconfig_property_namer"r"r#r>s z/ConfigChainFactory._get_scoped_config_providers)N)NNNNN)__name__ __module__ __qualname____doc__r6r-r=r>r"r"r"r#rs  > rc@s:eZdZdZd ddZddZddZd d Zd d ZdS)ConfigValueStorez8The ConfigValueStore object stores configuration values.NcCs6i|_i|_|dk r2|D]\}}|||qdS)aNInitialize 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)r5r.r/providerr"r"r#r6s zConfigValueStore.__init__cCs4||jkr|j|S||jkr"dS|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)rMrNprovider5r/rPr"r"r#get_config_variables     z$ConfigValueStore.get_config_variablecCs||j|<dS)aSet 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)rM)r5r/r8r"r"r#set_config_variable$sz$ConfigValueStore.set_config_variablecCs|j|ddS)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)rMpop)r5r/r"r"r#clear_config_variable>sz&ConfigValueStore.clear_config_variablecCs||j|<dS)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)rNrRr"r"r#rOGsz$ConfigValueStore.set_config_provider)N) rHrIrJrKr6rSrTrVrOr"r"r"r#rLs   rLc@seZdZdZddZdS) BaseProviderzBase class for configuration value providers. A configuration provider has some method of providing a configuration value. cCs tddS)zProvide a config value.rQN)NotImplementedErrorr5r"r"r#rQ_szBaseProvider.provideN)rHrIrJrKrQr"r"r"r#rWYsrWc@s2eZdZdZd ddZddZddZd d ZdS) r@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. NcCs|dkr g}||_||_dS)aInitalize 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)r5r9r+r"r"r#r6js zChainProvider.__init__cCs.|jD]"}|}|dk r||SqdS)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)rZrQ _convert_type)r5rPr8r"r"r#rQ{s  zChainProvider.providecCs|jdk r||S|SN)r[r5r8r"r"r#r\s  zChainProvider._convert_typecCsdddd|jDS)Nz[%s]z, cSsg|] }t|qSr")str).0pr"r"r# sz*ChainProvider.__repr__..)joinrZrYr"r"r#__repr__szChainProvider.__repr__)NN)rHrIrJrKr6rQr\rdr"r"r"r#r@ds   r@c@s(eZdZdZddZddZddZdS) r;z>This class loads config values from the session instance vars.cCs||_||_dS)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_varr1)r5r7rr"r"r#r6s zInstanceVarProvider.__init__cCs|j}||j}|S)z6Provide a config value from the session instance vars.)r1Zinstance_variablesgetrf)r5Z instance_varsr8r"r"r#rQs  zInstanceVarProvider.providecCsd|j|jfS)Nz0InstanceVarProvider(instance_var=%s, session=%s)rerYr"r"r#rdszInstanceVarProvider.__repr__NrHrIrJrKr6rQrdr"r"r"r#r;s r;c@s$eZdZddZddZddZdS)rGcCs||_||_dS)a2Initialize 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_namer1)r5rFrr"r"r#r6s zScopedConfigProvider.__init__cCsP|j}t|jtrD||jd}t|ts4dS||jdS||jS)z,Provide a value from a config file property.rNr)r1Zget_scoped_configrCrjtuplergdict)r5Z scoped_configsection_configr"r"r#rQs   zScopedConfigProvider.providecCsd|j|jfS)Nz4ScopedConfigProvider(config_var_name=%s, session=%s)rirYr"r"r#rdszScopedConfigProvider.__repr__N)rHrIrJr6rQrdr"r"r"r#rGs rGc@s(eZdZdZddZddZddZdS) rEz:This class loads config values from environment variables.cCs||_||_dS)aInitialize 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_nameZ_env)r5rArBr"r"r#r6s zEnvironmentProvider.__init__cCs|j|jkr|j|jSdS)z0Provide a config value from a source dictionary.NrnrYr"r"r#rQs  zEnvironmentProvider.providecCsd|j|jfS)Nz$EnvironmentProvider(name=%s, env=%s)rnrYr"r"r#rdszEnvironmentProvider.__repr__Nrhr"r"r"r#rEs rEc@s*eZdZdZd ddZddZddZdS) rzProvides 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. NcCs6||_||_t|j|j|_||_|jdkr2i|_dSr]) _section_namer1rG_scoped_config_provider_override_providers)r5 section_namerZoverride_providersr"r"r#r6s zSectionConfigProvider.__init__cCsh|j}|r,t|ts,td|j|dS|jD],\}}|}|dk r6|dkrZi}|||<q6|S)NzEThe %s config key is not a dictionary type, ignoring its value of: %s) rqrQrCrlloggerdebugrprrr,)r5rmZsection_config_varrPZ provider_valr"r"r#rQs  zSectionConfigProvider.providecCsd|j|j|jfS)NzISectionConfigProvider(section_name=%s, session=%s, override_providers=%s))rpr1rrrYr"r"r#rdszSectionConfigProvider.__repr__)Nrhr"r"r"r#rs rc@s(eZdZdZddZddZddZdS) r?z(This provider provides a constant value.cCs ||_dSr]_valuer^r"r"r#r6szConstantProvider.__init__cCs|jS)z7Provide the constant value given during initialization.rvrYr"r"r#rQszConstantProvider.providecCs d|jS)NzConstantProvider(value=%s)rvrYr"r"r#rdszConstantProvider.__repr__Nrhr"r"r"r#r?sr?)rKloggingr2Zbotocorer getLoggerrHrtintZensure_booleanrr r$robjectrrLrWr@r;rGrErr?r"r"r"r# s    0  m[ -"(