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", "SearchAncestorNodePerm": "Search for authorizations simultaneously on the current node and ancestor nodes",
"Secret": "Password", "Secret": "Password",
"SecretKey": "Key", "SecretKey": "Key",
"SubscriptionID": "Subscription authorization ID", "SubscriptionID": "ID",
"SecretKeyStrategy": "Password policy", "SecretKeyStrategy": "Password policy",
"Secure": "Security", "Secure": "Security",
"Security": "Security", "Security": "Security",

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

@ -1,12 +1,13 @@
# Generated by Django 4.1.13 on 2024-05-09 03:16 # Generated by Django 4.1.13 on 2024-05-09 03:16
import common.db.fields import uuid
import django.core.validators import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone import django.utils.timezone
from django.db import migrations, models
import common.db.fields
import terminal.models.component.terminal import terminal.models.component.terminal
import uuid
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -138,7 +139,7 @@ class Migration(migrations.Migration):
('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)), ('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
('name', models.CharField(max_length=128, unique=True, verbose_name='Name')), ('name', models.CharField(max_length=128, unique=True, verbose_name='Name')),
('meta', common.db.fields.EncryptJsonDictTextField(default={})), ('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')), ('type', models.CharField(choices=[('null', 'Null'), ('server', 'Server'), ('es', 'Elasticsearch')], default='server', max_length=16, verbose_name='Type')),
], ],
options={ options={
@ -201,7 +202,7 @@ class Migration(migrations.Migration):
('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)), ('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
('name', models.CharField(max_length=128, unique=True, verbose_name='Name')), ('name', models.CharField(max_length=128, unique=True, verbose_name='Name')),
('meta', common.db.fields.EncryptJsonDictTextField(default={})), ('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')), ('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={ options={

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

Loading…
Cancel
Save