mirror of https://github.com/jumpserver/jumpserver
perf: k8s tree proxy
parent
d7a793b4c4
commit
11a58dc7ad
|
@ -18,13 +18,15 @@ logger = get_logger(__file__)
|
|||
|
||||
|
||||
class KubernetesClient:
|
||||
def __init__(self, url, token):
|
||||
def __init__(self, url, token, proxy=None):
|
||||
self.url = url
|
||||
self.token = token
|
||||
self.proxy = proxy
|
||||
|
||||
def get_api(self):
|
||||
configuration = client.Configuration()
|
||||
configuration.host = self.url
|
||||
configuration.proxy = self.proxy
|
||||
configuration.verify_ssl = False
|
||||
configuration.api_key = {"authorization": "Bearer " + self.token}
|
||||
c = api_client.ApiClient(configuration=configuration)
|
||||
|
@ -81,11 +83,23 @@ class KubernetesClient:
|
|||
data[namespace] = [pod_info, ]
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def get_kubernetes_data(app_id, username):
|
||||
@classmethod
|
||||
def get_proxy_url(cls, asset):
|
||||
if not asset.domain:
|
||||
return None
|
||||
|
||||
gateway = asset.domain.select_gateway()
|
||||
if not gateway:
|
||||
return None
|
||||
return f'{gateway.address}:{gateway.port}'
|
||||
|
||||
@classmethod
|
||||
def get_kubernetes_data(cls, app_id, username):
|
||||
asset = get_object_or_404(Asset, id=app_id)
|
||||
account = get_object_or_404(Account, asset=asset, username=username)
|
||||
k8s = KubernetesClient(asset.address, account.secret)
|
||||
k8s_url = f'{asset.address}:{asset.port}'
|
||||
proxy_url = cls.get_proxy_url(asset)
|
||||
k8s = cls(k8s_url, account.secret, proxy=proxy_url)
|
||||
return k8s.get_pods()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue