From: Steve Baker Date: Fri, 12 Apr 2013 22:46:35 +0000 (+1000) Subject: Optionally allow ec2token config to come from .conf X-Git-Tag: 2014.1~698^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=a4d2b3edbd926c9dbe15c8443954f5b85cc52d9a;p=openstack-build%2Fheat-build.git Optionally allow ec2token config to come from .conf Just like keystoneclient.middleware.auth_token first checks paste.ini file then .conf file when fetching a config value Change-Id: I9db9744d0ab12fcf486de9a9d3f8e870a4ff66de --- diff --git a/heat/api/aws/ec2token.py b/heat/api/aws/ec2token.py index 83b06b17..173ea788 100644 --- a/heat/api/aws/ec2token.py +++ b/heat/api/aws/ec2token.py @@ -21,6 +21,7 @@ gettext.install('heat', unicode=1) from heat.common import wsgi from heat.openstack.common import jsonutils as json +from oslo.config import cfg import webob from heat.api.aws import exception @@ -30,6 +31,13 @@ from heat.openstack.common import log as logging logger = logging.getLogger(__name__) +opts = [ + cfg.StrOpt('auth_uri', default=None), + cfg.StrOpt('keystone_ec2_uri', default=None) +] +cfg.CONF.register_opts(opts, group='ec2token') + + class EC2Token(wsgi.Middleware): """Authenticate an EC2 request with keystone and convert to token.""" @@ -37,6 +45,13 @@ class EC2Token(wsgi.Middleware): self.conf = conf self.application = app + def _conf_get(self, name): + # try config from paste-deploy first + if name in self.conf: + return self.conf[name] + else: + return cfg.CONF.ec2token[name] + @webob.dec.wsgify(RequestClass=wsgi.Request) def __call__(self, req): # Read request signature and access id. @@ -88,8 +103,9 @@ class EC2Token(wsgi.Middleware): # for httplib and urlparse # pylint: disable-msg=E1101 - logger.info('Authenticating with %s' % self.conf['keystone_ec2_uri']) - o = urlparse.urlparse(self.conf['keystone_ec2_uri']) + keystone_ec2_uri = self._conf_get('keystone_ec2_uri') + logger.info('Authenticating with %s' % keystone_ec2_uri) + o = urlparse.urlparse(keystone_ec2_uri) if o.scheme == 'http': conn = httplib.HTTPConnection(o.netloc) else: @@ -127,8 +143,8 @@ class EC2Token(wsgi.Middleware): 'signature': signature}} req.headers['X-Auth-EC2-Creds'] = json.dumps(ec2_creds) req.headers['X-Auth-Token'] = token_id - req.headers['X-Auth-URL'] = self.conf['auth_uri'] - req.headers['X-Auth-EC2_URL'] = self.conf['keystone_ec2_uri'] + req.headers['X-Auth-URL'] = self._conf_get('auth_uri') + req.headers['X-Auth-EC2_URL'] = keystone_ec2_uri return self.application