Another update
This commit is contained in:
@@ -9,58 +9,58 @@ class ApiConfig(AppConfig):
|
||||
verbose_name = _('API')
|
||||
verbose_name_plural = _('APIs')
|
||||
|
||||
try:
|
||||
assert settings.SWAGGER_SETTINGS
|
||||
except AttributeError:
|
||||
# We only load this setting, if it is not available in the overall settings.py file
|
||||
settings.SWAGGER_SETTINGS = {
|
||||
'SECURITY_DEFINITIONS': {
|
||||
'Hawk': {
|
||||
'type': 'apiKey',
|
||||
'description': 'HTTP Holder-Of-Key Authentication Scheme, https://github.com/hapijs/hawk, https://hawkrest.readthedocs.io/en/latest/<br /><strong>Ex header:</strong><br />\'Authorization\': \'Hawk mac="F4+S9cu7yZiZEgdtqzMpOOdudvqcV2V2Yzk2WcphECc=", hash="+7fKUX+djeQolvnLTxr0X47e//UHKbkRlajwMw3tx3w=", id="7FI5JET4", ts="1592905433", nonce="DlV-fL"\'',
|
||||
'name': 'Authorization',
|
||||
'in': 'header'
|
||||
}
|
||||
}
|
||||
}
|
||||
# try:
|
||||
# assert settings.SWAGGER_SETTINGS
|
||||
# except AttributeError:
|
||||
# # We only load this setting, if it is not available in the overall settings.py file
|
||||
# settings.SWAGGER_SETTINGS = {
|
||||
# 'SECURITY_DEFINITIONS': {
|
||||
# 'Hawk': {
|
||||
# 'type': 'apiKey',
|
||||
# 'description': 'HTTP Holder-Of-Key Authentication Scheme, https://github.com/hapijs/hawk, https://hawkrest.readthedocs.io/en/latest/<br /><strong>Ex header:</strong><br />\'Authorization\': \'Hawk mac="F4+S9cu7yZiZEgdtqzMpOOdudvqcV2V2Yzk2WcphECc=", hash="+7fKUX+djeQolvnLTxr0X47e//UHKbkRlajwMw3tx3w=", id="7FI5JET4", ts="1592905433", nonce="DlV-fL"\'',
|
||||
# 'name': 'Authorization',
|
||||
# 'in': 'header'
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
|
||||
try:
|
||||
assert settings.REST_FRAMEWORK
|
||||
except AttributeError:
|
||||
# We only load this setting, if it is not available in the overall settings.py file
|
||||
# To protect all API views with Hawk by default, put this in your settings:
|
||||
# https://hawkrest.readthedocs.io/en/latest/usage.html#protecting-api-views-with-hawk
|
||||
settings.REST_FRAMEWORK = {
|
||||
# try:
|
||||
# assert settings.REST_FRAMEWORK
|
||||
# except AttributeError:
|
||||
# # We only load this setting, if it is not available in the overall settings.py file
|
||||
# # To protect all API views with Hawk by default, put this in your settings:
|
||||
# # https://hawkrest.readthedocs.io/en/latest/usage.html#protecting-api-views-with-hawk
|
||||
# settings.REST_FRAMEWORK = {
|
||||
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||
'apps.api.authentication.APIHawk',
|
||||
),
|
||||
# 'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||
# 'apps.api.authentication.APIHawk',
|
||||
# ),
|
||||
|
||||
'DEFAULT_PERMISSION_CLASSES': (
|
||||
'rest_framework.permissions.IsAuthenticated',
|
||||
),
|
||||
# 'DEFAULT_PERMISSION_CLASSES': (
|
||||
# 'rest_framework.permissions.IsAuthenticated',
|
||||
# ),
|
||||
|
||||
# 'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||
# 'rest_framework.authentication.TokenAuthentication',
|
||||
# ),
|
||||
# # 'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||
# # 'rest_framework.authentication.TokenAuthentication',
|
||||
# # ),
|
||||
|
||||
# 'DEFAULT_PERMISSION_CLASSES': (
|
||||
# 'rest_framework.permissions.IsAuthenticated', ),
|
||||
# # 'DEFAULT_PERMISSION_CLASSES': (
|
||||
# # 'rest_framework.permissions.IsAuthenticated', ),
|
||||
|
||||
# Use Django's standard `django.contrib.auth` permissions,
|
||||
# or allow read-only access for unauthenticated users.
|
||||
#'DEFAULT_PERMISSION_CLASSES': [
|
||||
# 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
|
||||
#],
|
||||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
||||
'PAGE_SIZE': 10
|
||||
}
|
||||
# # Use Django's standard `django.contrib.auth` permissions,
|
||||
# # or allow read-only access for unauthenticated users.
|
||||
# #'DEFAULT_PERMISSION_CLASSES': [
|
||||
# # 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
|
||||
# #],
|
||||
# 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
||||
# 'PAGE_SIZE': 10
|
||||
# }
|
||||
|
||||
try:
|
||||
assert settings.HAWK_MESSAGE_EXPIRATION
|
||||
except AttributeError:
|
||||
# We only load this setting, if it is not available in the overall settings.py file
|
||||
settings.HAWK_MESSAGE_EXPIRATION = 60
|
||||
# try:
|
||||
# assert settings.HAWK_MESSAGE_EXPIRATION
|
||||
# except AttributeError:
|
||||
# # We only load this setting, if it is not available in the overall settings.py file
|
||||
# settings.HAWK_MESSAGE_EXPIRATION = 60
|
||||
|
||||
def ready(self):
|
||||
from . import signals
|
@@ -7,24 +7,24 @@ 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)
|
||||
# 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",
|
||||
title="Synthea WebService 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",
|
||||
description="Info about Synthea WebServer API",
|
||||
terms_of_service="https://www.rug.nl",
|
||||
contact=openapi.Contact(email="vre_team@rug.nl"),
|
||||
license=openapi.License(name="MIT License"),
|
||||
@@ -33,27 +33,27 @@ schema_view = get_schema_view(
|
||||
permission_classes=(permissions.AllowAny,),
|
||||
)
|
||||
|
||||
api_router_v1 = routers.DefaultRouter()
|
||||
#api_router_v1 = routers.DefaultRouter()
|
||||
|
||||
api_router_v1.register(r'researchers', ResearcherViewSet)
|
||||
# api_router_v1.register(r'researchers', ResearcherViewSet)
|
||||
|
||||
api_router_v1.register(r'studies', StudyViewSet)
|
||||
# api_router_v1.register(r'studies', StudyViewSet)
|
||||
|
||||
api_router_v1.register(r'dropoffs', DatadropViewSet)
|
||||
# api_router_v1.register(r'dropoffs', DatadropViewSet)
|
||||
|
||||
api_router_v1.register(r'invitations', InvitationViewSet)
|
||||
# api_router_v1.register(r'invitations', InvitationViewSet)
|
||||
|
||||
api_router_v1.register(r'storageengines', StorageEngineViewSet)
|
||||
api_router_v1.register(r'storagelocations', StorageLocationViewSet)
|
||||
# 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)
|
||||
# # 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'
|
||||
@@ -66,6 +66,10 @@ urlpatterns = [
|
||||
# Also this will give the full url to the OpenAPI documentation
|
||||
path('info/', views.Info.as_view(), name='info'),
|
||||
|
||||
path('states/', views.States.as_view(), name='states'),
|
||||
path('modules/', views.Modules.as_view(), name='modules'),
|
||||
path('generate/', views.Generate.as_view(), name='generate'),
|
||||
|
||||
# Add extra namespace for versioning the API
|
||||
path('v1/', include((api_router_v1.urls,'api'),namespace='v1')),
|
||||
#path('v1/', include((api_router_v1.urls,'api'),namespace='v1')),
|
||||
]
|
@@ -1,11 +1,23 @@
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from django.http import FileResponse
|
||||
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from rest_framework.decorators import schema
|
||||
from rest_framework import status
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
from lib.utils.general import get_ip_address
|
||||
|
||||
from apps.synthea.api.serializers import SyntheaSerializer
|
||||
|
||||
from apps.synthea.lib.utils import available_states, available_modules,run_synthea
|
||||
|
||||
import mimetypes
|
||||
|
||||
|
||||
@schema(None)
|
||||
class Info(APIView):
|
||||
"""
|
||||
@@ -49,4 +61,37 @@ class Info(APIView):
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return Response(data)
|
||||
return Response(data)
|
||||
|
||||
|
||||
#@schema(None)
|
||||
class States(APIView):
|
||||
|
||||
def get(self, request, format=None):
|
||||
return Response(available_states())
|
||||
|
||||
|
||||
class Modules(APIView):
|
||||
|
||||
def get(self, request, format=None):
|
||||
return Response(available_modules())
|
||||
|
||||
class Generate(APIView):
|
||||
|
||||
def post(self, request, format=None):
|
||||
print('Post data')
|
||||
print(request.data)
|
||||
|
||||
serializer = SyntheaSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
synthea = serializer.save()
|
||||
zipfile = synthea.generate()
|
||||
print(zipfile)
|
||||
response = FileResponse(zipfile.open('rb'), content_type='application/zip')
|
||||
response['Content-Disposition'] = f'attachment; filename={zipfile.name}'
|
||||
|
||||
return response
|
||||
|
||||
|
||||
#return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
Reference in New Issue
Block a user