{"id":20111739,"url":"https://github.com/openstack/microversion-parse","last_synced_at":"2025-05-06T11:31:10.961Z","repository":{"id":66174758,"uuid":"55065338","full_name":"openstack/microversion-parse","owner":"openstack","description":"Simple library for parsing OpenStack microversion headers. Mirror of code maintained at opendev.org.","archived":false,"fork":false,"pushed_at":"2024-01-29T09:46:08.000Z","size":58,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-05-09T18:50:45.070Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://opendev.org/openstack/microversion-parse","language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openstack.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-03-30T13:28:33.000Z","updated_at":"2024-05-09T18:50:45.071Z","dependencies_parsed_at":"2024-01-10T17:31:39.272Z","dependency_job_id":"26328853-7b5f-4d8d-8e94-36d263805cc0","html_url":"https://github.com/openstack/microversion-parse","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openstack%2Fmicroversion-parse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openstack%2Fmicroversion-parse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openstack%2Fmicroversion-parse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openstack%2Fmicroversion-parse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openstack","download_url":"https://codeload.github.com/openstack/microversion-parse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224499851,"owners_count":17321605,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T18:17:31.193Z","updated_at":"2024-11-13T18:17:31.964Z","avatar_url":"https://github.com/openstack.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"microversion_parse\n==================\n\nA small set of functions to manage OpenStack `microversion`_ headers that can\nbe used in middleware, application handlers and decorators to effectively\nmanage microversions.\n\nAlso included, in the ``middleware`` module, is a ``MicroversionMiddleware``\nthat will process incoming microversion headers.\n\nget_version\n-----------\n\nA simple parser for OpenStack microversion headers::\n\n    import microversion_parse\n\n    # headers is a dict of headers with folded (comma-separated\n    # values) or a list of header, value tuples\n    version = microversion_parse.get_version(\n        headers, service_type='compute',\n        legacy_headers=['x-openstack-nova-api-version'])\n\n    # If headers are not already available, a dict of headers\n    # can be extracted from the WSGI environ\n    headers = microversion_parse.headers_from_wsgi_environ(environ)\n    version = microversion_parse.get_version(\n        headers, service_type='placement')\n\nIt processes microversion headers with the standard form::\n\n    OpenStack-API-Version: compute 2.1\n\nIn that case, the response will be '2.1'.\n\nIf provided with a ``legacy_headers`` argument, this is treated as\na list of additional headers to check for microversions. Some examples of\nheaders include::\n\n    OpenStack-telemetry-api-version: 2.1\n    OpenStack-nova-api-version: 2.1\n    X-OpenStack-nova-api-version: 2.1\n\nIf a version string cannot be found, ``None`` will be returned. If\nthe input is incorrect usual Python exceptions (ValueError,\nTypeError) are allowed to raise to the caller.\n\nparse_version_string\n--------------------\n\nA function to turn a version string into a ``Version``, a comparable\n``namedtuple``::\n\n    version_tuple = microversion_parse.parse_version_string('2.1')\n\nIf the provided string is not a valid microversion string, ``TypeError``\nis raised.\n\nextract_version\n---------------\n\nCombines ``get_version`` and ``parse_version_string`` to find and validate\na microversion for a given service type in a collection of headers::\n\n    version_tuple = microversion_parse.extract_version(\n        headers,  # a representation of headers, as accepted by get_version\n        service_type,  # service type identify to match in headers\n        versions_list,  # an ordered list of strings of version numbers that\n                        # are the valid versions presented by this service\n    )\n\n``latest`` will be translated to whatever the max version is in versions_list.\n\nIf the found version is not in versions_list a ``ValueError`` is raised.\n\nNote that ``extract_version`` does not support ``legacy_headers``.\n\nMicroversionMiddleware\n----------------------\n\nA WSGI middleware that can wrap an application that needs to be microversion\naware. The application will get a WSGI environ with a\n'SERVICE_TYPE.microversion' key that has a value of the microversion found at\nan 'openstack-api-version' header that matches SERVICE_TYPE.  If no header is\nfound, the minimum microversion will be set. If the special keyword 'latest' is\nused, the maximum microversion will be set.\n\nIf the requested microversion is not available a 406 response is returned.\n\nIf there is an error parsing a provided header, a 400 response is returned.\n\nOtherwise the application is called.\n\nThe middleware is configured when it is created. Three parameters are required:\n\napp\n  The next WSGI middleware or application in the stack.\n\nservice_type\n  The service type of the application, used to identify microversion headers.\n\nversions_list\n  An ordered list of legitimate microversions (as strings) for the application.\n  It's assumed that any application that is using microversions will have such\n  a list for its own housekeeping and documentation.\n\nOne named parameter is optional:\n\njson_error_formatter\n  A Webob error formatter that can be used to structure the response when JSON\n  is expected.\n\nFor example::\n\n    def app():\n        app = middleware.MicroversionMiddleware(\n            MyWSGIApp(), 'cats', ['1.0', '1.1', '1.2'])\n        return app\n\n\n.. _microversion: http://specs.openstack.org/openstack/api-wg/guidelines/microversion_specification.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenstack%2Fmicroversion-parse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenstack%2Fmicroversion-parse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenstack%2Fmicroversion-parse/lists"}