perf: k8s account ignore (#9188)

Co-authored-by: feng <1304903146@qq.com>
pull/9195/head
fit2bot 2022-12-12 11:43:19 +08:00 committed by GitHub
parent eba43f6a13
commit c861f390c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -118,7 +118,7 @@ class KubernetesTree:
def as_account_tree_node(self, account, parent_info):
username = account.username
name = f'{account.name}({account.username})'
name = str(account)
pid = urlencode({'asset_id': self.tree_id})
i = self.create_tree_id(pid, 'account', username)
parent_info.update({'account': username})

View File

@ -8,7 +8,7 @@ from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.generics import get_object_or_404
from assets.models import Asset
from assets.models import Asset, Account
from assets.utils import KubernetesTree
from assets.api import SerializeToTreeNodeMixin
from perms.hands import Node
@ -141,12 +141,19 @@ class UserGrantedK8sAsTreeApi(
asset = get_object_or_404(Asset, **kwargs)
return asset
def get_accounts(self, asset):
util = PermAccountUtil()
accounts = util.get_permed_accounts_for_user(self.user, asset)
ignore_username = [Account.AliasAccount.INPUT, Account.AliasAccount.USER]
accounts = filter(lambda x: x.username not in ignore_username, accounts)
accounts = list(accounts)
return accounts
def list(self, request: Request, *args, **kwargs):
tree_id = request.query_params.get('tree_id')
key = request.query_params.get('key', {})
tree = []
util = PermAccountUtil()
parent_info = dict(parse_qsl(key))
account_username = parent_info.get('account')
@ -155,7 +162,7 @@ class UserGrantedK8sAsTreeApi(
if tree_id and not account_username:
asset = self.asset(asset_id)
accounts = util.get_permed_accounts_for_user(self.user, asset)
accounts = self.get_accounts(asset)
asset_node = KubernetesTree(tree_id).as_asset_tree_node(asset)
tree.append(asset_node)
for account in accounts: