def update_session_config_mapping(self, logical_name, **kwargs):
     config_chain_builder = ConfigChainFactory(
         session=self.session,
         environ=self.environ,
     )
     self.session.get_component('config_store').set_config_provider(
         logical_name,
         config_chain_builder.create_config_chain(**kwargs),
     )
예제 #2
0
 def assert_chain_does_provide(self, instance_map, environ_map,
                               scoped_config_map, create_config_chain_args,
                               expected_value):
     fake_session = mock.Mock(spec=session.Session)
     fake_session.get_scoped_config.return_value = scoped_config_map
     fake_session.instance_variables.return_value = instance_map
     builder = ConfigChainFactory(fake_session, environ=environ_map)
     chain = builder.create_config_chain(**create_config_chain_args)
     value = chain.provide()
     self.assertEqual(value, expected_value)
 def setUp(self):
     self.environ = {}
     self.environ_patch = mock.patch('os.environ', self.environ)
     self.environ_patch.start()
     self.environ['FOO_PROFILE'] = 'foo'
     self.environ['FOO_REGION'] = 'us-west-11'
     data_path = os.path.join(os.path.dirname(__file__), 'data')
     self.environ['FOO_DATA_PATH'] = data_path
     config_path = os.path.join(os.path.dirname(__file__), 'cfg',
                                'foo_config')
     self.environ['FOO_CONFIG_FILE'] = config_path
     self.session = create_session()
     config_chain_builder = ConfigChainFactory(
         session=self.session,
         environ=self.environ,
     )
     config_store = self.session.get_component('config_store')
     config_updates = {
         'profile':
         config_chain_builder.create_config_chain(
             instance_name='profile',
             env_var_names='FOO_PROFILE',
         ),
         'region':
         config_chain_builder.create_config_chain(
             instance_name='region',
             env_var_names='FOO_REGION',
             config_property_names='foo_region',
         ),
         'data_path':
         config_chain_builder.create_config_chain(
             instance_name='data_path',
             env_var_names='FOO_DATA_PATH',
             config_property_names='data_path',
         ),
         'config_file':
         config_chain_builder.create_config_chain(
             instance_name='config_file',
             env_var_names='FOO_CONFIG_FILE',
         ),
         'credentials_file':
         config_chain_builder.create_config_chain(
             instance_name='credentials_file',
             default='/tmp/nowhere',
         ),
         'ca_bundle':
         config_chain_builder.create_config_chain(
             instance_name='ca_bundle',
             env_var_names='FOO_AWS_CA_BUNDLE',
             config_property_names='foo_ca_bundle',
         ),
         'api_versions':
         config_chain_builder.create_config_chain(
             instance_name='api_versions',
             config_property_names='foo_api_versions',
             default={},
         ),
     }
     for name, provider in config_updates.items():
         config_store.set_config_provider(name, provider)
예제 #4
0
 def _register_config_store(self):
     chain_builder = ConfigChainFactory(session=self)
     config_store_component = ConfigValueStore(
         mapping=create_botocore_default_config_mapping(chain_builder)
     )
     self._components.register_component('config_store',
                                         config_store_component)
예제 #5
0
 def _update_config_store_from_session_vars(self, logical_name,
                                            config_options):
     # This is for backwards compatibility. The new preferred way to
     # modify configuration logic is to use the component system to get
     # the config_store component from the session, and then update
     # a key with a custom config provider(s).
     # This backwards compatibility method takes the old session_vars
     # list of tuples and and transforms that into a set of updates to
     # the config_store component.
     config_chain_builder = ConfigChainFactory(session=self._session)
     config_name, env_vars, default, typecast = config_options
     config_store = self._session.get_component('config_store')
     config_store.set_config_provider(
         logical_name,
         config_chain_builder.create_config_chain(
             instance_name=logical_name,
             env_var_names=env_vars,
             config_property_names=config_name,
             default=default,
             conversion_func=typecast,
         ))
예제 #6
0
class SubsetChainConfigFactory(object):
    """A class for creating backwards compatible configuration chains.

    This class can be used instead of
    :class:`ibm_botocore.configprovider.ConfigChainFactory` to make it honor the
    methods argument to get_config_variable. This class can be used to filter
    out providers that are not in the methods tuple when creating a new config
    chain.
    """
    def __init__(self, session, methods, environ=None):
        self._factory = ConfigChainFactory(session, environ)
        self._supported_methods = methods

    def create_config_chain(self,
                            instance_name=None,
                            env_var_names=None,
                            config_property_name=None,
                            default=None,
                            conversion_func=None):
        """Build a config chain following the standard ibm_botocore pattern.

        This config chain factory will omit any providers not in the methods
        tuple provided at initialization. For example if given the tuple
        ('instance', 'config',) it will not inject the environment provider
        into the standard config chain. This lets the ibm_botocore session support
        the custom ``methods`` argument for all the default ibm_botocore config
        variables when calling ``get_config_variable``.
        """
        if 'instance' not in self._supported_methods:
            instance_name = None
        if 'env' not in self._supported_methods:
            env_var_names = None
        if 'config' not in self._supported_methods:
            config_property_name = None
        return self._factory.create_config_chain(
            instance_name=instance_name,
            env_var_names=env_var_names,
            config_property_names=config_property_name,
            default=default,
            conversion_func=conversion_func,
        )
예제 #7
0
 def __init__(self, session, methods, environ=None):
     self._factory = ConfigChainFactory(session, environ)
     self._supported_methods = methods