diff --git a/netbox_paas/constants.py b/netbox_paas/constants.py index c274b85..0ad20f0 100644 --- a/netbox_paas/constants.py +++ b/netbox_paas/constants.py @@ -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" @@ -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", diff --git a/netbox_paas/validators.py b/netbox_paas/validators.py new file mode 100644 index 0000000..fd3fb49 --- /dev/null +++ b/netbox_paas/validators.py @@ -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 diff --git a/setup.py b/setup.py index ccecf54..69534e9 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( name="netbox-paas", - version="0.3.2", + version="0.3.3", description="Enhances NetBox on CloudMyDC's PaaS with advanced management and control features.", long_description=long_description, long_description_content_type="text/markdown",