-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Backend support for Organisation-level integrations (#4400)
- Loading branch information
Showing
15 changed files
with
509 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
api/integrations/grafana/migrations/0002_add_grafana_organisation_configuration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Generated by Django 3.2.25 on 2024-07-27 14:21 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("organisations", "0055_alter_percent_usage"), | ||
("projects", "0024_add_project_edge_v2_migration_read_capacity_budget"), | ||
("grafana", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameModel( | ||
old_name="GrafanaConfiguration", | ||
new_name="GrafanaProjectConfiguration", | ||
), | ||
migrations.CreateModel( | ||
name="GrafanaOrganisationConfiguration", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"deleted_at", | ||
models.DateTimeField( | ||
blank=True, | ||
db_index=True, | ||
default=None, | ||
editable=False, | ||
null=True, | ||
), | ||
), | ||
( | ||
"uuid", | ||
models.UUIDField(default=uuid.uuid4, editable=False, unique=True), | ||
), | ||
("base_url", models.URLField(null=True)), | ||
("api_key", models.CharField(max_length=100)), | ||
( | ||
"organisation", | ||
models.OneToOneField( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="grafana_config", | ||
to="organisations.organisation", | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,50 @@ | ||
""" | ||
Example `integration_data` entry: | ||
``` | ||
"grafana": { | ||
"perEnvironment": false, | ||
"image": "/static/images/integrations/grafana.svg", | ||
"docs": "https://docs.flagsmith.com/integrations/apm/grafana", | ||
"fields": [ | ||
{ | ||
"key": "base_url", | ||
"label": "Base URL", | ||
"default": "https://grafana.com" | ||
}, | ||
{ | ||
"key": "api_key", | ||
"label": "Service account token", | ||
"hidden": true | ||
} | ||
], | ||
"tags": [ | ||
"logging" | ||
], | ||
"title": "Grafana", | ||
"description": "Receive Flagsmith annotations to your Grafana instance on feature flag and segment changes." | ||
}, | ||
``` | ||
""" | ||
|
||
import logging | ||
|
||
from django.db import models | ||
|
||
from integrations.common.models import IntegrationsModel | ||
from organisations.models import Organisation | ||
from projects.models import Project | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class GrafanaConfiguration(IntegrationsModel): | ||
""" | ||
Example `integration_data` entry: | ||
``` | ||
"grafana": { | ||
"perEnvironment": false, | ||
"image": "/static/images/integrations/grafana.svg", | ||
"docs": "https://docs.flagsmith.com/integrations/apm/grafana", | ||
"fields": [ | ||
{ | ||
"key": "base_url", | ||
"label": "Base URL", | ||
"default": "https://grafana.com" | ||
}, | ||
{ | ||
"key": "api_key", | ||
"label": "Service account token", | ||
"hidden": true | ||
} | ||
], | ||
"tags": [ | ||
"logging" | ||
], | ||
"title": "Grafana", | ||
"description": "Receive Flagsmith annotations to your Grafana instance on feature flag and segment changes." | ||
}, | ||
``` | ||
""" | ||
|
||
base_url = models.URLField(blank=False, null=True) | ||
class GrafanaProjectConfiguration(IntegrationsModel): | ||
project = models.OneToOneField( | ||
Project, on_delete=models.CASCADE, related_name="grafana_config" | ||
) | ||
|
||
|
||
class GrafanaOrganisationConfiguration(IntegrationsModel): | ||
organisation = models.OneToOneField( | ||
Organisation, on_delete=models.CASCADE, related_name="grafana_config" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
from integrations.common.serializers import ( | ||
BaseOrganisationIntegrationModelSerializer, | ||
BaseProjectIntegrationModelSerializer, | ||
) | ||
from integrations.grafana.models import ( | ||
GrafanaOrganisationConfiguration, | ||
GrafanaProjectConfiguration, | ||
) | ||
|
||
|
||
from .models import GrafanaConfiguration | ||
class GrafanaProjectConfigurationSerializer( | ||
BaseProjectIntegrationModelSerializer, | ||
): | ||
class Meta: | ||
model = GrafanaProjectConfiguration | ||
fields = ("id", "base_url", "api_key") | ||
|
||
|
||
class GrafanaConfigurationSerializer(BaseProjectIntegrationModelSerializer): | ||
class GrafanaOrganisationConfigurationSerializer( | ||
BaseOrganisationIntegrationModelSerializer, | ||
): | ||
class Meta: | ||
model = GrafanaConfiguration | ||
model = GrafanaOrganisationConfiguration | ||
fields = ("id", "base_url", "api_key") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
from integrations.common.views import ProjectIntegrationBaseViewSet | ||
from integrations.grafana.models import GrafanaConfiguration | ||
from integrations.grafana.serializers import GrafanaConfigurationSerializer | ||
from integrations.common.views import ( | ||
OrganisationIntegrationBaseViewSet, | ||
ProjectIntegrationBaseViewSet, | ||
) | ||
from integrations.grafana.models import ( | ||
GrafanaOrganisationConfiguration, | ||
GrafanaProjectConfiguration, | ||
) | ||
from integrations.grafana.serializers import ( | ||
GrafanaOrganisationConfigurationSerializer, | ||
GrafanaProjectConfigurationSerializer, | ||
) | ||
|
||
|
||
class GrafanaConfigurationViewSet(ProjectIntegrationBaseViewSet): | ||
serializer_class = GrafanaConfigurationSerializer | ||
class GrafanaProjectConfigurationViewSet(ProjectIntegrationBaseViewSet): | ||
serializer_class = GrafanaProjectConfigurationSerializer | ||
pagination_class = None # set here to ensure documentation is correct | ||
model_class = GrafanaConfiguration | ||
model_class = GrafanaProjectConfiguration | ||
|
||
|
||
class GrafanaOrganisationConfigurationViewSet(OrganisationIntegrationBaseViewSet): | ||
serializer_class = GrafanaOrganisationConfigurationSerializer | ||
pagination_class = None # set here to ensure documentation is correct | ||
model_class = GrafanaOrganisationConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.