2022-06-03 08:09:47 -06:00
|
|
|
from django.conf import settings
|
|
|
|
|
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
|
2022-06-03 08:09:47 -06:00
|
|
|
|
|
|
|
|
FEATURE_SLACK = "slack"
|
|
|
|
|
FEATURE_TELEGRAM = "telegram"
|
|
|
|
|
FEATURE_LIVE_SETTINGS = "live_settings"
|
2022-06-04 16:49:10 +04:00
|
|
|
FEATURE_GRAFANA_CLOUD_NOTIFICATIONS = "grafana_cloud_notifications"
|
2022-06-08 17:12:29 +04:00
|
|
|
FEATURE_GRAFANA_CLOUD_CONNECTION = "grafana_cloud_connection"
|
2023-08-03 11:12:52 +02:00
|
|
|
FEATURE_GRAFANA_ALERTING_V2 = "grafana_alerting_v2"
|
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,)
|
|
|
|
|
|
|
|
|
|
def get(self, request):
|
|
|
|
|
return Response(self._get_enabled_features(request))
|
|
|
|
|
|
|
|
|
|
def _get_enabled_features(self, request):
|
|
|
|
|
enabled_features = []
|
|
|
|
|
|
|
|
|
|
if settings.FEATURE_SLACK_INTEGRATION_ENABLED:
|
|
|
|
|
enabled_features.append(FEATURE_SLACK)
|
|
|
|
|
|
|
|
|
|
if settings.FEATURE_TELEGRAM_INTEGRATION_ENABLED:
|
|
|
|
|
enabled_features.append(FEATURE_TELEGRAM)
|
|
|
|
|
|
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
|
2022-06-08 17:12:29 +04:00
|
|
|
enabled_features.append(FEATURE_GRAFANA_CLOUD_CONNECTION)
|
|
|
|
|
if settings.FEATURE_LIVE_SETTINGS_ENABLED:
|
|
|
|
|
enabled_features.append(FEATURE_LIVE_SETTINGS)
|
|
|
|
|
if live_settings.GRAFANA_CLOUD_NOTIFICATIONS_ENABLED:
|
|
|
|
|
enabled_features.append(FEATURE_GRAFANA_CLOUD_NOTIFICATIONS)
|
|
|
|
|
|
2023-08-03 11:12:52 +02:00
|
|
|
if settings.FEATURE_GRAFANA_ALERTING_V2_ENABLED:
|
|
|
|
|
enabled_features.append(FEATURE_GRAFANA_ALERTING_V2)
|
|
|
|
|
|
2022-06-03 08:09:47 -06:00
|
|
|
return enabled_features
|