2024-01-12 15:11:22 +00:00
|
|
|
import enum
|
|
|
|
|
|
2022-06-03 08:09:47 -06:00
|
|
|
from django.conf import settings
|
2024-01-12 15:11:22 +00:00
|
|
|
from drf_spectacular.plumbing import resolve_type_hint
|
|
|
|
|
from drf_spectacular.utils import extend_schema
|
|
|
|
|
from rest_framework import status
|
2022-06-03 08:09:47 -06:00
|
|
|
from rest_framework.response import Response
|
|
|
|
|
from rest_framework.views import APIView
|
|
|
|
|
|
|
|
|
|
from apps.auth_token.auth import PluginAuthentication
|
2022-06-04 16:49:10 +04:00
|
|
|
from apps.base.utils import live_settings
|
2023-10-20 09:30:11 +02:00
|
|
|
from apps.labels.utils import is_labels_feature_enabled
|
2022-06-03 08:09:47 -06:00
|
|
|
|
2024-01-12 15:11:22 +00:00
|
|
|
|
|
|
|
|
class Feature(enum.StrEnum):
|
|
|
|
|
MSTEAMS = "msteams"
|
|
|
|
|
SLACK = "slack"
|
2024-08-08 16:16:19 +02:00
|
|
|
UNIFIED_SLACK = "unified_slack"
|
2024-01-12 15:11:22 +00:00
|
|
|
TELEGRAM = "telegram"
|
|
|
|
|
LIVE_SETTINGS = "live_settings"
|
|
|
|
|
GRAFANA_CLOUD_NOTIFICATIONS = "grafana_cloud_notifications"
|
|
|
|
|
GRAFANA_CLOUD_CONNECTION = "grafana_cloud_connection"
|
2024-02-01 16:20:47 +08:00
|
|
|
# GRAFANA_ALERTING_V2 enables advanced OnCall <-> Alerting integration.
|
|
|
|
|
# On Alerting side it enables integration dropdown in OnCall contact point.
|
|
|
|
|
# On OnCall side it do nothing, just indicating if OnCall API is ready to that integration.
|
2024-01-12 15:11:22 +00:00
|
|
|
GRAFANA_ALERTING_V2 = "grafana_alerting_v2"
|
|
|
|
|
LABELS = "labels"
|
2024-04-02 14:59:03 -04:00
|
|
|
GOOGLE_OAUTH2 = "google_oauth2"
|
2025-01-20 16:49:59 +01:00
|
|
|
SERVICE_DEPENDENCIES = "service_dependencies"
|
2025-02-18 14:53:07 -03:00
|
|
|
PERSONAL_WEBHOOK = "personal_webhook"
|
2022-06-03 08:09:47 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class FeaturesAPIView(APIView):
|
|
|
|
|
"""
|
|
|
|
|
Return whitelist of enabled features.
|
|
|
|
|
It is needed to disable features for On-prem installations.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
authentication_classes = (PluginAuthentication,)
|
|
|
|
|
|
2024-01-12 15:11:22 +00:00
|
|
|
@extend_schema(responses={status.HTTP_200_OK: resolve_type_hint(list[Feature])})
|
2022-06-03 08:09:47 -06:00
|
|
|
def get(self, request):
|
2023-08-16 14:13:56 +08:00
|
|
|
data = self._get_enabled_features(request)
|
|
|
|
|
return Response(data)
|
2022-06-03 08:09:47 -06:00
|
|
|
|
|
|
|
|
def _get_enabled_features(self, request):
|
|
|
|
|
enabled_features = []
|
|
|
|
|
|
|
|
|
|
if settings.FEATURE_SLACK_INTEGRATION_ENABLED:
|
2024-01-12 15:11:22 +00:00
|
|
|
enabled_features.append(Feature.SLACK)
|
2022-06-03 08:09:47 -06:00
|
|
|
|
2024-08-08 16:16:19 +02:00
|
|
|
if settings.UNIFIED_SLACK_APP_ENABLED:
|
|
|
|
|
enabled_features.append(Feature.UNIFIED_SLACK)
|
|
|
|
|
|
2022-06-03 08:09:47 -06:00
|
|
|
if settings.FEATURE_TELEGRAM_INTEGRATION_ENABLED:
|
2024-01-12 15:11:22 +00:00
|
|
|
enabled_features.append(Feature.TELEGRAM)
|
2022-06-03 08:09:47 -06:00
|
|
|
|
2023-03-07 19:07:42 +08:00
|
|
|
if settings.IS_OPEN_SOURCE:
|
2022-06-08 18:14:50 +04:00
|
|
|
# Features below should be enabled only in OSS
|
2024-01-12 15:11:22 +00:00
|
|
|
enabled_features.append(Feature.GRAFANA_CLOUD_CONNECTION)
|
2022-06-08 17:12:29 +04:00
|
|
|
if settings.FEATURE_LIVE_SETTINGS_ENABLED:
|
2024-01-12 15:11:22 +00:00
|
|
|
enabled_features.append(Feature.LIVE_SETTINGS)
|
2022-06-08 17:12:29 +04:00
|
|
|
if live_settings.GRAFANA_CLOUD_NOTIFICATIONS_ENABLED:
|
2024-01-12 15:11:22 +00:00
|
|
|
enabled_features.append(Feature.GRAFANA_CLOUD_NOTIFICATIONS)
|
2024-01-02 12:55:44 -03:00
|
|
|
else:
|
2024-01-12 15:11:22 +00:00
|
|
|
enabled_features.append(Feature.MSTEAMS)
|
2022-06-08 17:12:29 +04:00
|
|
|
|
2023-08-03 11:12:52 +02:00
|
|
|
if settings.FEATURE_GRAFANA_ALERTING_V2_ENABLED:
|
2024-01-12 15:11:22 +00:00
|
|
|
enabled_features.append(Feature.GRAFANA_ALERTING_V2)
|
2023-08-03 11:12:52 +02:00
|
|
|
|
2023-10-20 09:30:11 +02:00
|
|
|
if is_labels_feature_enabled(self.request.auth.organization):
|
2024-01-12 15:11:22 +00:00
|
|
|
enabled_features.append(Feature.LABELS)
|
2023-10-20 09:30:11 +02:00
|
|
|
|
2024-04-15 08:56:28 -04:00
|
|
|
if settings.GOOGLE_OAUTH2_ENABLED:
|
2024-04-02 14:59:03 -04:00
|
|
|
enabled_features.append(Feature.GOOGLE_OAUTH2)
|
|
|
|
|
|
2025-01-20 16:49:59 +01:00
|
|
|
if settings.FEATURE_SERVICE_DEPENDENCIES_ENABLED:
|
|
|
|
|
enabled_features.append(Feature.SERVICE_DEPENDENCIES)
|
|
|
|
|
|
2025-02-18 14:53:07 -03:00
|
|
|
if settings.FEATURE_PERSONAL_WEBHOOK_ENABLED:
|
|
|
|
|
enabled_features.append(Feature.PERSONAL_WEBHOOK)
|
|
|
|
|
|
2022-06-03 08:09:47 -06:00
|
|
|
return enabled_features
|