perf: 修改账号生成 (#11591)

* perf: 修改账号生成

* perf: 修改账号模版支持策略

* perf: 修改特殊字符数量

* perf: 修改 model 继承

* perf: 修改顺序

* perf: 修改 requirements

* perf: 修改翻译

* perf: 修改随机生成密码

* perf: 修改密钥生成

* perf: 修复 bug

---------

Co-authored-by: ibuler <ibuler@qq.com>
This commit is contained in:
fit2bot
2023-09-19 10:59:33 +08:00
committed by GitHub
parent 0b30f5cf88
commit e6fe7c489e
16 changed files with 432 additions and 326 deletions

View File

@@ -1,3 +1,5 @@
import copy
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers
@@ -18,9 +20,19 @@ class SecretGenerator:
return private_key
def generate_password(self):
length = int(self.password_rules.get('length', 0))
length = length if length else DEFAULT_PASSWORD_RULES['length']
return random_string(length, special_char=True)
password_rules = self.password_rules
if not password_rules or not isinstance(password_rules, dict):
password_rules = {}
rules = copy.deepcopy(DEFAULT_PASSWORD_RULES)
rules.update(password_rules)
rules = {
'length': rules['length'],
'lower': rules['lowercase'],
'upper': rules['uppercase'],
'digit': rules['digit'],
'special_char': rules['symbol']
}
return random_string(**rules)
def get_secret(self):
if self.secret_type == SecretType.SSH_KEY: