mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-18 00:08:31 +00:00
perf: add TERMINAL_SSH_KEY_LIMIT_COUNT conf
This commit is contained in:
@@ -18,6 +18,7 @@ from common.utils import (
|
||||
lazyproperty,
|
||||
)
|
||||
from users.signals import post_user_change_password
|
||||
from users.exceptions import CreateSSHKeyExceedLimit
|
||||
|
||||
logger = get_logger(__file__)
|
||||
|
||||
@@ -133,6 +134,15 @@ class AuthMixin:
|
||||
post_user_change_password.send(self.__class__, user=self)
|
||||
super().set_password(raw_password) # noqa
|
||||
|
||||
def set_ssh_key(self, name, public_key, private_key):
|
||||
if self.can_update_ssh_key():
|
||||
from authentication.models import SSHKey
|
||||
SSHKey.objects.create(name=name, public_key=public_key, private_key=private_key, user=self)
|
||||
post_user_change_password.send(self.__class__, user=self)
|
||||
|
||||
def can_create_ssh_key(self):
|
||||
return self.ssh_keys.count() < settings.TERMINAL_SSH_KEY_LIMIT_COUNT
|
||||
|
||||
def can_update_password(self):
|
||||
return self.is_local
|
||||
|
||||
|
Reference in New Issue
Block a user