Skip to content

Commit

Permalink
Fix ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
miaow2 committed Oct 25, 2023
1 parent 1e46ca7 commit 04297ca
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .

Expand Down
39 changes: 24 additions & 15 deletions netbox_config_diff/compliance/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
2 changes: 1 addition & 1 deletion netbox_config_diff/configurator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 5 additions & 6 deletions netbox_config_diff/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -213,20 +213,19 @@ 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,
),
),
)
description = models.CharField(
verbose_name=_('description'),
max_length=200,
blank=True,
)
Expand Down
15 changes: 0 additions & 15 deletions netbox_config_diff/navigation.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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')

0 comments on commit 04297ca

Please sign in to comment.