文档首页/ 安全云脑 SecMaster/ API参考/ 安全云脑 API V1/ 应急策略/ 查询策略视图列表 - SearchPolicy
更新时间:2026-02-05 GMT+08:00
分享

查询策略视图列表 - SearchPolicy

功能介绍

查询策略视图列表

调用方法

请参见如何调用API

授权信息

账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限,具体权限要求请参见权限和授权项

URI

POST /v1/{project_id}/workspaces/{workspace_id}/soc/policys/search

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释:

项目ID,用于明确项目归属,配置后可通过该ID查询项目下资产,可以通过调用API获取,也可以从控制台获取。获取项目ID

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

workspace_id

String

参数解释:

工作空间id。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数解释:

用户Token,通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。获取用户Token

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

Content-Type

String

参数解释:

内容类型

  • application/json;charset=UTF-8 普通API请求的类型

约束限制:

不涉及

取值范围:

  • application/json;charset=UTF-8

默认取值:

不涉及

X-Secmaster-Version

String

服务版本,例如25.5.0

表3 请求Body参数

参数

是否必选

参数类型

描述

limit

Integer

分页数量

offset

Integer

偏移量

condition

condition object

查询条件

sort

Array of sort objects

排序条件

group_by

group_by object

聚合条件

表4 condition

参数

是否必选

参数类型

描述

conditions

Array of conditions objects

查询条件

logics

Array of strings

条件名称

表5 conditions

参数

是否必选

参数类型

描述

name

String

条件名称

data

Array of strings

条件键值对

表6 sort

参数

是否必选

参数类型

描述

sort_by

String

排序字段

order

String

顺序或倒序

表7 group_by

参数

是否必选

参数类型

描述

group_by_fields

Array of strings

聚合字段

group_by_hit

group_by_hit object

聚合结果

表8 group_by_hit

参数

是否必选

参数类型

描述

source

String

源字段

dest

String

目标字段

响应参数

状态码:200

表9 响应Header参数

参数

参数类型

描述

content-type

String

内容类型

表10 响应Body参数

参数

参数类型

描述

code

String

返回编码

data

Array of objects

返回数据

message

String

返回消息

page

Integer

页码

request_id

String

请求ID

size

Integer

单页数量

success

Boolean

成功状态

total

Integer

总量

状态码:400

表11 响应Header参数

参数

参数类型

描述

content-type

String

内容类型

表12 响应Body参数

参数

参数类型

描述

code

String

参数解释:

错误码

取值范围:

不涉及

message

String

参数解释:

错误描述

取值范围:

不涉及

请求示例

查询策略视图列表

https://{endpoint}/v1/{project_id}/workspaces/{workspace_id}/soc/policys/search

{
  "limit" : 10,
  "offset" : 0,
  "condition" : {
    "conditions" : [ {
      "name" : "logic_0",
      "data" : [ "defense_policy_object.defense_block_status", "=", "SUCCESS" ]
    } ],
    "logics" : [ "logic_0" ]
  },
  "sort" : [ {
    "sort_by" : "create_time",
    "order" : "desc"
  } ],
  "group_by" : {
    "group_by_fields" : [ "block_target", "workspace_id", "policy_task_id" ],
    "group_by_hit" : {
      "source" : "defense_policy_object",
      "dest" : "defense_policy_list"
    }
  }
}

响应示例

状态码:200

成功

