Skip to content

Commit

Permalink
feat(config_management): ensure config doesn't use reserved config keys
Browse files Browse the repository at this point in the history
!17 #42
  • Loading branch information
jon-nfc committed Jun 2, 2024
1 parent d422f2f commit 746b7ac
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions app/config_management/models/groups.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

from django.db import models
from django.forms import ValidationError

from access.fields import *
from access.models import TenancyObject
Expand Down Expand Up @@ -32,6 +33,20 @@ def __str__(self):

class ConfigGroups(GroupsCommonFields, SaveHistory):

reserved_config_keys: list = [
'software'
]


def validate_config_keys(self):

value: dict = self

for invalid_key in ConfigGroups.reserved_config_keys:

if invalid_key in value.keys():
raise ValidationError(f'json key "{invalid_key}" is a reserved configuration key')


parent = models.ForeignKey(
'self',
Expand All @@ -53,6 +68,7 @@ class ConfigGroups(GroupsCommonFields, SaveHistory):
blank = True,
default = None,
null = True,
validators=[validate_config_keys]
)


Expand Down Expand Up @@ -102,5 +118,3 @@ def save(self, *args, **kwargs):
self.organization = ConfigGroups.objects.get(id=self.parent.id).organization

super().save(*args, **kwargs)


0 comments on commit 746b7ac

Please sign in to comment.