-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add user perms & view decorator response_perms (#1599)
- Loading branch information
Showing
35 changed files
with
930 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community | ||
Edition) available. | ||
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
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 logging | ||
|
||
from iam.collection import FancyDict | ||
from iam.resource.provider import ListResult, ResourceProvider | ||
from iam.resource.utils import Page | ||
|
||
from backend.components.base import ComponentAuth | ||
from backend.components.paas_cc import PaaSCCClient | ||
from backend.container_service.clusters.base import get_clusters | ||
|
||
from .utils import get_system_token | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ClusterProvider(ResourceProvider): | ||
"""集群 Provider""" | ||
|
||
def list_instance(self, filter_obj: FancyDict, page_obj: Page, **options) -> ListResult: | ||
""" | ||
获取集群列表 | ||
:param filter_obj: 查询参数字典。 以下为必传 如: {"parent": {"id": 1}} | ||
:param page_obj: 分页对象 | ||
:return: ListResult 类型的实例列表 | ||
""" | ||
project_id = filter_obj.parent['id'] | ||
cluster_list = get_clusters(get_system_token(), project_id) | ||
results = [ | ||
{'id': cluster['cluster_id'], 'display_name': cluster['name']} | ||
for cluster in cluster_list[page_obj.slice_from : page_obj.slice_to] | ||
] | ||
return ListResult(results=results, count=len(cluster_list)) | ||
|
||
def fetch_instance_info(self, filter_obj: FancyDict, **options) -> ListResult: | ||
""" | ||
批量获取集群属性详情 | ||
:param filter_obj: 查询参数字典 | ||
:return: ListResult 类型的实例列表 | ||
""" | ||
cluster_ids = filter_obj.ids | ||
paas_cc = PaaSCCClient(auth=ComponentAuth(get_system_token())) | ||
cluster_list = paas_cc.list_clusters(cluster_ids) | ||
results = [{'id': cluster['cluster_id'], 'display_name': cluster['name']} for cluster in cluster_list] | ||
return ListResult(results=results, count=len(results)) | ||
|
||
def list_instance_by_policy(self, filter_obj: FancyDict, page_obj: Page, **options) -> ListResult: | ||
return ListResult(results=[], count=0) | ||
|
||
def list_attr(self, **options) -> ListResult: | ||
return ListResult(results=[], count=0) | ||
|
||
def list_attr_value(self, filter_obj: FancyDict, page_obj: Page, **options) -> ListResult: | ||
return ListResult(results=[], count=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community | ||
Edition) available. | ||
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
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. | ||
""" | ||
from iam.collection import FancyDict | ||
from iam.resource.provider import ListResult, ResourceProvider | ||
from iam.resource.utils import Page | ||
|
||
from backend.templatesets.legacy_apps.configuration.models import Template | ||
|
||
|
||
class TemplatesetProvider(ResourceProvider): | ||
"""模板集 Provider""" | ||
|
||
def list_instance(self, filter_obj: FancyDict, page_obj: Page, **options) -> ListResult: | ||
""" | ||
获取模板集列表 | ||
:param filter_obj: 查询参数。 以下为必传如: {"parent": {"id": 1}} | ||
:param page_obj: 分页对象 | ||
:return: ListResult 类型的实例列表 | ||
""" | ||
template_qset = Template.objects.filter(project_id=filter_obj.parent['id']).values('id', 'name') | ||
results = [ | ||
{'id': template['id'], 'display_name': template['name']} | ||
for template in template_qset[page_obj.slice_from : page_obj.slice_to] | ||
] | ||
return ListResult(results=results, count=template_qset.count()) | ||
|
||
def fetch_instance_info(self, filter_obj: FancyDict, **options) -> ListResult: | ||
""" | ||
批量获取模板集属性详情 | ||
:param filter_obj: 查询参数 | ||
:return: ListResult 类型的实例列表 | ||
""" | ||
template_qset = Template.objects.filter(id__in=filter_obj.ids).values('id', 'name') | ||
results = [{'id': template['id'], 'display_name': template['name']} for template in template_qset] | ||
return ListResult(results=results, count=template_qset.count()) | ||
|
||
def list_instance_by_policy(self, filter_obj: FancyDict, page_obj: Page, **options) -> ListResult: | ||
return ListResult(results=[], count=0) | ||
|
||
def list_attr(self, **options) -> ListResult: | ||
return ListResult(results=[], count=0) | ||
|
||
def list_attr_value(self, filter_obj: FancyDict, page_obj: Page, **options) -> ListResult: | ||
return ListResult(results=[], count=0) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community | ||
Edition) available. | ||
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
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 logging | ||
|
||
from django.utils.module_loading import import_string | ||
|
||
from .permissions.exceptions import AttrValidationError | ||
from .permissions.perm import PermCtx, Permission | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def make_perm_ctx(res_type: str, username: str = 'anonymous', **ctx_kwargs) -> PermCtx: | ||
"""根据资源类型,生成对应的 PermCtx""" | ||
p_module_name = __name__.rsplit('.', 1)[0] | ||
perm_ctx_cls = import_string(f'{p_module_name}.permissions.resources.{res_type.capitalize()}PermCtx') | ||
|
||
try: | ||
perm_ctx = perm_ctx_cls(username=username, **ctx_kwargs) | ||
except TypeError as e: | ||
logger.error(e) | ||
raise AttrValidationError("perm ctx got an unexpected init argument") | ||
|
||
perm_ctx.validate() | ||
return perm_ctx | ||
|
||
|
||
def make_res_permission(res_type: str) -> Permission: | ||
"""根据资源类型,生成对应的 Permission""" | ||
p_module_name = __name__.rsplit('.', 1)[0] | ||
perm_cls = import_string(f'{p_module_name}.permissions.resources.{res_type.capitalize()}Permission') | ||
return perm_cls() |
Oops, something went wrong.