from django.urls import path, re_path, include from rest_framework import permissions, routers from drf_yasg2.views import get_schema_view from drf_yasg2 import openapi from . import views from apps.dropoff.api.views import DatadropViewSet from apps.invitation.api.views import InvitationViewSet from apps.researcher.api.views import ResearcherViewSet from apps.storage.api.views import StorageEngineViewSet, StorageLocationViewSet from apps.study.api.views import StudyViewSet from apps.virtual_machine.api.views import (VirtualMachineViewSet, VirtualMachineOperatingSystemViewSet, VirtualMachineProfileViewSet, VirtualMachineMemoryViewSet, VirtualMachineNetworkViewSet, VirtualMachineStorageViewSet, VirtualMachineGPUViewSet) schema_view = get_schema_view( openapi.Info( title="Virtual Research Environment API", default_version='v1', description="Here you can see a list of API endpoints and actions that are available to communicate with the VRE API", terms_of_service="https://www.rug.nl", contact=openapi.Contact(email="vre_team@rug.nl"), license=openapi.License(name="MIT License"), ), public=True, permission_classes=(permissions.AllowAny,), ) api_router_v1 = routers.DefaultRouter() api_router_v1.register(r'researchers', ResearcherViewSet) api_router_v1.register(r'studies', StudyViewSet) api_router_v1.register(r'dropoffs', DatadropViewSet) api_router_v1.register(r'invitations', InvitationViewSet) api_router_v1.register(r'storageengines', StorageEngineViewSet) api_router_v1.register(r'storagelocations', StorageLocationViewSet) # Order is important for virtual machines. Longest match first api_router_v1.register(r'virtualmachines/profiles', VirtualMachineProfileViewSet) api_router_v1.register(r'virtualmachines/storage', VirtualMachineStorageViewSet) api_router_v1.register(r'virtualmachines/memory', VirtualMachineMemoryViewSet) api_router_v1.register(r'virtualmachines/network', VirtualMachineNetworkViewSet) api_router_v1.register(r'virtualmachines/gpu', VirtualMachineGPUViewSet) api_router_v1.register(r'virtualmachines/os', VirtualMachineOperatingSystemViewSet) api_router_v1.register(r'virtualmachines', VirtualMachineViewSet) # Main namespace for the API urls app_name = 'api' urlpatterns = [ re_path(r'^swagger(?P\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'), path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'), # Extra /api/info path for checking if the Hawk authentication is working. # Also this will give the full url to the OpenAPI documentation path('info/', views.Info.as_view(), name='info'), # Add extra namespace for versioning the API path('v1/', include((api_router_v1.urls,'api'),namespace='v1')), ]