示例#1
0
 def _get_config_variable_with_custom_methods(self, logical_name, methods):
     # If a custom list of methods was supplied we need to perserve the
     # behavior with the new system. To do so a new chain that is a copy of
     # the old one will be constructed, but only with the supplied methods
     # being added to the chain. This chain will be consulted for a value
     # and then thrown out. This is not efficient, nor is the methods arg
     # used in ibm_botocore, this is just for backwards compatibility.
     chain_builder = SubsetChainConfigFactory(session=self, methods=methods)
     mapping = create_botocore_default_config_mapping(self)
     for name, config_options in self.session_var_map.items():
         config_name, env_vars, default, typecast = config_options
         build_chain_config_args = {
             'conversion_func': typecast,
             'default': default,
         }
         if 'instance' in methods:
             build_chain_config_args['instance_name'] = name
         if 'env' in methods:
             build_chain_config_args['env_var_names'] = env_vars
         if 'config' in methods:
             build_chain_config_args['config_property_name'] = config_name
         mapping[name] = chain_builder.create_config_chain(
             **build_chain_config_args)
     config_store_component = ConfigValueStore(mapping=mapping)
     value = config_store_component.get_config_variable(logical_name)
     return value
 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)
示例#3
0
 def test_does_provide_value_if_variable_exists(self):
     mock_value_provider = mock.Mock(spec=BaseProvider)
     mock_value_provider.provide.return_value = 'foo'
     provider = ConfigValueStore(mapping={
         'fake_variable': mock_value_provider,
     })
     value = provider.get_config_variable('fake_variable')
     self.assertEqual(value, 'foo')
示例#4
0
 def test_can_get_config_provider_non_chain_provider(self):
     constant_provider = ConstantProvider(value='bar')
     config_value_store = ConfigValueStore(
         mapping={
             'fake_variable': constant_provider,
         })
     provider = config_value_store.get_config_provider('fake_variable')
     value = config_value_store.get_config_variable('fake_variable')
     self.assertIsInstance(provider, ConstantProvider)
     self.assertEqual(value, 'bar')
示例#5
0
 def setUp(self):
     self.event_emitter = mock.Mock(HierarchicalEmitter)
     self.config_store = ConfigValueStore()
     self.args_create = args.ClientArgsCreator(self.event_emitter, None,
                                               None, None, None,
                                               self.config_store)
     self.service_name = 's3'
     self.region = 'us-west-2'
     self.endpoint_url = 'https://ec2/'
     self.service_model = self._get_service_model()
     self.bridge = mock.Mock(ClientEndpointBridge)
     self._set_endpoint_bridge_resolve()
     self.default_socket_options = [(socket.IPPROTO_TCP, socket.TCP_NODELAY,
                                     1)]
示例#6
0
    def test_can_set_config_provider(self):
        foo_value_provider = mock.Mock(spec=BaseProvider)
        foo_value_provider.provide.return_value = 'foo'
        provider = ConfigValueStore(mapping={
            'fake_variable': foo_value_provider,
        })

        value = provider.get_config_variable('fake_variable')
        self.assertEqual(value, 'foo')

        bar_value_provider = mock.Mock(spec=BaseProvider)
        bar_value_provider.provide.return_value = 'bar'
        provider.set_config_provider('fake_variable', bar_value_provider)

        value = provider.get_config_variable('fake_variable')
        self.assertEqual(value, 'bar')
示例#7
0
 def test_can_set_variable(self):
     provider = ConfigValueStore()
     provider.set_config_variable('fake_variable', 'foo')
     value = provider.get_config_variable('fake_variable')
     self.assertEquals(value, 'foo')
示例#8
0
 def test_does_provide_none_if_no_variable_exists(self):
     provider = ConfigValueStore()
     value = provider.get_config_variable('fake_variable')
     self.assertIsNone(value)
示例#9
0
 def _register_config_store(self):
     config_store_component = ConfigValueStore(
         mapping=create_botocore_default_config_mapping(self))
     self._components.register_component('config_store',
                                         config_store_component)