Skip to content

Commit

Permalink
Adding Swagger documentation to Gateway (#1205)
Browse files Browse the repository at this point in the history
* adding api documentation (swagger & redoc) to gateway

* allow unauthenticated users to read RuntimeJobViewSet

* allow swagger docu if user is not yet set

* only show api/v1/ patterns, add token authorization, rm django login

* drop jupyter from main helm readme (#1208)

Signed-off-by: Paul S. Schweigert <[email protected]>

* CatalogEntry API (#1204)

* add ModelView API for CatalogEntry

* additional apis for catalogentry

---------

Signed-off-by: Akihiko Kuroda <[email protected]>

* Repository removal (#1207)

* Removed main components from repository project

* Updated chart lock

* Remove repository references from the client

* add catalog status (#1211)

Signed-off-by: Akihiko Kuroda <[email protected]>

* Use LocalProvider for test (#1212)

* use LocalProvider for notebook test

Signed-off-by: Akihiko Kuroda <[email protected]>

* Documentation update (#1214)

* Update contribution guidelines

* Update contributing doc with supported python versions

* Remove Python 3.7 badge from README files

* Upgrade min python version in setup.py

* Test notebooks against k8s qs deployment (#1216)

* test notebooks against k8s qs deployment

Signed-off-by: Paul S. Schweigert <[email protected]>

* update notebook location

Signed-off-by: Paul S. Schweigert <[email protected]>

* use action for kind creation

Signed-off-by: Paul S. Schweigert <[email protected]>

* test all notebooks

Signed-off-by: Paul S. Schweigert <[email protected]>

* drop sleep

Signed-off-by: Paul S. Schweigert <[email protected]>

This was redundant, as the python setup in the next few steps takes
waaaay longer than 60s

---------

Signed-off-by: Paul S. Schweigert <[email protected]>

* Take out unnecessary Job.save() (#1217)

* take out unnecessary Job.save()

Signed-off-by: Akihiko Kuroda <[email protected]>

* Update Helm release kuberay-operator to v1 (#1121)

* Update Helm release kuberay-operator to v1

* Update api version

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: David <[email protected]>

* Fix link for Qiskit deprecation policy (#1218)

* Remove default login view (#1215)

* remove default login view

Signed-off-by: Akihiko Kuroda <[email protected]>

* adding api documentation (swagger & redoc) to gateway

---------

Signed-off-by: Paul S. Schweigert <[email protected]>
Signed-off-by: Akihiko Kuroda <[email protected]>
Co-authored-by: Paul Schweigert <[email protected]>
Co-authored-by: Akihiko (Aki) Kuroda <[email protected]>
Co-authored-by: David <[email protected]>
Co-authored-by: Karla Spuldaro <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Eric Arellano <[email protected]>
  • Loading branch information
7 people authored Feb 27, 2024
1 parent c4a85de commit bd64e47
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
3 changes: 3 additions & 0 deletions gateway/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def get_serializer_class(self):
return v1_serializers.RuntimeJobSerializer

def get_queryset(self):
# Allow unauthenticated users to read the swagger documentation
if self.request.user is None or not self.request.user.is_authenticated:
return RuntimeJob.objects.none()
return RuntimeJob.objects.all().filter(job__author=self.request.user)


Expand Down
9 changes: 8 additions & 1 deletion gateway/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Version views inherit from the different views.
"""

import glob
import json
import logging
Expand Down Expand Up @@ -132,6 +133,9 @@ def get_serializer_class(self):
return self.serializer_class

def get_queryset(self):
# Allow unauthenticated users to read the swagger documentation
if self.request.user is None or not self.request.user.is_authenticated:
return Program.objects.none()
return (
Program.objects.all().filter(author=self.request.user).order_by("-created")
)
Expand Down Expand Up @@ -322,7 +326,10 @@ def get_serializer_class(self):
return self.serializer_class

def get_queryset(self):
return Job.objects.all().filter(author=self.request.user).order_by("-created")
# Allow unauthenticated users to read the swagger documentation
if self.request.user is None or not self.request.user.is_authenticated:
return Job.objects.none()
return (Job.objects.all()).filter(author=self.request.user).order_by("-created")

def perform_create(self, serializer):
serializer.save(author=self.request.user)
Expand Down
18 changes: 18 additions & 0 deletions gateway/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""

import os
import os.path
import sys
Expand Down Expand Up @@ -59,6 +60,7 @@
"allauth",
"api",
"psycopg2",
"drf_yasg",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -242,6 +244,17 @@
# 'JWT_AUTH_REFRESH_COOKIE': 'gateway-refresh-token',
}

SWAGGER_SETTINGS = {
"SECURITY_DEFINITIONS": {
"Bearer Token": {
"type": "apiKey",
"name": "Authorization",
"in": "header",
},
},
"USE_SESSION_AUTH": False,
}

SITE_ID = 1
SITE_HOST = os.environ.get("SITE_HOST", "http://localhost:8000")

Expand Down Expand Up @@ -346,3 +359,8 @@
CSP_SCRIPT_SRC = "'none'"
CSP_FRAME_ANCESTORS = "'self'"
CSP_OBJECT_SRC = "'self'"
CSP_IMG_SRC = ("'self'", "data:", "https://cdn.redoc.ly")
CSP_STYLE_SRC_ELEM = ("'self'", "'unsafe-inline'")
CSP_SCRIPT_SRC_ELEM = "'self'"
CSP_CONNECT_SRC = "'self'"
CSP_WORKER_SRC = ("'self'", "blob:")
33 changes: 31 additions & 2 deletions gateway/main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,31 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.conf import settings
from django.conf.urls.static import static
from django.urls import path, include, re_path
from django.views.generic import TemplateView
from rest_framework import routers

from rest_framework import routers, permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
import probes.views

schema = get_schema_view( # pylint: disable=invalid-name
openapi.Info(
title="Gateway API",
default_version="v1",
description="List of available API endpoint for gateway.",
),
public=True,
permission_classes=[permissions.AllowAny],
# Patterns to be included in the Swagger documentation
patterns=[
re_path(r"^api/v1/", include(("api.v1.urls", "api"), namespace="v1")),
# Add other included patterns if necessary
],
)

router = routers.DefaultRouter()


Expand All @@ -30,6 +47,18 @@
path("liveness/", probes.views.liveness, name="liveness"),
path("", include("django_prometheus.urls")),
re_path(r"^api/v1/", include(("api.v1.urls", "api"), namespace="v1")),
# docs
re_path(
r"^swagger(?P<format>\.json|\.yaml)$",
schema.without_ui(cache_timeout=0),
name="schema-json",
),
re_path(
r"^swagger/$",
schema.with_ui("swagger", cache_timeout=0),
name="schema-swagger-ui",
),
re_path(r"^redoc/$", schema.with_ui("redoc", cache_timeout=0), name="schema-redoc"),
path(
"DomainVerification.html",
TemplateView.as_view(template_name="DomainVerification.html"),
Expand Down
1 change: 1 addition & 0 deletions gateway/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ kubernetes>=26.1.0
opentelemetry-distro>=0.40b0
opentelemetry-exporter-otlp>=1.19.0
django-concurrency>=2.4
drf-yasg>=1.21.7

0 comments on commit bd64e47

Please sign in to comment.