diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index 2c6ad81..0000000 --- a/.coveragerc +++ /dev/null @@ -1,8 +0,0 @@ -[run] -branch = True -source = oslo_context -omit = oslo_context/tests/* - -[report] -ignore_errors = True -precision = 2 diff --git a/.gitignore b/.gitignore deleted file mode 100644 index facf719..0000000 --- a/.gitignore +++ /dev/null @@ -1,55 +0,0 @@ -*.py[cod] - -# C extensions -*.so - -# Packages -*.egg* -*.egg-info -dist -build -eggs -parts -bin -var -sdist -develop-eggs -.installed.cfg -lib -lib64 - -# Installer logs -pip-log.txt - -# Unit test / coverage reports -.coverage -cover -.tox -nosetests.xml -.testrepository - -# Translations -*.mo - -# Mr Developer -.mr.developer.cfg -.project -.pydevproject - -# Complexity -output/*.html -output/*/index.html - -# Sphinx -doc/build - -# pbr generates these -AUTHORS -ChangeLog - -# Editors -*~ -.*.swp - -# reno build -releasenotes/build diff --git a/.gitreview b/.gitreview deleted file mode 100644 index 54aec1b..0000000 --- a/.gitreview +++ /dev/null @@ -1,4 +0,0 @@ -[gerrit] -host=review.openstack.org -port=29418 -project=openstack/oslo.context.git diff --git a/.mailmap b/.mailmap deleted file mode 100644 index 516ae6f..0000000 --- a/.mailmap +++ /dev/null @@ -1,3 +0,0 @@ -# Format is: -# -# diff --git a/.testr.conf b/.testr.conf deleted file mode 100644 index ccafd7c..0000000 --- a/.testr.conf +++ /dev/null @@ -1,7 +0,0 @@ -[DEFAULT] -test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ - OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ - OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \ - ${PYTHON:-python} -m subunit.run discover -t ./ ./oslo_context $LISTOPT $IDOPTION -test_id_option=--load-list $IDFILE -test_list_option=--list diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst deleted file mode 100644 index 31f7fdd..0000000 --- a/CONTRIBUTING.rst +++ /dev/null @@ -1,16 +0,0 @@ -If you would like to contribute to the development of OpenStack, -you must follow the steps in this page: - - http://docs.openstack.org/infra/manual/developers.html - -Once those steps have been completed, changes to OpenStack -should be submitted for review via the Gerrit tool, following -the workflow documented at: - - http://docs.openstack.org/infra/manual/developers.html#development-workflow - -Pull requests submitted through GitHub will be ignored. - -Bugs should be filed on Launchpad, not GitHub: - - https://bugs.launchpad.net/oslo.context diff --git a/HACKING.rst b/HACKING.rst deleted file mode 100644 index ef0558b..0000000 --- a/HACKING.rst +++ /dev/null @@ -1,4 +0,0 @@ -oslo.context Style Commandments -====================================================== - -Read the OpenStack Style Commandments http://docs.openstack.org/developer/hacking/ diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 68c771a..0000000 --- a/LICENSE +++ /dev/null @@ -1,176 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - diff --git a/README.rst b/README.rst deleted file mode 100644 index 776ec24..0000000 --- a/README.rst +++ /dev/null @@ -1,20 +0,0 @@ -==================== -Oslo Context Library -==================== - -.. image:: https://img.shields.io/pypi/v/oslo.context.svg - :target: https://pypi.python.org/pypi/oslo.context/ - :alt: Latest Version - -.. image:: https://img.shields.io/pypi/dm/oslo.context.svg - :target: https://pypi.python.org/pypi/oslo.context/ - :alt: Downloads - -The Oslo context library has helpers to maintain useful information -about a request context. The request context is usually populated in -the WSGI pipeline and used by various modules such as logging. - -* License: Apache License, Version 2.0 -* Documentation: http://docs.openstack.org/developer/oslo.context -* Source: http://git.openstack.org/cgit/openstack/oslo.context -* Bugs: http://bugs.launchpad.net/oslo.context diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..0038364 --- /dev/null +++ b/README.txt @@ -0,0 +1,13 @@ +This project is no longer maintained. + +The contents of this repository are still available in the Git +source code management system. To see the contents of this +repository before it reached its end of life, please check out the +previous commit with "git checkout HEAD^1". + +Use instead the project deb-python-oslo.context at +http://git.openstack.org/cgit/openstack/deb-python-oslo.context . + +For any further questions, please email +openstack-dev@lists.openstack.org or join #openstack-dev on +Freenode. diff --git a/babel.cfg b/babel.cfg deleted file mode 100644 index 15cd6cb..0000000 --- a/babel.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[python: **.py] - diff --git a/doc/source/api/context.rst b/doc/source/api/context.rst deleted file mode 100644 index d9ddf35..0000000 --- a/doc/source/api/context.rst +++ /dev/null @@ -1,7 +0,0 @@ -The :mod:`oslo_context.context` Module -====================================== - -.. automodule:: oslo_context.context - :members: - :undoc-members: - :show-inheritance: diff --git a/doc/source/api/fixture.rst b/doc/source/api/fixture.rst deleted file mode 100644 index 58ef47f..0000000 --- a/doc/source/api/fixture.rst +++ /dev/null @@ -1,7 +0,0 @@ -The :mod:`oslo_context.fixture` Module -====================================== - -.. automodule:: oslo_context.fixture - :members: - :undoc-members: - :show-inheritance: diff --git a/doc/source/api/index.rst b/doc/source/api/index.rst deleted file mode 100644 index a123a00..0000000 --- a/doc/source/api/index.rst +++ /dev/null @@ -1,9 +0,0 @@ -================== - oslo.context API -================== - -.. toctree:: - :maxdepth: 1 - - context.rst - fixture.rst diff --git a/doc/source/conf.py b/doc/source/conf.py deleted file mode 100755 index ca1f348..0000000 --- a/doc/source/conf.py +++ /dev/null @@ -1,75 +0,0 @@ -# -*- coding: utf-8 -*- -# 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. - -import os -import sys - -sys.path.insert(0, os.path.abspath('../..')) -# -- General configuration ---------------------------------------------------- - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = [ - 'sphinx.ext.autodoc', - #'sphinx.ext.intersphinx', - 'oslosphinx' -] - -# autodoc generation is a bit aggressive and a nuisance when doing heavy -# text edit cycles. -# execute "export SPHINX_DEBUG=1" in your terminal to disable - -# The suffix of source filenames. -source_suffix = '.rst' - -# The master toctree document. -master_doc = 'index' - -# General information about the project. -project = u'oslo.context' -copyright = u'2016, OpenStack Foundation' - -# If true, '()' will be appended to :func: etc. cross-reference text. -add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -add_module_names = True - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' - -# -- Options for HTML output -------------------------------------------------- - -# The theme to use for HTML and HTML Help pages. Major themes that come with -# Sphinx are currently 'default' and 'sphinxdoc'. -# html_theme_path = ["."] -# html_theme = '_theme' -# html_static_path = ['static'] - -# Output file base name for HTML help builder. -htmlhelp_basename = '%sdoc' % project - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, author, documentclass -# [howto/manual]). -latex_documents = [ - ('index', - '%s.tex' % project, - u'%s Documentation' % project, - u'OpenStack Foundation', 'manual'), -] - -# Example configuration for intersphinx: refer to the Python standard library. -#intersphinx_mapping = {'http://docs.python.org/': None} diff --git a/doc/source/contributing.rst b/doc/source/contributing.rst deleted file mode 100644 index 2ca75d1..0000000 --- a/doc/source/contributing.rst +++ /dev/null @@ -1,5 +0,0 @@ -============== - Contributing -============== - -.. include:: ../../CONTRIBUTING.rst diff --git a/doc/source/examples.rst b/doc/source/examples.rst deleted file mode 100644 index 016487a..0000000 --- a/doc/source/examples.rst +++ /dev/null @@ -1,37 +0,0 @@ -========== - Examples -========== - -.. _examples: - -These files can be found in the doc/source/examples directory of -the git source of this project. They can also be found at the -`online git respository`_ of this project. - -.. _online git respository: http://git.openstack.org/cgit/openstack/oslo.context/tree/doc/source/examples - - -.. _example_usage_simple.py: - -usage_simple.py ---------------- - -.. highlight:: python -.. literalinclude:: examples/usage_simple.py - :linenos: - -.. _example_usage.py: - -usage.py --------- - -.. literalinclude:: examples/usage.py - :linenos: - -.. _example_usage_user_identity.py: - -usage_user_identity.py ----------------------- - -.. literalinclude:: examples/usage_user_identity.py - :linenos: diff --git a/doc/source/examples/usage.py b/doc/source/examples/usage.py deleted file mode 100644 index 53c4654..0000000 --- a/doc/source/examples/usage.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2015 OpenStack Foundation -# -# 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. - -"""A respresentative usage example of Oslo Context - -This example requires the following modules to be installed. - -$ pip install oslo.context oslo.log - -More information can be found at: - - http://docs.openstack.org/developer/oslo.context/usage.html -""" - -from oslo_config import cfg -from oslo_context import context -from oslo_log import log as logging - -CONF = cfg.CONF -DOMAIN = "demo" - -logging.register_options(CONF) -logging.setup(CONF, DOMAIN) - -LOG = logging.getLogger(__name__) - -LOG.info("Message without context") -# ids in Openstack are 32 characters long -# For readability a shorter id value is used -context.RequestContext(user='6ce90b4d', - tenant='d6134462', - project_domain='a6b9360e') -LOG.info("Message with context") - -context = context.RequestContext(user='ace90b4d', - tenant='b6134462', - project_domain='c6b9360e') -LOG.info("Message with passed context", context=context) diff --git a/doc/source/examples/usage_simple.py b/doc/source/examples/usage_simple.py deleted file mode 100644 index 4755395..0000000 --- a/doc/source/examples/usage_simple.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2015 OpenStack Foundation -# -# 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. - -"""A simple usage example of Oslo Context - -This example requires the following modules to be installed. - -$ pip install oslo.context oslo.log - -More information can be found at: - - http://docs.openstack.org/developer/oslo.context/usage.html -""" - -from oslo_config import cfg -from oslo_context import context -from oslo_log import log as logging - -CONF = cfg.CONF -DOMAIN = "demo" - -logging.register_options(CONF) -logging.setup(CONF, DOMAIN) - -LOG = logging.getLogger(__name__) - -LOG.info("Message without context") -context.RequestContext() -LOG.info("Message with context") diff --git a/doc/source/examples/usage_user_identity.py b/doc/source/examples/usage_user_identity.py deleted file mode 100644 index 609f696..0000000 --- a/doc/source/examples/usage_user_identity.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2015 OpenStack Foundation -# -# 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. - -"""A usage example of Oslo Context with user_identity - -This example requires the following modules to be installed. - -$ pip install oslo.context oslo.log - -More information can be found at: - - http://docs.openstack.org/developer/oslo.context/usage.html -""" - -from oslo_config import cfg -from oslo_context import context -from oslo_log import log as logging - -CONF = cfg.CONF -DOMAIN = "demo" - -logging.register_options(CONF) -CONF.logging_user_identity_format = "%(user)s/%(tenant)s@%(project_domain)s" -logging.setup(CONF, DOMAIN) - -LOG = logging.getLogger(__name__) - -LOG.info("Message without context") -# ids in Openstack are 32 characters long -# For readability a shorter id value is used -context.RequestContext(request_id='req-abc', - user='6ce90b4d', - tenant='d6134462', - project_domain='a6b9360e') -LOG.info("Message with context") diff --git a/doc/source/history.rst b/doc/source/history.rst deleted file mode 100644 index 69ed4fe..0000000 --- a/doc/source/history.rst +++ /dev/null @@ -1 +0,0 @@ -.. include:: ../../ChangeLog diff --git a/doc/source/index.rst b/doc/source/index.rst deleted file mode 100644 index 411f6f3..0000000 --- a/doc/source/index.rst +++ /dev/null @@ -1,27 +0,0 @@ -.. include:: ../../README.rst - -Contents: - -.. toctree:: - :maxdepth: 2 - - installation - usage - examples - contributing - history - -Code Documentation -================== - -.. toctree:: - :maxdepth: 1 - - api/index - -Indices and tables -================== - -* :ref:`genindex` -* :ref:`modindex` -* :ref:`search` diff --git a/doc/source/installation.rst b/doc/source/installation.rst deleted file mode 100644 index 0ee7ae1..0000000 --- a/doc/source/installation.rst +++ /dev/null @@ -1,7 +0,0 @@ -============ -Installation -============ - -At the command line:: - - $ pip install oslo.context diff --git a/doc/source/usage.rst b/doc/source/usage.rst deleted file mode 100644 index 8c84163..0000000 --- a/doc/source/usage.rst +++ /dev/null @@ -1,124 +0,0 @@ -======= - Usage -======= - -oslo.context is used in conjunction with `oslo.log`_ to provide context -aware log records when specifying a :class:`~oslo_context.context.RequestContext` -object. - -This code example demonstrates two INFO log records with varying output -format due to the use of RequestContext. - -.. _oslo.log: http://docs.openstack.org/developer/oslo.log/ - -.. highlight:: python -.. literalinclude:: examples/usage_simple.py - :linenos: - :lines: 28-42 - :emphasize-lines: 2,14 - -Source: :ref:`example_usage_simple.py` - -**Example Logging Output:** - -:: - - 2016-01-20 21:56:29.283 8428 INFO __main__ [-] Message without context - 2016-01-20 21:56:29.284 8428 INFO __main__ [req-929d23e9-f50e-46ae-a8a7-02bc8c3fd2c8 - - - - -] Message with context - -The format of these log records are defined by the -`logging_default_format_string`_ and `logging_context_format_string`_ -configuration options respectively. The `logging_user_identity_format`_ option -also provides further context aware definition flexibility. - -.. _logging_default_format_string: http://docs.openstack.org/developer/oslo.log/opts.html#logging_default_format_string -.. _logging_context_format_string: http://docs.openstack.org/developer/oslo.log/opts.html#logging_context_format_string -.. _logging_user_identity_format: http://docs.openstack.org/developer/oslo.log/opts.html#logging_user_identity_format - ------------------ -Context Variables ------------------ - -The oslo.context variables used in the **logging_context_format_string** and -**logging_user_identity_format** configuration options include: - -* request_id - A request id (e.g. req-9f2c484a-b504-4fd9-b44c-4357544cca50) -* user - A user id (e.g. e5bc7033e6b7473c9fe8ee1bd4df79a3) -* tenant - A tenant/project id (e.g. 79e338475db84f7c91ee4e86b79b34c1) -* domain - A domain id -* user_domain - A user domain id -* project_domain - A project domain id - - -This code example demonstrates defining a context with specific attributes -that are presented in the output log record. - -.. literalinclude:: examples/usage.py - :linenos: - :lines: 28-46 - :emphasize-lines: 2,16-18 - -Source: :ref:`example_usage.py` - -**Example Logging Output:** - -:: - - 2016-01-21 17:30:50.263 12201 INFO __main__ [-] Message without context - 2016-01-21 17:30:50.264 12201 INFO __main__ [req-e591e881-36c3-4627-a5d8-54df200168ef 6ce90b4d d6134462 - - a6b9360e] Message with context - -A context object can also be passed as an argument to any logging level -message. - -.. literalinclude:: examples/usage.py - :linenos: - :lines: 48-51 - :emphasize-lines: 4 - -**Example Logging Output:** - -:: - - 2016-01-21 22:43:55.621 17295 INFO __main__ [req-ac2d4a3a-ff3c-4c2b-97a0-2b76b33d9e72 ace90b4d b6134462 - - c6b9360e] Message with passed context - -.. note:: - - To maintain consistent log messages for operators across multiple - OpenStack projects it is highly recommended that - **logging_default_format_string** and **logging_context_format_string** are - not modified from oslo.log default values. - - --------------------------- -Project Specific Variables --------------------------- - -Individual projects can also subclass :class:`~oslo_context.context.RequestContext` -to provide additional attributes that can be using with oslo.log. The Nova -`RequestContext`_ class for example provides additional variables including -user_name and project_name. - -.. _RequestContext: http://git.openstack.org/cgit/openstack/nova/tree/nova/context.py - -This can for example enable the defining of **logging_user_identity_format = -%(user_name)s %(project_name)s** which would produce a log record -containing a context portion using names instead of ids such as -**[req-e4b9a194-a9b1-4829-b7d0-35226fc101fc admin demo]** - -This following code example shows how a modified **logging_user_identity_format** -configuration alters the context portion of the log record. - -.. literalinclude:: examples/usage_user_identity.py - :linenos: - :lines: 28-48 - :emphasize-lines: 9 - -Source: :ref:`example_usage_user_identity.py` - - -**Example Logging Output:** - -:: - - 2016-01-21 20:56:43.964 14816 INFO __main__ [-] Message without context - 2016-01-21 20:56:43.965 14816 INFO __main__ [req-abc 6ce90b4d/d6134462@a6b9360e] Message with context diff --git a/oslo_context/__init__.py b/oslo_context/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/oslo_context/context.py b/oslo_context/context.py deleted file mode 100644 index d0d79c0..0000000 --- a/oslo_context/context.py +++ /dev/null @@ -1,256 +0,0 @@ -# Copyright 2011 OpenStack Foundation. -# All Rights Reserved. -# -# 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. - -""" -Base class for holding contextual information of a request - -This class has several uses: - -* Used for storing security information in a web request. -* Used for passing contextual details to oslo.log. - -Projects should subclass this class if they wish to enhance the request -context or provide additional information in their specific WSGI pipeline -or logging context. -""" - -import inspect -import itertools -import threading -import uuid - - -_request_store = threading.local() - -# These arguments will be passed to a new context from the first available -# header to support backwards compatibility. -_ENVIRON_HEADERS = {'auth_token': ['HTTP_X_AUTH_TOKEN', - 'HTTP_X_STORAGE_TOKEN'], - 'user': ['HTTP_X_USER_ID', - 'HTTP_X_USER'], - 'tenant': ['HTTP_X_PROJECT_ID', - 'HTTP_X_TENANT_ID', - 'HTTP_X_TENANT'], - 'user_domain': ['HTTP_X_USER_DOMAIN_ID'], - 'project_domain': ['HTTP_X_PROJECT_DOMAIN_ID'], - 'user_name': ['HTTP_X_USER_NAME'], - 'project_name': ['HTTP_X_PROJECT_NAME', - 'HTTP_X_TENANT_NAME'], - 'user_domain_name': ['HTTP_X_USER_DOMAIN_NAME'], - 'project_domain_name': ['HTTP_X_PROJECT_DOMAIN_NAME'], - 'request_id': ['openstack.request_id'], - } - - -def generate_request_id(): - """Generate a unique request id.""" - return 'req-%s' % uuid.uuid4() - - -class RequestContext(object): - - """Helper class to represent useful information about a request context. - - Stores information about the security context under which the user - accesses the system, as well as additional request information. - """ - - user_idt_format = u'{user} {tenant} {domain} {user_domain} {p_domain}' - - def __init__(self, auth_token=None, user=None, tenant=None, domain=None, - user_domain=None, project_domain=None, is_admin=False, - read_only=False, show_deleted=False, request_id=None, - resource_uuid=None, overwrite=True, roles=None, - user_name=None, project_name=None, domain_name=None, - user_domain_name=None, project_domain_name=None, - is_admin_project=True): - """Initialize the RequestContext - - :param overwrite: Set to False to ensure that the greenthread local - copy of the index is not overwritten. - :param is_admin_project: Whether the specified project is specified in - the token as the admin project. Defaults to - True for backwards compatibility. - :type is_admin_project: bool - """ - self.auth_token = auth_token - self.user = user - self.user_name = user_name - # NOTE (rbradfor): tenant will become project - # See spec discussion on https://review.openstack.org/#/c/290907/ - self.tenant = tenant - self.project_name = project_name - self.domain = domain - self.domain_name = domain_name - self.user_domain = user_domain - self.user_domain_name = user_domain_name - self.project_domain = project_domain - self.project_domain_name = project_domain_name - self.is_admin = is_admin - self.is_admin_project = is_admin_project - self.read_only = read_only - self.show_deleted = show_deleted - self.resource_uuid = resource_uuid - self.roles = roles or [] - if not request_id: - request_id = generate_request_id() - self.request_id = request_id - if overwrite or not get_current(): - self.update_store() - - def update_store(self): - """Store the context in the current thread.""" - _request_store.context = self - - def to_policy_values(self): - """A dictionary of context attributes to enforce policy with. - - oslo.policy enforcement requires a dictionary of attributes - representing the current logged in user on which it applies policy - enforcement. This dictionary defines a standard list of attributes that - should be available for enforcement across services. - - It is expected that services will often have to override this method - with either deprecated values or additional attributes used by that - service specific policy. - """ - return {'user_id': self.user, - 'user_domain_id': self.user_domain, - 'project_id': self.tenant, - 'project_domain_id': self.project_domain, - 'roles': self.roles, - 'is_admin_project': self.is_admin_project} - - def to_dict(self): - """Return a dictionary of context attributes.""" - user_idt = ( - self.user_idt_format.format(user=self.user or '-', - tenant=self.tenant or '-', - domain=self.domain or '-', - user_domain=self.user_domain or '-', - p_domain=self.project_domain or '-')) - - return {'user': self.user, - 'tenant': self.tenant, - 'domain': self.domain, - 'user_domain': self.user_domain, - 'project_domain': self.project_domain, - 'is_admin': self.is_admin, - 'read_only': self.read_only, - 'show_deleted': self.show_deleted, - 'auth_token': self.auth_token, - 'request_id': self.request_id, - 'resource_uuid': self.resource_uuid, - 'roles': self.roles, - 'user_identity': user_idt, - 'is_admin_project': self.is_admin_project} - - def get_logging_values(self): - """Return a dictionary of logging specific context attributes.""" - values = {'user_name': self.user_name, - 'project_name': self.project_name, - 'domain_name': self.domain_name, - 'user_domain_name': self.user_domain_name, - 'project_domain_name': self.project_domain_name} - values.update(self.to_dict()) - return values - - @classmethod - def from_dict(cls, values): - """Construct a context object from a provided dictionary.""" - allowed = [arg for arg in - inspect.getargspec(RequestContext.__init__).args - if arg != 'self'] - kwargs = {k: v for (k, v) in values.items() if k in allowed} - return cls(**kwargs) - - @classmethod - def from_environ(cls, environ, **kwargs): - """Load a context object from a request environment. - - If keyword arguments are provided then they override the values in the - request environment. - - :param environ: The environment dictionary associated with a request. - :type environ: dict - """ - # Load a new context object from the environment variables set by - # auth_token middleware. See: - # http://docs.openstack.org/developer/keystonemiddleware/api/keystonemiddleware.auth_token.html#what-auth-token-adds-to-the-request-for-use-by-the-openstack-service - - # add kwarg if not specified by user from a list of possible headers - for k, v_list in _ENVIRON_HEADERS.items(): - if k in kwargs: - continue - - for v in v_list: - if v in environ: - kwargs[k] = environ[v] - break - - if 'roles' not in kwargs: - roles = environ.get('HTTP_X_ROLES', environ.get('HTTP_X_ROLE')) - roles = [r.strip() for r in roles.split(',')] if roles else [] - kwargs['roles'] = roles - - if 'is_admin_project' not in kwargs: - # NOTE(jamielennox): we default is_admin_project to true because if - # nothing is provided we have to assume it is the admin project to - # make old policy continue to work. - is_admin_proj_str = environ.get('HTTP_X_IS_ADMIN_PROJECT', 'true') - kwargs['is_admin_project'] = is_admin_proj_str.lower() == 'true' - - return cls(**kwargs) - - -def get_admin_context(show_deleted=False): - """Create an administrator context.""" - context = RequestContext(None, - tenant=None, - is_admin=True, - show_deleted=show_deleted, - overwrite=False) - return context - - -def get_context_from_function_and_args(function, args, kwargs): - """Find an arg of type RequestContext and return it. - - This is useful in a couple of decorators where we don't - know much about the function we're wrapping. - """ - - for arg in itertools.chain(kwargs.values(), args): - if isinstance(arg, RequestContext): - return arg - - return None - - -def is_user_context(context): - """Indicates if the request context is a normal user.""" - if not context or not isinstance(context, RequestContext): - return False - if context.is_admin: - return False - return True - - -def get_current(): - """Return this thread's current context - - If no context is set, returns None - """ - return getattr(_request_store, 'context', None) diff --git a/oslo_context/fixture.py b/oslo_context/fixture.py deleted file mode 100644 index a7bb0ff..0000000 --- a/oslo_context/fixture.py +++ /dev/null @@ -1,40 +0,0 @@ -# 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. - -import fixtures - -from oslo_context import context - - -class ClearRequestContext(fixtures.Fixture): - """Clears any cached RequestContext - - This resets RequestContext at the beginning and end of tests that - use this fixture to ensure that we have a clean slate for running - tests, and that we leave a clean slate for other tests that might - run later in the same process. - """ - - def setUp(self): - super(ClearRequestContext, self).setUp() - # we need to clear both when we start, and when we finish, - # because there might be other tests running that don't handle - # this correctly. - self._remove_cached_context() - self.addCleanup(self._remove_cached_context) - - def _remove_cached_context(self): - """Remove the thread-local context stored in the module.""" - try: - del context._request_store.context - except AttributeError: - pass diff --git a/oslo_context/tests/__init__.py b/oslo_context/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/oslo_context/tests/test_context.py b/oslo_context/tests/test_context.py deleted file mode 100644 index 54046cb..0000000 --- a/oslo_context/tests/test_context.py +++ /dev/null @@ -1,451 +0,0 @@ -# -*- encoding: utf-8 -*- -# Copyright 2011 OpenStack Foundation. -# All Rights Reserved. -# -# 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. - -import hashlib -import uuid - -from oslotest import base as test_base - -from oslo_context import context -from oslo_context import fixture - - -def generate_id(name): - return hashlib.md5(name.encode('utf-8')).hexdigest() - - -class Object(object): - pass - - -class ContextTest(test_base.BaseTestCase): - - def setUp(self): - super(ContextTest, self).setUp() - self.useFixture(fixture.ClearRequestContext()) - - def test_context(self): - ctx = context.RequestContext() - self.assertTrue(ctx) - - def test_store_when_no_overwrite(self): - # If no context exists we store one even if overwrite is false - # (since we are not overwriting anything). - ctx = context.RequestContext(overwrite=False) - self.assertIs(context.get_current(), ctx) - - def test_no_overwrite(self): - # If there is already a context in the cache a new one will - # not overwrite it if overwrite=False. - ctx1 = context.RequestContext(overwrite=True) - context.RequestContext(overwrite=False) - self.assertIs(context.get_current(), ctx1) - - def test_admin_no_overwrite(self): - # If there is already a context in the cache creating an admin - # context will not overwrite it. - ctx1 = context.RequestContext(overwrite=True) - context.get_admin_context() - self.assertIs(context.get_current(), ctx1) - self.assertFalse(ctx1.is_admin) - - def test_store_current(self): - # By default a new context is stored. - ctx = context.RequestContext() - self.assertIs(context.get_current(), ctx) - - def test_no_context(self): - self.assertIsNone(context.get_current()) - - def test_admin_context_show_deleted_flag_default(self): - ctx = context.get_admin_context() - self.assertIsInstance(ctx, context.RequestContext) - self.assertTrue(ctx.is_admin) - self.assertFalse(ctx.show_deleted) - self.assertIsNone(ctx.tenant) - - def test_admin_context_show_deleted_flag_set(self): - ctx = context.get_admin_context(show_deleted=True) - self.assertTrue(ctx.is_admin) - self.assertTrue(ctx.show_deleted) - - def test_from_dict(self): - dct = { - "auth_token": "token1", - "user": "user1", - "user_name": "user1_name", - "tenant": "tenant1", - "project_name": "tenant1_name", - "domain": "domain1", - "domain_name": "domain1_name", - "user_domain": "user_domain1", - "user_domain_name": "user_domain1_name", - "project_domain": "project_domain1", - "project_domain_name": "project_domain1_name", - "is_admin": True, - "read_only": True, - "show_deleted": True, - "request_id": "request1", - "resource_uuid": "instance1", - "extra_data": "foo" - } - ctx = context.RequestContext.from_dict(dct) - self.assertEqual(dct['auth_token'], ctx.auth_token) - self.assertEqual(dct['user'], ctx.user) - self.assertEqual(dct['tenant'], ctx.tenant) - self.assertEqual(dct['domain'], ctx.domain) - self.assertEqual(dct['user_domain'], ctx.user_domain) - self.assertEqual(dct['project_domain'], ctx.project_domain) - self.assertTrue(ctx.is_admin) - self.assertTrue(ctx.read_only) - self.assertTrue(ctx.show_deleted) - self.assertEqual(dct['request_id'], ctx.request_id) - self.assertEqual(dct['resource_uuid'], ctx.resource_uuid) - self.assertEqual(dct['user_name'], ctx.user_name) - self.assertEqual(dct['project_name'], ctx.project_name) - self.assertEqual(dct['domain_name'], ctx.domain_name) - self.assertEqual(dct['user_domain_name'], ctx.user_domain_name) - self.assertEqual(dct['project_domain_name'], ctx.project_domain_name) - - def test_from_dict_unknown_keys(self): - dct = { - "auth_token": "token1", - "user": "user1", - "read_only": True, - "roles": "role1,role2,role3", # future review provides this - "color": "red", - "unknown": "" - } - ctx = context.RequestContext.from_dict(dct) - self.assertEqual("token1", ctx.auth_token) - self.assertEqual("user1", ctx.user) - self.assertIsNone(ctx.tenant) - self.assertFalse(ctx.is_admin) - self.assertTrue(ctx.read_only) - self.assertRaises(KeyError, lambda: ctx.__dict__['color']) - - def test_is_user_context(self): - self.assertFalse(context.is_user_context(None)) - ctx = context.RequestContext(is_admin=True) - self.assertFalse(context.is_user_context(ctx)) - ctx = context.RequestContext(is_admin=False) - self.assertTrue(context.is_user_context(ctx)) - self.assertFalse(context.is_user_context("non context object")) - - def test_from_environ_variables(self): - auth_token = uuid.uuid4().hex - user_name = uuid.uuid4().hex - user_id = generate_id(user_name) - project_name = uuid.uuid4().hex - project_id = generate_id(project_name) - user_domain_name = uuid.uuid4().hex - user_domain_id = generate_id(user_domain_name) - project_domain_name = uuid.uuid4().hex - project_domain_id = generate_id(project_domain_name) - roles = [uuid.uuid4().hex, uuid.uuid4().hex, uuid.uuid4().hex] - request_id = uuid.uuid4().hex - - environ = {'HTTP_X_AUTH_TOKEN': auth_token, - 'HTTP_X_USER_ID': user_id, - 'HTTP_X_PROJECT_ID': project_id, - 'HTTP_X_USER_DOMAIN_ID': user_domain_id, - 'HTTP_X_PROJECT_DOMAIN_ID': project_domain_id, - 'HTTP_X_ROLES': ','.join(roles), - 'HTTP_X_USER_NAME': user_name, - 'HTTP_X_PROJECT_NAME': project_name, - 'HTTP_X_USER_DOMAIN_NAME': user_domain_name, - 'HTTP_X_PROJECT_DOMAIN_NAME': project_domain_name, - 'openstack.request_id': request_id} - - ctx = context.RequestContext.from_environ(environ) - - self.assertEqual(auth_token, ctx.auth_token) - self.assertEqual(user_id, ctx.user) - self.assertEqual(user_name, ctx.user_name) - self.assertEqual(project_id, ctx.tenant) - self.assertEqual(project_name, ctx.project_name) - self.assertEqual(user_domain_id, ctx.user_domain) - self.assertEqual(user_domain_name, ctx.user_domain_name) - self.assertEqual(project_domain_id, ctx.project_domain) - self.assertEqual(project_domain_name, ctx.project_domain_name) - self.assertEqual(roles, ctx.roles) - self.assertEqual(request_id, ctx.request_id) - - def test_from_environ_no_roles(self): - ctx = context.RequestContext.from_environ(environ={}) - self.assertEqual([], ctx.roles) - - ctx = context.RequestContext.from_environ(environ={'HTTP_X_ROLES': ''}) - self.assertEqual([], ctx.roles) - - def test_from_environ_deprecated_variables(self): - value = uuid.uuid4().hex - - environ = {'HTTP_X_USER': value} - ctx = context.RequestContext.from_environ(environ=environ) - self.assertEqual(value, ctx.user) - - environ = {'HTTP_X_TENANT_ID': value} - ctx = context.RequestContext.from_environ(environ=environ) - self.assertEqual(value, ctx.tenant) - - environ = {'HTTP_X_STORAGE_TOKEN': value} - ctx = context.RequestContext.from_environ(environ=environ) - self.assertEqual(value, ctx.auth_token) - - environ = {'HTTP_X_TENANT': value} - ctx = context.RequestContext.from_environ(environ=environ) - self.assertEqual(value, ctx.tenant) - - environ = {'HTTP_X_ROLE': value} - ctx = context.RequestContext.from_environ(environ=environ) - self.assertEqual([value], ctx.roles) - - environ = {'HTTP_X_TENANT_NAME': value} - ctx = context.RequestContext.from_environ(environ=environ) - self.assertEqual(value, ctx.project_name) - - def test_from_environ_deprecated_precendence(self): - old = uuid.uuid4().hex - new = uuid.uuid4().hex - override = uuid.uuid4().hex - - environ = {'HTTP_X_USER': old, - 'HTTP_X_USER_ID': new} - - ctx = context.RequestContext.from_environ(environ=environ) - self.assertEqual(ctx.user, new) - - ctx = context.RequestContext.from_environ(environ=environ, - user=override) - self.assertEqual(ctx.user, override) - - environ = {'HTTP_X_TENANT': old, - 'HTTP_X_PROJECT_ID': new} - - ctx = context.RequestContext.from_environ(environ=environ) - self.assertEqual(ctx.tenant, new) - - ctx = context.RequestContext.from_environ(environ=environ, - tenant=override) - self.assertEqual(ctx.tenant, override) - - environ = {'HTTP_X_TENANT_NAME': old, - 'HTTP_X_PROJECT_NAME': new} - - ctx = context.RequestContext.from_environ(environ=environ) - self.assertEqual(ctx.project_name, new) - - def test_from_environ_strip_roles(self): - environ = {'HTTP_X_ROLES': ' abc\t,\ndef\n,ghi\n\n'} - ctx = context.RequestContext.from_environ(environ=environ) - self.assertEqual(['abc', 'def', 'ghi'], ctx.roles) - - def test_environ_admin_project(self): - environ = {} - ctx = context.RequestContext.from_environ(environ=environ) - self.assertIs(True, ctx.is_admin_project) - self.assertIs(True, ctx.to_policy_values()['is_admin_project']) - - environ = {'HTTP_X_IS_ADMIN_PROJECT': 'True'} - ctx = context.RequestContext.from_environ(environ=environ) - self.assertIs(True, ctx.is_admin_project) - self.assertIs(True, ctx.to_policy_values()['is_admin_project']) - - environ = {'HTTP_X_IS_ADMIN_PROJECT': 'False'} - ctx = context.RequestContext.from_environ(environ=environ) - self.assertIs(False, ctx.is_admin_project) - self.assertIs(False, ctx.to_policy_values()['is_admin_project']) - - def test_from_function_and_args(self): - ctx = context.RequestContext(user="user1") - arg = [] - kw = dict(c=ctx, s="s") - fn = context.get_context_from_function_and_args - ctx1 = context.get_context_from_function_and_args(fn, arg, kw) - self.assertIs(ctx1, ctx) - - def test_not_in_from_function_and_args(self): - arg = [] - kw = dict() - fn = context.get_context_from_function_and_args - ctx1 = context.get_context_from_function_and_args(fn, arg, kw) - self.assertIsNone(ctx1) - - def test_values(self): - auth_token = "token1" - # test unicode support - user_name = u"John Gāo" - user_id = generate_id(user_name) - project_name = 'tenant1' - project_id = generate_id(project_name) - domain_name = 'domain1' - domain_id = generate_id(domain_name) - user_domain_name = 'user_domain1' - user_domain_id = generate_id(user_domain_name) - project_domain_name = 'project_domain1' - project_domain_id = generate_id(project_domain_name) - is_admin = True - read_only = True - show_deleted = True - request_id = "id1" - resource_uuid = "uuid1" - - ctx = context.RequestContext(auth_token=auth_token, - user=user_id, - user_name=user_name, - tenant=project_id, - project_name=project_name, - domain=domain_id, - domain_name=domain_name, - user_domain=user_domain_id, - user_domain_name=user_domain_name, - project_domain=project_domain_id, - project_domain_name=project_domain_name, - is_admin=is_admin, - read_only=read_only, - show_deleted=show_deleted, - request_id=request_id, - resource_uuid=resource_uuid) - self.assertEqual(auth_token, ctx.auth_token) - self.assertEqual(user_id, ctx.user) - self.assertEqual(user_name, ctx.user_name) - self.assertEqual(project_id, ctx.tenant) - self.assertEqual(project_name, ctx.project_name) - self.assertEqual(domain_id, ctx.domain) - self.assertEqual(domain_name, ctx.domain_name) - self.assertEqual(user_domain_id, ctx.user_domain) - self.assertEqual(user_domain_name, ctx.user_domain_name) - self.assertEqual(project_domain_id, ctx.project_domain) - self.assertEqual(project_domain_name, ctx.project_domain_name) - self.assertEqual(is_admin, ctx.is_admin) - self.assertEqual(read_only, ctx.read_only) - self.assertEqual(show_deleted, ctx.show_deleted) - self.assertEqual(request_id, ctx.request_id) - self.assertEqual(resource_uuid, ctx.resource_uuid) - - d = ctx.to_dict() - self.assertIn('auth_token', d) - self.assertIn('user', d) - self.assertIn('tenant', d) - self.assertIn('domain', d) - self.assertIn('user_domain', d) - self.assertIn('project_domain', d) - self.assertIn('is_admin', d) - self.assertIn('read_only', d) - self.assertIn('show_deleted', d) - self.assertIn('request_id', d) - self.assertIn('resource_uuid', d) - self.assertIn('user_identity', d) - self.assertIn('roles', d) - self.assertNotIn('user_name', d) - self.assertNotIn('project_name', d) - self.assertNotIn('domain_name', d) - self.assertNotIn('user_domain_name', d) - self.assertNotIn('project_domain_name', d) - - self.assertEqual(auth_token, d['auth_token']) - self.assertEqual(project_id, d['tenant']) - self.assertEqual(domain_id, d['domain']) - self.assertEqual(user_domain_id, d['user_domain']) - self.assertEqual(project_domain_id, d['project_domain']) - self.assertEqual(is_admin, d['is_admin']) - self.assertEqual(read_only, d['read_only']) - self.assertEqual(show_deleted, d['show_deleted']) - self.assertEqual(request_id, d['request_id']) - self.assertEqual(resource_uuid, d['resource_uuid']) - user_identity = "%s %s %s %s %s" % (user_id, project_id, domain_id, - user_domain_id, project_domain_id) - self.assertEqual(user_identity, d['user_identity']) - self.assertEqual([], d['roles']) - - d = ctx.get_logging_values() - self.assertIn('auth_token', d) - self.assertIn('user', d) - self.assertIn('tenant', d) - self.assertIn('domain', d) - self.assertIn('user_domain', d) - self.assertIn('project_domain', d) - self.assertIn('is_admin', d) - self.assertIn('read_only', d) - self.assertIn('show_deleted', d) - self.assertIn('request_id', d) - self.assertIn('resource_uuid', d) - self.assertIn('user_identity', d) - self.assertIn('roles', d) - self.assertIn('user_name', d) - self.assertIn('project_name', d) - self.assertIn('domain_name', d) - self.assertIn('user_domain_name', d) - self.assertIn('project_domain_name', d) - - self.assertEqual(user_name, d['user_name']) - self.assertEqual(project_name, d['project_name']) - self.assertEqual(domain_name, d['domain_name']) - self.assertEqual(user_domain_name, d['user_domain_name']) - self.assertEqual(project_domain_name, d['project_domain_name']) - - def test_dict_empty_user_identity(self): - ctx = context.RequestContext() - d = ctx.to_dict() - self.assertEqual("- - - - -", d['user_identity']) - - def test_generate_request_id(self): - id = context.generate_request_id() - self.assertEqual("req-", id[:4]) - - def test_generate_request_id_unique(self): - id1 = context.generate_request_id() - id2 = context.generate_request_id() - self.assertNotEqual(id1, id2) - - def test_policy_dict(self): - user = uuid.uuid4().hex - user_domain = uuid.uuid4().hex - tenant = uuid.uuid4().hex - project_domain = uuid.uuid4().hex - roles = [uuid.uuid4().hex, uuid.uuid4().hex, uuid.uuid4().hex] - - # default is_admin_project is True - ctx = context.RequestContext(user=user, - user_domain=user_domain, - tenant=tenant, - project_domain=project_domain, - roles=roles) - - self.assertEqual({'user_id': user, - 'user_domain_id': user_domain, - 'project_id': tenant, - 'project_domain_id': project_domain, - 'roles': roles, - 'is_admin_project': True}, - ctx.to_policy_values()) - - # is_admin_project False gets passed through - ctx = context.RequestContext(user=user, - user_domain=user_domain, - tenant=tenant, - project_domain=project_domain, - roles=roles, - is_admin_project=False) - - self.assertEqual({'user_id': user, - 'user_domain_id': user_domain, - 'project_id': tenant, - 'project_domain_id': project_domain, - 'roles': roles, - 'is_admin_project': False}, - ctx.to_policy_values()) diff --git a/oslo_context/tests/test_fixture.py b/oslo_context/tests/test_fixture.py deleted file mode 100644 index e566b52..0000000 --- a/oslo_context/tests/test_fixture.py +++ /dev/null @@ -1,46 +0,0 @@ -# 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. - -from oslotest import base as test_base - -from oslo_context import context -from oslo_context import fixture - - -class ClearRequestContextTest(test_base.BaseTestCase): - - # def setUp(self): - # super(ContextTest, self).setUp() - # self.useFixture(fixture.ClearRequestContext()) - - def test_store_current(self): - # By default a new context is stored. - ctx = context.RequestContext() - self.assertIs(context.get_current(), ctx) - fixture.ClearRequestContext()._remove_cached_context() - self.assertIsNone(context.get_current()) - - def test_store_current_resets_correctly(self): - # By default a new context is stored. - ctx = context.RequestContext() - - # the use of the fixture should put us in a reset state, not - # doing so is a bug because when this fixture is consumed by - # other test suites there is no guaruntee that all tests use - # this fixture. - self.useFixture(fixture.ClearRequestContext()) - self.assertIsNone(context.get_current()) - - ctx = context.RequestContext() - self.assertIs(context.get_current(), ctx) - fixture.ClearRequestContext()._remove_cached_context() - self.assertIsNone(context.get_current()) diff --git a/oslo_context/version.py b/oslo_context/version.py deleted file mode 100644 index 62ce6e6..0000000 --- a/oslo_context/version.py +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2016 OpenStack Foundation -# -# 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. - - -import pbr.version - -version_info = pbr.version.VersionInfo('oslo_context') diff --git a/releasenotes/notes/add_reno-3b4ae0789e9c45b4.yaml b/releasenotes/notes/add_reno-3b4ae0789e9c45b4.yaml deleted file mode 100644 index 46a2da6..0000000 --- a/releasenotes/notes/add_reno-3b4ae0789e9c45b4.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -other: - - Switch to reno for managing release notes. \ No newline at end of file diff --git a/releasenotes/source/_static/.placeholder b/releasenotes/source/_static/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/releasenotes/source/_templates/.placeholder b/releasenotes/source/_templates/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/releasenotes/source/conf.py b/releasenotes/source/conf.py deleted file mode 100644 index ada9ce0..0000000 --- a/releasenotes/source/conf.py +++ /dev/null @@ -1,273 +0,0 @@ -# -*- coding: utf-8 -*- -# 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. - -# This file is execfile()d with the current directory set to its -# containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -# sys.path.insert(0, os.path.abspath('.')) - -# -- General configuration ------------------------------------------------ - -# If your documentation needs a minimal Sphinx version, state it here. -# needs_sphinx = '1.0' - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -extensions = [ - 'oslosphinx', - 'reno.sphinxext', -] - -# Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] - -# The suffix of source filenames. -source_suffix = '.rst' - -# The encoding of source files. -# source_encoding = 'utf-8-sig' - -# The master toctree document. -master_doc = 'index' - -# General information about the project. -project = u'oslo.context Release Notes' -copyright = u'2016, oslo.context Developers' - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# The short X.Y version. -from oslo_context.version import version_info as oslo_context_version -# The full version, including alpha/beta/rc tags. -release = oslo_context_version.version_string_with_vcs() -# The short X.Y version. -version = oslo_context_version.canonical_version_string() - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# language = None - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -# today = '' -# Else, today_fmt is used as the format for a strftime call. -# today_fmt = '%B %d, %Y' - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns = [] - -# The reST default role (used for this markup: `text`) to use for all -# documents. -# default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -# add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -# add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -# show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' - -# A list of ignored prefixes for module index sorting. -# modindex_common_prefix = [] - -# If true, keep warnings as "system message" paragraphs in the built documents. -# keep_warnings = False - - -# -- Options for HTML output ---------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = 'default' - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -# html_theme_options = {} - -# Add any paths that contain custom themes here, relative to this directory. -# html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# " v documentation". -# html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -# html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -# html_logo = None - -# The name of an image file (within the static path) to use as favicon of the -# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -# html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] - -# Add any extra paths that contain custom files (such as robots.txt or -# .htaccess) here, relative to this directory. These files are copied -# directly to the root of the documentation. -# html_extra_path = [] - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, -# using the given strftime format. -# html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -# html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -# html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names to -# template names. -# html_additional_pages = {} - -# If false, no module index is generated. -# html_domain_indices = True - -# If false, no index is generated. -# html_use_index = True - -# If true, the index is split into individual pages for each letter. -# html_split_index = False - -# If true, links to the reST sources are added to the pages. -# html_show_sourcelink = True - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -# html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -# html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -# html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -# html_file_suffix = None - -# Output file base name for HTML help builder. -htmlhelp_basename = 'oslo.contextReleaseNotesDoc' - - -# -- Options for LaTeX output --------------------------------------------- - -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # 'preamble': '', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, -# author, documentclass [howto, manual, or own class]). -latex_documents = [ - ('index', 'oslo.contextReleaseNotes.tex', - u'oslo.context Release Notes Documentation', - u'oslo.context Developers', 'manual'), -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -# latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -# latex_use_parts = False - -# If true, show page references after internal links. -# latex_show_pagerefs = False - -# If true, show URL addresses after external links. -# latex_show_urls = False - -# Documents to append as an appendix to all manuals. -# latex_appendices = [] - -# If false, no module index is generated. -# latex_domain_indices = True - - -# -- Options for manual page output --------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - ('index', 'oslo.contextReleaseNotes', - u'oslo.context Release Notes Documentation', - [u'oslo.context Developers'], 1) -] - -# If true, show URL addresses after external links. -# man_show_urls = False - - -# -- Options for Texinfo output ------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - ('index', 'oslo.contextReleaseNotes', - u'oslo.context Release Notes Documentation', - u'oslo.context Developers', 'oslo.contextReleaseNotes', - 'One line description of project.', - 'Miscellaneous'), -] - -# Documents to append as an appendix to all manuals. -# texinfo_appendices = [] - -# If false, no module index is generated. -# texinfo_domain_indices = True - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -# texinfo_show_urls = 'footnote' - -# If true, do not generate a @detailmenu in the "Top" node's menu. -# texinfo_no_detailmenu = False diff --git a/releasenotes/source/index.rst b/releasenotes/source/index.rst deleted file mode 100644 index d3d2708..0000000 --- a/releasenotes/source/index.rst +++ /dev/null @@ -1,8 +0,0 @@ -=========================== - oslo.context Release Notes -=========================== - - .. toctree:: - :maxdepth: 1 - - unreleased diff --git a/releasenotes/source/unreleased.rst b/releasenotes/source/unreleased.rst deleted file mode 100644 index 5860a46..0000000 --- a/releasenotes/source/unreleased.rst +++ /dev/null @@ -1,5 +0,0 @@ -========================== - Unreleased Release Notes -========================== - -.. release-notes:: diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 95d0fe8..0000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -# The order of packages is significant, because pip processes them in the order -# of appearance. Changing the order has an impact on the overall integration -# process, which may cause wedges in the gate later. - -pbr>=1.6 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index e18818d..0000000 --- a/setup.cfg +++ /dev/null @@ -1,52 +0,0 @@ -[metadata] -name = oslo.context -summary = Oslo Context library -description-file = - README.rst -author = OpenStack -author-email = openstack-dev@lists.openstack.org -home-page = http://launchpad.net/oslo -classifier = - Environment :: OpenStack - Intended Audience :: Information Technology - Intended Audience :: System Administrators - License :: OSI Approved :: Apache Software License - Operating System :: POSIX :: Linux - Programming Language :: Python - Programming Language :: Python :: 2 - Programming Language :: Python :: 2.7 - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.4 - Programming Language :: Python :: 3.5 - -[files] -packages = - oslo_context - -[pbr] -warnerrors = true - -[build_sphinx] -source-dir = doc/source -build-dir = doc/build -all_files = 1 - -[upload_sphinx] -upload-dir = doc/build/html - -[compile_catalog] -directory = oslo_context/locale -domain = oslo_context - -[update_catalog] -domain = oslo_context -output_dir = oslo_context/locale -input_file = oslo_context/locale/oslo_context.pot - -[extract_messages] -keywords = _ gettext ngettext l_ lazy_gettext -mapping_file = babel.cfg -output_file = oslo_context/locale/oslo_context.pot - -[wheel] -universal = true diff --git a/setup.py b/setup.py deleted file mode 100644 index 782bb21..0000000 --- a/setup.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. -# -# 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. - -# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT -import setuptools - -# In python < 2.7.4, a lazy loading of package `pbr` will break -# setuptools if some other modules registered functions in `atexit`. -# solution from: http://bugs.python.org/issue15881#msg170215 -try: - import multiprocessing # noqa -except ImportError: - pass - -setuptools.setup( - setup_requires=['pbr>=1.8'], - pbr=True) diff --git a/test-requirements.txt b/test-requirements.txt deleted file mode 100644 index 79fca04..0000000 --- a/test-requirements.txt +++ /dev/null @@ -1,12 +0,0 @@ -# The order of packages is significant, because pip processes them in the order -# of appearance. Changing the order has an impact on the overall integration -# process, which may cause wedges in the gate later. - -hacking<0.11,>=0.10.0 -oslotest>=1.10.0 # Apache-2.0 -coverage>=3.6 # Apache-2.0 - -# These are needed for docs generation -oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0 -sphinx!=1.3b1,<1.3,>=1.2.1 # BSD -reno>=1.8.0 # Apache2 diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 7b473bc..0000000 --- a/tox.ini +++ /dev/null @@ -1,40 +0,0 @@ -[tox] -minversion = 1.6 -envlist = py35,py34,py27,pypy,pep8 - -[testenv] -deps = -r{toxinidir}/test-requirements.txt -commands = python setup.py testr --slowest --testr-args='{posargs}' - -[testenv:pep8] -commands = flake8 - -[testenv:venv] -commands = {posargs} - -[testenv:docs] -commands = python setup.py build_sphinx - -[testenv:cover] -commands = python setup.py test --coverage --coverage-package-name=oslo_context --testr-args='{posargs}' - -[flake8] -# E123, E125 skipped as they are invalid PEP-8. - -show-source = True -ignore = E123,E125 -exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build - -[hacking] -import_exceptions = - -[testenv:pip-missing-reqs] -# do not install test-requirements as that will pollute the virtualenv for -# determining missing packages -# this also means that pip-missing-reqs must be installed separately, outside -# of the requirements.txt files -deps = pip_missing_reqs -commands = pip-missing-reqs -d --ignore-module=oslo_context* --ignore-file=oslo_context/tests/* --ignore-file=tests/ oslo_context - -[testenv:releasenotes] -commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html