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 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)
def setup_client(self): with open(self.example_model_file, 'w') as f: json.dump(self.example_json_model, f) with open(self.waiter_model_file, 'w') as f: json.dump(self.waiter_json_model, f) with open(self.paginator_model_file, 'w') as f: json.dump(self.paginator_json_model, f) with open(self.model_file, 'w') as f: json.dump(self.json_model, f) self.loader = Loader(extra_search_paths=[self.root_dir]) endpoint_resolver = mock.Mock() endpoint_resolver.construct_endpoint.return_value = { 'hostname': 'foo.us-east-1', 'partition': 'aws', 'endpointName': 'us-east-1', 'signatureVersions': ['v4'] } self.creator = ClientCreator(loader=self.loader, endpoint_resolver=endpoint_resolver, user_agent='user-agent', event_emitter=self.events, retry_handler_factory=mock.Mock(), retry_config_translator=mock.Mock(), exceptions_factory=mock.Mock(), config_store=ConfigValueStore()) self.client = self.creator.create_client('myservice', 'us-east-1')
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')
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')
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 = 'ec2' 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)]
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')
def _create_config_value_store(self, s3_mapping={}, **override_kwargs): provider_foo = ConstantProvider(value='foo') environment_provider_foo = EnvironmentProvider( name='AWS_RETRY_MODE', env={'AWS_RETRY_MODE': None}) fake_session = mock.Mock(spec=session.Session) fake_session.get_scoped_config.return_value = {} # Testing with three different providers to validate # SmartDefaultsConfigStoreFactory._get_new_chain_provider mapping = { 'sts_regional_endpoints': ChainProvider(providers=[provider_foo]), 'retry_mode': ChainProvider(providers=[environment_provider_foo]), 's3': SectionConfigProvider('s3', fake_session, s3_mapping) } mapping.update(**override_kwargs) config_store = ConfigValueStore(mapping=mapping) return config_store
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')
def test_does_provide_none_if_no_variable_exists(self): provider = ConfigValueStore() value = provider.get_config_variable('fake_variable') self.assertIsNone(value)
def _register_config_store(self): chain_builder = ConfigChainFactory(session=self) config_store = ConfigValueStore( mapping=create_botocore_default_config_mapping(chain_builder)) return config_store
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)