Skip to content

Commit

Permalink
perf: Resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
O-Jiangweidong committed May 27, 2024
2 parents c470331 + 4034e21 commit 8673904
Show file tree
Hide file tree
Showing 68 changed files with 4,080 additions and 3,540 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ RUN --mount=type=cache,target=/root/.cache,sharing=locked \
&& pip install poetry -i ${PIP_MIRROR} \
&& poetry config virtualenvs.create false \
&& . /opt/py3/bin/activate \
&& poetry install --only=main
&& poetry install --without xpack

COPY --from=stage-1 /opt/jumpserver /opt/jumpserver

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-ee
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ RUN --mount=type=cache,target=/root/.cache,sharing=locked \
&& pip install poetry -i ${PIP_MIRROR} \
&& poetry config virtualenvs.create false \
&& . /opt/py3/bin/activate \
&& poetry install
&& poetry install --with xpack

COPY --from=stage-1 /opt/jumpserver /opt/jumpserver

Expand Down
8 changes: 5 additions & 3 deletions apps/accounts/automations/change_secret/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ def host_callback(

accounts = self.get_accounts(account)
if not accounts:
print('没有发现待处理的账号: %s 用户ID: %s 类型: %s' % (
asset.name, self.account_ids, self.secret_type
))
print(
_("No pending accounts found: {name} User ID: {account_ids} Type: {secret_type}").format(
name=asset.name,
account_ids=self.account_ids,
secret_type=self.secret_type))
return []

records = []
Expand Down
71 changes: 44 additions & 27 deletions apps/accounts/serializers/account/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,34 @@
from common.serializers.fields import EncryptedField, LabeledChoiceField
from orgs.mixins.serializers import BulkOrgResourceModelSerializer

__all__ = ['AuthValidateMixin', 'BaseAccountSerializer']
__all__ = ["AuthValidateMixin", "BaseAccountSerializer"]


class AuthValidateMixin(serializers.Serializer):
secret_type = LabeledChoiceField(
choices=SecretType.choices, label=_('Secret type'), default='password'
choices=SecretType.choices, label=_("Secret type"), default="password"
)
secret = EncryptedField(
label=_('Secret'), required=False, max_length=40960, allow_blank=True,
allow_null=True, write_only=True,
label=_("Secret"),
required=False,
max_length=40960,
allow_blank=True,
allow_null=True,
write_only=True,
)
passphrase = serializers.CharField(
allow_blank=True, allow_null=True, required=False, max_length=512,
write_only=True, label=_('Passphrase')
allow_blank=True,
allow_null=True,
required=False,
max_length=512,
write_only=True,
label=_("Passphrase"),
)

@staticmethod
def handle_secret(secret, secret_type, passphrase=None):
if not secret:
return ''
return ""
if secret_type == SecretType.PASSWORD:
validate_password_for_ansible(secret)
return secret
Expand All @@ -40,17 +48,15 @@ def handle_secret(secret, secret_type, passphrase=None):
return secret

def clean_auth_fields(self, validated_data):
secret_type = validated_data.get('secret_type')
passphrase = validated_data.get('passphrase')
secret = validated_data.pop('secret', None)
validated_data['secret'] = self.handle_secret(
secret, secret_type, passphrase
)
for field in ('secret',):
secret_type = validated_data.get("secret_type")
passphrase = validated_data.get("passphrase")
secret = validated_data.pop("secret", None)
validated_data["secret"] = self.handle_secret(secret, secret_type, passphrase)
for field in ("secret",):
value = validated_data.get(field)
if not value:
validated_data.pop(field, None)
validated_data.pop('passphrase', None)
validated_data.pop("passphrase", None)

def create(self, validated_data):
self.clean_auth_fields(validated_data)
Expand All @@ -61,23 +67,34 @@ def update(self, instance, validated_data):
return super().update(instance, validated_data)


class BaseAccountSerializer(AuthValidateMixin, ResourceLabelsMixin, BulkOrgResourceModelSerializer):
class BaseAccountSerializer(
AuthValidateMixin, ResourceLabelsMixin, BulkOrgResourceModelSerializer
):
class Meta:
model = BaseAccount
fields_mini = ['id', 'name', 'username']
fields_mini = ["id", "name", "username"]
fields_small = fields_mini + [
'secret_type', 'secret', 'passphrase',
'privileged', 'is_active', 'spec_info',
"secret_type",
"secret",
"passphrase",
"privileged",
"is_active",
"spec_info",
]
fields_other = ['created_by', 'date_created', 'date_updated', 'comment']
fields = fields_small + fields_other + ['labels']
fields_other = ["created_by", "date_created", "date_updated", "comment"]
fields = fields_small + fields_other + ["labels"]
read_only_fields = [
'spec_info', 'date_verified', 'created_by', 'date_created',
"spec_info",
"date_verified",
"created_by",
"date_created",
]
extra_kwargs = {
'spec_info': {'label': _('Spec info')},
'username': {'help_text': _(
"Tip: If no username is required for authentication, fill in `null`, "
"If AD account, like `username@domain`"
)},
"spec_info": {"label": _("Spec info")},
"username": {
"help_text": _(
"* If no username is required for authentication, enter null. "
"For AD accounts, use the format username@domain."
)
},
}
2 changes: 1 addition & 1 deletion apps/acls/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Migration(migrations.Migration):
('org_id', models.CharField(blank=True, db_index=True, default='', max_length=36, verbose_name='Organization')),
('name', models.CharField(max_length=128, verbose_name='Name')),
('type', models.CharField(choices=[('command', 'Command'), ('regex', 'Regex')], default='command', max_length=16, verbose_name='Type')),
('content', models.TextField(help_text='One line one command', verbose_name='Content')),
('content', models.TextField(help_text='One command per line', verbose_name='Content')),
('ignore_case', models.BooleanField(default=True, verbose_name='Ignore case')),
],
options={
Expand Down
2 changes: 1 addition & 1 deletion apps/acls/models/command_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CommandGroup(JMSOrgBaseModel):
max_length=16, default=TypeChoices.command, choices=TypeChoices.choices,
verbose_name=_("Type")
)
content = models.TextField(verbose_name=_("Content"), help_text=_("One line one command"))
content = models.TextField(verbose_name=_("Content"), help_text=_("One command per line"))
ignore_case = models.BooleanField(default=True, verbose_name=_('Ignore case'))

