oslo.context-2.20.0/0000775000175100017510000000000013224676267014275 5ustar zuulzuul00000000000000oslo.context-2.20.0/HACKING.rst0000666000175100017510000000022213224676027016063 0ustar zuulzuul00000000000000oslo.context Style Commandments =============================== Read the OpenStack Style Commandments https://docs.openstack.org/hacking/latest/ oslo.context-2.20.0/test-requirements.txt0000666000175100017510000000063213224676050020527 0ustar zuulzuul00000000000000# 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. fixtures>=3.0.0 # Apache-2.0/BSD hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 oslotest>=1.10.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 # Bandit security code scanner bandit>=1.1.0 # Apache-2.0 oslo.context-2.20.0/CONTRIBUTING.rst0000666000175100017510000000102513224676027016730 0ustar zuulzuul00000000000000If you would like to contribute to the development of OpenStack, you must follow the steps in this page: https://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: https://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 oslo.context-2.20.0/ChangeLog0000664000175100017510000001504413224676266016052 0ustar zuulzuul00000000000000CHANGES ======= 2.20.0 ------ * Updated from global requirements * Follow the new PTI for document build * Remove -U from pip install * Avoid tox\_install.sh for constraints support * add bandit to pep8 job * Remove setting of version/release from releasenotes 2.19.3 ------ * Ouput a placeholder instead of the auth\_token 2.19.2 ------ * Make from\_dict extensible 2.19.1 ------ * Output 'project' key in context's to\_dict function * Rename deprecated context params 2.19.0 ------ * Updated from global requirements 2.18.1 ------ * Update the documentation link for doc migration * Revert "Postpone deprecation warnings to Pike" 2.18.0 ------ * Updated from global requirements * Remove use of positional decorator * Update reno for stable/pike * Updated from global requirements 2.17.0 ------ * Fix URLs according to document migration * Cleanup document formatting * rearrange the documentation to fit into the new standard layout 2.16.0 ------ * Switch from oslosphinx to openstackdocstheme * Updated from global requirements 2.15.0 ------ * Optimize the link address * Remove pbr warnerrors in favor of sphinx check * Updated from global requirements 2.14.0 ------ * Provide unified calling interface for global\_id * Add global\_request\_id to context * Updated from global requirements * Updated from global requirements * Updated from global requirements 2.13.0 ------ * Updated from global requirements * [Fix gate]Update test requirement * Updated from global requirements * pbr.version.VersionInfo needs package name (oslo.xyz and not oslo\_xyz) * Postpone deprecation warnings to Pike * Update reno for stable/ocata 2.12.0 ------ * Updated from global requirements * Remove references to Python 3.4 * Add Constraints support * Show team and repo badges on README * Add the service token details to context * Reformat the Context.\_\_init\_\_ arguments * Move existing attributes to \_id suffixed attributes 2.11.0 ------ * Updated from global requirements * Revert "Fix X-User and X-Tenant deprecated headers in from\_environ" * Updated from global requirements * Updated from global requirements * Changed the home-page link 2.10.0 ------ * Enable release notes translation * Updated from global requirements * Provide a way to deprecate policy values * Update reno for stable/newton * Fix typos * Fix X-User and X-Tenant deprecated headers in from\_environ 2.9.0 ----- * Updated from global requirements 2.8.0 ----- * Delete H803 in flake8 ignore list * Fix parameters of assertEqual are misplaced * Manually specify from\_dict parameters 2.7.0 ----- * Add Python 3.5 classifier and venv * Emit deprecation warnings when positional args passed 2.6.0 ----- * Allow deprecated X-Tenant-Name in from\_environ * Handle openstack.request\_id in from\_environ * Add is\_admin\_project to context * Updated from global requirements 2.5.0 ----- * Add reno for releasenotes management * Add oslo.context name attributes matching ids 2.4.0 ----- * Trivial: ignore openstack/common in flake8 exclude list * Strip roles in from\_environ * Allow deprecated headers in from\_environ 2.3.0 ----- * Drop babel as requirement since its not used * Updated from global requirements * Ensure to\_dict() supports unicode 2.2.0 ----- * Standardize an oslo.policy credentials dictionary * Revert "Add common oslo.log format parameters" * Add roles to context 2.1.0 ----- * Agnostic approach to construct context from\_dict * Add common oslo.log format parameters 2.0.0 ----- * Improve Context docs with example syntax * Define method for oslo.log context parameters * Add additional unit tests * Fix request\_id type on Python 3: use text (Unicode) * Updated from global requirements * Provide a helper to load a context from environment 1.0.1 ----- * Revert "Add properties for id attributes" * Add properties for id attributes * Trival: Remove 'MANIFEST.in' 1.0.0 ----- * Updated from global requirements * Remove python 2.6 classifier * Remove python 2.6 and cleanup tox.ini 0.9.0 ----- * Remove reference to undefined attributes 0.8.0 ----- * Fix coverage configuration and execution 0.7.0 ----- * Add shields.io version/downloads links/badges into README.rst * Change ignore-errors to ignore\_errors * Updated from global requirements 0.6.0 ----- * Updated from global requirements * Updated from global requirements * Updated from global requirements 0.5.0 ----- * Updated from global requirements * Updated from global requirements * Add tox target to find missing requirements * Updated from global requirements * Updated from global requirements 0.4.0 ----- * Remove support for Python 3.3 * Do not sync run\_cross\_tests.sh * Updated from global requirements 0.3.0 ----- * Uncap library requirements for liberty * Standardize setup.cfg summary for oslo libs * Update to latest hacking * Updated from global requirements * fix bug tracker link 0.2.0 ----- * ensure we reset contexts when fixture is used * Activate pep8 check that \_ is imported 0.1.0 ----- * Workflow documentation is now in infra-manual * Documentation cleanup * Add ClearRequestContext fixture * Cache the current context for the thread * Add docstring to get\_admin\_context() * Change instance\_uuid to resource\_uuid * Better information in the README * Generate better documentation for the module * Move out of the oslo namespace package * get test to actually run * fix links and requirements to latest versions * Make the unit test run properly - fix import * exported from oslo-incubator by graduate.sh * Add a RequestContext.from\_dict method * Use oslotest instead of common test module * Python 3: enable tests/unit/middleware/test\_request\_id.py * Add model\_query() to db.sqlalchemy.utils module * Adding domain to context and log * Remove vim header * Remove uuidutils imports in oslo modules * Revert "Removes generate\_uuid from uuidutils" * Removes generate\_uuid from uuidutils * Adding instance\_uuid to context and log * Replace using tests.utils with openstack.common.test * Fix bad default for show\_deleted * Enable hacking H404 test * Replaces the standard uuid with common in the context module * Fix Copyright Headers - Rename LLC to Foundation * Fix inconsistency with auth\_tok/auth\_token * Replace direct use of testtools BaseTestCase * Use testtools as test base class * Move get\_context\_from\_function\_and\_args() to context.py * Added dictify() and uuids to the common request context * add context 'tests' * make the skeleton project a template * reog from import merge * Add some more generic middleware, request context, utils, and versioning. Add basic template for server binary * Initial skeleton project oslo.context-2.20.0/requirements.txt0000666000175100017510000000042613224676027017557 0ustar zuulzuul00000000000000# 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!=2.1.0,>=2.0.0 # Apache-2.0 debtcollector>=1.2.0 # Apache-2.0 oslo.context-2.20.0/LICENSE0000666000175100017510000002363713224676027015311 0ustar zuulzuul00000000000000 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. oslo.context-2.20.0/AUTHORS0000664000175100017510000000325213224676266015346 0ustar zuulzuul00000000000000Akihiro Motoki Alexander Gorodnev Andreas Jaeger Andrew Bogott Atsushi SAKAI Ben Nemec ChangBo Guo(gcb) Cyril Roelandt Davanum Srinivas (dims) Davanum Srinivas Davanum Srinivas Dina Belova Doug Hellmann Eric Brown Flavio Percoco Flavio Percoco James Carey Jamie Lennox Jason Kölker Jay Pipes Jeremy Stanley Joe Gordon Joshua Harlow Joshua Harlow Juan Antonio Osorio Robles Kirill Bespalov Michael Basnight Monty Taylor Morgan Fainberg OpenStack Release Bot Ronald Bradford Sean Dague Steve Martinelli Thomas Herve Tony Breeds Van Hung Pham Victor Sergeyev Victor Stinner Vu Cong Tuan Wei Li Zhongyue Luo Zuul lingyongxu melissaml ricolin yanheven oslo.context-2.20.0/PKG-INFO0000664000175100017510000000373313224676267015400 0ustar zuulzuul00000000000000Metadata-Version: 1.1 Name: oslo.context Version: 2.20.0 Summary: Oslo Context library Home-page: https://docs.openstack.org/oslo.context/latest/ Author: OpenStack Author-email: openstack-dev@lists.openstack.org License: UNKNOWN Description-Content-Type: UNKNOWN Description: ==================== Oslo Context Library ==================== 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: https://docs.openstack.org/oslo.context/latest/ * Source: https://git.openstack.org/cgit/openstack/oslo.context * Bugs: https://bugs.launchpad.net/oslo.context Team and repository tags ======================== .. image:: https://governance.openstack.org/badges/oslo.context.svg :target: https://governance.openstack.org/reference/tags/index.html .. Change things from this point on .. 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 Platform: UNKNOWN Classifier: Environment :: OpenStack Classifier: Intended Audience :: Information Technology Classifier: Intended Audience :: System Administrators Classifier: License :: OSI Approved :: Apache Software License Classifier: Operating System :: POSIX :: Linux Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.5 oslo.context-2.20.0/tox.ini0000666000175100017510000000337413224676050015607 0ustar zuulzuul00000000000000[tox] minversion = 2.0 envlist = py35,py27,pypy,pep8 [testenv] install_command = pip install {opts} {packages} deps = -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} -r{toxinidir}/test-requirements.txt -r{toxinidir}/requirements.txt commands = python setup.py testr --slowest --testr-args='{posargs}' [testenv:pep8] deps = -r{toxinidir}/test-requirements.txt commands = flake8 # Run security linter bandit -r oslo_context -x tests -n5 [testenv:venv] commands = {posargs} [testenv:docs] deps = -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} -r{toxinidir}/doc/requirements.txt commands = sphinx-build -b html doc/source doc/build/html [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] deps = -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} -r{toxinidir}/doc/requirements.txt commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html oslo.context-2.20.0/.mailmap0000666000175100017510000000013113224676027015705 0ustar zuulzuul00000000000000# Format is: # # oslo.context-2.20.0/releasenotes/0000775000175100017510000000000013224676267016766 5ustar zuulzuul00000000000000oslo.context-2.20.0/releasenotes/source/0000775000175100017510000000000013224676267020266 5ustar zuulzuul00000000000000oslo.context-2.20.0/releasenotes/source/conf.py0000666000175100017510000002154413224676027021567 0ustar zuulzuul00000000000000# -*- 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 = [ 'openstackdocstheme', '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' # Release notes do not need a version in the title, they span # multiple versions. # The full version, including alpha/beta/rc tags. release = '' # The short X.Y version. version = '' # 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 = 'openstackdocs' # 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' html_last_updated_fmt = '%Y-%m-%d %H:%M' # 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 # -- Options for Internationalization output ------------------------------ locale_dirs = ['locale/'] # openstackdocstheme options repository_name = 'openstack/oslo.context' bug_project = 'oslo.context' bug_tag = '' oslo.context-2.20.0/releasenotes/source/newton.rst0000666000175100017510000000021613224676027022325 0ustar zuulzuul00000000000000============================= Newton Series Release Notes ============================= .. release-notes:: :branch: origin/stable/newton oslo.context-2.20.0/releasenotes/source/_static/0000775000175100017510000000000013224676267021714 5ustar zuulzuul00000000000000oslo.context-2.20.0/releasenotes/source/_static/.placeholder0000666000175100017510000000000013224676027024161 0ustar zuulzuul00000000000000oslo.context-2.20.0/releasenotes/source/unreleased.rst0000666000175100017510000000014413224676027023142 0ustar zuulzuul00000000000000========================== Unreleased Release Notes ========================== .. release-notes:: oslo.context-2.20.0/releasenotes/source/index.rst0000666000175100017510000000024213224676027022121 0ustar zuulzuul00000000000000=========================== oslo.context Release Notes =========================== .. toctree:: :maxdepth: 1 unreleased pike ocata newton oslo.context-2.20.0/releasenotes/source/ocata.rst0000666000175100017510000000023013224676027022076 0ustar zuulzuul00000000000000=================================== Ocata Series Release Notes =================================== .. release-notes:: :branch: origin/stable/ocata oslo.context-2.20.0/releasenotes/source/_templates/0000775000175100017510000000000013224676267022423 5ustar zuulzuul00000000000000oslo.context-2.20.0/releasenotes/source/_templates/.placeholder0000666000175100017510000000000013224676027024670 0ustar zuulzuul00000000000000oslo.context-2.20.0/releasenotes/source/pike.rst0000666000175100017510000000021713224676027021744 0ustar zuulzuul00000000000000=================================== Pike Series Release Notes =================================== .. release-notes:: :branch: stable/pike oslo.context-2.20.0/releasenotes/notes/0000775000175100017510000000000013224676267020116 5ustar zuulzuul00000000000000oslo.context-2.20.0/releasenotes/notes/dont-leak-auth-token-fb7075316cf87b7c.yaml0000666000175100017510000000041213224676027027154 0ustar zuulzuul00000000000000--- security: - | The ``get_logging_values`` function no longer outputs the auth_token, but instead leaves it as ``***`` instead. As the name suggests, this function is meant for logging, and letting the auth_token there might leak sensitive data. oslo.context-2.20.0/releasenotes/notes/add_reno-3b4ae0789e9c45b4.yaml0000666000175100017510000000007113224676027024773 0ustar zuulzuul00000000000000--- other: - Switch to reno for managing release notes.oslo.context-2.20.0/.coveragerc0000666000175100017510000000016313224676027016412 0ustar zuulzuul00000000000000[run] branch = True source = oslo_context omit = oslo_context/tests/* [report] ignore_errors = True precision = 2 oslo.context-2.20.0/.testr.conf0000666000175100017510000000051413224676027016357 0ustar zuulzuul00000000000000[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 oslo.context-2.20.0/README.rst0000666000175100017510000000173213224676027015763 0ustar zuulzuul00000000000000==================== Oslo Context Library ==================== 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: https://docs.openstack.org/oslo.context/latest/ * Source: https://git.openstack.org/cgit/openstack/oslo.context * Bugs: https://bugs.launchpad.net/oslo.context Team and repository tags ======================== .. image:: https://governance.openstack.org/badges/oslo.context.svg :target: https://governance.openstack.org/reference/tags/index.html .. Change things from this point on .. 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 oslo.context-2.20.0/doc/0000775000175100017510000000000013224676267015042 5ustar zuulzuul00000000000000oslo.context-2.20.0/doc/requirements.txt0000666000175100017510000000055713224676050020325 0ustar zuulzuul00000000000000# 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. # These are needed for docs generation openstackdocstheme>=1.17.0 # Apache-2.0 sphinx>=1.6.2 # BSD reno>=2.5.0 # Apache-2.0 fixtures>=3.0.0 # Apache-2.0/BSD oslo.context-2.20.0/doc/source/0000775000175100017510000000000013224676267016342 5ustar zuulzuul00000000000000oslo.context-2.20.0/doc/source/user/0000775000175100017510000000000013224676267017320 5ustar zuulzuul00000000000000oslo.context-2.20.0/doc/source/user/usage.rst0000666000175100017510000001066413224676027021161 0ustar zuulzuul00000000000000======= 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: https://docs.openstack.org/oslo.log/latest/ .. highlight:: python .. literalinclude:: examples/usage_simple.py :linenos: :lines: 28-42 :emphasize-lines: 2,14 Source: :ref:`example_usage_simple.py` **Example Logging Output:** .. code-block:: none 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: https://docs.openstack.org/oslo.log/latest/configuration/index.html#DEFAULT.logging_default_format_string .. _logging_context_format_string: https://docs.openstack.org/oslo.log/latest/configuration/index.html#DEFAULT.logging_context_format_string .. _logging_user_identity_format: https://docs.openstack.org/oslo.log/latest/configuration/index.html#DEFAULT.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: * global_request_id - A request id (e.g. req-9f2c484a-b504-4fd9-b44c-4357544cca50) which may have been sent in from another service to indicate this is part of a chain of requests. * 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:** .. code-block:: none 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:** .. code-block:: none 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: https://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:** .. code-block:: none 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 oslo.context-2.20.0/doc/source/user/examples.rst0000666000175100017510000000131213224676027021661 0ustar zuulzuul00000000000000========== 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 repository`_ of this project. .. _online git repository: https://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: oslo.context-2.20.0/doc/source/user/history.rst0000666000175100017510000000004013224676027021541 0ustar zuulzuul00000000000000.. include:: ../../../ChangeLog oslo.context-2.20.0/doc/source/user/examples/0000775000175100017510000000000013224676267021136 5ustar zuulzuul00000000000000oslo.context-2.20.0/doc/source/user/examples/usage.py0000666000175100017510000000310013224676027022602 0ustar zuulzuul00000000000000#!/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 representative 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: https://docs.openstack.org/oslo.context/latest/user/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) oslo.context-2.20.0/doc/source/user/examples/usage_simple.py0000666000175100017510000000223213224676027024160 0ustar zuulzuul00000000000000#!/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: https://docs.openstack.org/oslo.context/latest/user/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") oslo.context-2.20.0/doc/source/user/examples/usage_user_identity.py0000666000175100017510000000274213224676027025564 0ustar zuulzuul00000000000000#!/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: https://docs.openstack.org/oslo.context/latest/user/index.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") oslo.context-2.20.0/doc/source/user/index.rst0000666000175100017510000000033713224676027021160 0ustar zuulzuul00000000000000================== Using oslo.context ================== .. toctree:: :maxdepth: 2 usage examples .. history contains a lot of sections, toctree with maxdepth 1 is used. .. toctree:: :maxdepth: 1 history oslo.context-2.20.0/doc/source/conf.py0000777000175100017510000000533613224676027017647 0ustar zuulzuul00000000000000# -*- 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', 'openstackdocstheme', ] # 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_static_path = ['static'] html_theme = 'openstackdocs' # 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' html_last_updated_fmt = '%Y-%m-%d %H:%M' # 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'), ] # openstackdocstheme options repository_name = 'openstack/oslo.context' bug_project = 'oslo.context' bug_tag = '' # Example configuration for intersphinx: refer to the Python standard library. #intersphinx_mapping = {'http://docs.python.org/': None} oslo.context-2.20.0/doc/source/install/0000775000175100017510000000000013224676267020010 5ustar zuulzuul00000000000000oslo.context-2.20.0/doc/source/install/index.rst0000666000175100017510000000013613224676027021645 0ustar zuulzuul00000000000000============ Installation ============ At the command line:: $ pip install oslo.context oslo.context-2.20.0/doc/source/index.rst0000666000175100017510000000047113224676027020201 0ustar zuulzuul00000000000000.. include:: ../../README.rst Contents ======== .. toctree:: :maxdepth: 2 install/index user/index contributor/index Code Documentation ================== .. toctree:: :maxdepth: 1 reference/index Indices and tables ================== * :ref:`genindex` * :ref:`modindex` * :ref:`search` oslo.context-2.20.0/doc/source/reference/0000775000175100017510000000000013224676267020300 5ustar zuulzuul00000000000000oslo.context-2.20.0/doc/source/reference/fixture.rst0000666000175100017510000000024713224676027022517 0ustar zuulzuul00000000000000The :mod:`oslo_context.fixture` Module ====================================== .. automodule:: oslo_context.fixture :members: :undoc-members: :show-inheritance: oslo.context-2.20.0/doc/source/reference/context.rst0000666000175100017510000000024713224676027022515 0ustar zuulzuul00000000000000The :mod:`oslo_context.context` Module ====================================== .. automodule:: oslo_context.context :members: :undoc-members: :show-inheritance: oslo.context-2.20.0/doc/source/reference/index.rst0000666000175100017510000000014713224676027022137 0ustar zuulzuul00000000000000============= API reference ============= .. toctree:: :maxdepth: 1 context.rst fixture.rst oslo.context-2.20.0/doc/source/contributor/0000775000175100017510000000000013224676267020714 5ustar zuulzuul00000000000000oslo.context-2.20.0/doc/source/contributor/index.rst0000666000175100017510000000012413224676027022546 0ustar zuulzuul00000000000000============== Contributing ============== .. include:: ../../../CONTRIBUTING.rst oslo.context-2.20.0/oslo.context.egg-info/0000775000175100017510000000000013224676267020426 5ustar zuulzuul00000000000000oslo.context-2.20.0/oslo.context.egg-info/requires.txt0000664000175100017510000000005013224676266023020 0ustar zuulzuul00000000000000pbr!=2.1.0,>=2.0.0 debtcollector>=1.2.0 oslo.context-2.20.0/oslo.context.egg-info/SOURCES.txt0000664000175100017510000000265113224676267022316 0ustar zuulzuul00000000000000.coveragerc .mailmap .testr.conf AUTHORS CONTRIBUTING.rst ChangeLog HACKING.rst LICENSE README.rst babel.cfg requirements.txt setup.cfg setup.py test-requirements.txt tox.ini doc/requirements.txt doc/source/conf.py doc/source/index.rst doc/source/contributor/index.rst doc/source/install/index.rst doc/source/reference/context.rst doc/source/reference/fixture.rst doc/source/reference/index.rst doc/source/user/examples.rst doc/source/user/history.rst doc/source/user/index.rst doc/source/user/usage.rst doc/source/user/examples/usage.py doc/source/user/examples/usage_simple.py doc/source/user/examples/usage_user_identity.py oslo.context.egg-info/PKG-INFO oslo.context.egg-info/SOURCES.txt oslo.context.egg-info/dependency_links.txt oslo.context.egg-info/not-zip-safe oslo.context.egg-info/pbr.json oslo.context.egg-info/requires.txt oslo.context.egg-info/top_level.txt oslo_context/__init__.py oslo_context/context.py oslo_context/fixture.py oslo_context/version.py oslo_context/tests/__init__.py oslo_context/tests/test_context.py oslo_context/tests/test_fixture.py releasenotes/notes/add_reno-3b4ae0789e9c45b4.yaml releasenotes/notes/dont-leak-auth-token-fb7075316cf87b7c.yaml releasenotes/source/conf.py releasenotes/source/index.rst releasenotes/source/newton.rst releasenotes/source/ocata.rst releasenotes/source/pike.rst releasenotes/source/unreleased.rst releasenotes/source/_static/.placeholder releasenotes/source/_templates/.placeholderoslo.context-2.20.0/oslo.context.egg-info/pbr.json0000664000175100017510000000005613224676266022104 0ustar zuulzuul00000000000000{"git_version": "bfdeba6", "is_release": true}oslo.context-2.20.0/oslo.context.egg-info/dependency_links.txt0000664000175100017510000000000113224676266024473 0ustar zuulzuul00000000000000 oslo.context-2.20.0/oslo.context.egg-info/not-zip-safe0000664000175100017510000000000113224676240022643 0ustar zuulzuul00000000000000 oslo.context-2.20.0/oslo.context.egg-info/PKG-INFO0000664000175100017510000000373313224676266021530 0ustar zuulzuul00000000000000Metadata-Version: 1.1 Name: oslo.context Version: 2.20.0 Summary: Oslo Context library Home-page: https://docs.openstack.org/oslo.context/latest/ Author: OpenStack Author-email: openstack-dev@lists.openstack.org License: UNKNOWN Description-Content-Type: UNKNOWN Description: ==================== Oslo Context Library ==================== 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: https://docs.openstack.org/oslo.context/latest/ * Source: https://git.openstack.org/cgit/openstack/oslo.context * Bugs: https://bugs.launchpad.net/oslo.context Team and repository tags ======================== .. image:: https://governance.openstack.org/badges/oslo.context.svg :target: https://governance.openstack.org/reference/tags/index.html .. Change things from this point on .. 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 Platform: UNKNOWN Classifier: Environment :: OpenStack Classifier: Intended Audience :: Information Technology Classifier: Intended Audience :: System Administrators Classifier: License :: OSI Approved :: Apache Software License Classifier: Operating System :: POSIX :: Linux Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.5 oslo.context-2.20.0/oslo.context.egg-info/top_level.txt0000664000175100017510000000001513224676266023153 0ustar zuulzuul00000000000000oslo_context oslo.context-2.20.0/setup.cfg0000666000175100017510000000226313224676267016123 0ustar zuulzuul00000000000000[metadata] name = oslo.context summary = Oslo Context library description-file = README.rst author = OpenStack author-email = openstack-dev@lists.openstack.org home-page = https://docs.openstack.org/oslo.context/latest/ 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.5 [files] packages = oslo_context [build_sphinx] source-dir = doc/source build-dir = doc/build all_files = 1 warning-is-error = 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 [egg_info] tag_build = tag_date = 0 oslo.context-2.20.0/babel.cfg0000666000175100017510000000002113224676027016010 0ustar zuulzuul00000000000000[python: **.py] oslo.context-2.20.0/oslo_context/0000775000175100017510000000000013224676267017015 5ustar zuulzuul00000000000000oslo.context-2.20.0/oslo_context/tests/0000775000175100017510000000000013224676267020157 5ustar zuulzuul00000000000000oslo.context-2.20.0/oslo_context/tests/test_context.py0000666000175100017510000006512013224676027023254 0ustar zuulzuul00000000000000# -*- 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 fixtures import hashlib import uuid import warnings 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 WarningsFixture(fixtures.Fixture): def __init__(self, action="always", category=DeprecationWarning): super(WarningsFixture, self).__init__() self.action = action self.category = category def setUp(self): super(WarningsFixture, self).setUp() self._w = warnings.catch_warnings(record=True) self.log = self._w.__enter__() self.addCleanup(self._w.__exit__) warnings.simplefilter(self.action, self.category) def __len__(self): return len(self.log) def __getitem__(self, item): return self.log[item] class Object(object): pass class TestContext(context.RequestContext): """A test context with additional members This is representative of how at least some of our consumers use the RequestContext class in their projects. """ FROM_DICT_EXTRA_KEYS = ['foo'] def __init__(self, foo=None, **kwargs): super(TestContext, self).__init__(**kwargs) self.foo = foo def to_dict(self): d = super(TestContext, self).to_dict() d['foo'] = self.foo return d class ContextTest(test_base.BaseTestCase): def setUp(self): super(ContextTest, self).setUp() self.warnings = self.useFixture(WarningsFixture()) 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.project_id) 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", "global_request_id": "req-uuid", "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_id) self.assertEqual(dct['tenant'], ctx.project_id) self.assertEqual(dct['domain'], ctx.domain_id) self.assertEqual(dct['user_domain'], ctx.user_domain_id) self.assertEqual(dct['project_domain'], ctx.project_domain_id) 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['global_request_id'], ctx.global_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_id) self.assertIsNone(ctx.project_id) self.assertFalse(ctx.is_admin) self.assertTrue(ctx.read_only) self.assertRaises(KeyError, lambda: ctx.__dict__['color']) def test_from_dict_overrides(self): dct = { "auth_token": "token1", "user": "user1", "read_only": True, "roles": "role1,role2,role3", "color": "red", "unknown": "" } ctx = context.RequestContext.from_dict(dct, user="user2", project_name="project1") self.assertEqual("token1", ctx.auth_token) self.assertEqual("user2", ctx.user) self.assertEqual("project1", ctx.project_name) self.assertIsNone(ctx.tenant) self.assertFalse(ctx.is_admin) self.assertTrue(ctx.read_only) def test_from_dict_extended(self): initial = TestContext(foo='bar') dct = initial.to_dict() final = TestContext.from_dict(dct) self.assertEqual('bar', final.foo) self.assertEqual(dct, final.to_dict()) 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 global_request_id = uuid.uuid4().hex service_token = uuid.uuid4().hex service_user_id = uuid.uuid4().hex service_user_name = uuid.uuid4().hex service_user_domain_id = uuid.uuid4().hex service_user_domain_name = uuid.uuid4().hex service_project_id = uuid.uuid4().hex service_project_name = uuid.uuid4().hex service_project_domain_id = uuid.uuid4().hex service_project_domain_name = uuid.uuid4().hex service_roles = [uuid.uuid4().hex, uuid.uuid4().hex, 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, 'HTTP_X_SERVICE_TOKEN': service_token, 'HTTP_X_SERVICE_USER_ID': service_user_id, 'HTTP_X_SERVICE_USER_NAME': service_user_name, 'HTTP_X_SERVICE_USER_DOMAIN_ID': service_user_domain_id, 'HTTP_X_SERVICE_USER_DOMAIN_NAME': service_user_domain_name, 'HTTP_X_SERVICE_PROJECT_ID': service_project_id, 'HTTP_X_SERVICE_PROJECT_NAME': service_project_name, 'HTTP_X_SERVICE_PROJECT_DOMAIN_ID': service_project_domain_id, 'HTTP_X_SERVICE_PROJECT_DOMAIN_NAME': service_project_domain_name, 'HTTP_X_SERVICE_ROLES': ','.join(service_roles), 'openstack.request_id': request_id, 'openstack.global_request_id': global_request_id, } ctx = context.RequestContext.from_environ(environ) self.assertEqual(auth_token, ctx.auth_token) self.assertEqual(user_id, ctx.user_id) self.assertEqual(user_name, ctx.user_name) self.assertEqual(project_id, ctx.project_id) self.assertEqual(project_name, ctx.project_name) self.assertEqual(user_domain_id, ctx.user_domain_id) self.assertEqual(user_domain_name, ctx.user_domain_name) self.assertEqual(project_domain_id, ctx.project_domain_id) self.assertEqual(project_domain_name, ctx.project_domain_name) self.assertEqual(roles, ctx.roles) self.assertEqual(request_id, ctx.request_id) self.assertEqual(global_request_id, ctx.global_request_id) self.assertEqual(service_token, ctx.service_token) self.assertEqual(service_user_id, ctx.service_user_id) self.assertEqual(service_user_name, ctx.service_user_name) self.assertEqual(service_user_domain_id, ctx.service_user_domain_id) self.assertEqual(service_user_domain_name, ctx.service_user_domain_name) self.assertEqual(service_project_id, ctx.service_project_id) self.assertEqual(service_project_name, ctx.service_project_name) self.assertEqual(service_project_domain_id, ctx.service_project_domain_id) self.assertEqual(service_project_domain_name, ctx.service_project_domain_name) self.assertEqual(service_roles, ctx.service_roles) 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.project_id) 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(new, ctx.user) ctx = context.RequestContext.from_environ(environ=environ, user=override) self.assertEqual(override, ctx.user) environ = {'HTTP_X_TENANT': old, 'HTTP_X_PROJECT_ID': new} ctx = context.RequestContext.from_environ(environ=environ) self.assertEqual(new, ctx.project_id) ctx = context.RequestContext.from_environ(environ=environ, tenant=override) self.assertEqual(override, ctx.project_id) environ = {'HTTP_X_TENANT_NAME': old, 'HTTP_X_PROJECT_NAME': new} ctx = context.RequestContext.from_environ(environ=environ) self.assertEqual(new, ctx.project_name) def test_from_environ_strip_roles(self): environ = {'HTTP_X_ROLES': ' abc\t,\ndef\n,ghi\n\n', 'HTTP_X_SERVICE_ROLES': ' jkl\t,\nmno\n,pqr\n\n'} ctx = context.RequestContext.from_environ(environ=environ) self.assertEqual(['abc', 'def', 'ghi'], ctx.roles) self.assertEqual(['jkl', 'mno', 'pqr'], ctx.service_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" global_request_id = "req-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, global_request_id=global_request_id, resource_uuid=resource_uuid) self.assertEqual(auth_token, ctx.auth_token) self.assertEqual(user_id, ctx.user_id) self.assertEqual(user_name, ctx.user_name) self.assertEqual(project_id, ctx.project_id) self.assertEqual(project_name, ctx.project_name) self.assertEqual(domain_id, ctx.domain_id) self.assertEqual(domain_name, ctx.domain_name) self.assertEqual(user_domain_id, ctx.user_domain_id) self.assertEqual(user_domain_name, ctx.user_domain_name) self.assertEqual(project_domain_id, ctx.project_domain_id) 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.assertEqual(d['auth_token'], '***') 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('global_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_no_global_id_by_default(self): ctx = context.RequestContext() self.assertIsNone(ctx.global_request_id) d = ctx.to_dict() self.assertIsNone(d['global_request_id']) 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] service_user_id = uuid.uuid4().hex service_project_id = uuid.uuid4().hex service_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, service_user_id=service_user_id, service_project_id=service_project_id, service_roles=service_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, 'service_user_id': service_user_id, 'service_user_domain_id': None, 'service_project_id': service_project_id, 'service_project_domain_id': None, 'service_roles': service_roles}, ctx.to_policy_values()) ctx = context.RequestContext(user=user, user_domain=user_domain, tenant=tenant, project_domain=project_domain, roles=roles, is_admin_project=False, service_user_id=service_user_id, service_project_id=service_project_id, service_roles=service_roles) self.assertEqual({'user_id': user, 'user_domain_id': user_domain, 'project_id': tenant, 'project_domain_id': project_domain, 'roles': roles, 'is_admin_project': False, 'service_user_id': service_user_id, 'service_user_domain_id': None, 'service_project_id': service_project_id, 'service_project_domain_id': None, 'service_roles': service_roles}, ctx.to_policy_values()) def test_policy_deprecations(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] ctx = context.RequestContext(user=user, user_domain=user_domain, tenant=tenant, project_domain=project_domain, roles=roles) policy = ctx.to_policy_values() key = uuid.uuid4().hex val = uuid.uuid4().hex with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") # no warning triggered by adding key to dict policy[key] = val self.assertEqual(0, len(w)) # warning triggered by fetching key from dict self.assertIs(val, policy[key]) self.assertEqual(1, len(w)) self.assertIn(key, str(w[0].message)) def test_deprecated_args(self): user_id = uuid.uuid4().hex project_id = uuid.uuid4().hex domain_id = uuid.uuid4().hex user_domain_id = uuid.uuid4().hex project_domain_id = uuid.uuid4().hex ctx = context.RequestContext(user_id=user_id, project_id=project_id, domain_id=domain_id, user_domain_id=user_domain_id, project_domain_id=project_domain_id) self.assertEqual(0, len(self.warnings)) self.assertEqual(user_id, ctx.user_id) self.assertEqual(project_id, ctx.project_id) self.assertEqual(domain_id, ctx.domain_id) self.assertEqual(user_domain_id, ctx.user_domain_id) self.assertEqual(project_domain_id, ctx.project_domain_id) self.assertEqual(0, len(self.warnings)) self.assertEqual(user_id, ctx.user) self.assertEqual(1, len(self.warnings)) self.assertEqual(project_id, ctx.tenant) self.assertEqual(2, len(self.warnings)) self.assertEqual(domain_id, ctx.domain) self.assertEqual(3, len(self.warnings)) self.assertEqual(user_domain_id, ctx.user_domain) self.assertEqual(4, len(self.warnings)) self.assertEqual(project_domain_id, ctx.project_domain) self.assertEqual(5, len(self.warnings)) oslo.context-2.20.0/oslo_context/tests/__init__.py0000666000175100017510000000000013224676027022252 0ustar zuulzuul00000000000000oslo.context-2.20.0/oslo_context/tests/test_fixture.py0000666000175100017510000000343113224676027023253 0ustar zuulzuul00000000000000# 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()) oslo.context-2.20.0/oslo_context/__init__.py0000666000175100017510000000000013224676027021110 0ustar zuulzuul00000000000000oslo.context-2.20.0/oslo_context/fixture.py0000666000175100017510000000274113224676027021055 0ustar zuulzuul00000000000000# 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 oslo.context-2.20.0/oslo_context/context.py0000666000175100017510000004535013224676027021056 0ustar zuulzuul00000000000000# 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 collections import functools import itertools import threading import uuid import warnings import debtcollector from debtcollector import renames _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_id': ['HTTP_X_USER_ID', 'HTTP_X_USER'], 'project_id': ['HTTP_X_PROJECT_ID', 'HTTP_X_TENANT_ID', 'HTTP_X_TENANT'], 'user_domain_id': ['HTTP_X_USER_DOMAIN_ID'], 'project_domain_id': ['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'], 'global_request_id': ['openstack.global_request_id'], 'service_token': ['HTTP_X_SERVICE_TOKEN'], 'service_user_id': ['HTTP_X_SERVICE_USER_ID'], 'service_user_name': ['HTTP_X_SERVICE_USER_NAME'], 'service_user_domain_id': ['HTTP_X_SERVICE_USER_DOMAIN_ID'], 'service_user_domain_name': ['HTTP_X_SERVICE_USER_DOMAIN_NAME'], 'service_project_id': ['HTTP_X_SERVICE_PROJECT_ID'], 'service_project_name': ['HTTP_X_SERVICE_PROJECT_NAME'], 'service_project_domain_id': ['HTTP_X_SERVICE_PROJECT_DOMAIN_ID'], 'service_project_domain_name': ['HTTP_X_SERVICE_PROJECT_DOMAIN_NAME'], } def generate_request_id(): """Generate a unique request id.""" return 'req-%s' % uuid.uuid4() class _DeprecatedPolicyValues(collections.MutableMapping): """A Dictionary that manages current and deprecated policy values. Anything added to this dictionary after initial creation is considered a deprecated key that we are trying to move services away from. Accessing these values as oslo.policy will do will trigger a DeprecationWarning. """ def __init__(self, data): self._data = data self._deprecated = {} def __getitem__(self, k): try: return self._data[k] except KeyError: pass try: val = self._deprecated[k] except KeyError: pass else: warnings.warn('Policy enforcement is depending on the value of ' '%s. This key is deprecated. Please update your ' 'policy file to use the standard policy values.' % k, DeprecationWarning) return val raise KeyError(k) def __setitem__(self, k, v): self._deprecated[k] = v def __delitem__(self, k): del self._deprecated[k] def __iter__(self): return iter(self._dict) def __len__(self): return len(self._dict) def __str__(self): return self._dict.__str__() def __repr__(self): return self._dict.__repr__() @property def _dict(self): d = self._deprecated.copy() d.update(self._data) return d def _moved_msg(new_name, old_name): if old_name: deprecated_msg = "Property '%(old_name)s' has moved to '%(new_name)s'" deprecated_msg = deprecated_msg % {'old_name': old_name, 'new_name': new_name} debtcollector.deprecate(deprecated_msg, version='2.6', removal_version='3.0', stacklevel=5) def _moved_property(new_name, old_name=None, target=None): if not target: target = new_name def getter(self): _moved_msg(new_name, old_name) return getattr(self, target) def setter(self, value): _moved_msg(new_name, old_name) setattr(self, target, value) def deleter(self): _moved_msg(new_name, old_name) delattr(self, target) return property(getter, setter, deleter) _renamed_kwarg = functools.partial(renames.renamed_kwarg, version='2.18', removal_version='3.0', replace=True) 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}' # Can be overridden in subclasses to specify extra keys that should be # read when constructing a context using from_dict. FROM_DICT_EXTRA_KEYS = [] @_renamed_kwarg('user', 'user_id') @_renamed_kwarg('tenant', 'project_id') @_renamed_kwarg('domain', 'domain_id') @_renamed_kwarg('user_domain', 'user_domain_id') @_renamed_kwarg('project_domain', 'project_domain_id') def __init__(self, auth_token=None, user_id=None, project_id=None, domain_id=None, user_domain_id=None, project_domain_id=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, service_token=None, service_user_id=None, service_user_name=None, service_user_domain_id=None, service_user_domain_name=None, service_project_id=None, service_project_name=None, service_project_domain_id=None, service_project_domain_name=None, service_roles=None, global_request_id=None): """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 """ # setting to private variables to avoid triggering subclass properties self._user_id = user_id self._project_id = project_id self._domain_id = domain_id self._user_domain_id = user_domain_id self._project_domain_id = project_domain_id self.auth_token = auth_token self.user_name = user_name self.project_name = project_name self.domain_name = domain_name self.user_domain_name = user_domain_name 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 [] self.service_token = service_token self.service_user_id = service_user_id self.service_user_name = service_user_name self.service_user_domain_id = service_user_domain_id self.service_user_domain_name = service_user_domain_name self.service_project_id = service_project_id self.service_project_name = service_project_name self.service_project_domain_id = service_project_domain_id self.service_project_domain_name = service_project_domain_name self.service_roles = service_roles or [] if not request_id: request_id = generate_request_id() self.request_id = request_id self.global_request_id = global_request_id if overwrite or not get_current(): self.update_store() # NOTE(jamielennox): To prevent circular lookups on subclasses that might # point user to user_id we make user/user_id tenant/project_id etc point # to the same private variable rather than each other. tenant = _moved_property('project_id', 'tenant', target='_project_id') user = _moved_property('user_id', 'user', target='_user_id') domain = _moved_property('domain_id', 'domain', target='_domain_id') user_domain = _moved_property('user_domain_id', 'user_domain', target='_user_domain_id') project_domain = _moved_property('project_domain_id', 'project_domain', target='_project_domain_id') user_id = _moved_property('_user_id') project_id = _moved_property('_project_id') domain_id = _moved_property('_domain_id') user_domain_id = _moved_property('_user_domain_id') project_domain_id = _moved_property('_project_domain_id') 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. """ # NOTE(jamielennox): We need a way to allow projects to provide old # deprecated policy values that trigger a warning when used in favour # of our standard ones. This object acts like a dict but only values # from oslo.policy don't show a warning. return _DeprecatedPolicyValues({ 'user_id': self.user_id, 'user_domain_id': self.user_domain_id, 'project_id': self.project_id, 'project_domain_id': self.project_domain_id, 'roles': self.roles, 'is_admin_project': self.is_admin_project, 'service_user_id': self.service_user_id, 'service_user_domain_id': self.service_user_domain_id, 'service_project_id': self.service_project_id, 'service_project_domain_id': self.service_project_domain_id, 'service_roles': self.service_roles}) def to_dict(self): """Return a dictionary of context attributes.""" user_idt = self.user_idt_format.format( user=self.user_id or '-', tenant=self.project_id or '-', domain=self.domain_id or '-', user_domain=self.user_domain_id or '-', p_domain=self.project_domain_id or '-') return {'user': self.user_id, 'tenant': self.project_id, 'project': self.project_id, 'domain': self.domain_id, 'user_domain': self.user_domain_id, 'project_domain': self.project_domain_id, '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, 'global_request_id': self.global_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()) if self.auth_token: # NOTE(jaosorior): Gotta obfuscate the token since this dict is # meant for logging and we shouldn't leak it. values['auth_token'] = '***' else: values['auth_token'] = None return values @property def global_id(self): """Return a sensible value for global_id to pass on. When we want to make a call with to another service, it's important that we try to use global_request_id if available, and fall back to the locally generated request_id if not. """ return self.global_request_id or self.request_id @classmethod @_renamed_kwarg('user', 'user_id') @_renamed_kwarg('tenant', 'project_id') @_renamed_kwarg('domain', 'domain_id') @_renamed_kwarg('user_domain', 'user_domain_id') @_renamed_kwarg('project_domain', 'project_domain_id') def from_dict(cls, values, **kwargs): """Construct a context object from a provided dictionary.""" kwargs.setdefault('auth_token', values.get('auth_token')) kwargs.setdefault('user_id', values.get('user')) kwargs.setdefault('project_id', values.get('tenant')) kwargs.setdefault('domain_id', values.get('domain')) kwargs.setdefault('user_domain_id', values.get('user_domain')) kwargs.setdefault('project_domain_id', values.get('project_domain')) kwargs.setdefault('is_admin', values.get('is_admin', False)) kwargs.setdefault('read_only', values.get('read_only', False)) kwargs.setdefault('show_deleted', values.get('show_deleted', False)) kwargs.setdefault('request_id', values.get('request_id')) kwargs.setdefault('global_request_id', values.get('global_request_id')) kwargs.setdefault('resource_uuid', values.get('resource_uuid')) kwargs.setdefault('roles', values.get('roles')) kwargs.setdefault('user_name', values.get('user_name')) kwargs.setdefault('project_name', values.get('project_name')) kwargs.setdefault('domain_name', values.get('domain_name')) kwargs.setdefault('user_domain_name', values.get('user_domain_name')) kwargs.setdefault('project_domain_name', values.get('project_domain_name')) kwargs.setdefault('is_admin_project', values.get('is_admin_project', True)) for key in cls.FROM_DICT_EXTRA_KEYS: kwargs.setdefault(key, values.get(key)) return cls(**kwargs) @classmethod @_renamed_kwarg('user', 'user_id') @_renamed_kwarg('tenant', 'project_id') @_renamed_kwarg('domain', 'domain_id') @_renamed_kwarg('user_domain', 'user_domain_id') @_renamed_kwarg('project_domain', 'project_domain_id') 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: # https://docs.openstack.org/keystonemiddleware/latest/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 'service_roles' not in kwargs: roles = environ.get('HTTP_X_SERVICE_ROLES') roles = [r.strip() for r in roles.split(',')] if roles else [] kwargs['service_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, project_id=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) oslo.context-2.20.0/oslo_context/version.py0000666000175100017510000000126413224676027021053 0ustar zuulzuul00000000000000# 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') oslo.context-2.20.0/setup.py0000666000175100017510000000200613224676027016001 0ustar zuulzuul00000000000000# 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>=2.0.0'], pbr=True)