def test_with_idbroker_and_config(self): try: finish = conf.AWS_ACCOUNTS.set_for_testing( {'default': { 'region': 'ap-northeast-1' }}) with patch('aws.client.conf_idbroker.get_conf') as get_conf: with patch('aws.client.Client.get_s3_connection'): with patch('aws.client.IDBroker.get_cab') as get_cab: get_conf.return_value = { 'fs.s3a.ext.cab.address': 'address' } get_cab.return_value = { 'Credentials': { 'AccessKeyId': 'AccessKeyId', 'Expiration': 0 } } provider = get_credential_provider('default', 'hue') assert_equal( provider.get_credentials().get('AccessKeyId'), 'AccessKeyId') client = Client.from_config( conf.AWS_ACCOUNTS['default'], get_credential_provider('default', 'hue')) assert_equal(client._region, 'ap-northeast-1') finally: finish() clear_cache() conf.clear_cache()
def test_with_idbroker_on_ec2(self): try: finish = conf.AWS_ACCOUNTS.set_for_testing( {}) # Set empty to test when no configs are set with patch('aws.client.aws_conf.get_region') as get_region: with patch('aws.client.conf_idbroker.get_conf') as get_conf: with patch('aws.client.Client.get_s3_connection'): with patch('aws.client.IDBroker.get_cab') as get_cab: get_region.return_value = 'us-west-1' get_conf.return_value = { 'fs.s3a.ext.cab.address': 'address' } get_cab.return_value = { 'Credentials': { 'AccessKeyId': 'AccessKeyId', 'Expiration': 0 } } client = Client.from_config( None, get_credential_provider('default', 'hue')) assert_equal( client._region, 'us-west-1' ) # Test different user have different clients finally: finish() clear_cache() conf.clear_cache()
def _make_client(identifier): client_conf = conf.AWS_ACCOUNTS[identifier] return Client.from_config(client_conf)