Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove(api): Versions 1 to 2 are Gone or Not Found #667

Merged
merged 6 commits into from May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions documentation/api/change_log.rst
Expand Up @@ -112,6 +112,11 @@ v3.0-0 | 2022-03-25
- Rewrote the sections on roles and sources into a combined section that refers to account roles rather than USEF roles.
- Deprecated the section on group notation.

v2.0-7 | 2022-05-05
"""""""""""""""""""

*API v2.0 is removed.*

v2.0-6 | 2022-04-26
"""""""""""""""""""

Expand Down Expand Up @@ -163,6 +168,12 @@ v2.0-0 | 2020-11-14

- Added REST endpoints for managing assets: `/assets/` (GET, POST) and `/asset/<id>` (GET, PATCH, DELETE).


v1.3-14 | 2022-05-05
""""""""""""""""""""

*API v1.3 is removed.*

v1.3-13 | 2022-04-26
""""""""""""""""""""

Expand Down Expand Up @@ -259,6 +270,11 @@ v1.3-0 | 2020-01-28
- The *postUdiEvent* endpoint now triggers scheduling jobs to be set up (rather than scheduling directly triggered by the *getDeviceMessage* endpoint)
- The *getDeviceMessage* now queries the job queue and database for an available schedule

v1.2-6 | 2022-05-05
"""""""""""""""""""

*API v1.2 is removed.*

v1.2-5 | 2022-04-26
"""""""""""""""""""

Expand Down Expand Up @@ -315,6 +331,11 @@ v1.2-0 | 2018-09-08
- Added a description of the *postUdiEvent* endpoint in the Prosumer and Simulation sections
- Added a description of the *getDeviceMessage* endpoint in the Prosumer and Simulation sections

v1.1-8 | 2022-05-05
"""""""""""""""""""

*API v1.1 is removed.*

v1.1-7 | 2022-04-26
"""""""""""""""""""

Expand Down Expand Up @@ -378,6 +399,11 @@ v1.1-0 | 2018-07-15

- Added a description of the *getPrognosis* endpoint in the Supplier section

v1.0-4 | 2022-05-05
"""""""""""""""""""

*API v1.0 is removed.*

v1.0-3 | 2022-04-26
"""""""""""""""""""

Expand Down
1 change: 1 addition & 0 deletions documentation/changelog.rst
Expand Up @@ -16,6 +16,7 @@ Infrastructure / Support
----------------------

* The setting FLEXMEASURES_PLUGINS can be set as environment variable now (as a comma-separated list) [see `PR #660 <https://www.github.com/FlexMeasures/flexmeasures/pull/660>`_]
* Remove API versions 1.0, 1.1, 1.2, 1.3 and 2.0, while allowing hosts to switch between ``HTTP status 410 (Gone)`` and ``HTTP status 404 (Not Found)`` responses [see `PR #667 <https://www.github.com/FlexMeasures/flexmeasures/pull/667>`_]

.. warning:: The setting `FLEXMEASURES_PLUGIN_PATHS` has been deprecated since v0.7. It has now been sunset. Please replace it with :ref:`plugin-config`.

Expand Down
6 changes: 3 additions & 3 deletions documentation/configuration.rst
Expand Up @@ -618,10 +618,10 @@ FLEXMEASURES_API_SUNSET_ACTIVE
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Allow control over the effect of sunsetting API versions.
Specifically, if True, the endpoints in sunset versions will return ``HTTP status 410 (Gone)`` status codes.
If False, the endpoints will work like before, including Deprecation and Sunset headers in their response.
Specifically, if True, the endpoints of sunset API versions will return ``HTTP status 410 (Gone)`` status codes.
If False, these endpoints will either return ``HTTP status 404 (Not Found) status codes``, or work like before (including Deprecation and Sunset headers in their response), depending on whether the installed FlexMeasures version still contains the endpoint implementations.

Default: ``True``
Default: ``False``
Flix6x marked this conversation as resolved.
Show resolved Hide resolved

FLEXMEASURES_API_SUNSET_DATE
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
16 changes: 14 additions & 2 deletions flexmeasures/api/common/utils/deprecation_utils.py
Expand Up @@ -14,10 +14,16 @@ def sunset_blueprint(
api_version_sunset: str,
sunset_link: str,
api_version_upgrade_to: str = "3.0",
blueprint_contents_removed: bool = True,
):
"""Sunsets every route on a blueprint by returning 410 (Gone) responses.
"""Sunsets every route on a blueprint by returning 410 (Gone) responses, if sunset is active.
Such errors will be logged by utils.error_utils.error_handling_router.
Whether the sunset is active can be toggled using the config setting "FLEXMEASURES_API_SUNSET_ACTIVE".
If inactive, either:
- return 404 (Not Found) if the blueprint contents have been removed, or
- pass the request to be handled by the endpoint implementation.
Errors will be logged by utils.error_utils.error_handling_router.
"""

def let_host_switch_to_returning_410():
Expand All @@ -30,6 +36,12 @@ def let_host_switch_to_returning_410():
410,
f"API version {api_version_sunset} has been sunset. Please upgrade to API version {api_version_upgrade_to}. See {_sunset_link} for more information.",
)
elif blueprint_contents_removed:
abort(404)
else:
# Sunset is inactive and blueprint contents are still there,
# so we let the request pass to the endpoint implementation
pass

blueprint.before_request(let_host_switch_to_returning_410)

Expand Down