Correct provider dictionary structure

This commit is contained in:
Joseph Hall 2014-11-20 11:31:11 -07:00
parent 499566879c
commit 937343615f

View File

@ -53,7 +53,7 @@ def sig2(method, endpoint, params, provider, aws_api_version):
timestamp = timenow.strftime('%Y-%m-%dT%H:%M:%SZ')
params_with_headers = params.copy()
params_with_headers['AWSAccessKeyId'] = provider.get('id', None)
params_with_headers['AWSAccessKeyId'] = provider.get('id', '')
params_with_headers['SignatureVersion'] = '2'
params_with_headers['SignatureMethod'] = 'HmacSHA256'
params_with_headers['Timestamp'] = '{0}'.format(timestamp)
@ -74,7 +74,7 @@ def sig2(method, endpoint, params, provider, aws_api_version):
return params_with_headers
def sig4(method, endpoint, params, provider, aws_api_version, location,
def sig4(method, endpoint, params, prov_dict, aws_api_version, location,
product='ec2', uri='/', requesturl=None):
'''
Sign a query against AWS services using Signature Version 4 Signing
@ -137,7 +137,7 @@ def sig4(method, endpoint, params, provider, aws_api_version, location,
# Create the signing key using the function defined above.
signing_key = _sig_key(
provider.get('key', None),
prov_dict.get('key', ''),
datestamp,
location,
product
@ -154,7 +154,7 @@ def sig4(method, endpoint, params, provider, aws_api_version, location,
'{0} Credential={1}/{2}, SignedHeaders={3}, Signature={4}'
).format(
algorithm,
provider.get('id', None),
prov_dict.get('id', None),
credential_scope,
signed_headers,
signature,
@ -219,35 +219,35 @@ def query(params=None, setname=None, requesturl=None, location=None,
- importexport (Import/Export)
- monitoring (CloudWatch)
- rds (Relational Database Service)
- sdb (SimpleDB)
- simpledb (SimpleDB)
- sns (Simple Notification Service)
- sqs (Simple Queue Service)
'''
if params is None:
params = {}
if opts is None:
opts = {}
if provider is None:
function = opts.get('function', (None, None))
providers = opts.get('providers', {})
prov_dict = providers.get(function[1], None)
if prov_dict is not None and len(prov_dict.keys()) > 0:
driver = list(list(prov_dict.keys()))[0]
provider = prov_dict[driver]
else:
provider = {}
function = opts.get('function', (None, product))
providers = opts.get('providers', {})
service_url = provider.get('service_url', 'amazonaws.com')
if provider is None:
prov_dict = providers.get(function[1], {}).get(product, {})
if prov_dict:
driver = list(list(prov_dict.keys()))[0]
provider = providers.get(driver, product)
else:
prov_dict = providers.get(provider, {}).get(product, {})
service_url = prov_dict.get('service_url', 'amazonaws.com')
if not location:
location = get_location(opts, provider)
if endpoint is None:
if not requesturl:
endpoint = provider.get(
endpoint = prov_dict.get(
'endpoint',
'{0}.{1}.{2}'.format(product, location, service_url)
)
@ -269,8 +269,8 @@ def query(params=None, setname=None, requesturl=None, location=None,
LOG.debug('Using AWS endpoint: {0}'.format(endpoint))
method = 'GET'
aws_api_version = provider.get(
'aws_api_version', provider.get(
aws_api_version = prov_dict.get(
'aws_api_version', prov_dict.get(
'{0}_api_version'.format(product),
DEFAULT_AWS_API_VERSION
)
@ -278,12 +278,12 @@ def query(params=None, setname=None, requesturl=None, location=None,
if sigver == '4':
headers, requesturl = sig4(
method, endpoint, params, provider, aws_api_version, location, product, requesturl=requesturl
method, endpoint, params, prov_dict, aws_api_version, location, product, requesturl=requesturl
)
params_with_headers = {}
else:
params_with_headers = sig2(
method, endpoint, params, provider, aws_api_version
method, endpoint, params, prov_dict, aws_api_version
)
headers = {}