Skip to content

Commit

Permalink
NB-12 lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kprince28 committed Jul 10, 2024
1 parent fb7c915 commit 0a9fdb7
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 27 deletions.
2 changes: 0 additions & 2 deletions netbox_secrets/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def __init__(self, *args, nested=False, fields=None, **kwargs):
super().__init__(*args, **kwargs)

def to_internal_value(self, data):

# If initialized as a nested serializer, we should expect to receive the attrs or PK
# identifying a related object.
if self.nested:
Expand Down Expand Up @@ -144,7 +143,6 @@ def __init__(self, *args, nested=False, fields=None, **kwargs):
super().__init__(*args, **kwargs)

def to_internal_value(self, data):

# If initialized as a nested serializer, we should expect to receive the attrs or PK
# identifying a related object.
if self.nested:
Expand Down
8 changes: 4 additions & 4 deletions netbox_secrets/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class UserKeyFilterSet(NetBoxModelFilterSet):

class Meta:
model = UserKey
fields = ['id',]
fields = [
'id',
]

def search(self, queryset, name, value):
if not value.strip():
return queryset
return queryset.filter(
Q(user__username__icontains=value)
)
return queryset.filter(Q(user__username__icontains=value))


class SecretRoleFilterSet(NetBoxModelFilterSet):
Expand Down
8 changes: 2 additions & 6 deletions netbox_secrets/forms/bulk_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class SecretRoleBulkEditForm(NetBoxModelBulkEditForm):

model = SecretRole

FieldSets = (
FieldSet('description', name=None),
)
FieldSets = (FieldSet('description', name=None),)

class Meta:
nullable_fields = ['description', 'comments']
Expand All @@ -33,9 +31,7 @@ class SecretBulkEditForm(NetBoxModelBulkEditForm):

model = Secret

FieldSets = (
FieldSet('description', name=None),
)
FieldSets = (FieldSet('description', name=None),)

class Meta:
nullable_fields = ['description', 'comments']
2 changes: 1 addition & 1 deletion netbox_secrets/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class UserKeyForm(forms.ModelForm):
),
label='Public Key (PEM format)',
help_text='Enter your public RSA key. Keep the private one with you; you will need it for decryption. Please '
'note that passphrase-protected keys are not supported.',
'note that passphrase-protected keys are not supported.',
)

class Meta:
Expand Down
7 changes: 4 additions & 3 deletions netbox_secrets/models/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ class UserKey(NetBoxModel):
"""

id = models.BigAutoField(primary_key=True)
user = models.OneToOneField(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='user_key',
editable=False)
user = models.OneToOneField(
to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='user_key', editable=False
)
public_key = models.TextField(
verbose_name='RSA public key',
)
Expand Down Expand Up @@ -323,7 +324,7 @@ def _unpad(self, s):
plaintext_length = (ord(s[0]) << 8) + ord(s[1])
else:
plaintext_length = (s[0] << 8) + s[1]
return s[2: plaintext_length + 2].decode('utf8')
return s[2 : plaintext_length + 2].decode('utf8')

def encrypt(self, secret_key):
"""
Expand Down
22 changes: 16 additions & 6 deletions netbox_secrets/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,24 @@ class UserKeyTable(NetBoxTable):
verbose_name=_('Is Active'),
)
tags = columns.TagColumn(url_name='plugins:netbox_secrets:userkey_list')
actions = columns.ActionsColumn(
actions=(),
extra_buttons=ACTIVATE_BUTTON
)
actions = columns.ActionsColumn(actions=(), extra_buttons=ACTIVATE_BUTTON)

class Meta(NetBoxTable.Meta):
model = UserKey
fields = (
'pk', 'user', 'is_active', 'created', 'last_updated', 'tags', 'actions',
'pk',
'user',
'is_active',
'created',
'last_updated',
'tags',
'actions',
)
default_columns = (
'pk',
'id',
'user',
'is_active',
'created',
'last_updated',
)
default_columns = ('pk', 'id', 'user', 'is_active', 'created', 'last_updated',)
1 change: 0 additions & 1 deletion netbox_secrets/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@
path('user-key/add/', views.UserKeyEditView.as_view(), name='userkey_add'),
path('user-key/<int:pk>/', include(get_model_urls('netbox_secrets', 'userkey'))),
path('user-key/<int:pk>/activate/', views.ActivateUserkeyView.as_view(), name='userkey_activate'),

path('session-key/delete/', views.SessionKeyDeleteView.as_view(), name='sessionkey_delete'),
]
14 changes: 10 additions & 4 deletions netbox_secrets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class SecretBulkDeleteView(generic.BulkDeleteView):


if plugin_settings.get('enable_contacts'):

@register_model_view(models.Secret, 'contacts')
class SecretContactsView(ObjectContactsView):
queryset = models.Secret.objects.prefetch_related('role', 'tags')
Expand All @@ -289,6 +290,7 @@ class SecretContactsView(ObjectContactsView):
# User Key
#


class UserKeyListView(generic.ObjectListView):
queryset = models.UserKey.objects.all()
table = tables.UserKeyTable
Expand Down Expand Up @@ -380,10 +382,14 @@ def dispatch(self, request, *args, **kwargs):
def get(self, request, pk):
instance = self.get_instance()
form = forms.ActivateUserKeyForm()
return render(request, self.template_name, {
'object': instance,
'form': form,
})
return render(
request,
self.template_name,
{
'object': instance,
'form': form,
},
)

def post(self, request, pk):
if not self.userkey or not self.userkey.is_active():
Expand Down

0 comments on commit 0a9fdb7

Please sign in to comment.