From 510ca9a5b855dacbdbcce7fb5a68bfd6977e12fd Mon Sep 17 00:00:00 2001 From: feng <1304903146@qq.com> Date: Wed, 21 Dec 2022 17:32:55 +0800 Subject: [PATCH] perf: k8s tree --- apps/perms/api/user_permission/tree/node_with_asset.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/perms/api/user_permission/tree/node_with_asset.py b/apps/perms/api/user_permission/tree/node_with_asset.py index fd8c8c233..f65cfc0b1 100644 --- a/apps/perms/api/user_permission/tree/node_with_asset.py +++ b/apps/perms/api/user_permission/tree/node_with_asset.py @@ -159,8 +159,8 @@ class UserGrantedK8sAsTreeApi(SelfOrPKUserMixin, ListAPIView): else: return account.secret - def get_namespace_and_pod(self): - key = self.request.query_params.get('key') + @staticmethod + def get_namespace_and_pod(key): namespace_and_pod = dict(parse_qsl(key)) pod = namespace_and_pod.get('pod') namespace = namespace_and_pod.get('namespace') @@ -170,11 +170,12 @@ class UserGrantedK8sAsTreeApi(SelfOrPKUserMixin, ListAPIView): token = self.get_token() asset = token.asset secret = self.get_account_secret(token) - namespace, pod = self.get_namespace_and_pod() + key = self.request.query_params.get('key') + namespace, pod = self.get_namespace_and_pod(key) tree = [] k8s_tree_instance = KubernetesTree(asset, secret) - if not any([namespace, pod]): + if not any([namespace, pod]) and not key: asset_node = k8s_tree_instance.as_asset_tree_node() tree.append(asset_node) tree.extend(k8s_tree_instance.async_tree_node(namespace, pod))