{
  "code" : "00000000",
  "data" : [ {
    "aggs_data_objects" : [ {
      "modifier_name" : "test_domain_name",
      "block_age" : {
        "is_block_ageing" : false,
        "block_ageing" : null
      },
      "description" : "",
      "policy_task_id" : "e5384393-95d8-4767-bec1-b9d83cd19bd7",
      "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
      "workspace_id" : "ff631ed9-96ac-439f-880f-5de3ddd72cbb",
      "domain_name" : "test_domain_name",
      "update_time" : "2025-10-14T14:55:52.648+08:00",
      "is_deleted" : false,
      "block_target" : "2.2.2.2",
      "project_id" : "3bb27e024693436da46b5f5aaf499060",
      "region_name" : null,
      "defense_policy_object" : {
        "target_project_name" : "RegionName",
        "defense_connection_name" : "VPC",
        "defense_type" : "VPC",
        "defense_policy_list" : null,
        "target_enterprise_id" : "0",
        "defense_connection_region_id" : "RegionId",
        "description" : null,
        "defense_policy_name" : "SecMaster_Group_IPv4_EGRESS_BLOCK0",
        "defense_modifier_name" : "test_domain_name",
        "defense_connection_id" : "4c1adb13-10a4-383d-8216-4f5714b6128c",
        "defense_id" : "a4b06b03-7971-402e-a330-b5e806d7ca10",
        "defense_connection_region_name" : "RegionName",
        "target_enterprise_name" : "default",
        "defense_update_time" : "2025-10-14T14:55:48.612+08:00",
        "dataobject_id" : null,
        "defense_block_status" : "SUCCESS",
        "target_project_id" : "3bb27e024693436da46b5f5aaf499060",
        "defense_modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
        "defense_policy_id" : "7fa91ea0-d6e6-4718-9677-21bbc90750be"
      },
      "id" : "61afc7ba-e2ee-4200-b725-8ca71955ebc4",
      "policy_direction" : "EGRESS",
      "create_time" : "2025-10-14T14:55:48.691+08:00",
      "region_id" : "RegionId",
      "dataclass_id" : "782353cb-e951-3f94-be8c-9ab0e140a137",
      "policy_task_name" : "test_domain_name-VPC-20251014145548",
      "labels" : "",
      "environment" : {
        "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
        "domain_name" : "test_domain_name",
        "project_id" : "3bb27e024693436da46b5f5aaf499060",
        "region_id" : "RegionId",
        "region_name" : "RegionName",
        "vendor_type" : "cloud"
      },
      "policy_type" : {
        "policy_type" : "Source Ip",
        "id" : "4d67fe756fcefbf60337e5c8debdff6d",
        "category" : "defense direction"
      },
      "trigger_flag" : true,
      "policy_category" : "BLOCK",
      "creator_id" : "b6566bce94194f3d9dc6d397c72e40b2",
      "modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
      "creator_name" : "test_domain_name"
    }, {
      "modifier_name" : "test_domain_name",
      "block_age" : {
        "is_block_ageing" : false,
        "block_ageing" : null
      },
      "description" : "",
      "policy_task_id" : "36e11d45-45a5-4ddf-8fd7-2899f18e96d4",
      "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
      "workspace_id" : "ff631ed9-96ac-439f-880f-5de3ddd72cbb",
      "domain_name" : "test_domain_name",
      "update_time" : "2025-10-14T15:14:46.363+08:00",
      "is_deleted" : false,
      "block_target" : "2.2.2.2",
      "project_id" : "3bb27e024693436da46b5f5aaf499060",
      "region_name" : null,
      "defense_policy_object" : {
        "target_project_name" : "RegionName",
        "defense_connection_name" : "VPC",
        "defense_type" : "VPC",
        "defense_policy_list" : null,
        "target_enterprise_id" : "0",
        "defense_connection_region_id" : "RegionId",
        "description" : null,
        "defense_policy_name" : "SecMaster_Group_IPv4_EGRESS_BLOCK0",
        "defense_modifier_name" : "test_domain_name",
        "defense_connection_id" : "4c1adb13-10a4-383d-8216-4f5714b6128c",
        "defense_id" : "fb619dcd-30dc-4b00-beb7-db9f960a7bcd",
        "defense_connection_region_name" : "RegionName",
        "target_enterprise_name" : "default",
        "defense_update_time" : "2025-10-14T15:14:42.861+08:00",
        "dataobject_id" : null,
        "defense_block_status" : "SUCCESS",
        "target_project_id" : "8846a9979e464df3817056a9e8f70e53",
        "defense_modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
        "defense_policy_id" : "c7caf237-c8cd-45cc-ba5d-2e8af3567878"
      },
      "id" : "e08a7d0f-1e3f-4e2d-b19a-4051ad1061b3",
      "policy_direction" : "EGRESS",
      "create_time" : "2025-10-14T15:14:42.927+08:00",
      "region_id" : "RegionId",
      "dataclass_id" : "782353cb-e951-3f94-be8c-9ab0e140a137",
      "policy_task_name" : "test_domain_name-VPC-20251014151442",
      "labels" : "",
      "environment" : {
        "domain_id" : "c54198aa774c48eabb0ed1f018f2f2de",
        "domain_name" : "DomainName",
        "project_id" : "8846a9979e464df3817056a9e8f70e53",
        "region_id" : "RegionId",
        "region_name" : "RegionName",
        "vendor_type" : "cloud"
      },
      "policy_type" : {
        "policy_type" : "Source Ip",
        "id" : "4d67fe756fcefbf60337e5c8debdff6d",
        "category" : "defense direction"
      },
      "trigger_flag" : true,
      "policy_category" : "BLOCK",
      "creator_id" : "b6566bce94194f3d9dc6d397c72e40b2",
      "modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
      "creator_name" : "test_domain_name"
    } ],
    "create_time" : null,
    "data_object" : {
      "modifier_name" : "test_domain_name",
      "block_age" : {
        "is_block_ageing" : false,
        "block_ageing" : null
      },
      "description" : "",
      "policy_task_id" : "e5384393-95d8-4767-bec1-b9d83cd19bd7",
      "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
      "workspace_id" : "ff631ed9-96ac-439f-880f-5de3ddd72cbb",
      "domain_name" : "test_domain_name",
      "update_time" : "2025-10-14T14:55:52.648Z+0800",
      "is_deleted" : false,
      "block_target" : "2.2.2.2",
      "project_id" : "3bb27e024693436da46b5f5aaf499060",
      "region_name" : null,
      "id" : "61afc7ba-e2ee-4200-b725-8ca71955ebc4",
      "policy_direction" : "EGRESS",
      "defense_policy_list" : [ {
        "target_project_name" : "RegionName",
        "defense_connection_name" : "VPC",
        "defense_type" : "VPC",
        "defense_policy_list" : null,
        "target_enterprise_id" : "0",
        "defense_connection_region_id" : "RegionId",
        "description" : null,
        "defense_policy_name" : "SecMaster_Group_IPv4_EGRESS_BLOCK0",
        "defense_modifier_name" : "test_domain_name",
        "defense_connection_id" : "4c1adb13-10a4-383d-8216-4f5714b6128c",
        "defense_id" : "a4b06b03-7971-402e-a330-b5e806d7ca10",
        "defense_connection_region_name" : "RegionName",
        "target_enterprise_name" : "default",
        "defense_update_time" : "2025-10-14T14:55:48.612+08:00",
        "dataobject_id" : null,
        "defense_block_status" : "SUCCESS",
        "target_project_id" : "3bb27e024693436da46b5f5aaf499060",
        "defense_modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
        "defense_policy_id" : "7fa91ea0-d6e6-4718-9677-21bbc90750be"
      }, {
        "target_project_name" : "RegionName",
        "defense_connection_name" : "VPC",
        "defense_type" : "VPC",
        "defense_policy_list" : null,
        "target_enterprise_id" : "0",
        "defense_connection_region_id" : "RegionId",
        "description" : null,
        "defense_policy_name" : "SecMaster_Group_IPv4_EGRESS_BLOCK0",
        "defense_modifier_name" : "test_domain_name",
        "defense_connection_id" : "4c1adb13-10a4-383d-8216-4f5714b6128c",
        "defense_id" : "fb619dcd-30dc-4b00-beb7-db9f960a7bcd",
        "defense_connection_region_name" : "RegionName",
        "target_enterprise_name" : "default",
        "defense_update_time" : "2025-10-14T15:14:42.861+08:00",
        "dataobject_id" : null,
        "defense_block_status" : "SUCCESS",
        "target_project_id" : "8846a9979e464df3817056a9e8f70e53",
        "defense_modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
        "defense_policy_id" : "c7caf237-c8cd-45cc-ba5d-2e8af3567878"
      } ],
      "create_time" : "2025-10-14T14:55:48.691Z+0800",
      "region_id" : "RegionId",
      "dataclass_id" : "782353cb-e951-3f94-be8c-9ab0e140a137",
      "policy_task_name" : "test_domain_name-VPC-20251014145548",
      "labels" : "",
      "environment" : {
        "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
        "domain_name" : "test_domain_name",
        "project_id" : "3bb27e024693436da46b5f5aaf499060",
        "region_id" : "RegionId",
        "region_name" : "RegionName",
        "vendor_type" : "cloud"
      },
      "policy_type" : {
        "policy_type" : "Source Ip",
        "id" : "4d67fe756fcefbf60337e5c8debdff6d",
        "category" : "defense direction"
      },
      "trigger_flag" : true,
      "policy_category" : "BLOCK",
      "creator_id" : "b6566bce94194f3d9dc6d397c72e40b2",
      "modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
      "creator_name" : "test_domain_name"
    },
    "dataclass_ref" : null,
    "format_version" : 0,
    "id" : "",
    "project_id" : "",
    "type" : null,
    "update_time" : null,
    "version" : 0,
    "workspace_id" : ""
  }, {
    "aggs_data_objects" : [ {
      "modifier_name" : "test_domain_name",
      "block_age" : {
        "is_block_ageing" : false,
        "block_ageing" : null
      },
      "description" : "",
      "policy_task_id" : "892b17e8-36fb-431e-92a3-2b65b43a3cb4",
      "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
      "workspace_id" : "ff631ed9-96ac-439f-880f-5de3ddd72cbb",
      "domain_name" : "test_domain_name",
      "update_time" : "2025-10-14T14:38:41.855+08:00",
      "is_deleted" : false,
      "block_target" : "20.25.10.14",
      "project_id" : "3bb27e024693436da46b5f5aaf499060",
      "region_name" : null,
      "defense_policy_object" : {
        "target_project_name" : "RegionName",
        "defense_connection_name" : "CFW",
        "defense_type" : "CFW",
        "defense_policy_list" : null,
        "target_enterprise_id" : "0",
        "defense_connection_region_id" : "RegionId",
        "description" : null,
        "defense_policy_name" : "SecMaster_Group_IPv4_INGRESS_BLOCK0",
        "defense_modifier_name" : "test_domain_name",
        "defense_connection_id" : "88b8d048-4f83-3923-80de-d41178e53700",
        "defense_id" : "66cb0fe9-a567-4c09-9f2a-51918db3cc23",
        "defense_connection_region_name" : "RegionName",
        "target_enterprise_name" : "default",
        "defense_update_time" : "2025-10-14T14:38:36.631+08:00",
        "dataobject_id" : null,
        "defense_block_status" : "SUCCESS",
        "target_project_id" : "3bb27e024693436da46b5f5aaf499060",
        "defense_modifier_id" : "fb520ccb7d94467588e4bf20f5191d77",
        "defense_policy_id" : "7febc6f5-b9f6-4aa7-b0f5-ca7889e8187c"
      },
      "id" : "90212f27-a0fb-4bf7-a7aa-97b73ef98421",
      "policy_direction" : "INGRESS",
      "create_time" : "2025-10-14T14:38:36.902+08:00",
      "region_id" : "RegionId",
      "dataclass_id" : "782353cb-e951-3f94-be8c-9ab0e140a137",
      "policy_task_name" : "test_domain_name-CFW-VPC-WAF-20251014143836",
      "labels" : "",
      "environment" : {
        "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
        "domain_name" : "test_domain_name",
        "project_id" : "3bb27e024693436da46b5f5aaf499060",
        "region_id" : "RegionId",
        "region_name" : "RegionName",
        "vendor_type" : "cloud"
      },
      "policy_type" : {
        "policy_type" : "Source Ip",
        "id" : "4d67fe756fcefbf60337e5c8debdff6d",
        "category" : "defense direction"
      },
      "trigger_flag" : true,
      "policy_category" : "BLOCK",
      "creator_id" : "fb520ccb7d94467588e4bf20f5191d77",
      "modifier_id" : "fb520ccb7d94467588e4bf20f5191d77",
      "creator_name" : "test_domain_name"
    }, {
      "modifier_name" : "test_domain_name",
      "block_age" : {
        "is_block_ageing" : false,
        "block_ageing" : null
      },
      "description" : "",
      "policy_task_id" : "892b17e8-36fb-431e-92a3-2b65b43a3cb4",
      "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
      "workspace_id" : "ff631ed9-96ac-439f-880f-5de3ddd72cbb",
      "domain_name" : "test_domain_name",
      "update_time" : "2025-10-14T14:38:40.431+08:00",
      "is_deleted" : false,
      "block_target" : "20.25.10.14",
      "project_id" : "3bb27e024693436da46b5f5aaf499060",
      "region_name" : null,
      "defense_policy_object" : {
        "target_project_name" : "RegionName",
        "defense_connection_name" : "VPC",
        "defense_type" : "VPC",
        "defense_policy_list" : null,
        "target_enterprise_id" : "0",
        "defense_connection_region_id" : "RegionId",
        "description" : null,
        "defense_policy_name" : "SecMaster_Group_IPv4_INGRESS_BLOCK0",
        "defense_modifier_name" : "test_domain_name",
        "defense_connection_id" : "4c1adb13-10a4-383d-8216-4f5714b6128c",
        "defense_id" : "a0fe2ee5-d957-4e4a-a746-cf70dd1ddf30",
        "defense_connection_region_name" : "RegionName",
        "target_enterprise_name" : "default",
        "defense_update_time" : "2025-10-14T14:38:36.631+08:00",
        "dataobject_id" : null,
        "defense_block_status" : "SUCCESS",
        "target_project_id" : "3bb27e024693436da46b5f5aaf499060",
        "defense_modifier_id" : "fb520ccb7d94467588e4bf20f5191d77",
        "defense_policy_id" : "d5c257da-840c-4fa3-8245-b0881c9823e2"
      },
      "id" : "6d87192b-86a9-44ac-bd5d-3aa28c027f8d",
      "policy_direction" : "INGRESS",
      "create_time" : "2025-10-14T14:38:36.902+08:00",
      "region_id" : "RegionId",
      "dataclass_id" : "782353cb-e951-3f94-be8c-9ab0e140a137",
      "policy_task_name" : "test_domain_name-CFW-VPC-WAF-20251014143836",
      "labels" : "",
      "environment" : {
        "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
        "domain_name" : "test_domain_name",
        "project_id" : "3bb27e024693436da46b5f5aaf499060",
        "region_id" : "RegionId",
        "region_name" : "RegionName",
        "vendor_type" : "cloud"
      },
      "policy_type" : {
        "policy_type" : "Source Ip",
        "id" : "4d67fe756fcefbf60337e5c8debdff6d",
        "category" : "defense direction"
      },
      "trigger_flag" : true,
      "policy_category" : "BLOCK",
      "creator_id" : "fb520ccb7d94467588e4bf20f5191d77",
      "modifier_id" : "fb520ccb7d94467588e4bf20f5191d77",
      "creator_name" : "test_domain_name"
    }, {
      "modifier_name" : "test_domain_name",
      "block_age" : {
        "is_block_ageing" : false,
        "block_ageing" : null
      },
      "description" : "",
      "policy_task_id" : "892b17e8-36fb-431e-92a3-2b65b43a3cb4",
      "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
      "workspace_id" : "ff631ed9-96ac-439f-880f-5de3ddd72cbb",
      "domain_name" : "test_domain_name",
      "update_time" : "2025-10-14T14:38:43.188+08:00",
      "is_deleted" : false,
      "block_target" : "20.25.10.14",
      "project_id" : "3bb27e024693436da46b5f5aaf499060",
      "region_name" : null,
      "defense_policy_object" : {
        "target_project_name" : "RegionName",
        "defense_connection_name" : "WAF",
        "defense_type" : "WAF",
        "defense_policy_list" : null,
        "target_enterprise_id" : "0",
        "defense_connection_region_id" : "RegionId",
        "description" : null,
        "defense_policy_name" : "SecMaster_Ip_Group_BLOCK0",
        "defense_modifier_name" : "test_domain_name",
        "defense_connection_id" : "034f0a01-0d90-36c9-a1a1-f87e9af23833",
        "defense_id" : "c412f52a-4f35-4da5-912c-5129acd6a844",
        "defense_connection_region_name" : "RegionName",
        "target_enterprise_name" : "default",
        "defense_update_time" : "2025-10-14T14:38:36.631+08:00",
        "dataobject_id" : null,
        "defense_block_status" : "SUCCESS",
        "target_project_id" : "3bb27e024693436da46b5f5aaf499060",
        "defense_modifier_id" : "fb520ccb7d94467588e4bf20f5191d77",
        "defense_policy_id" : "ab5a6a1c79c7408080ef88aaa8099f31"
      },
      "id" : "fc59ad0b-8418-42b0-a20e-db10263dcecc",
      "policy_direction" : "INGRESS",
      "create_time" : "2025-10-14T14:38:36.902+08:00",
      "region_id" : "RegionId",
      "dataclass_id" : "782353cb-e951-3f94-be8c-9ab0e140a137",
      "policy_task_name" : "test_domain_name-CFW-VPC-WAF-20251014143836",
      "labels" : "",
      "environment" : {
        "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
        "domain_name" : "test_domain_name",
        "project_id" : "3bb27e024693436da46b5f5aaf499060",
        "region_id" : "RegionId",
        "region_name" : "RegionName",
        "vendor_type" : "cloud"
      },
      "policy_type" : {
        "policy_type" : "Source Ip",
        "id" : "4d67fe756fcefbf60337e5c8debdff6d",
        "category" : "defense direction"
      },
      "trigger_flag" : true,
      "policy_category" : "BLOCK",
      "creator_id" : "fb520ccb7d94467588e4bf20f5191d77",
      "modifier_id" : "fb520ccb7d94467588e4bf20f5191d77",
      "creator_name" : "test_domain_name"
    } ],
    "create_time" : null,
    "data_object" : {
      "modifier_name" : "test_domain_name",
      "block_age" : {
        "is_block_ageing" : false,
        "block_ageing" : null
      },
      "description" : "",
      "policy_task_id" : "892b17e8-36fb-431e-92a3-2b65b43a3cb4",
      "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
      "workspace_id" : "ff631ed9-96ac-439f-880f-5de3ddd72cbb",
      "domain_name" : "test_domain_name",
      "update_time" : "2025-10-14T14:38:41.855Z+0800",
      "is_deleted" : false,
      "block_target" : "20.25.10.14",
      "project_id" : "3bb27e024693436da46b5f5aaf499060",
      "region_name" : null,
      "id" : "90212f27-a0fb-4bf7-a7aa-97b73ef98421",
      "policy_direction" : "INGRESS",
      "defense_policy_list" : [ {
        "target_project_name" : "RegionName",
        "defense_connection_name" : "CFW",
        "defense_type" : "CFW",
        "defense_policy_list" : null,
        "target_enterprise_id" : "0",
        "defense_connection_region_id" : "RegionId",
        "description" : null,
        "defense_policy_name" : "SecMaster_Group_IPv4_INGRESS_BLOCK0",
        "defense_modifier_name" : "test_domain_name",
        "defense_connection_id" : "88b8d048-4f83-3923-80de-d41178e53700",
        "defense_id" : "66cb0fe9-a567-4c09-9f2a-51918db3cc23",
        "defense_connection_region_name" : "RegionName",
        "target_enterprise_name" : "default",
        "defense_update_time" : "2025-10-14T14:38:36.631+08:00",
        "dataobject_id" : null,
        "defense_block_status" : "SUCCESS",
        "target_project_id" : "3bb27e024693436da46b5f5aaf499060",
        "defense_modifier_id" : "fb520ccb7d94467588e4bf20f5191d77",
        "defense_policy_id" : "7febc6f5-b9f6-4aa7-b0f5-ca7889e8187c"
      }, {
        "target_project_name" : "RegionName",
        "defense_connection_name" : "VPC",
        "defense_type" : "VPC",
        "defense_policy_list" : null,
        "target_enterprise_id" : "0",
        "defense_connection_region_id" : "RegionId",
        "description" : null,
        "defense_policy_name" : "SecMaster_Group_IPv4_INGRESS_BLOCK0",
        "defense_modifier_name" : "test_domain_name",
        "defense_connection_id" : "4c1adb13-10a4-383d-8216-4f5714b6128c",
        "defense_id" : "a0fe2ee5-d957-4e4a-a746-cf70dd1ddf30",
        "defense_connection_region_name" : "RegionName",
        "target_enterprise_name" : "default",
        "defense_update_time" : "2025-10-14T14:38:36.631+08:00",
        "dataobject_id" : null,
        "defense_block_status" : "SUCCESS",
        "target_project_id" : "3bb27e024693436da46b5f5aaf499060",
        "defense_modifier_id" : "fb520ccb7d94467588e4bf20f5191d77",
        "defense_policy_id" : "d5c257da-840c-4fa3-8245-b0881c9823e2"
      }, {
        "target_project_name" : "RegionName",
        "defense_connection_name" : "WAF",
        "defense_type" : "WAF",
        "defense_policy_list" : null,
        "target_enterprise_id" : "0",
        "defense_connection_region_id" : "RegionId",
        "description" : null,
        "defense_policy_name" : "SecMaster_Ip_Group_BLOCK0",
        "defense_modifier_name" : "test_domain_name",
        "defense_connection_id" : "034f0a01-0d90-36c9-a1a1-f87e9af23833",
        "defense_id" : "c412f52a-4f35-4da5-912c-5129acd6a844",
        "defense_connection_region_name" : "RegionName",
        "target_enterprise_name" : "default",
        "defense_update_time" : "2025-10-14T14:38:36.631+08:00",
        "dataobject_id" : null,
        "defense_block_status" : "SUCCESS",
        "target_project_id" : "3bb27e024693436da46b5f5aaf499060",
        "defense_modifier_id" : "fb520ccb7d94467588e4bf20f5191d77",
        "defense_policy_id" : "ab5a6a1c79c7408080ef88aaa8099f31"
      } ],
      "create_time" : "2025-10-14T14:38:36.902Z+0800",
      "region_id" : "RegionId",
      "dataclass_id" : "782353cb-e951-3f94-be8c-9ab0e140a137",
      "policy_task_name" : "test_domain_name-CFW-VPC-WAF-20251014143836",
      "labels" : "",
      "environment" : {
        "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
        "domain_name" : "test_domain_name",
        "project_id" : "3bb27e024693436da46b5f5aaf499060",
        "region_id" : "RegionId",
        "region_name" : "RegionName",
        "vendor_type" : "cloud"
      },
      "policy_type" : {
        "policy_type" : "Source Ip",
        "id" : "4d67fe756fcefbf60337e5c8debdff6d",
        "category" : "defense direction"
      },
      "trigger_flag" : true,
      "policy_category" : "BLOCK",
      "creator_id" : "fb520ccb7d94467588e4bf20f5191d77",
      "modifier_id" : "fb520ccb7d94467588e4bf20f5191d77",
      "creator_name" : "test_domain_name"
    },
    "dataclass_ref" : null,
    "format_version" : 0,
    "id" : "",
    "project_id" : "",
    "type" : null,
    "update_time" : null,
    "version" : 0,
    "workspace_id" : ""
  }, {
    "aggs_data_objects" : [ {
      "modifier_name" : "test_domain_name",
      "block_age" : {
        "is_block_ageing" : false,
        "block_ageing" : null
      },
      "description" : "",
      "policy_task_id" : "9d678c08-1622-43c6-91e4-1544dec0a027",
      "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
      "workspace_id" : "ff631ed9-96ac-439f-880f-5de3ddd72cbb",
      "domain_name" : "test_domain_name",
      "update_time" : "2025-10-14T14:20:40.411+08:00",
      "is_deleted" : false,
      "block_target" : "1.1.1.1",
      "project_id" : "3bb27e024693436da46b5f5aaf499060",
      "region_name" : null,
      "defense_policy_object" : {
        "target_project_name" : "RegionName",
        "defense_connection_name" : "CFW",
        "defense_type" : "CFW",
        "defense_policy_list" : null,
        "target_enterprise_id" : "0",
        "defense_connection_region_id" : "RegionId",
        "description" : null,
        "defense_policy_name" : "SecMaster_Group_IPv4_INGRESS_BLOCK0",
        "defense_modifier_name" : "test_domain_name",
        "defense_connection_id" : "88b8d048-4f83-3923-80de-d41178e53700",
        "defense_id" : "dccd5aa3-be3c-4839-9fa4-38d2fd70547e",
        "defense_connection_region_name" : "RegionName",
        "target_enterprise_name" : "default",
        "defense_update_time" : "2025-10-14T14:20:36.222+08:00",
        "dataobject_id" : null,
        "defense_block_status" : "SUCCESS",
        "target_project_id" : "3bb27e024693436da46b5f5aaf499060",
        "defense_modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
        "defense_policy_id" : "7febc6f5-b9f6-4aa7-b0f5-ca7889e8187c"
      },
      "id" : "4036391d-8e53-4c0c-a79f-7e272b3cb26c",
      "policy_direction" : "INGRESS",
      "create_time" : "2025-10-14T14:20:36.338+08:00",
      "region_id" : "RegionId",
      "dataclass_id" : "782353cb-e951-3f94-be8c-9ab0e140a137",
      "policy_task_name" : "test_domain_name-CFW-20251014142036",
      "labels" : "",
      "environment" : {
        "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
        "domain_name" : "test_domain_name",
        "project_id" : "3bb27e024693436da46b5f5aaf499060",
        "region_id" : "RegionId",
        "region_name" : "RegionName",
        "vendor_type" : "cloud"
      },
      "policy_type" : {
        "policy_type" : "Source Ip",
        "id" : "4d67fe756fcefbf60337e5c8debdff6d",
        "category" : "defense direction"
      },
      "trigger_flag" : true,
      "policy_category" : "BLOCK",
      "creator_id" : "b6566bce94194f3d9dc6d397c72e40b2",
      "modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
      "creator_name" : "test_domain_name"
    }, {
      "modifier_name" : "test_domain_name",
      "block_age" : {
        "is_block_ageing" : false,
        "block_ageing" : null
      },
      "description" : "",
      "policy_task_id" : "f5b13ebd-4f65-4a1b-b79f-d7da5a64c435",
      "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
      "workspace_id" : "ff631ed9-96ac-439f-880f-5de3ddd72cbb",
      "domain_name" : "test_domain_name",
      "update_time" : "2025-10-14T14:23:56.696+08:00",
      "is_deleted" : false,
      "block_target" : "1.1.1.1",
      "project_id" : "3bb27e024693436da46b5f5aaf499060",
      "region_name" : null,
      "defense_policy_object" : {
        "target_project_name" : "RegionName",
        "defense_connection_name" : "VPC",
        "defense_type" : "VPC",
        "defense_policy_list" : null,
        "target_enterprise_id" : "0",
        "defense_connection_region_id" : "RegionId",
        "description" : null,
        "defense_policy_name" : "SecMaster_Group_IPv4_INGRESS_BLOCK0",
        "defense_modifier_name" : "test_domain_name",
        "defense_connection_id" : "4c1adb13-10a4-383d-8216-4f5714b6128c",
        "defense_id" : "6e924a55-0fc2-47a0-9e23-f39f7cc3062a",
        "defense_connection_region_name" : "RegionName",
        "target_enterprise_name" : "default",
        "defense_update_time" : "2025-10-14T14:23:53.708+08:00",
        "dataobject_id" : null,
        "defense_block_status" : "SUCCESS",
        "target_project_id" : "3bb27e024693436da46b5f5aaf499060",
        "defense_modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
        "defense_policy_id" : "d5c257da-840c-4fa3-8245-b0881c9823e2"
      },
      "id" : "354ddb04-887e-44f2-b5b4-bb3a31019a22",
      "policy_direction" : "INGRESS",
      "create_time" : "2025-10-14T14:23:53.819+08:00",
      "region_id" : "RegionId",
      "dataclass_id" : "782353cb-e951-3f94-be8c-9ab0e140a137",
      "policy_task_name" : "test_domain_name-VPC-20251014142353",
      "labels" : "",
      "environment" : {
        "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
        "domain_name" : "test_domain_name",
        "project_id" : "3bb27e024693436da46b5f5aaf499060",
        "region_id" : "RegionId",
        "region_name" : "RegionName",
        "vendor_type" : "cloud"
      },
      "policy_type" : {
        "policy_type" : "Source Ip",
        "id" : "4d67fe756fcefbf60337e5c8debdff6d",
        "category" : "defense direction"
      },
      "trigger_flag" : true,
      "policy_category" : "BLOCK",
      "creator_id" : "b6566bce94194f3d9dc6d397c72e40b2",
      "modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
      "creator_name" : "test_domain_name"
    }, {
      "modifier_name" : "test_domain_name",
      "block_age" : {
        "is_block_ageing" : false,
        "block_ageing" : null
      },
      "description" : "",
      "policy_task_id" : "a96c2b30-cb08-48ec-9f94-0e4d12c4cfaa",
      "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
      "workspace_id" : "ff631ed9-96ac-439f-880f-5de3ddd72cbb",
      "domain_name" : "test_domain_name",
      "update_time" : "2025-10-14T14:24:49.920+08:00",
      "is_deleted" : false,
      "block_target" : "1.1.1.1",
      "project_id" : "3bb27e024693436da46b5f5aaf499060",
      "region_name" : null,
      "defense_policy_object" : {
        "target_project_name" : "RegionName",
        "defense_connection_name" : "WAF",
        "defense_type" : "WAF",
        "defense_policy_list" : null,
        "target_enterprise_id" : "0",
        "defense_connection_region_id" : "RegionId",
        "description" : null,
        "defense_policy_name" : "SecMaster_Ip_Group_BLOCK0",
        "defense_modifier_name" : "test_domain_name",
        "defense_connection_id" : "034f0a01-0d90-36c9-a1a1-f87e9af23833",
        "defense_id" : "24ff4061-6614-4425-b553-c060615faf1b",
        "defense_connection_region_name" : "RegionName",
        "target_enterprise_name" : "default",
        "defense_update_time" : "2025-10-14T14:24:37.793+08:00",
        "dataobject_id" : null,
        "defense_block_status" : "SUCCESS",
        "target_project_id" : "3bb27e024693436da46b5f5aaf499060",
        "defense_modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
        "defense_policy_id" : "ab5a6a1c79c7408080ef88aaa8099f31"
      },
      "id" : "6c34f1f8-f851-4fed-8f45-6eff1cfc35c8",
      "policy_direction" : "INGRESS",
      "create_time" : "2025-10-14T14:24:37.904+08:00",
      "region_id" : "RegionId",
      "dataclass_id" : "782353cb-e951-3f94-be8c-9ab0e140a137",
      "policy_task_name" : "test_domain_name-WAF-20251014142437",
      "labels" : "",
      "environment" : {
        "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
        "domain_name" : "test_domain_name",
        "project_id" : "3bb27e024693436da46b5f5aaf499060",
        "region_id" : "RegionId",
        "region_name" : "RegionName",
        "vendor_type" : "cloud"
      },
      "policy_type" : {
        "policy_type" : "Source Ip",
        "id" : "4d67fe756fcefbf60337e5c8debdff6d",
        "category" : "defense direction"
      },
      "trigger_flag" : true,
      "policy_category" : "BLOCK",
      "creator_id" : "b6566bce94194f3d9dc6d397c72e40b2",
      "modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
      "creator_name" : "test_domain_name"
    } ],
    "create_time" : null,
    "data_object" : {
      "modifier_name" : "test_domain_name",
      "block_age" : {
        "is_block_ageing" : false,
        "block_ageing" : null
      },
      "description" : "",
      "policy_task_id" : "9d678c08-1622-43c6-91e4-1544dec0a027",
      "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
      "workspace_id" : "ff631ed9-96ac-439f-880f-5de3ddd72cbb",
      "domain_name" : "test_domain_name",
      "update_time" : "2025-10-14T14:20:40.411Z+0800",
      "is_deleted" : false,
      "block_target" : "1.1.1.1",
      "project_id" : "3bb27e024693436da46b5f5aaf499060",
      "region_name" : null,
      "id" : "4036391d-8e53-4c0c-a79f-7e272b3cb26c",
      "policy_direction" : "INGRESS",
      "defense_policy_list" : [ {
        "target_project_name" : "RegionName",
        "defense_connection_name" : "CFW",
        "defense_type" : "CFW",
        "defense_policy_list" : null,
        "target_enterprise_id" : "0",
        "defense_connection_region_id" : "RegionId",
        "description" : null,
        "defense_policy_name" : "SecMaster_Group_IPv4_INGRESS_BLOCK0",
        "defense_modifier_name" : "test_domain_name",
        "defense_connection_id" : "88b8d048-4f83-3923-80de-d41178e53700",
        "defense_id" : "dccd5aa3-be3c-4839-9fa4-38d2fd70547e",
        "defense_connection_region_name" : "RegionName",
        "target_enterprise_name" : "default",
        "defense_update_time" : "2025-10-14T14:20:36.222+08:00",
        "dataobject_id" : null,
        "defense_block_status" : "SUCCESS",
        "target_project_id" : "3bb27e024693436da46b5f5aaf499060",
        "defense_modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
        "defense_policy_id" : "7febc6f5-b9f6-4aa7-b0f5-ca7889e8187c"
      }, {
        "target_project_name" : "RegionName",
        "defense_connection_name" : "VPC",
        "defense_type" : "VPC",
        "defense_policy_list" : null,
        "target_enterprise_id" : "0",
        "defense_connection_region_id" : "RegionId",
        "description" : null,
        "defense_policy_name" : "SecMaster_Group_IPv4_INGRESS_BLOCK0",
        "defense_modifier_name" : "test_domain_name",
        "defense_connection_id" : "4c1adb13-10a4-383d-8216-4f5714b6128c",
        "defense_id" : "6e924a55-0fc2-47a0-9e23-f39f7cc3062a",
        "defense_connection_region_name" : "RegionName",
        "target_enterprise_name" : "default",
        "defense_update_time" : "2025-10-14T14:23:53.708+08:00",
        "dataobject_id" : null,
        "defense_block_status" : "SUCCESS",
        "target_project_id" : "3bb27e024693436da46b5f5aaf499060",
        "defense_modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
        "defense_policy_id" : "d5c257da-840c-4fa3-8245-b0881c9823e2"
      }, {
        "target_project_name" : "RegionName",
        "defense_connection_name" : "WAF",
        "defense_type" : "WAF",
        "defense_policy_list" : null,
        "target_enterprise_id" : "0",
        "defense_connection_region_id" : "RegionId",
        "description" : null,
        "defense_policy_name" : "SecMaster_Ip_Group_BLOCK0",
        "defense_modifier_name" : "test_domain_name",
        "defense_connection_id" : "034f0a01-0d90-36c9-a1a1-f87e9af23833",
        "defense_id" : "24ff4061-6614-4425-b553-c060615faf1b",
        "defense_connection_region_name" : "RegionName",
        "target_enterprise_name" : "default",
        "defense_update_time" : "2025-10-14T14:24:37.793+08:00",
        "dataobject_id" : null,
        "defense_block_status" : "SUCCESS",
        "target_project_id" : "3bb27e024693436da46b5f5aaf499060",
        "defense_modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
        "defense_policy_id" : "ab5a6a1c79c7408080ef88aaa8099f31"
      } ],
      "create_time" : "2025-10-14T14:20:36.338Z+0800",
      "region_id" : "RegionId",
      "dataclass_id" : "782353cb-e951-3f94-be8c-9ab0e140a137",
      "policy_task_name" : "test_domain_name-CFW-20251014142036",
      "labels" : "",
      "environment" : {
        "domain_id" : "94aee09081c649cfa9eef5d25200ec50",
        "domain_name" : "test_domain_name",
        "project_id" : "3bb27e024693436da46b5f5aaf499060",
        "region_id" : "RegionId",
        "region_name" : "RegionName",
        "vendor_type" : "cloud"
      },
      "policy_type" : {
        "policy_type" : "Source Ip",
        "id" : "4d67fe756fcefbf60337e5c8debdff6d",
        "category" : "defense direction"
      },
      "trigger_flag" : true,
      "policy_category" : "BLOCK",
      "creator_id" : "b6566bce94194f3d9dc6d397c72e40b2",
      "modifier_id" : "b6566bce94194f3d9dc6d397c72e40b2",
      "creator_name" : "test_domain_name"
    },
    "dataclass_ref" : null,
    "format_version" : 0,
    "id" : "",
    "project_id" : "",
    "type" : null,
    "update_time" : null,
    "version" : 0,
    "workspace_id" : ""
  } ],
  "message" : "",
  "page" : 0,
  "request_id" : "",
  "size" : 10,
  "success" : true,
  "total" : 3
}

