mirror of https://github.com/jumpserver/jumpserver
60 lines
2.7 KiB
Python
60 lines
2.7 KiB
Python
from django.db import models
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from common.db import fields
|
|
from common.db.models import JMSBaseModel
|
|
from .base import BaseAutomation
|
|
|
|
|
|
__all__ = ['ChangeSecretAutomation', 'ChangeSecretRecord', 'SecretStrategy']
|
|
|
|
|
|
class SecretStrategy(models.TextChoices):
|
|
custom = 'specific', _('Specific')
|
|
random_one = 'random_one', _('All assets use the same random password')
|
|
random_all = 'random_all', _('All assets use different random password')
|
|
|
|
|
|
class SSHKeyStrategy(models.TextChoices):
|
|
add = 'add', _('Append SSH KEY')
|
|
set = 'set', _('Empty and append SSH KEY')
|
|
set_jms = 'set_jms', _('Replace (The key generated by JumpServer) ')
|
|
|
|
|
|
class ChangeSecretAutomation(BaseAutomation):
|
|
secret_types = models.JSONField(default=list, verbose_name=_('Secret types'))
|
|
password_strategy = models.CharField(choices=SecretStrategy.choices, max_length=16,
|
|
default=SecretStrategy.random_one, verbose_name=_('Password strategy'))
|
|
password = fields.EncryptTextField(blank=True, null=True, verbose_name=_('Secret'))
|
|
password_rules = models.JSONField(default=dict, verbose_name=_('Password rules'))
|
|
|
|
ssh_key_strategy = models.CharField(choices=SecretStrategy.choices, default=SecretStrategy.random_one, max_length=16)
|
|
ssh_key = fields.EncryptTextField(blank=True, null=True, verbose_name=_('SSH key'))
|
|
ssh_key_change_strategy = models.CharField(choices=SSHKeyStrategy.choices, max_length=16,
|
|
default=SSHKeyStrategy.add, verbose_name=_('SSH key strategy'))
|
|
recipients = models.ManyToManyField('users.User', blank=True, verbose_name=_("Recipient"))
|
|
|
|
def save(self, *args, **kwargs):
|
|
self.type = 'change_secret'
|
|
super().save(*args, **kwargs)
|
|
|
|
class Meta:
|
|
verbose_name = _("Change auth strategy")
|
|
|
|
|
|
class ChangeSecretRecord(JMSBaseModel):
|
|
execution = models.ForeignKey('assets.AutomationExecution', on_delete=models.CASCADE)
|
|
account = models.ForeignKey('assets.Account', on_delete=models.CASCADE, null=True)
|
|
old_secret = fields.EncryptTextField(blank=True, null=True, verbose_name=_('Old secret'))
|
|
new_secret = fields.EncryptTextField(blank=True, null=True, verbose_name=_('Secret'))
|
|
date_started = models.DateTimeField(blank=True, null=True, verbose_name=_('Date started'))
|
|
date_finished = models.DateTimeField(blank=True, null=True, verbose_name=_('Date finished'))
|
|
status = models.CharField(max_length=16, default='pending')
|
|
error = models.TextField(blank=True, null=True, verbose_name=_('Error'))
|
|
|
|
class Meta:
|
|
verbose_name = _("Change secret")
|
|
|
|
def __str__(self):
|
|
return self.account.__str__()
|