perf: 修改翻译

pull/13305/head
ibuler 6 months ago
parent f127aca5f8
commit f16ec02c40

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -989,7 +989,7 @@
"SearchAncestorNodePerm": "Search for authorizations simultaneously on the current node and ancestor nodes",
"Secret": "Password",
"SecretKey": "Key",
"SubscriptionID": "Subscription authorization ID",
"SubscriptionID": "ID",
"SecretKeyStrategy": "Password policy",
"Secure": "Security",
"Security": "Security",

@ -208,7 +208,7 @@
"BelongAll": "同时包含",
"BelongTo": "任意包含",
"Bind": "绑定",
"BindLabel": "关联标签",
"BindTag": "关联标签",
"BindResource": "关联资源",
"BindSuccess": "绑定成功",
"BlockedIPS": "已锁定的 IP",
@ -589,7 +589,7 @@
"IsLocked": "是否暂停",
"IsSuccess": "成功",
"IsSyncAccountHelpText": "收集完成后会把收集的账号同步到资产",
"IsSyncAccountLabel": "同步到资产",
"IsSyncAccountTag": "同步到资产",
"JDCloud": "京东云",
"Job": "作业",
"JobCenter": "作业中心",
@ -603,11 +603,11 @@
"GeneralSetting": "通用配置",
"LAN": "局域网",
"LDAPUser": "LDAP 用户",
"Label": "标签",
"LabelCreate": "创建标签",
"LabelInputFormatValidation": "标签格式错误正确格式为name:value",
"LabelList": "标签列表",
"LabelUpdate": "更新标签",
"Tag": "标签",
"TagCreate": "创建标签",
"TagInputFormatValidation": "标签格式错误正确格式为name:value",
"TagList": "标签列表",
"TagUpdate": "更新标签",
"Language": "语言",
"Last30": "最近 30 次",
"Last30Days": "近30天",
@ -981,7 +981,7 @@
"SelectByAttr": "属性筛选",
"SelectFile": "选择文件",
"SelectKeyOrCreateNew": "选择标签键或创建新的",
"SelectLabelFilter": "选择标签搜索",
"SelectTagFilter": "选择标签搜索",
"SelectPlatforms": "选择平台",
"SelectProperties": "选择属性",
"SelectResource": "选择资源",