SDK代码示例

SDK代码示例如下。

查询策略视图列表

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.secmaster.v1.region.SecMasterRegion;
import com.huaweicloud.sdk.secmaster.v1.*;
import com.huaweicloud.sdk.secmaster.v1.model.*;

import java.util.List;
import java.util.ArrayList;

public class SearchPolicySolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        SecMasterClient client = SecMasterClient.newBuilder()
                .withCredential(auth)
                .withRegion(SecMasterRegion.valueOf("<YOUR REGION>"))
                .build();
        SearchPolicyRequest request = new SearchPolicyRequest();
        request.withWorkspaceId("{workspace_id}");
        SearchPolicyRequestBody body = new SearchPolicyRequestBody();
        SearchPolicyRequestBodyGroupByGroupByHit groupByHitGroupBy = new SearchPolicyRequestBodyGroupByGroupByHit();
        groupByHitGroupBy.withSource("defense_policy_object")
            .withDest("defense_policy_list");
        List<String> listGroupByGroupByFields = new ArrayList<>();
        listGroupByGroupByFields.add("block_target");
        listGroupByGroupByFields.add("workspace_id");
        listGroupByGroupByFields.add("policy_task_id");
        SearchPolicyRequestBodyGroupBy groupBybody = new SearchPolicyRequestBodyGroupBy();
        groupBybody.withGroupByFields(listGroupByGroupByFields)
            .withGroupByHit(groupByHitGroupBy);
        List<SearchPolicyRequestBodySort> listbodySort = new ArrayList<>();
        listbodySort.add(
            new SearchPolicyRequestBodySort()
                .withSortBy("create_time")
                .withOrder("desc")
        );
        List<String> listConditionLogics = new ArrayList<>();
        listConditionLogics.add("logic_0");
        List<String> listConditionsData = new ArrayList<>();
        listConditionsData.add("defense_policy_object.defense_block_status");
        listConditionsData.add("=");
        listConditionsData.add("SUCCESS");
        List<SearchPolicyRequestBodyConditionConditions> listConditionConditions = new ArrayList<>();
        listConditionConditions.add(
            new SearchPolicyRequestBodyConditionConditions()
                .withName("logic_0")
                .withData(listConditionsData)
        );
        SearchPolicyRequestBodyCondition conditionbody = new SearchPolicyRequestBodyCondition();
        conditionbody.withConditions(listConditionConditions)
            .withLogics(listConditionLogics);
        body.withGroupBy(groupBybody);
        body.withSort(listbodySort);
        body.withCondition(conditionbody);
        body.withOffset(0);
        body.withLimit(10);
        request.withBody(body);
        try {
            SearchPolicyResponse response = client.searchPolicy(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

查询策略视图列表

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdksecmaster.v1.region.secmaster_region import SecMasterRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdksecmaster.v1 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = SecMasterClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(SecMasterRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = SearchPolicyRequest()
        request.workspace_id = "{workspace_id}"
        groupByHitGroupBy = SearchPolicyRequestBodyGroupByGroupByHit(
            source="defense_policy_object",
            dest="defense_policy_list"
        )
        listGroupByFieldsGroupBy = [
            "block_target",
            "workspace_id",
            "policy_task_id"
        ]
        groupBybody = SearchPolicyRequestBodyGroupBy(
            group_by_fields=listGroupByFieldsGroupBy,
            group_by_hit=groupByHitGroupBy
        )
        listSortbody = [
            SearchPolicyRequestBodySort(
                sort_by="create_time",
                order="desc"
            )
        ]
        listLogicsCondition = [
            "logic_0"
        ]
        listDataConditions = [
            "defense_policy_object.defense_block_status",
            "=",
            "SUCCESS"
        ]
        listConditionsCondition = [
            SearchPolicyRequestBodyConditionConditions(
                name="logic_0",
                data=listDataConditions
            )
        ]
        conditionbody = SearchPolicyRequestBodyCondition(
            conditions=listConditionsCondition,
            logics=listLogicsCondition
        )
        request.body = SearchPolicyRequestBody(
            group_by=groupBybody,
            sort=listSortbody,
            condition=conditionbody,
            offset=0,
            limit=10
        )
        response = client.search_policy(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

查询策略视图列表

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    secmaster "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := secmaster.NewSecMasterClient(
        secmaster.SecMasterClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.SearchPolicyRequest{}
	request.WorkspaceId = "{workspace_id}"
	sourceGroupByHit:= "defense_policy_object"
	destGroupByHit:= "defense_policy_list"
	groupByHitGroupBy := &model.SearchPolicyRequestBodyGroupByGroupByHit{
		Source: &sourceGroupByHit,
		Dest: &destGroupByHit,
	}
	var listGroupByFieldsGroupBy = []string{
        "block_target",
	    "workspace_id",
	    "policy_task_id",
    }
	groupBybody := &model.SearchPolicyRequestBodyGroupBy{
		GroupByFields: &listGroupByFieldsGroupBy,
		GroupByHit: groupByHitGroupBy,
	}
	sortBySort:= "create_time"
	orderSort:= "desc"
	var listSortbody = []model.SearchPolicyRequestBodySort{
        {
            SortBy: &sortBySort,
            Order: &orderSort,
        },
    }
	var listLogicsCondition = []string{
        "logic_0",
    }
	var listDataConditions = []string{
        "defense_policy_object.defense_block_status",
	    "=",
	    "SUCCESS",
    }
	nameConditions:= "logic_0"
	var listConditionsCondition = []model.SearchPolicyRequestBodyConditionConditions{
        {
            Name: &nameConditions,
            Data: &listDataConditions,
        },
    }
	conditionbody := &model.SearchPolicyRequestBodyCondition{
		Conditions: &listConditionsCondition,
		Logics: &listLogicsCondition,
	}
	offsetSearchPolicyRequestBody:= int32(0)
	limitSearchPolicyRequestBody:= int32(10)
	request.Body = &model.SearchPolicyRequestBody{
		GroupBy: groupBybody,
		Sort: &listSortbody,
		Condition: conditionbody,
		Offset: &offsetSearchPolicyRequestBody,
		Limit: &limitSearchPolicyRequestBody,
	}
	response, err := client.SearchPolicy(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

成功

400

查询策略视图错误返回body体

错误码

请参见错误码

相关文档