Skip to content

Commit

Permalink
Merge pull request #464 from peteeckel/fix/validate-setting-type-for-…
Browse files Browse the repository at this point in the history
…lists

Detect misconfigured plugin config lists at start time
  • Loading branch information
peteeckel authored Oct 28, 2024
2 parents f8d8723 + 0dcf075 commit 0673c38
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions netbox_dns/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
from django.conf import settings
from django.utils.translation import gettext_lazy as _
from django.core.exceptions import ImproperlyConfigured

from netbox.plugins import PluginConfig
from netbox.plugins.utils import get_plugin_config
from ipam.choices import IPAddressStatusChoices

from netbox_dns.choices import RecordTypeChoices, RecordStatusChoices, ZoneStatusChoices

__version__ = "1.1.4"


def _check_list(setting):
if not isinstance(get_plugin_config("netbox_dns", setting), list):
raise ImproperlyConfigured(f"{setting} must be a list")


class DNSConfig(PluginConfig):
name = "netbox_dns"
verbose_name = _("NetBox DNS")
Expand Down Expand Up @@ -61,10 +67,18 @@ class DNSConfig(PluginConfig):
def ready(self):
super().ready()

if not settings.PLUGINS_CONFIG["netbox_dns"].get("dnssync_disabled"):
if not get_plugin_config("netbox_dns", "dnssync_disabled"):
import netbox_dns.signals.ipam_dnssync # noqa: F401
import netbox_dns.tables.ipam_dnssync # noqa: F401

for setting in (
"zone_active_status",
"record_active_status",
"dnssync_ipaddress_active_status",
"tolerate_leading_underscore_types",
):
_check_list(setting)


#
# Initialize plugin config
Expand Down

0 comments on commit 0673c38

Please sign in to comment.