Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve metadata endpoint #311

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions src/argus/site/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
)
from django.shortcuts import render, reverse

from rest_framework.views import APIView
from drf_spectacular.utils import extend_schema, inline_serializer
from rest_framework import permissions
from rest_framework import serializers
from rest_framework.response import Response
from rest_framework.views import APIView


ERROR_TEMPLATE = """<html>
Expand Down Expand Up @@ -80,13 +82,48 @@ class MetadataView(APIView):
authentication_classes = []
permission_classes = [permissions.AllowAny]

@extend_schema(
responses={
200: inline_serializer(
name="Metadata",
fields={
"server-version": serializers.CharField(),
"api-version": inline_serializer(
name="APIVersion",
fields={
"stable": serializers.CharField(),
"unstable": serializers.CharField(),
},
),
"jsonapi-schema": inline_serializer(
name="OpenAPISchemaLocation",
fields={
"stable": serializers.URLField(),
"v1": serializers.URLField(),
"v2": serializers.URLField(),
},
),
},
)
}
)
def get(self, request, format=None):
try:
from argus.version import __version__
except (ModuleNotFoundError, ImportError):
import pkg_resources
# Run from source-dir
import argus.version

__version__ = argus.version.version
except (AttributeError, ModuleNotFoundError, ImportError):
# Installed from package
try:
from importlib.metadata import version

__version__ = version("wheel")
except ImportError:
# Python < 3.8
import pkg_resources

__version__ = pkg_resources.get_distribution("argus-server").version
__version__ = pkg_resources.get_distribution("argus-server").version

metadata = {
"server-version": __version__,
Expand Down
Loading