heat engine : Make Resource::swift handle auth_token

Make Resource::swift() handle auth_token so the S3
resource will work with AWS auth

Fixes #271

Change-Id: Ie5aca026dea25045e42aab677a2c793c79de1658
Signed-off-by: Steven Hardy <shardy@redhat.com>
This commit is contained in:
Steven Hardy 2012-10-22 18:38:06 +01:00
parent 7036a387f4
commit d65ae5b313
1 changed files with 29 additions and 3 deletions

View File

@ -293,10 +293,36 @@ class Resource(object):
return self._swift
con = self.context
self._swift = swiftclient.Connection(
con.auth_url, con.username, con.password,
tenant_name=con.tenant, auth_version='2')
args = {
'auth_version': '2'
}
if con.password is not None:
args['user'] = con.username
args['key'] = con.password
args['authurl'] = con.auth_url
args['tenant_name'] = con.tenant
elif con.auth_token is not None:
args['user'] = None
args['key'] = None
args['authurl'] = None
args['preauthtoken'] = con.auth_token
# Lookup endpoint for object-store service type
service_type = 'object-store'
endpoints = self.keystone().service_catalog.get_endpoints(
service_type=service_type)
if len(endpoints[service_type]) == 1:
args['preauthurl'] = endpoints[service_type][0]['publicURL']
else:
logger.error("No endpoint found for %s service type" %
service_type)
return None
else:
logger.error("Swift connection failed, no password or " +
"auth_token!")
return None
self._swift = swiftclient.Connection(**args)
return self._swift
def calculate_properties(self):