From 57c6b3187fc47e7d5cf6f1b5cde10fd867edb49f Mon Sep 17 00:00:00 2001 From: Artem Goncharov Date: Thu, 10 Oct 2024 14:02:32 +0200 Subject: [PATCH] Add new keystone.wsgi module This allows deployment tooling to easily switch from passing a binary path to passing a Python module path. We'll use it shortly. Change-Id: I36bb9ab43c3263b5064f35f4fc550722a0e83279 --- doc/source/conf.py | 1 + httpd/keystone-uwsgi-admin.ini | 2 +- httpd/keystone-uwsgi-public.ini | 2 +- keystone/wsgi/__init__.py | 0 keystone/wsgi/api.py | 22 +++++++++++++++++++ ...keystone-wsgi-module-afae3f86df07eca9.yaml | 22 +++++++++++++++++++ 6 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 keystone/wsgi/__init__.py create mode 100644 keystone/wsgi/api.py create mode 100644 releasenotes/notes/add-keystone-wsgi-module-afae3f86df07eca9.yaml diff --git a/doc/source/conf.py b/doc/source/conf.py index 213e7621b7..0717141633 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -58,6 +58,7 @@ apidoc_excluded_paths = [ 'tests/*', 'tests', 'test', + 'wsgi', # TODO(gmann): with new release of SQLAlchemy(1.4.27) TypeDecorator used # in common/sql/core.py file started failing. Remove this oncethe issue of # TypeDecorator is fixed. diff --git a/httpd/keystone-uwsgi-admin.ini b/httpd/keystone-uwsgi-admin.ini index fe7ef7bb4d..d3d4ef6d89 100644 --- a/httpd/keystone-uwsgi-admin.ini +++ b/httpd/keystone-uwsgi-admin.ini @@ -1,5 +1,5 @@ [uwsgi] -wsgi-file = /usr/local/bin/keystone-wsgi-admin +module = keystone.wsgi.api:application # Versions of mod_proxy_uwsgi>=2.0.6 should use a UNIX socket, see # http://uwsgi-docs.readthedocs.org/en/latest/Apache.html#mod-proxy-uwsgi diff --git a/httpd/keystone-uwsgi-public.ini b/httpd/keystone-uwsgi-public.ini index 8decf2023a..a1616beb3b 100644 --- a/httpd/keystone-uwsgi-public.ini +++ b/httpd/keystone-uwsgi-public.ini @@ -1,5 +1,5 @@ [uwsgi] -wsgi-file = /usr/local/bin/keystone-wsgi-public +module = keystone.wsgi.api:application # Versions of mod_proxy_uwsgi>=2.0.6 should use a UNIX socket, see # http://uwsgi-docs.readthedocs.org/en/latest/Apache.html#mod-proxy-uwsgi diff --git a/keystone/wsgi/__init__.py b/keystone/wsgi/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/keystone/wsgi/api.py b/keystone/wsgi/api.py new file mode 100644 index 0000000000..f3a1bbf7fe --- /dev/null +++ b/keystone/wsgi/api.py @@ -0,0 +1,22 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""WSGI application entry-point for Keystone API.""" + +import threading + +from keystone.server import wsgi + +application = None +with threading.Lock(): + if application is None: + application = wsgi.initialize_public_application() diff --git a/releasenotes/notes/add-keystone-wsgi-module-afae3f86df07eca9.yaml b/releasenotes/notes/add-keystone-wsgi-module-afae3f86df07eca9.yaml new file mode 100644 index 0000000000..3295b14b04 --- /dev/null +++ b/releasenotes/notes/add-keystone-wsgi-module-afae3f86df07eca9.yaml @@ -0,0 +1,22 @@ +--- +features: + - | + A new module, ``keystone.wsgi``, has been added as a place to gather WSGI + ``application`` objects. This is intended to ease deployment by providing + a consistent location for these objects. For example, if using uWSGI then + instead of: + + .. code-block:: ini + + [uwsgi] + wsgi-file = /bin/keystone-wsgi-public + + You can now use: + + .. code-block:: ini + + [uwsgi] + module = keystone.wsgi.api:application + + This also simplifies deployment with other WSGI servers that expect module + paths such as gunicorn.