Skip to content

Commit

Permalink
feature: 新版导航 (#1620)
Browse files Browse the repository at this point in the history
* fix: webconsole token invalid (#1564)

* fix: webconsole token invalid

* minor: use smart_str to convert bytes to str

* fix: 集群信息界面 mem_usage -> memory_usage (#1566)

* feat: update perm for access webconsole api (#1565)

* feat: update perm for access webconsole api

* feat: update perm for access webconsole api

* refactor: 重构 components.cc 模块 (#1502)

* refactor: components.cc

* minor: resolve #1502 conversations

* minor: get_application_name 调整为使用 admin 身份获取

* fix: 业务拓扑 补充 空闲机等 内部模块

* minor: APIError -> ComponentError

* minor: use normal class rather than dataclass

* fix: DEFAULT_SUPPLIER_ACCOUNT 改存 settings (#1567)

* fix: DEFAULT_SUPPLIER_ACCOUNT 改存 settings

* minor: BKCC_DEFAULT_SUPPLIER_ACCOUNT 支持从环境变量获取

* Iamv3 framework (#1580)

* feat: project, cluster, namespace based and templateset on iam v3

* feat: add project & namespace iam api

* minor: update license

* chore: add requests_mock

* minor: fix review

* refactor: 删除K8S metriclist逻辑

* optimization: 节点选择 - 自定义输入不显示精确匹配勾选项 & refactor: 删除K8S metriclist逻辑 (#1587)

* optimization: 节点选择 - 自定义输入不显示精确匹配勾选项

* refactor: 删除K8S metriclist逻辑

* feat  (#1568)

* fix: 0923节点选择器验收问题

* feat: Helm Release列表复选框去除, 删除release后列表不更新问题修复

* feat: Helm Release列表复选框去除, 删除release后列表不更新问题修复

* feat: Helm Release列表复选框去除, 删除release后列表不更新问题修复

* fix: 带有tooltip指令的button需要在外面包一层dom实现按钮禁用时的tooltip issue #1554

* feat: 自定义资源优化项 issue #1342

* fix: 创建集群弹框提示样式优化 issue #1552

* fix

* feat: 申请主机功能优化|前端限制申请主机的数量

* fix

* feat: 配额表单展示调整 | 命名空间侧边栏表单样式调整 | 节点详情网络图表展示问题

* feat: 资源视图优化项 #1574

* 样式调整 (#1589)

* feat: MESOS应用页面展示调整

* feat: helm操作 命令行参数调整

* feat: helm操作 命令行参数调整

* feat: info组件添加defaultInfo配置项,值为true则使用组件库默认样式

* feat: info组件添加defaultInfo配置项,值为true则使用组件库默认样式

* fix: 节点管理页面搜索框自适应宽度调整

* feat: Helm Chart的readme内容渲染展示

* fix: 样式调整

* fix: ignore empty tasks in async_run (#1590)

* docs: update helm push guide docs (#1592)

* fix: AppQueryService.fetch_all add arg self.fields (#1593)

* feat: update chart model default manager (#1598)

* fix: 修复gamestatefulsets和gamedeployments批量删除功能缺失问题 (#1601)

* Update cluster configure (#1553)

* feat: update cluster configure

* feat: add white list and update method for getting cluster cred

* feat: update cluster configure

* optimization: 优化代码批量删除弹窗宽度 (#1602)

* optimization: 优化权限弹窗逻辑

* optimization: 集群首页重构

* refactor: 集群首页重构 (#1605)

* refactor: 项目配置信息界面抽取 (#1608)

* minor: set CORS_ALLOWED_ORIGINS (#1511)

* feat: 标准化推送chart api的返回格式 (#1597)

* feature: 新版导航 - 项目管理逻辑兼容多版本

* optimization: 同步修改helm md文档的数据返回格式

* optimization: 同步修改helm md文档的数据返回格式 (#1611)

* optimization: 新版导航兼容监控中心跳转

* fix: 修复IP选择器表格模糊搜索分割符问题 & 自定义输入光标失效问题

* Fix: LoginSuccessView not render success (#1613)

* fix: 修复IP选择器表格模糊搜索分割符问题 & 自定义输入光标失效问题 (#1614)

* feature: 登录对接

* Fix: SESSION_COOKIE_DOMAIN not strip left dot (#1616)

* optimization: 菜单配置优化

* fix: 修复集群指标watch集群时diff判断问题,导致指标重复请求 (#1617)

* optimization: 菜单逻辑优化

* refator: 新导航 - 切换不同项目时重新刷新界面

* fix: 删除重复Key

Co-authored-by: jamesge <[email protected]>
Co-authored-by: bellke <[email protected]>
Co-authored-by: schnee <[email protected]>
Co-authored-by: vhwweng <[email protected]>
Co-authored-by: Joe Lei <[email protected]>
  • Loading branch information
6 people committed Oct 20, 2021
1 parent a7c637a commit f435e27
Show file tree
Hide file tree
Showing 169 changed files with 5,837 additions and 2,300 deletions.
2 changes: 1 addition & 1 deletion bcs-app/backend/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
include("backend.templatesets.open_apis.template_urls"),
),
# 提供给iam拉取资源实例的url(已注册到iam后台)
url(r"^iam/", include("backend.bcs_web.iam.open_apis.urls")),
url(r"^iam/", include("backend.iam.open_apis.urls")),
# web_console API
url(
r"^projects/(?P<project_id_or_code>[\w\-]+)/clusters/(?P<cluster_id>[\w\-]+)/web_console/sessions/",
Expand Down
8 changes: 2 additions & 6 deletions bcs-app/backend/bcs_web/apis/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from rest_framework import permissions

from backend.components.paas_auth import get_access_token
from backend.utils import FancyDict
from backend.utils import FancyDict, whitelist

from .constants import ACCESS_TOKEN_KEY_NAME

Expand Down Expand Up @@ -87,9 +87,5 @@ def has_permission(self, request, view):
return False

app_code = request.user.client.app.app_code
project_whitelist = settings.BK_APP_WHITELIST.get(app_code) or []

if project_id_or_code in project_whitelist:
return True

return False
return whitelist.check_app_access_webconsole_enable(app_code, project_id_or_code)
1 change: 0 additions & 1 deletion bcs-app/backend/bcs_web/iam/bcs_iam_migration/__init__.py

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion bcs-app/backend/bcs_web/iam/open_apis/__init__.py

This file was deleted.

This file was deleted.

49 changes: 0 additions & 49 deletions bcs-app/backend/bcs_web/iam/open_apis/resources/project.py

This file was deleted.

64 changes: 0 additions & 64 deletions bcs-app/backend/bcs_web/iam/open_apis/resources/provider.py

This file was deleted.

1 change: 0 additions & 1 deletion bcs-app/backend/bcs_web/iam/open_apis/v1/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion bcs-app/backend/bcs_web/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

from backend.accounts import bcs_perm
from backend.bcs_web.audit_log.audit.context import AuditContext
from backend.bcs_web.iam import permissions
from backend.components.base import ComponentAuth
from backend.components.paas_cc import PaaSCCClient
from backend.container_service.clusters.base.models import CtxCluster
from backend.container_service.projects.base.models import CtxProject
from backend.iam import legacy_perms as permissions
from backend.utils import FancyDict
from backend.utils.cache import region

Expand Down
14 changes: 9 additions & 5 deletions bcs-app/backend/components/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ class BkCommonResponseHandler:
:param func: 调用的函数
"""

def __init__(self, default_data: Optional[Any] = None, func: Callable = None):
self.default_data = default_data
def __init__(self, default: Optional[Any] = None, func: Callable = None):
self.default = default
self.func = func

def __get__(self, instance, cls):
Expand All @@ -244,12 +244,16 @@ def __get__(self, instance, cls):
def __call__(self, *args, **kwargs) -> Any:
resp = self.func(*args, **kwargs)
if resp.get("code") == 0 or resp.get("result") is True:
return resp.get("data") or self.default_data
return resp.get("data") or self._get_default()
raise CompParseBkCommonResponseError(resp, resp.get("message"))

def _get_default(self):
""" 参考 drf Serializer Field get_default 方法,兼容可调用对象,如 dict, list """
return self.default() if callable(self.default) else self.default

def raw_request(self, *args, **kwargs) -> Any:
return self.func(*args, **kwargs)


def response_handler(default_data: Optional[Any] = None):
return functools.partial(BkCommonResponseHandler, default_data)
def response_handler(default: Optional[Any] = None):
return functools.partial(BkCommonResponseHandler, default)
55 changes: 18 additions & 37 deletions bcs-app/backend/components/bcs/k8s_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,30 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
import json
import logging
from functools import lru_cache
from typing import Dict

from cachetools import LRUCache, cached
from cachetools.keys import hashkey
from django.conf import settings
from django.utils.functional import cached_property
from kubernetes import client

from backend.components.bcs import BCSClientBase, resources
from backend.components.utils import http_get
from backend.container_service.clusters.base import CtxCluster
from backend.resources.client import BcsKubeConfigurationService

logger = logging.getLogger(__name__)

# 获取cluster context使用的缓存策略
cluster_context_cache_policy = LRUCache(maxsize=128)


@cached(
cache=cluster_context_cache_policy,
key=lambda url_prefix, access_token, project_id, cluster_id: hashkey(url_prefix, project_id, cluster_id),
)
def make_cluster_context(url_prefix: str, access_token: str, project_id: str, cluster_id: str) -> Dict:
"""组装集群的Context"""
# 获取bcs api的集群信息
url = f"{url_prefix}/bcs/query_by_id/"
params = {"access_token": access_token, "project_id": project_id, "cluster_id": cluster_id}
headers = {"Authorization": getattr(settings, "BCS_AUTH_TOKEN", ""), "Content-Type": "application/json"}
context = http_get(url, params=params, raise_for_status=False, headers=headers)
# 获取集群的credential
url = f"{url_prefix}/{context['id']}/client_credentials"
params = {"access_token": access_token}
credentials = http_get(url, params=params, raise_for_status=False, headers=headers)
context.update(credentials)

return context
@lru_cache(maxsize=32)
def make_cluster_configuration(access_token: str, project_id: str, cluster_id: str) -> Dict:
ctx_cluster = CtxCluster.create(
id=cluster_id,
project_id=project_id,
token=access_token,
)
return BcsKubeConfigurationService(ctx_cluster).make_configuration()


class K8SAPIClient(BCSClientBase):
Expand All @@ -61,19 +49,12 @@ def _headers_for_bcs_agent_api(self):

@cached_property
def api_client(self):
configure = client.Configuration()
configure.verify_ssl = False
# 获取集群context,如果调用接口或者其它异常导致失败,需要主动使缓存失效
try:
context = make_cluster_context(self.rest_host, self.access_token, self.project_id, self.cluster_id)
configure.host = f"{self._bcs_server_host}{context['server_address_path']}".rstrip("/")
configure.api_key = {"authorization": f"Bearer {context['user_token']}"}
except Exception as e:
logger.exception("make cluster context error, %s", e)
# 当出现异常时,需要清空缓存
cluster_context_cache_policy.clear()
raise
api_client = client.ApiClient(configure)
configure = make_cluster_configuration(self.access_token, self.project_id, self.cluster_id)
api_client = client.ApiClient(
configure,
header_name='X-BKAPI-AUTHORIZATION',
header_value=json.dumps({"access_token": self.access_token}),
)
return api_client


Expand Down
Loading

0 comments on commit f435e27

Please sign in to comment.