From 3b45ad0c61118fc710ad01ea4ae418c8632ca94d Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Thu, 23 Mar 2023 11:20:48 +0800 Subject: [PATCH 1/2] feat: account remove secret (#10045) Co-authored-by: feng <1304903146@qq.com> --- apps/accounts/api/account/account.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/accounts/api/account/account.py b/apps/accounts/api/account/account.py index d12f11549..63ec374df 100644 --- a/apps/accounts/api/account/account.py +++ b/apps/accounts/api/account/account.py @@ -2,6 +2,7 @@ from django.shortcuts import get_object_or_404 from rest_framework.decorators import action from rest_framework.generics import ListAPIView from rest_framework.response import Response +from rest_framework.status import HTTP_200_OK from accounts import serializers from accounts.filters import AccountFilterSet @@ -29,6 +30,7 @@ class AccountViewSet(OrgBulkModelViewSet): 'partial_update': ['accounts.change_account'], 'su_from_accounts': 'accounts.view_account', 'username_suggestions': 'accounts.view_account', + 'remove_secret': 'accounts.change_account', } @action(methods=['get'], detail=False, url_path='su-from-accounts') @@ -71,6 +73,11 @@ class AccountViewSet(OrgBulkModelViewSet): usernames = common + others return Response(data=usernames) + @action(methods=['patch'], detail=False, url_path='remove-secret') + def remove_secret(self, request, *args, **kwargs): + account_ids = request.data.get('account_ids', []) + self.model.objects.filter(id__in=account_ids).update(secret=None) + return Response(status=HTTP_200_OK) class AccountSecretsViewSet(RecordViewLogMixin, AccountViewSet): """ From 166d074adb062f3e97ff5f8c317dc88b66f7677f Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Thu, 23 Mar 2023 14:13:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=20port=20(#10049?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ibuler --- apps/assets/models/gateway.py | 13 ++++++++++--- apps/ops/ansible/inventory.py | 9 +-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/assets/models/gateway.py b/apps/assets/models/gateway.py index d9d4d891b..0fc6626df 100644 --- a/apps/assets/models/gateway.py +++ b/apps/assets/models/gateway.py @@ -2,11 +2,10 @@ # from django.utils.translation import ugettext_lazy as _ -from orgs.mixins.models import OrgManager -from assets.models.platform import Platform from assets.const import GATEWAY_NAME +from assets.models.platform import Platform from common.utils import get_logger, lazyproperty - +from orgs.mixins.models import OrgManager from .asset.host import Host logger = get_logger(__file__) @@ -57,6 +56,14 @@ class Gateway(Host): account = self.select_account return account.password if account else None + @lazyproperty + def port(self): + protocol = self.protocols.filter(name='ssh').first() + if protocol: + return protocol.port + else: + return '22' + @lazyproperty def private_key(self): account = self.select_account diff --git a/apps/ops/ansible/inventory.py b/apps/ops/ansible/inventory.py index fb143cda5..6abf6d18e 100644 --- a/apps/ops/ansible/inventory.py +++ b/apps/ops/ansible/inventory.py @@ -101,15 +101,8 @@ class JMSInventory: @staticmethod def get_primary_protocol(protocols): - primary_protocol = [p for p in protocols if p.primary] - if len(primary_protocol) >= 1: - primary = primary_protocol[0] - elif protocols: + if protocols: primary = protocols[0] - else: - primary = None - - if primary: protocol = primary.name port = primary.port else: