mirror of https://github.com/jumpserver/jumpserver
perf: account
parent
651c7ca152
commit
0fdc30bed3
|
@ -3,22 +3,21 @@
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
|
import sshpubkeys
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
|
|
||||||
import sshpubkeys
|
|
||||||
from django.core.cache import cache
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import QuerySet
|
from django.db.models import QuerySet
|
||||||
|
|
||||||
|
from common.db import fields
|
||||||
from common.utils import (
|
from common.utils import (
|
||||||
ssh_key_string_to_obj, ssh_key_gen, get_logger,
|
ssh_key_string_to_obj, ssh_key_gen, get_logger,
|
||||||
random_string, ssh_pubkey_gen,
|
random_string, ssh_pubkey_gen,
|
||||||
)
|
)
|
||||||
from common.db import fields
|
from assets.const import Connectivity, SecretType
|
||||||
from assets.const import Connectivity
|
|
||||||
from orgs.mixins.models import OrgModelMixin
|
from orgs.mixins.models import OrgModelMixin
|
||||||
|
|
||||||
logger = get_logger(__file__)
|
logger = get_logger(__file__)
|
||||||
|
@ -49,12 +48,6 @@ class AbsConnectivity(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class BaseAccount(OrgModelMixin):
|
class BaseAccount(OrgModelMixin):
|
||||||
class SecretType(models.TextChoices):
|
|
||||||
password = 'password', _('Password')
|
|
||||||
ssh_key = 'ssh_key', _('SSH key')
|
|
||||||
access_key = 'access_key', _('Access key')
|
|
||||||
token = 'token', _('Token')
|
|
||||||
|
|
||||||
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
|
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
|
||||||
name = models.CharField(max_length=128, verbose_name=_("Name"))
|
name = models.CharField(max_length=128, verbose_name=_("Name"))
|
||||||
username = models.CharField(max_length=128, blank=True, verbose_name=_('Username'), db_index=True)
|
username = models.CharField(max_length=128, blank=True, verbose_name=_('Username'), db_index=True)
|
||||||
|
@ -78,7 +71,7 @@ class BaseAccount(OrgModelMixin):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def private_key(self):
|
def private_key(self):
|
||||||
if self.secret_type == self.SecretType.ssh_key:
|
if self.secret_type == SecretType.ssh_key:
|
||||||
return self.secret
|
return self.secret
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -89,7 +82,7 @@ class BaseAccount(OrgModelMixin):
|
||||||
@private_key.setter
|
@private_key.setter
|
||||||
def private_key(self, value):
|
def private_key(self, value):
|
||||||
self.secret = value
|
self.secret = value
|
||||||
self.secret_type = 'private_key'
|
self.secret_type = SecretType.ssh_key
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ssh_key_fingerprint(self):
|
def ssh_key_fingerprint(self):
|
||||||
|
|
Loading…
Reference in New Issue