api: add CAN_BACKUP capability

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-06-06 12:44:43 +02:00
parent 8ea02e4cc9
commit 1f35f73c66
3 changed files with 13 additions and 2 deletions

View File

@ -8,6 +8,7 @@ from typing import TypedDict
from django.utils.timezone import now from django.utils.timezone import now
from drf_spectacular.utils import extend_schema from drf_spectacular.utils import extend_schema
from gunicorn import version_info as gunicorn_version from gunicorn import version_info as gunicorn_version
from kubernetes.config.incluster_config import SERVICE_HOST_ENV_NAME
from rest_framework.fields import SerializerMethodField from rest_framework.fields import SerializerMethodField
from rest_framework.permissions import IsAdminUser from rest_framework.permissions import IsAdminUser
from rest_framework.request import Request from rest_framework.request import Request
@ -61,7 +62,7 @@ class SystemSerializer(PassiveSerializer):
"python_version": python_version, "python_version": python_version,
"gunicorn_version": ".".join(str(x) for x in gunicorn_version), "gunicorn_version": ".".join(str(x) for x in gunicorn_version),
"environment": "kubernetes" "environment": "kubernetes"
if "KUBERNETES_PORT" in os.environ if SERVICE_HOST_ENV_NAME in os.environ
else "compose", else "compose",
"architecture": platform.machine(), "architecture": platform.machine(),
"platform": platform.platform(), "platform": platform.platform(),

View File

@ -1,9 +1,10 @@
"""core Configs API""" """core Configs API"""
from os import path from os import environ, path
from django.conf import settings from django.conf import settings
from django.db import models from django.db import models
from drf_spectacular.utils import extend_schema from drf_spectacular.utils import extend_schema
from kubernetes.config.incluster_config import SERVICE_HOST_ENV_NAME
from rest_framework.fields import BooleanField, CharField, ChoiceField, ListField from rest_framework.fields import BooleanField, CharField, ChoiceField, ListField
from rest_framework.permissions import AllowAny from rest_framework.permissions import AllowAny
from rest_framework.request import Request from rest_framework.request import Request
@ -20,6 +21,7 @@ class Capabilities(models.TextChoices):
CAN_SAVE_MEDIA = "can_save_media" CAN_SAVE_MEDIA = "can_save_media"
CAN_GEO_IP = "can_geo_ip" CAN_GEO_IP = "can_geo_ip"
CAN_BACKUP = "can_backup"
class ConfigSerializer(PassiveSerializer): class ConfigSerializer(PassiveSerializer):
@ -45,6 +47,13 @@ class ConfigView(APIView):
caps.append(Capabilities.CAN_SAVE_MEDIA) caps.append(Capabilities.CAN_SAVE_MEDIA)
if GEOIP_READER.enabled: if GEOIP_READER.enabled:
caps.append(Capabilities.CAN_GEO_IP) caps.append(Capabilities.CAN_GEO_IP)
if SERVICE_HOST_ENV_NAME in environ:
# Running in k8s, only s3 backup is supported
if CONFIG.y("postgresql.s3_backup"):
caps.append(Capabilities.CAN_BACKUP)
else:
# Running in compose, backup is always supported
caps.append(Capabilities.CAN_BACKUP)
return caps return caps
@extend_schema(responses={200: ConfigSerializer(many=False)}) @extend_schema(responses={200: ConfigSerializer(many=False)})

View File

@ -16203,6 +16203,7 @@ components:
enum: enum:
- can_save_media - can_save_media
- can_geo_ip - can_geo_ip
- can_backup
type: string type: string
CaptchaChallenge: CaptchaChallenge:
type: object type: object