-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(service): backport API versioning changes from 1.0.0 release
Conflicts:
- Loading branch information
Showing
17 changed files
with
208 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright 2020 - Swiss Data Science Center (SDSC) | ||
# A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
# Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
# | ||
# 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. | ||
"""Renku service api versions.""" | ||
from typing import Any, Callable, List, Optional | ||
|
||
from flask import Blueprint | ||
|
||
|
||
class ApiVersion: | ||
"""Represents a Blueprint API version.""" | ||
|
||
def __init__(self, name: str, is_base_version: bool = False): | ||
self.name = name | ||
self.is_base_version = is_base_version | ||
|
||
|
||
class VersionedBlueprint(Blueprint): | ||
"""A Blueprint that supports versioning.""" | ||
|
||
def add_url_rule( | ||
self, | ||
rule: str, | ||
endpoint: Optional[str] = None, | ||
view_func: Optional[Callable] = None, | ||
provide_automatic_options: Optional[bool] = None, | ||
versions: List[str] = None, | ||
**options: Any, | ||
) -> None: | ||
"""Overwrite Blueprint add_url_rule to support versioning.""" | ||
|
||
for version in versions: | ||
if version.is_base_version: | ||
super().add_url_rule( | ||
rule, endpoint, view_func, provide_automatic_options=provide_automatic_options, **options | ||
) | ||
|
||
version_rule = f"/{version.name}{rule}" | ||
super().add_url_rule( | ||
version_rule, endpoint, view_func, provide_automatic_options=provide_automatic_options, **options | ||
) | ||
|
||
|
||
V0_9 = ApiVersion("0.9", is_base_version=True) | ||
|
||
MINIMUM_VERSION = V0_9 | ||
MAXIMUM_VERSION = V0_9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.