"Fossies" - the Fresh Open Source Software Archive

Member "zaqar-9.0.0/zaqar/transport/middleware/auth.py" (16 Oct 2019, 2036 Bytes) of package /linux/misc/openstack/zaqar-9.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "auth.py" see the Fossies "Dox" file reference documentation.

    1 # Copyright (c) 2013 Red Hat, Inc.
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License");
    4 # you may not use this file except in compliance with the License.
    5 # You may obtain a copy of the License at
    6 #
    7 #    http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 # Unless required by applicable law or agreed to in writing, software
   10 # distributed under the License is distributed on an "AS IS" BASIS,
   11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
   12 # implied.
   13 # See the License for the specific language governing permissions and
   14 # limitations under the License.
   15 
   16 """Middleware for handling authorization and authentication."""
   17 
   18 from keystonemiddleware import auth_token
   19 from oslo_log import log
   20 
   21 
   22 STRATEGIES = {}
   23 
   24 LOG = log.getLogger(__name__)
   25 
   26 
   27 class SignedHeadersAuth(object):
   28 
   29     def __init__(self, app, auth_app):
   30         self._app = app
   31         self._auth_app = auth_app
   32 
   33     def __call__(self, environ, start_response):
   34         path = environ.get('PATH_INFO')
   35         # NOTE(flwang): The root path of Zaqar service shouldn't require any
   36         # auth.
   37         if path == '/':
   38             return self._app(environ, start_response)
   39 
   40         signature = environ.get('HTTP_URL_SIGNATURE')
   41 
   42         if signature is None or path.startswith('/v1'):
   43             return self._auth_app(environ, start_response)
   44 
   45         return self._app(environ, start_response)
   46 
   47 
   48 class KeystoneAuth(object):
   49 
   50     @classmethod
   51     def install(cls, app, conf):
   52         """Install Auth check on application."""
   53         LOG.debug(u'Installing Keystone\'s auth protocol')
   54 
   55         return auth_token.AuthProtocol(app,
   56                                        conf={"oslo-config-config": conf,
   57                                              "oslo-config-project": "zaqar"})
   58 
   59 
   60 STRATEGIES['keystone'] = KeystoneAuth
   61 
   62 
   63 def strategy(strategy):
   64     """Returns the Auth Strategy.
   65 
   66     :param strategy: String representing
   67         the strategy to use
   68     """
   69     try:
   70         return STRATEGIES[strategy]
   71     except KeyError:
   72         raise RuntimeError