TypeChoices = TypeChoices
Expand Down
10 changes: 5 additions & 5 deletions apps/assets/automations/base/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,19 +320,19 @@ def delete_runtime_dir(self):
shutil.rmtree(self.runtime_dir, ignore_errors=True)

def run(self, *args, **kwargs):
print(">>> 任务准备阶段\n")
print(_(">>> Task preparation phase"), end="\n")
runners = self.get_runners()
if len(runners) > 1:
print("### 分次执行任务, 总共 {}\n".format(len(runners)))
print(_(">>> Executing tasks in batches, total {runner_count}").format(runner_count=len(runners)))
elif len(runners) == 1:
print(">>> 开始执行任务\n")
print(_(">>> Start executing tasks"))
else:
print("### 没有需要执行的任务\n")
print(_(">>> No tasks need to be executed"), end="\n")

self.execution.date_start = timezone.now()
for i, runner in enumerate(runners, start=1):
if len(runners) > 1:
print(">>> 开始执行第 {} 批任务".format(i))
print(_(">>> Begin executing batch {index} of tasks").format(index=i))
ssh_tunnel = SSHTunnelManager()
ssh_tunnel.local_gateway_prepare(runner)
try:
Expand Down
2 changes: 1 addition & 1 deletion apps/assets/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Migration(migrations.Migration):
('date_verified', models.DateTimeField(null=True, verbose_name='Date verified')),
('name', models.CharField(max_length=128, verbose_name='Name')),
('address', models.CharField(db_index=True, max_length=767, verbose_name='Address')),
('is_active', models.BooleanField(default=True, verbose_name='Is active')),
('is_active', models.BooleanField(default=True, verbose_name='Active')),
('gathered_info', models.JSONField(blank=True, default=dict, verbose_name='Gathered info')),
('custom_info', models.JSONField(default=dict, verbose_name='Custom info')),
],
Expand Down
2 changes: 1 addition & 1 deletion apps/assets/models/asset/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Asset(NodesRelationMixin, LabeledMixin, AbsConnectivity, JSONFilterMixin,
domain = models.ForeignKey("assets.Domain", null=True, blank=True, related_name='assets',
verbose_name=_("Zone"), on_delete=models.SET_NULL)
nodes = models.ManyToManyField('assets.Node', default=default_node, related_name='assets', verbose_name=_("Nodes"))
is_active = models.BooleanField(default=True, verbose_name=_('Is active'))
is_active = models.BooleanField(default=True, verbose_name=_('Active'))
gathered_info = models.JSONField(verbose_name=_('Gathered info'), default=dict, blank=True) # 资产的一些信息,如 硬件信息
custom_info = models.JSONField(verbose_name=_('Custom info'), default=dict)

Expand Down
2 changes: 1 addition & 1 deletion apps/assets/models/cmd_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ActionChoices(models.IntegerChoices):
default=50, verbose_name=_("Priority"), help_text=_("1-100, the lower the value will be match first"),
validators=[MinValueValidator(1), MaxValueValidator(100)]
)
content = models.TextField(verbose_name=_("Content"), help_text=_("One line one command"))
content = models.TextField(verbose_name=_("Content"), help_text=_("One command per line"))
ignore_case = models.BooleanField(default=True, verbose_name=_('Ignore case'))
action = models.IntegerField(default=ActionChoices.deny, choices=ActionChoices.choices, verbose_name=_("Action"))
# 动作: 附加字段
Expand Down
2 changes: 1 addition & 1 deletion apps/assets/serializers/asset/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Meta:
fields_unexport = ['auto_config']
extra_kwargs = {
'auto_config': {'label': _('Auto info')},
'name': {'label': _("Name")},
'name': {'label': _("Name"), 'initial': 'Asset name'},
'address': {'label': _('Address')},
'nodes_display': {'label': _('Node path')},
'nodes': {'allow_empty': True, 'label': _("Nodes")},
Expand Down
7 changes: 5 additions & 2 deletions apps/assets/serializers/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers

from assets.models.gateway import Gateway
from common.serializers import ResourceLabelsMixin
from common.serializers.fields import ObjectRelatedField
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
from assets.models.gateway import Gateway
from .gateway import GatewayWithAccountSecretSerializer
from ..models import Domain

Expand All @@ -16,7 +16,10 @@

class DomainSerializer(ResourceLabelsMixin, BulkOrgResourceModelSerializer):
gateways = ObjectRelatedField(
many=True, required=False, label=_('Gateway'), queryset=Gateway.objects
many=True, required=False, label=_('Gateway'), queryset=Gateway.objects,
help_text=_(
"A gateway is a network proxy for a zone, and when connecting assets within the zone, "
"the connection is routed through the gateway.")
)
assets_amount = serializers.IntegerField(label=_('Assets amount'), read_only=True)

Expand Down
4 changes: 2 additions & 2 deletions apps/audits/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Migration(migrations.Migration):
('reason', models.CharField(blank=True, default='', max_length=128, verbose_name='Reason')),
('status', models.BooleanField(choices=[(1, 'Success'), (0, 'Failed')], default=1, verbose_name='Status')),
('datetime', models.DateTimeField(db_index=True, default=django.utils.timezone.now, verbose_name='Login Date')),
('backend', models.CharField(default='', max_length=32, verbose_name='Authentication backend')),
('backend', models.CharField(default='', max_length=32, verbose_name='Auth backend')),
],
options={
'verbose_name': 'User login log',
Expand All @@ -111,7 +111,7 @@ class Migration(migrations.Migration):
('city', models.CharField(blank=True, max_length=254, null=True, verbose_name='Login city')),
('user_agent', models.CharField(blank=True, max_length=254, null=True, verbose_name='User agent')),
('type', models.CharField(choices=[('W', 'Web'), ('T', 'Terminal'), ('U', 'Unknown')], max_length=2, verbose_name='Login type')),
('backend', models.CharField(default='', max_length=32, verbose_name='Authentication backend')),
('backend', models.CharField(default='', max_length=32, verbose_name='Auth backend')),
('date_created', models.DateTimeField(blank=True, null=True, verbose_name='Date created')),
],
options={
Expand Down
2 changes: 1 addition & 1 deletion apps/authentication/backends/saml2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def post(self, request):

if settings.SAML2_LOGOUT_COMPLETELY:
saml_instance = self.init_saml_auth(request)
logger.debug(log_prompt.format('Log out IDP user session synchronously'))
logger.debug(log_prompt.format('Logout IDP user session synchronously'))
return HttpResponseRedirect(saml_instance.logout())

logger.debug(log_prompt.format('Redirect logout url'))
Expand Down
30 changes: 15 additions & 15 deletions apps/common/signal_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ def digest_sql_query():
path = current_request.get_full_path()

print(">>>. [{}] {}".format(method, path))
for table_name, queries in table_queries.items():
if table_name.startswith('rbac_') or table_name.startswith('auth_permission'):
continue

for query in queries:
sql = query['sql']
print(" # {}: {}".format(query['time'], sql[:1000]))
if len(queries) < 3:
continue
print("- Table: {}".format(table_name))
for i, query in enumerate(queries, 1):
sql = query['sql']
if not sql or not sql.startswith('SELECT'):
continue
print('\t{}.[{}s] {}'.format(i, round(float(query['time']), 2), sql[:1000]))
# for table_name, queries in table_queries.items():
# if table_name.startswith('rbac_') or table_name.startswith('auth_permission'):
# continue
#
# for query in queries:
# sql = query['sql']
# print(" # {}: {}".format(query['time'], sql[:1000]))
# if len(queries) < 3:
# continue
# print("- Table: {}".format(table_name))
# for i, query in enumerate(queries, 1):
# sql = query['sql']
# if not sql or not sql.startswith('SELECT'):
# continue
# print('\t{}.[{}s] {}'.format(i, round(float(query['time']), 2), sql[:1000]))

# logger.debug(">>> [{}] {}".format(method, path))
for name, counter in counters:
Expand Down
4 changes: 2 additions & 2 deletions apps/i18n/_translator/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class BaseTranslateManager:
bulk_size = 15
SEPARATOR = "<SEP>"
LANG_MAPPER = {
# 'ja': 'Japanese',
'en': 'English',
'ja': 'Japanese',
# 'en': 'English',
}

def __init__(self, dir_path, oai_trans_instance):
Expand Down
Loading

0 comments on commit 8673904

Please sign in to comment.