B \HB@sdZddlZddlmZdddgddfdddd d didfd d d defdddefddddejfdddefddddejfdZddZGdddeZ Gd d!d!eZ Gd"d#d#eZ Gd$d%d%e Z Gd&d'd'e Z Gd(d)d)e ZGd*d+d+e ZGd,d-d-e ZdS).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_ENABLEDFcsm_portZ AWS_CSM_PORTiy) csm_client_idZAWS_CSM_CLIENT_IDNendpoint_discovery_enabledZAWS_ENDPOINT_DISCOVERY_ENABLED)Zprofilerr config_filerrZcredentials_filerr r r r r rcCsFi}x config_property_name -> default. Any values that were none are omitted form the chain. N) instance_varr')namesenv)config_var_namer')value) providersr)appendInstanceVarProviderr"EnvironmentProviderr%ScopedConfigProviderConstantProvider ChainProvider)r&rrrrrr.rrrrxs*'   z&ConfigChainFactory.create_config_chain)N)NNNNN)__name__ __module__ __qualname____doc__r(rrrrrr!as  r!c@s:eZdZdZd ddZddZddZd d Zd d ZdS)ConfigValueStorez8The ConfigValueStore object stores configuration values.NcCs:i|_i|_|dk r6x |D]\}}|||qWdS)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_mappingrset_config_provider)r&rrproviderrrrr(s 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)r:r;provide)r&rr=rrrget_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)r:)r&rr-rrrset_config_variablesz$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)r:pop)r&rrrrclear_config_variablesz&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)r;)r&rr=rrrr<sz$ConfigValueStore.set_config_provider)N) r5r6r7r8r(r?r@rBr<rrrrr9s   r9c@seZdZdZddZdS) BaseProviderzBase class for configuration value providers. A configuration provider has some method of providing a configuration value. cCs tddS)zProvide a config value.r>N)NotImplementedError)r&rrrr>szBaseProvider.provideN)r5r6r7r8r>rrrrrCsrCc@s2eZdZdZd ddZddZddZd d ZdS) r4zThis 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)r&r.rrrrr(*s zChainProvider.__init__cCs.x(|jD]}|}|dk r||SqWdS)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)rEr> _convert_type)r&r=r-rrrr>;s  zChainProvider.providecCs|jdk r||S|S)N)rF)r&r-rrrrGHs  zChainProvider._convert_typecCsdddd|jDS)Nz[%s]z, cSsg|] }t|qSr)str).0prrr Nsz*ChainProvider.__repr__..)joinrE)r&rrr__repr__MszChainProvider.__repr__)NN)r5r6r7r8r(r>rGrMrrrrr4$s   r4c@s(eZdZdZddZddZddZdS) r0z>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_varr")r&r)r'rrrr(Ss zInstanceVarProvider.__init__cCs|j}||j}|S)z6Provide a config value from the session instance vars.)r"Zinstance_variablesgetrN)r&Z instance_varsr-rrrr>`s  zInstanceVarProvider.providecCsd|j|jfS)Nz0InstanceVarProvider(instance_var=%s, session=%s))rNr")r&rrrrMfszInstanceVarProvider.__repr__N)r5r6r7r8r(r>rMrrrrr0Qs r0c@s$eZdZddZddZddZdS)r2cCs||_||_dS)afInitialize ScopedConfigProvider. :type config_var_name: str :param config_var_name: The name of the config variable to load from the configuration file. :type session: :class:`botocore.session.Session` :param session: The botocore session to get the loaded configuration file variables from. N)_config_var_namer")r&r,r'rrrr(ns zScopedConfigProvider.__init__cCs|j}||j}|S)z,Provide a value from a config file property.)r"Zget_scoped_configrOrP)r&rr-rrrr>|s  zScopedConfigProvider.providecCsd|j|jfS)Nz4ScopedConfigProvider(config_var_name=%s, session=%s))rPr")r&rrrrMszScopedConfigProvider.__repr__N)r5r6r7r(r>rMrrrrr2msr2c@s(eZdZdZddZddZddZdS) r1z:This class loads config values from environment variables.cCs||_||_dS)aInitialize with the keys in the dictionary to check. :type names: str or list :param names: If this is a str, the key with that name will be loaded and returned. If this variable is a list, then it must be a list of str. The same process will be repeated for each string in the list, the first that returns non None will be returned. :type env: dict :param env: Environment variables dictionary to get variables from. N)_names_env)r&r*r+rrrr(s zEnvironmentProvider.__init__cCs<|j}t|ts|g}x |D]}||jkr|j|SqWdS)z0Provide a config value from a source dictionary.N)rQ isinstancelistrR)r&r*namerrrr>s   zEnvironmentProvider.providecCsd|j|jfS)Nz%EnvironmentProvider(names=%s, env=%s))rQrR)r&rrrrMszEnvironmentProvider.__repr__N)r5r6r7r8r(r>rMrrrrr1s r1c@s(eZdZdZddZddZddZdS) r3z(This provider provides a constant value.cCs ||_dS)N)_value)r&r-rrrr(szConstantProvider.__init__cCs|jS)z7Provide the constant value given during initialization.)rV)r&rrrr>szConstantProvider.providecCs d|jS)NzConstantProvider(value=%s))rV)r&rrrrMszConstantProvider.__repr__N)r5r6r7r8r(r>rMrrrrr3sr3)r8r#ZbotocorerintZensure_booleanrr objectr!r9rCr4r0r2r1r3rrrrs8     ][ -!