diff --git a/.github/workflows/commit.yaml b/.github/workflows/commit.yaml index 244dc79..4731536 100644 --- a/.github/workflows/commit.yaml +++ b/.github/workflows/commit.yaml @@ -22,7 +22,7 @@ jobs: python -m pip install --upgrade setuptools wheel python -m pip install -r requirements/dev.txt - name: Run ruff format - run: ruff format + run: ruff format . - name: Run ruff run: ruff . diff --git a/netbox_config_diff/compliance/secrets.py b/netbox_config_diff/compliance/secrets.py index 998311c..862adae 100644 --- a/netbox_config_diff/compliance/secrets.py +++ b/netbox_config_diff/compliance/secrets.py @@ -15,9 +15,9 @@ class SecretsMixin: def get_session_key(self) -> None: if "netbox_secrets_sessionid" in self.request.COOKIES: - self.session_key = base64.b64decode(self.request.COOKIES['netbox_secrets_sessionid']) + self.session_key = base64.b64decode(self.request.COOKIES["netbox_secrets_sessionid"]) elif "HTTP_X_SESSION_KEY" in self.request.META: - self.session_key = base64.b64decode(self.request.META['HTTP_X_SESSION_KEY']) + self.session_key = base64.b64decode(self.request.META["HTTP_X_SESSION_KEY"]) else: self.session_key = None @@ -45,24 +45,33 @@ def get_secret(self, secret: "Secret") -> str | None: return None return secret.plaintext - def get_credentials(self, device: Device) -> tuple[str, str]: - if self.netbox_secrets_installed: - if secret := device.secrets.filter(role__name=self.user_role).first(): - if value := self.get_secret(secret): - username = value - if secret := device.secrets.filter(role__name=self.password_role).first(): - if value := self.get_secret(secret): - password = value - return username, password + def get_credentials(self, device: Device) -> tuple[str, str, str]: + if not self.netbox_secrets_installed: + return self.username, self.password, self.auth_secondary - return self.username, self.password + if secret := device.secrets.filter(role__name=self.user_role).first(): + username = value if (value := self.get_secret(secret)) else self.username + else: + username = self.username + if secret := device.secrets.filter(role__name=self.password_role).first(): + password = value if (value := self.get_secret(secret)) else self.password + else: + password = self.password + if secret := device.secrets.filter(role__name=self.auth_secondary_role).first(): + auth_secondary = value if (value := self.get_secret(secret)) else self.auth_secondary + else: + auth_secondary = self.auth_secondary + + return username, password, auth_secondary def check_netbox_secrets(self) -> None: if "netbox_secrets" in get_installed_plugins(): self.get_master_key() self.user_role = get_plugin_config("netbox_config_diff", "USER_SECRET_ROLE") self.password_role = get_plugin_config("netbox_config_diff", "PASSWORD_SECRET_ROLE") + self.auth_secondary_role = get_plugin_config("netbox_config_diff", "SECOND_AUTH_SECRET_ROLE") self.netbox_secrets_installed = True - else: - self.username = get_plugin_config("netbox_config_diff", "USERNAME") - self.password = get_plugin_config("netbox_config_diff", "PASSWORD") + + self.username = get_plugin_config("netbox_config_diff", "USERNAME") + self.password = get_plugin_config("netbox_config_diff", "PASSWORD") + self.auth_secondary = get_plugin_config("netbox_config_diff", "AUTH_SECONDARY") diff --git a/netbox_config_diff/configurator/utils.py b/netbox_config_diff/configurator/utils.py index c556f32..cf751cb 100644 --- a/netbox_config_diff/configurator/utils.py +++ b/netbox_config_diff/configurator/utils.py @@ -15,7 +15,7 @@ def _log(self, message: str, log_level: str | None = None) -> None: raise Exception(f"Unknown logging level: {log_level}") if log_level is None: log_level = LogLevelChoices.LOG_DEFAULT - self.log_data.append((timezone.now().strftime('%Y-%m-%d %H:%M:%S'), log_level, message)) + self.log_data.append((timezone.now().strftime("%Y-%m-%d %H:%M:%S"), log_level, message)) def log(self, message: str) -> None: self._log(message, log_level=LogLevelChoices.LOG_DEFAULT) diff --git a/netbox_config_diff/models/models.py b/netbox_config_diff/models/models.py index 46228af..4bb0dfd 100644 --- a/netbox_config_diff/models/models.py +++ b/netbox_config_diff/models/models.py @@ -110,21 +110,21 @@ class ConfigurationRequest(AbsoluteURLMixin, JobsMixin, PrimaryModel): created_by = models.ForeignKey( to=settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, - related_name='+', + related_name="+", blank=True, null=True, ) approved_by = models.ForeignKey( to=settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, - related_name='+', + related_name="+", blank=True, null=True, ) scheduled_by = models.ForeignKey( to=settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, - related_name='+', + related_name="+", blank=True, null=True, ) @@ -213,12 +213,12 @@ class Substitute(AbsoluteURLMixin, NetBoxModel): unique=True, validators=( RegexValidator( - regex=r'^[a-z0-9_]+$', + regex=r"^[a-z0-9_]+$", message=_("Only alphanumeric characters and underscores are allowed."), flags=re.IGNORECASE, ), RegexValidator( - regex=r'__', + regex=r"__", message=_("Double underscores are not permitted in names."), flags=re.IGNORECASE, inverse_match=True, @@ -226,7 +226,6 @@ class Substitute(AbsoluteURLMixin, NetBoxModel): ), ) description = models.CharField( - verbose_name=_('description'), max_length=200, blank=True, ) diff --git a/netbox_config_diff/navigation.py b/netbox_config_diff/navigation.py index 0e08eb1..ddada5d 100644 --- a/netbox_config_diff/navigation.py +++ b/netbox_config_diff/navigation.py @@ -1,6 +1,3 @@ -from django import forms -from extras.dashboard.utils import register_widget -from extras.dashboard.widgets import DashboardWidget, WidgetConfigForm from extras.plugins import PluginMenuButton, PluginMenuItem from utilities.choices import ButtonColorChoices @@ -47,15 +44,3 @@ def get_add_button(model: str) -> PluginMenuButton: permissions=["netbox_config_diff.view_substitute"], ), ) - - -@register_widget -class ReminderWidget(DashboardWidget): - default_title = 'Reminder' - description = 'Add a virtual sticky note' - - class ConfigForm(WidgetConfigForm): - content = forms.CharField(widget=forms.Textarea()) - - def render(self, request): - return self.config.get('content')