def retrieve(self, request, project_id, cluster_id, namespace, name): self._validate_perm(request.user.username, project_id, cluster_id, namespace, DashboardAction.View) client = self.resource_client(request.ctx_cluster) response_data = RetrieveApiRespBuilder(client, namespace, name).build() # 补充页面信息注解,包含权限信息 web_annotations = gen_base_web_annotations(request.user.username, project_id, cluster_id, namespace) return BKAPIResponse(response_data, web_annotations=web_annotations)
def list(self, request, project_id, cluster_id, namespace=None): params = self.params_validate(ListResourceSLZ) client = self.resource_client(request.ctx_cluster) response_data = ListApiRespBuilder(client, namespace=namespace, **params).build() # 补充页面信息注解,包含权限信息 web_annotations = gen_base_web_annotations(request, project_id, cluster_id) return BKAPIResponse(response_data, web_annotations=web_annotations)
def retrieve(self, request, project_id, cluster_id, crd_name, custom_obj_name): """ 获取单个自定义对象 """ params = self.params_validate(slzs.FetchCustomObjectSLZ) client = get_cobj_client_by_crd(request.ctx_cluster, crd_name) response_data = RetrieveApiRespBuilder( client, namespace=params.get('namespace'), name=custom_obj_name, formatter=CustomObjectCommonFormatter() ).build() web_annotations = gen_base_web_annotations(request, project_id, cluster_id) return BKAPIResponse(response_data, web_annotations=web_annotations)
def gen_cobj_web_annotations(request, project_id, cluster_id, crd_name: str) -> Dict: """ 构造 custom_object 相关 web_annotations """ client = CustomResourceDefinition(request.ctx_cluster) crd = client.get(name=crd_name, is_format=False) if not crd: raise ResourceNotExist( _('集群 {} 中未注册自定义资源 {}').format(cluster_id, crd_name)) # 先获取基础的,仅包含权限信息的 web_annotations web_annotations = gen_base_web_annotations(request, project_id, cluster_id) web_annotations.update({'additional_columns': crd.additional_columns}) return web_annotations
def retrieve(self, request, project_id, cluster_id, crd_name, custom_obj_name): """获取单个自定义对象""" params = self.params_validate(slzs.FetchCustomObjectSLZ, context={ 'crd_name': crd_name, 'ctx_cluster': request.ctx_cluster }) client = get_cobj_client_by_crd(request.ctx_cluster, crd_name) namespace = params.get('namespace') self._validate_perm(request.user.username, project_id, cluster_id, namespace, DashboardAction.View) response_data = RetrieveApiRespBuilder( client, namespace=namespace, name=custom_obj_name, formatter=CustomObjectCommonFormatter()).build() web_annotations = gen_base_web_annotations(request.user.username, project_id, cluster_id, namespace) return BKAPIResponse(response_data, web_annotations=web_annotations)
def retrieve(self, request, project_id, cluster_id, namespace, name): client = self.resource_client(request.ctx_cluster) response_data = RetrieveApiRespBuilder(client, namespace, name).build() # 补充页面信息注解,包含权限信息 web_annotations = gen_base_web_annotations(request, project_id, cluster_id) return BKAPIResponse(response_data, web_annotations=web_annotations)