Skip to content

Commit

Permalink
fix: [gen_perms_apply_data]拓扑资源需考虑system id (#87)
Browse files Browse the repository at this point in the history
* fix: [gen_perms_apply_data]拓扑资源需考虑system id

* fix: 资源反向拉取增加ancestors过滤字段

* fix: 补充资源反向拉取单元测试 & 存量单元测试修复

* fix: 更新 release 信息及版本号
  • Loading branch information
iSecloud authored Nov 9, 2023
1 parent 450e616 commit fe97bf7
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 51 deletions.
2 changes: 1 addition & 1 deletion iam/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

__version__ = "1.3.4"
__version__ = "1.3.5"
6 changes: 4 additions & 2 deletions iam/contrib/django/dispatcher/dispatchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ def _dispatch_list_attr_value(self, request, data, request_id):
def _dispatch_list_instance(self, request, data, request_id):
options = self._get_options(request)

filter_obj = get_filter_obj(data.get("filter"), ["parent", "search", "action", "resource_type_chain"])
filter_obj = get_filter_obj(
data.get("filter"), ["parent", "search", "action", "resource_type_chain", "ancestors"]
)
page_obj = get_page_obj(data.get("page"))

provider = self._provider[data["type"]]
Expand Down Expand Up @@ -198,7 +200,7 @@ def _dispatch_list_instance_by_policy(self, request, data, request_id):
def _dispatch_search_instance(self, request, data, request_id):
options = self._get_options(request)

filter_obj = get_filter_obj(data.get("filter"), ["parent", "action", "keyword"])
filter_obj = get_filter_obj(data.get("filter"), ["parent", "action", "keyword", "ancestors"])

if filter_obj.keyword is None or len(filter_obj.keyword) < 2:
raise KeywordTooShortException("the length of keyword should be greater than or equals to 2")
Expand Down
7 changes: 4 additions & 3 deletions iam/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ def gen_perms_apply_data(system, subject, action_to_resources_list):
# NOTE: old _bk_iam_path_ is like /set,1/host,2/
# while the new _bk_iam_path_ is like /bk_cmdb,set,1/bk_cmdb,host,2/
node_parts = part.split(",")
rtype, rid = "", ""
# NOTE: topo resources should be considered to belong to different systems
rsystem, rtype, rid = system_id, "", ""
if len(node_parts) == 2:
rtype, rid = node_parts[0], node_parts[1]
elif len(node_parts) == 3:
rtype, rid = node_parts[1], node_parts[2]
rsystem, rtype, rid = node_parts[0], node_parts[1], node_parts[2]
# NOTE: currently, keep the name of /bk_cmdb,set,1/ same as /set,1/
part = ",".join(node_parts[1:])
else:
Expand All @@ -99,7 +100,7 @@ def gen_perms_apply_data(system, subject, action_to_resources_list):
inst_item.append(
{
"type": rtype,
"type_name": meta.get_resource_name(system_id, rtype),
"type_name": meta.get_resource_name(rsystem, rtype),
"id": rid,
"name": part,
}
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![](docs/resource/img/bk_iam_zh.png)
---

[![license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/TencentBlueKing/iam-python-sdk/blob/master/LICENSE.txt) [![Release Version](https://img.shields.io/badge/release-1.3.4-brightgreen.svg)](https://github.com/TencentBlueKing/iam-python-sdk/releases) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/TencentBlueKing/iam-python-sdk/pulls) [![BK Pipelines Status](https://api.bkdevops.qq.com/process/api/external/pipelines/projects/iam/p-5c359e750bb9457984ab84656651d843/badge?X-DEVOPS-PROJECT-ID=iam)](http://devops.oa.com/process/api-html/user/builds/projects/iam/pipelines/p-5c359e750bb9457984ab84656651d843/latestFinished?X-DEVOPS-PROJECT-ID=iam)
[![license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/TencentBlueKing/iam-python-sdk/blob/master/LICENSE.txt) [![Release Version](https://img.shields.io/badge/release-1.3.5-brightgreen.svg)](https://github.com/TencentBlueKing/iam-python-sdk/releases) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/TencentBlueKing/iam-python-sdk/pulls) [![BK Pipelines Status](https://api.bkdevops.qq.com/process/api/external/pipelines/projects/iam/p-5c359e750bb9457984ab84656651d843/badge?X-DEVOPS-PROJECT-ID=iam)](http://devops.oa.com/process/api-html/user/builds/projects/iam/pipelines/p-5c359e750bb9457984ab84656651d843/latestFinished?X-DEVOPS-PROJECT-ID=iam)

[(English Documents Available)](readme_en.md)

Expand Down
2 changes: 1 addition & 1 deletion readme_en.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![](docs/resource/img/bk_iam_en.png)
---

[![license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/TencentBlueKing/iam-python-sdk/blob/master/LICENSE.txt) [![Release Version](https://img.shields.io/badge/release-1.3.4-brightgreen.svg)](https://github.com/TencentBlueKing/iam-python-sdk/releases) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/TencentBlueKing/iam-python-sdk/pulls) [![BK Pipelines Status](https://api.bkdevops.qq.com/process/api/external/pipelines/projects/iam/p-5c359e750bb9457984ab84656651d843/badge?X-DEVOPS-PROJECT-ID=iam)](http://devops.oa.com/process/api-html/user/builds/projects/iam/pipelines/p-5c359e750bb9457984ab84656651d843/latestFinished?X-DEVOPS-PROJECT-ID=iam)
[![license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/TencentBlueKing/iam-python-sdk/blob/master/LICENSE.txt) [![Release Version](https://img.shields.io/badge/release-1.3.5-brightgreen.svg)](https://github.com/TencentBlueKing/iam-python-sdk/releases) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/TencentBlueKing/iam-python-sdk/pulls) [![BK Pipelines Status](https://api.bkdevops.qq.com/process/api/external/pipelines/projects/iam/p-5c359e750bb9457984ab84656651d843/badge?X-DEVOPS-PROJECT-ID=iam)](http://devops.oa.com/process/api-html/user/builds/projects/iam/pipelines/p-5c359e750bb9457984ab84656651d843/latestFinished?X-DEVOPS-PROJECT-ID=iam)

## Overview

Expand Down
5 changes: 5 additions & 0 deletions release.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
版本日志
===============

# v1.3.5

- add: list_instance、search_instance 新增 ancestors 返回
- fix: gen_perms_apply_data拓扑资源需考虑system id

# v1.3.4

- IAMMigrator 将 bk_app_code/bk_app_secret 设置为类实例属性
Expand Down
32 changes: 25 additions & 7 deletions tests/contrib/django/dispatcher/test_dispatchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_basic_resource_api_dispatcher__dispatch__json_load_fail():
assert resp["code"] == 400
assert resp["result"] is False
assert resp["data"] is None
assert resp["message"] == "reqeust body is not a valid json"
assert resp["message"] == "request body is not a valid json"
assert "X-Request-Id" in resp


Expand Down Expand Up @@ -369,7 +369,13 @@ def fetch_resource_type_schema(self, **options):
{
"method": "list_instance",
"type": "spy",
"filter": {"parent": "parent", "search": "search", "resource_type_chain": "resource_type_chain"},
"filter": {
"parent": "parent",
"search": "search",
"ancestors": "ancestors",
"action": "action",
"resource_type_chain": "resource_type_chain"
},
"page": {"limit": "limit", "offset": "offset"},
}
)
Expand All @@ -378,7 +384,13 @@ def fetch_resource_type_schema(self, **options):
resp = dispatcher._dispatch(list_instance_req)

provider.pre_list_instance.assert_called_once_with(
{"parent": "parent", "search": "search", "resource_type_chain": "resource_type_chain"},
{
"parent": "parent",
"search": "search",
"ancestors": "ancestors",
"resource_type_chain": "resource_type_chain",
"action": "action",
},
{"limit": "limit", "offset": "offset"},
language="en",
)
Expand All @@ -389,7 +401,13 @@ def fetch_resource_type_schema(self, **options):
assert "message" in resp
assert provider.list_instance_spy == {
"options": {"language": "en"},
"filter": {"parent": "parent", "search": "search", "resource_type_chain": "resource_type_chain"},
"filter": {
"parent": "parent",
"search": "search",
"ancestors": "ancestors",
"resource_type_chain": "resource_type_chain",
"action": "action"
},
"page": {"limit": "limit", "offset": "offset"},
}

Expand All @@ -399,7 +417,7 @@ def fetch_resource_type_schema(self, **options):
{
"method": "search_instance",
"type": "spy",
"filter": {"parent": "parent", "keyword": "keyword"},
"filter": {"parent": "parent", "keyword": "keyword", "action": "action", "ancestors": "ancestors"},
"page": {"limit": "limit", "offset": "offset"},
}
)
Expand All @@ -408,7 +426,7 @@ def fetch_resource_type_schema(self, **options):
resp = dispatcher._dispatch(search_instance_req)

provider.pre_search_instance.assert_called_once_with(
{"parent": "parent", "keyword": "keyword"},
{"parent": "parent", "keyword": "keyword", "action": "action", "ancestors": "ancestors"},
{"limit": "limit", "offset": "offset"},
language="en",
)
Expand All @@ -419,7 +437,7 @@ def fetch_resource_type_schema(self, **options):
assert "message" in resp
assert provider.search_instance_spy == {
"options": {"language": "en"},
"filter": {"parent": "parent", "keyword": "keyword"},
"filter": {"parent": "parent", "keyword": "keyword", "action": "action", "ancestors": "ancestors"},
"page": {"limit": "limit", "offset": "offset"},
}

Expand Down
Loading

0 comments on commit fe97bf7

Please sign in to comment.