@ -1,12 +1,13 @@
# Generated by Django 4.1.13 on 2024-05-09 03:16
import common.db.fields
import uuid
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
from django.db import migrations, models
import common.db.fields
import terminal.models.component.terminal
import uuid
class Migration(migrations.Migration):
@ -138,7 +139,7 @@ class Migration(migrations.Migration):
('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
('name', models.CharField(max_length=128, unique=True, verbose_name='Name')),
('meta', common.db.fields.EncryptJsonDictTextField(default={})),
('is_default', models.BooleanField(default=False, verbose_name='Default storage')),
('is_default', models.BooleanField(default=False, verbose_name='Default')),
('type', models.CharField(choices=[('null', 'Null'), ('server', 'Server'), ('es', 'Elasticsearch')], default='server', max_length=16, verbose_name='Type')),
],
options={
@ -201,7 +202,7 @@ class Migration(migrations.Migration):
('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
('name', models.CharField(max_length=128, unique=True, verbose_name='Name')),
('meta', common.db.fields.EncryptJsonDictTextField(default={})),
('is_default', models.BooleanField(default=False, verbose_name='Default storage')),
('is_default', models.BooleanField(default=False, verbose_name='Default')),
('type', models.CharField(choices=[('null', 'Null'), ('server', 'Server'), ('s3', 'S3'), ('ceph', 'Ceph'), ('swift', 'Swift'), ('oss', 'OSS'), ('azure', 'Azure'), ('obs', 'OBS'), ('cos', 'COS'), ('sftp', 'SFTP')], default='server', max_length=16, verbose_name='Type')),
],
options={

@ -25,7 +25,7 @@ logger = get_logger(__file__)
class CommonStorageModelMixin(models.Model):
name = models.CharField(max_length=128, verbose_name=_("Name"), unique=True)
meta = EncryptJsonDictTextField(default={})
is_default = models.BooleanField(default=False, verbose_name=_('Default storage'))
is_default = models.BooleanField(default=False, verbose_name=_("Default"))
class Meta:
abstract = True
@ -35,17 +35,16 @@ class CommonStorageModelMixin(models.Model):
def set_to_default(self):
self.is_default = True
self.save(update_fields=['is_default'])
self.__class__.objects.select_for_update() \
.filter(is_default=True) \
.exclude(id=self.id) \
.update(is_default=False)
self.save(update_fields=["is_default"])
self.__class__.objects.select_for_update().filter(is_default=True).exclude(
id=self.id
).update(is_default=False)
@classmethod
def default(cls):
objs = cls.objects.filter(is_default=True)
if not objs:
objs = cls.objects.filter(name='default', type='server')
objs = cls.objects.filter(name="default", type="server")
if not objs:
objs = cls.objects.all()
return objs.first()
@ -53,8 +52,10 @@ class CommonStorageModelMixin(models.Model):
class CommandStorage(CommonStorageModelMixin, JMSBaseModel):
type = models.CharField(
max_length=16, choices=const.CommandStorageType.choices,
default=const.CommandStorageType.server.value, verbose_name=_('Type'),
max_length=16,
choices=const.CommandStorageType.choices,
default=const.CommandStorageType.server.value,
verbose_name=_("Type"),
)
@property
@ -76,20 +77,20 @@ class CommandStorage(CommonStorageModelMixin, JMSBaseModel):
@property
def config(self):
config = copy.deepcopy(self.meta)
config.update({'TYPE': self.type})
config.update({"TYPE": self.type})
return config
@property
def valid_config(self):
config = self.config
if self.type_es and config.get('INDEX_BY_DATE'):
if self.type_es and config.get("INDEX_BY_DATE"):
engine_mod = import_module(TYPE_ENGINE_MAPPING[self.type])
# 这里使用一个全新的 config, 防止修改当前的 config
store = engine_mod.CommandStore(self.config)
store._ensure_index_exists()
index_prefix = config.get('INDEX') or 'jumpserver'
index_prefix = config.get("INDEX") or "jumpserver"
date = local_now_date_display()
config['INDEX'] = '%s-%s' % (index_prefix, date)
config["INDEX"] = "%s-%s" % (index_prefix, date)
return config
def is_valid(self):
@ -97,7 +98,7 @@ class CommandStorage(CommonStorageModelMixin, JMSBaseModel):
return True
if self.type not in TYPE_ENGINE_MAPPING:
logger.error(f'Command storage `{self.type}` not support')
logger.error(f"Command storage `{self.type}` not support")
return False
engine_mod = import_module(TYPE_ENGINE_MAPPING[self.type])
@ -105,7 +106,9 @@ class CommandStorage(CommonStorageModelMixin, JMSBaseModel):
return store.ping(timeout=3)
def is_use(self):
return Terminal.objects.filter(command_storage=self.name, is_deleted=False).exists()
return Terminal.objects.filter(
command_storage=self.name, is_deleted=False
).exists()
def get_command_queryset(self):
if self.type_null:
@ -121,14 +124,17 @@ class CommandStorage(CommonStorageModelMixin, JMSBaseModel):
qs.model = Command
return qs
logger.error(f'Command storage `{self.type}` not support')
logger.error(f"Command storage `{self.type}` not support")
return Command.objects.none()
def save(self, force_insert=False, force_update=False, using=None,
update_fields=None):
def save(
self, force_insert=False, force_update=False, using=None, update_fields=None
):
super().save(
force_insert=force_insert, force_update=force_update,
using=using, update_fields=update_fields
force_insert=force_insert,
force_update=force_update,
using=using,
update_fields=update_fields,
)
if self.type in TYPE_ENGINE_MAPPING:
@ -142,8 +148,10 @@ class CommandStorage(CommonStorageModelMixin, JMSBaseModel):
class ReplayStorage(CommonStorageModelMixin, JMSBaseModel):
type = models.CharField(
max_length=16, choices=const.ReplayStorageType.choices,
default=const.ReplayStorageType.server.value, verbose_name=_('Type')
max_length=16,
choices=const.ReplayStorageType.choices,
default=const.ReplayStorageType.server.value,
verbose_name=_("Type"),
)
@property
@ -179,11 +187,11 @@ class ReplayStorage(CommonStorageModelMixin, JMSBaseModel):
_type = const.ReplayStorageType.s3.value
else:
_type = self.type
_config.update({'TYPE': _type})
_config.update({"TYPE": _type})
# add special config
if self.type_swift:
_config.update({'signer': 'S3SignerType'})
_config.update({"signer": "S3SignerType"})
# add meta config
_config.update(self.meta)
@ -193,12 +201,14 @@ class ReplayStorage(CommonStorageModelMixin, JMSBaseModel):
if self.type_null_or_server:
return True
storage = jms_storage.get_object_storage(self.config)
target = 'tests.py'
src = os.path.join(settings.BASE_DIR, 'common', target)
target = "tests.py"
src = os.path.join(settings.BASE_DIR, "common", target)
return storage.is_valid(src, target)
def is_use(self):
return Terminal.objects.filter(replay_storage=self.name, is_deleted=False).exists()
return Terminal.objects.filter(
replay_storage=self.name, is_deleted=False
).exists()
class Meta:
verbose_name = _("Replay storage")

Loading…
Cancel
Save