]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Optionally allow ec2token config to come from .conf
authorSteve Baker <sbaker@redhat.com>
Fri, 12 Apr 2013 22:46:35 +0000 (08:46 +1000)
committerSteve Baker <sbaker@redhat.com>
Tue, 23 Apr 2013 19:37:20 +0000 (07:37 +1200)
Just like keystoneclient.middleware.auth_token
first checks paste.ini file then .conf file when fetching
a config value

Change-Id: I9db9744d0ab12fcf486de9a9d3f8e870a4ff66de

heat/api/aws/ec2token.py

index 83b06b17d82b3cd14590b9d79c2a5df4d50346bc..173ea788b4e2255598910a0394affa8f8bd8e7cb 100644 (file)
@@ -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