
# 获取集群所有防护项 - ListClusterProtectionItem
#### 功能介绍
获取集群所有防护项。
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-hss2.0/hss_02_0007.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-hss2.0/hss_02_0022.html)。
- 如果使用身份策略授权，当前API调用无需身份策略权限。
 
#### URI
GET /v5/{project_id}/cluster-protect/protection-item
表1路径参数 
| 参数         | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
|:---|:---|:---|:---|
| project_id | 是    | String | **参数解释**: 项目ID，用于明确项目归属，配置后可通过该ID查询项目下资产。获取方式请参见[获取项目ID](https://support.huaweicloud.com/api-hss2.0/hss_02_0024.html)。 **约束限制**: 不涉及 **取值范围**: 字符长度1-256位 **默认取值**: 不涉及 |
   
表2Query参数 
| 参数                    | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
|:---|:---|:---|:---|
| enterprise_project_id | 否    | String | **参数解释**: 企业项目ID，用于过滤不同企业项目下的资产。获取方式请参见[获取企业项目ID](https://support.huaweicloud.com/api-hss2.0/hss_02_0027.html)。 如需查询所有企业项目下的资产请传参"all_granted_eps"。 **约束限制**: 开通企业项目功能后才需要配置企业项目ID参数。 **取值范围**: 字符长度1-256位 **默认取值**: 0，表示默认企业项目（default）。 |
   
#### 请求参数
表3请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
|:---|:---|:---|:---|
| X-Auth-Token | 是    | String | **参数解释**: 用户Token，包含了用户的身份、权限等信息，在调用API接口时，可通过Token进行身份认证。获取方式请参见[获取用户Token](https://support.huaweicloud.com/api-hss2.0/hss_02_0009.html)。 **约束限制**: 不涉及 **取值范围**: 字符长度1-32768位 **默认取值**: 不涉及 |
   
#### 响应参数
**状态码：200**
表4响应Body参数 
| 参数        | 参数类型                                                                                                             | 描述     |
|:---|:---|:---|
| total_num | Integer                                                                                                          | 总数     |
| vuls      | Array of strings                                                                                                 | 漏洞信息   |
| baselines | Array of [ClusterBaselineResponseInfo] objects | 基线信息   |
| malwares  | Array of [ClusterMalwareResponseInfo] objects   | 恶意文件信息 |
| images    | Array of [ClusterImageResponseInfo] objects       | 镜像信息   |
| clusters  | Array of [ClusterItemResponseInfo] objects         | 集群信息   |
   
 表5ClusterBaselineResponseInfo 
| 参数             | 参数类型   | 描述    |
|:---|:---|:---|
| baseline_desc  | String | 检查项描述 |
| baseline_index | String | 检查项ID |
| baseline_type  | String | 检查项类型 |
   
 表6ClusterMalwareResponseInfo 
| 参数           | 参数类型   | 描述     |
|:---|:---|:---|
| malware_type | String | 恶意文件类型 |
   
 表7ClusterImageResponseInfo 
| 参数            | 参数类型   | 描述   |
|:---|:---|:---|
| image_name    | String | 镜像名称 |
| image_version | String | 镜像版本 |
| id            | String | ID   |
   
 表8ClusterItemResponseInfo 
| 参数             | 参数类型             | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
|:---|:---|:---|
| cluster_id     | String           | 集群id                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| cluster_name   | String           | 集群名称                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| cluster_ns     | Array of strings | 集群命名空间                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| cluster_labels | Array of strings | 集群标签                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| cluster_type   | String           | **参数解释**： 集群类型 **取值范围**: - k8s：原生集群。   - cce：CCE集群。   - ali：阿里云集群。   - tencent：腾讯云集群。   - azure：微软云集群。   - aws：亚马逊集群。   - self_built_hw：华为云自建集群。   - self_built_idc：IDC自建集群。                                                                     |
| protect_status | String           | **参数解释**： 集群防护状态 **取值范围**: - unprotected：未受保护。   - plugin error：插件错误。   - protected with policy：受策略保护。   - deploy policy failed：部署策略失败。   - protected without policy：无策略保护。   - uninstall failed：卸载失败。   - uninstall：卸载。   - installing：正在安装。    |
   
#### 请求示例
获取集群所有防护项
```
GET https://{endpoint}/v5/{project_id}/cluster-protect/protection-item?enterprise_project_id=all_granted_eps
```
#### 响应示例
**状态码：200**
请求已成功
```
{
  "vuls" : [ "CVE-2002-2443", "CVE-2005-1849", "CVE-2009-5155", "CVE-2011-2895", "CVE-2011-5325", "CVE-2012-3425", "CVE-2012-5630" ],
  "baselines" : [ {
    "baseline_desc" : "规则：需限制/etc/ssh/sshd_config的访问权限",
    "baseline_index" : "1.1",
    "baseline_type" : "SSH"
  }, {
    "baseline_desc" : "规则：使用更加安全的Ciphers算法",
    "baseline_index" : "1.10",
    "baseline_type" : "SSH"
  } ],
  "malwares" : [ {
    "malware_type" : "malwares"
  } ],
  "images" : [ {
    "id" : "43170",
    "image_name" : "anp-agent",
    "image_version" : "0.0.2"
  }, {
    "id" : "17518",
    "image_name" : "webshell-ljx",
    "image_version" : "v1"
  } ],
  "clusters" : [ {
    "cluster_id" : "08e932a3-a7f0-4d60-ae45-09a629eb3be7",
    "cluster_name" : "test-617-rrrrrrrr",
    "protect_status" : "unprotected"
  }, {
    "cluster_id" : "441e4d05-7f90-11ee-b311-0255ac1001b2",
    "cluster_name" : "ops-show-cluster-1110",
    "cluster_ns" : [ "default", "cgs-provider", "monitoring", "test-dasd", "hss", "ljx-test" ],
    "protect_status" : "unprotected"
  }, {
    "cluster_id" : "ba732ee6-3067-11ef-8743-0255ac1001b4",
    "cluster_name" : "liuzhaoling-tarenwudong",
    "cluster_ns" : [ "default", "hss" ],
    "protect_status" : "unprotected"
  }, {
    "cluster_id" : "a24b6cb6-3469-11ef-846b-0255ac100b03",
    "cluster_name" : "cce-lxl-0627-2",
    "protect_status" : "unprotected"
  } ],
  "total_num" : 2817
}
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  ```
  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.hss.v5.region.HssRegion;
  import com.huaweicloud.sdk.hss.v5.*;
  import com.huaweicloud.sdk.hss.v5.model.*;
  public class ListClusterProtectionItemSolution {
      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);
          HssClient client = HssClient.newBuilder()
                  .withCredential(auth)
                  .withRegion(HssRegion.valueOf("<YOUR REGION>"))
                  .build();
          ListClusterProtectionItemRequest request = new ListClusterProtectionItemRequest();
          try {
              ListClusterProtectionItemResponse response = client.listClusterProtectionItem(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());
          }
      }
  }
  ```
- [Python]
  ```
  # coding: utf-8
  import os
  from huaweicloudsdkcore.auth.credentials import BasicCredentials
  from huaweicloudsdkhss.v5.region.hss_region import HssRegion
  from huaweicloudsdkcore.exceptions import exceptions
  from huaweicloudsdkhss.v5 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 = HssClient.new_builder() \
          .with_credentials(credentials) \
          .with_region(HssRegion.value_of("<YOUR REGION>")) \
          .build()
      try:
          request = ListClusterProtectionItemRequest()
          response = client.list_cluster_protection_item(request)
          print(response)
      except exceptions.ClientRequestException as e:
          print(e.status_code)
          print(e.request_id)
          print(e.error_code)
          print(e.error_msg)
  ```
- [Go]
  ```
  package main
  import (
  "fmt"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
      hss "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/hss/v5"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/hss/v5/model"
      region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/hss/v5/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, err := basic.NewCredentialsBuilder().
          WithAk(ak).
          WithSk(sk).
          WithProjectId(projectId).
          SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      hcClient, err := hss.HssClientBuilder().
           WithRegion(region.ValueOf("<YOUR REGION>")).
           WithCredential(auth).
           SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      client := hss.NewHssClient(hcClient)
      request := &model.ListClusterProtectionItemRequest{}
  response, err := client.ListClusterProtectionItem(request)
  if err == nil {
          fmt.Printf("%+v\n", response)
      } else {
          fmt.Println(err)
      }
  }
  ```
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/HSS/sdk?api=ListClusterProtectionItem&version=v5)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述    |
|:---|:---|
| 200 | 请求已成功 |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-hss2.0/ErrorCode.html)。
