文档首页/ 数据加密服务 DEW/ API参考/ 应用示例/ 示例3:查询密钥相关信息
更新时间:2024-07-11 GMT+08:00

示例3:查询密钥相关信息

场景描述

本章节指导您通过KMS接口查询密钥列表、密钥信息、密钥实例以及密钥标签。

涉及接口

操作步骤

  1. 查询密钥列表。

    • 接口相关信息

      URI格式:POST /v1.0/{project_id}/kms/list-keys

      详情请参见“查询密钥列表”。

    • 请求示例

      POST: https://{endpoint}/v1.0/53d1aefc533f4ce9a59c26b01667cbcf/kms/list-keys

      {endpoint}信息请从地区和终端节点获取。

      Body:

      {  
         "limit": "2", 
          "marker": "1"
       }
    • 响应示例
      { 
          "keys": [
               "0d0466b0-e727-4d9c-b35d-f84bb474a37f", 
              "2e258389-bb1e-4568-a1d5-e1f50adf70ea"
           ],
           "key_details": [ 
           {   
            "key_id":"0d0466b0-e727-4d9c-b35d-f84bb474a37f",  
             "domain_id":"00074811d5c27c4f8d48bb91e4a1dcfd",
               "key_alias":"caseuirpr",
               "realm":"aaaa",
               "key_description":"123", 
              "creation_date":"1502799822000",
               "scheduled_deletion_date":"",
               "key_state":"2",
               "default_key_flag":"0",
               "key_type":"1",
               "expiration_time":"1501578672000",
               "origin":"kms"
       }, 
              {   
            "key_id":"2e258389-bb1e-4568-a1d5-e1f50adf70ea",  
             "domain_id":"00074811d5c27c4f8d48bb91e4a1dcfd",  
             "key_alias":"casehvniz",
              "realm":"aaaa",   
            "key_description":"234", 
              "creation_date":"1502799820000", 
               "scheduled_deletion_date":"",
               "key_state":"2",
               "default_key_flag":"0",
               "key_type":"1", 
              "expiration_time":"1501578673000",
               "origin":"kms"
       }
            ],
           "next_marker": "", 
          "truncated": "false",
           "total":2 
      }

  2. 查询密钥信息。

    • 接口相关信息

      URI格式:POST /v1.0/{project_id}/kms/describe-key

      详情请参见“查询密钥信息”。

    • 请求示例

      POST: https://{endpoint}/v1.0/53d1aefc533f4ce9a59c26b01667cbcf/kms/describe-key

      {endpoint}信息请从地区和终端节点获取。

      您可使用查询密钥列表接口获取当前用户密钥列表,包括key_id等信息 。

      Body:

      {  
         "key_id": "0d0466b0-e727-4d9c-b35d-f84bb474a37f" 
      }
    • 响应示例
      { 
          "key_info": { 
              "key_id": "0d0466b0-e727-4d9c-b35d-f84bb474a37f", 
              "domain_id": "b168fe00ff56492495a7d22974df2d0b", 
              "key_alias": "kms_test", 
              "realm": "aaa",
               "key_description": "",  
             "creation_date": "1472442386000", 
              "scheduled_deletion_date": "", 
              "key_state": "2", 
              "default_key_flag": "0", 
              "key_type": "1", 
              "expiration_time":"1501578672000", 
              "origin":"kms", 
              "key_rotation_enabled":"false", 
              "sys_enterprise_project_id ": "0",
           }
       }

  3. 查询密钥实例。

    • 接口相关信息

      URI格式:POST /v1.0/{project_id}/kms/resource_instances/action

      详情请参见“查询密钥实例”。

    • 请求示例

      POST: https://{endpoint}/v1.0/53d1aefc533f4ce9a59c26b01667cbcf/kms//resource_instances/action

      {endpoint}信息请从地区和终端节点获取。

      Body:

         { 
                "offset": "100",  
                "limit": "100",  
                "action": "filter",
                  "matches":[   
              {    
                      "key": "resource_name",  
                         "value": "resource1"    
                   }  
                ],  
                "tags": [  
                    {      
                    "key": "key1",    
                       "values": [    
                               "value1",   
                                 "value2"   
                       ]  
                    }   
              ]   
         }
    • 响应示例
      {
        "resources" : [ {
          "resource_id" : "90c03e67-5534-4ed0-acfa-89780e47a535",
          "resource_detail" : [ {
            "key_id" : "90c03e67-5534-4ed0-acfa-89780e47a535",
            "domain_id" : "4B688Fb77412Aee5570E7ecdbeB5afdc",
            "key_alias" : "tagTest_xmdmi",
            "key_description" : "123",
            "creation_date" : 1521449277000,
            "scheduled_deletion_date" : "",
            "key_state" : 2,
            "default_key_flag" : 0,
            "key_type" : 1,
            "key_rotation_enabled" : false,
            "expiration_time" : "",
            "origin" : "kms",
            "sys_enterprise_project_id" : "0",
            "realm" :  "cn-hongkong-7"
          } ],
          "resource_name" : "tagTest_xmdmi",
          "tags" : [ {
            "key" : "key",
            "value" : "testValue!"
          }, {
            "key" : "haha",
            "value" : "testValue"
          } ]
        } ],
        "total_count" : 1
      }

  4. 查询密钥标签。

    • 接口相关信息

      URI格式:GET /v1.0/{project_id}/kms/{key_id}/tags

      详情请参见“查询密钥标签”。

    • 请求示例

      GET: https://{endpoint}/v1.0/53d1aefc533f4ce9a59c26b01667cbcf/kms/94752282-805e-4032-ada8-34966f70e02f/tags

      {endpoint}信息请从地区和终端节点获取。

      Body:

    • 响应示例
      { 
              "tags": [   
               {   
                "key": "key1",   
                "value": "value1" 
                 }, 
                 {  
                 "key": "key2",  
                 "value": "value3" 
                 } 
                 ], 
                 "existTagsNum":2  
      }