Skip to content

Commit

Permalink
Merge pull request #54 from Onemind-Services-LLC/OMS-120-Allowed-Host…
Browse files Browse the repository at this point in the history
…-field-error

OMS-120 fixed allowed host parsing issue
  • Loading branch information
abhi1693 authored Sep 2, 2024
2 parents ff86ea3 + 76042f3 commit 5058886
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions netbox_paas/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from extras.constants import DEFAULT_DASHBOARD
from utilities.forms import BOOLEAN_WITH_BLANK_CHOICES
from .nb_settings import *
from .validators import validate_comma_separated

JELASTIC_API = "https://app.xapp.cloudmydc.com"
NETBOX_JPS_REPO = "https://raw.githubusercontent.com/Onemind-Services-LLC/netbox-jps/master"
Expand Down Expand Up @@ -33,8 +34,8 @@
label="Allowed Hosts",
help_text="Comma separated list of allowed hosts (FQDN, IP address, or pattern), or '*' for all",
placeholder="netbox.example.com, localhost, *",
field=SimpleArrayField,
field_kwargs={'base_field': forms.CharField()},
field=forms.CharField,
field_kwargs={"validators": [validate_comma_separated]},
),
Param(
key="DB_CONN_MAX_AGE",
Expand Down
13 changes: 13 additions & 0 deletions netbox_paas/validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.core.exceptions import ValidationError

__all__ = ('validate_comma_separated',)


def validate_comma_separated(value):
if not isinstance(value, str):
raise ValidationError("This field requires a string of comma-separated values.")
values = value.split(',')
if any(not item.strip() for item in values):
raise ValidationError("Each value should be non-empty and comma-separated without extra spaces.")

return value

0 comments on commit 5058886

Please sign in to comment.