Skip to content

Commit

Permalink
update rest api versioning (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Sep 10, 2024
1 parent 2868dda commit 185955a
Show file tree
Hide file tree
Showing 17 changed files with 322 additions and 113 deletions.
30 changes: 6 additions & 24 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@
'knox.auth.TokenAuthentication',
),
'EXCEPTION_HANDLER': 'rest_framework.views.exception_handler',
'PAGE_SIZE': env.int('SODAR_API_PAGE_SIZE', 100),
}


Expand Down Expand Up @@ -579,30 +580,11 @@ def set_logging(level=None):


# General API settings
SODAR_API_DEFAULT_VERSION = '0.15.0'
SODAR_API_ALLOWED_VERSIONS = [
'0.7.0',
'0.7.1',
'0.8.0',
'0.9.0',
'0.10.0',
'0.10.1',
'0.11.0',
'0.11.1',
'0.11.2',
'0.11.3',
'0.12.0',
'0.12.1',
'0.13.0',
'0.13.1',
'0.13.2',
'0.13.3',
'0.13.4',
'0.14.0',
'0.14.1',
'0.14.2',
'0.15.0',
]
# NOTE: All except SODAR_API_DEFAULT_HOST are deprecated
# TODO: Remove after upgrading to SODAR Core v1.0.3
# (see bihealth/sodar-core#1495)
SODAR_API_DEFAULT_VERSION = '1.0'
SODAR_API_ALLOWED_VERSIONS = ['1.0']
SODAR_API_MEDIA_TYPE = 'application/vnd.bihealth.sodar+json'
SODAR_API_DEFAULT_HOST = env.url(
'SODAR_API_DEFAULT_HOST', 'http://127.0.0.1:8000'
Expand Down
24 changes: 13 additions & 11 deletions docs_manual/source/api_irodsinfo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ Irods Info API
The REST API for the iRODS Info app is described in this document.


Versioning
==========

Media Type
``application/vnd.bihealth.sodar.irodsinfo+json``
Current Version
``1.0``
Accepted Versions
``1.0``
Header Example
``Accept: application/vnd.bihealth.sodar.irodsinfo+json; version=x.y``


API Views
=========

.. currentmodule:: irodsinfo.views_api

.. autoclass:: IrodsEnvRetrieveAPIView


Versioning
==========

For accept header versioning, the following header is expected in the current
SODAR version:

.. code-block:: console
Accept: application/vnd.bihealth.sodar+json; version=0.15.0
24 changes: 13 additions & 11 deletions docs_manual/source/api_landingzones.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ Landing Zones API
The REST API for landing zone operations is described in this document.


Versioning
==========

Media Type
``application/vnd.bihealth.sodar.landingzones+json``
Current Version
``1.0``
Accepted Versions
``1.0``
Header Example
``Accept: application/vnd.bihealth.sodar.landingzones+json; version=x.y``


API Views
=========

Expand All @@ -22,14 +35,3 @@ API Views
.. autoclass:: ZoneSubmitDeleteAPIView

.. autoclass:: ZoneSubmitMoveAPIView


Versioning
==========

For accept header versioning, the following header is expected in the current
SODAR version:

.. code-block:: console
Accept: application/vnd.bihealth.sodar+json; version=0.15.0
24 changes: 13 additions & 11 deletions docs_manual/source/api_samplesheets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ Sample Sheets API
The REST API for sample sheet operations is described in this document.


Versioning
==========

Media Type
``application/vnd.bihealth.sodar.samplesheets+json``
Current Version
``1.0``
Accepted Versions
``1.0``
Header Example
``Accept: application/vnd.bihealth.sodar.samplesheets+json; version=x.y``


API Views
=========

Expand Down Expand Up @@ -58,14 +71,3 @@ iRODS Data Requests
.. autoclass:: IrodsDataRequestAcceptAPIView

.. autoclass:: IrodsDataRequestRejectAPIView


Versioning
==========

For accept header versioning, the following header is expected in the current
SODAR version:

.. code-block:: console
Accept: application/vnd.bihealth.sodar+json; version=0.15.0
17 changes: 14 additions & 3 deletions irodsinfo/tests/test_permissions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@

# Projectroles dependency
from projectroles.tests.test_permissions import SiteAppPermissionTestBase
from projectroles.tests.test_permissions_api import SODARAPIPermissionTestMixin

from irodsinfo.views_api import (
IRODSINFO_API_MEDIA_TYPE,
IRODSINFO_API_DEFAULT_VERSION,
)

class TestIrodsConfigRetrieveAPIView(SiteAppPermissionTestBase):

class TestIrodsConfigRetrieveAPIView(
SODARAPIPermissionTestMixin, SiteAppPermissionTestBase
):
"""Tests for irodsinfo API"""

media_type = IRODSINFO_API_MEDIA_TYPE
api_version = IRODSINFO_API_DEFAULT_VERSION

def test_get_irods_config(self):
"""Test IrodsConfigRetrieveAPIView GET"""
url = reverse('irodsinfo:api_env')
good_users = [self.superuser, self.regular_user]
bad_users = [self.anonymous]
self.assert_response(url, good_users, 200)
self.assert_response(url, bad_users, 401)
self.assert_response_api(url, good_users, 200)
self.assert_response_api(url, bad_users, 401)
7 changes: 7 additions & 0 deletions irodsinfo/tests/test_views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
from test_plus.test import TestCase

from irodsinfo.tests.test_views import PLUGINS_DISABLE_IRODS
from irodsinfo.views_api import (
IRODSINFO_API_MEDIA_TYPE,
IRODSINFO_API_DEFAULT_VERSION,
)


class TestIrodsConfigRetrieveAPIView(TestCase):
"""Tests for IrodsConfigRetrieveAPIView"""

media_type = IRODSINFO_API_MEDIA_TYPE
api_version = IRODSINFO_API_DEFAULT_VERSION

def setUp(self):
# Create users
self.superuser = self.make_user('superuser')
Expand Down
29 changes: 28 additions & 1 deletion irodsinfo/views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import logging

from rest_framework.permissions import IsAuthenticated
from rest_framework.renderers import JSONRenderer
from rest_framework.response import Response
from rest_framework.versioning import AcceptHeaderVersioning
from rest_framework.views import APIView

# Projectroles dependency
Expand All @@ -15,7 +17,32 @@
logger = logging.getLogger(__name__)


class IrodsEnvRetrieveAPIView(IrodsConfigMixin, APIView):
# Local constants
IRODSINFO_API_MEDIA_TYPE = 'application/vnd.bihealth.sodar.irodsinfo+json'
IRODSINFO_API_ALLOWED_VERSIONS = ['1.0']
IRODSINFO_API_DEFAULT_VERSION = '1.0'


class IrodsinfoAPIVersioningMixin:
"""
Irodsinfo API view versioning mixin for overriding media type and
accepted versions.
"""

class IrodsinfoAPIRenderer(JSONRenderer):
media_type = IRODSINFO_API_MEDIA_TYPE

class IrodsinfoAPIVersioning(AcceptHeaderVersioning):
allowed_versions = IRODSINFO_API_ALLOWED_VERSIONS
default_version = IRODSINFO_API_DEFAULT_VERSION

renderer_classes = [IrodsinfoAPIRenderer]
versioning_class = IrodsinfoAPIVersioning


class IrodsEnvRetrieveAPIView(
IrodsConfigMixin, IrodsinfoAPIVersioningMixin, APIView
):
"""
Retrieve iRODS environment file for the current user.
Expand Down
7 changes: 7 additions & 0 deletions landingzones/tests/test_permissions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
ZONE_TITLE,
ZONE_DESC,
)
from landingzones.views_api import (
LANDINGZONES_API_MEDIA_TYPE,
LANDINGZONES_API_DEFAULT_VERSION,
)


# SODAR constants
Expand All @@ -36,6 +40,9 @@ class ZoneAPIPermissionTestBase(
):
"""Base class for landingzones REST API view permission tests"""

media_type = LANDINGZONES_API_MEDIA_TYPE
api_version = LANDINGZONES_API_DEFAULT_VERSION


class TestZoneListAPIView(ZoneAPIPermissionTestBase):
"""Tests for ZoneListAPIView permissions"""
Expand Down
7 changes: 7 additions & 0 deletions landingzones/tests/test_permissions_api_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
ZONE_TITLE,
ZONE_DESC,
)
from landingzones.views_api import (
LANDINGZONES_API_MEDIA_TYPE,
LANDINGZONES_API_DEFAULT_VERSION,
)


# Local constants
Expand All @@ -41,6 +45,9 @@ class ZoneAPIPermissionTaskflowTestBase(
):
"""Base class for landing zone permission tests with Taskflow"""

media_type = LANDINGZONES_API_MEDIA_TYPE
api_version = LANDINGZONES_API_DEFAULT_VERSION

def setUp(self):
super().setUp()
# Import investigation
Expand Down
7 changes: 7 additions & 0 deletions landingzones/tests/test_views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
)
from landingzones.tests.test_models import LandingZoneMixin
from landingzones.tests.test_views_taskflow import ZONE_TITLE, ZONE_DESC
from landingzones.views_api import (
LANDINGZONES_API_MEDIA_TYPE,
LANDINGZONES_API_DEFAULT_VERSION,
)


# SODAR constants
Expand All @@ -42,6 +46,9 @@ class TestLandingZoneAPIViewsBase(
):
"""Base class for Landingzones API view testing"""

media_type = LANDINGZONES_API_MEDIA_TYPE
api_version = LANDINGZONES_API_DEFAULT_VERSION

def setUp(self):
super().setUp()
# Init contributor user and assignment
Expand Down
7 changes: 7 additions & 0 deletions landingzones/tests/test_views_api_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
ZONE_ALL_COLLS,
TEST_OBJ_NAME,
)
from landingzones.views_api import (
LANDINGZONES_API_MEDIA_TYPE,
LANDINGZONES_API_DEFAULT_VERSION,
)


# SODAR constants
Expand All @@ -65,6 +69,9 @@ class ZoneAPIViewTaskflowTestBase(
):
"""Base landing zone API view test class with Taskflow enabled"""

media_type = LANDINGZONES_API_MEDIA_TYPE
api_version = LANDINGZONES_API_DEFAULT_VERSION

def setUp(self):
super().setUp()
# Get iRODS backend for session access
Expand Down
Loading

0 comments on commit 185955a

Please sign in to comment.