Example 3: Querying Information About Keys
Scenario
Use KMS APIs to obtain the list of keys, key information, key instances, and key tags.
Involved APIs
- Query key list
 - Query key information
 - Query key instance
 - Query key tags Tag Management Service (TMS) needs to query all the tags of a specified CMK.
 
Procedure
- Query the list of keys.
     
     
- API information 
       
URI format: POST /v1.0/{project_id}/kms/list-keys
For details, see "Querying Key List".
 - Example request 
       
POST: https://{endpoint}/v1.0/53d1aefc533f4ce9a59c26b01667cbcf/kms/list-keys
Obtain {endpoint} from Regions and Endpoints.
Body:
{ "limit": "2", "marker": "1" } - Example response 
       
{ "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 } 
 - API information 
       
 - Query the information about keys.
     
     
- API information 
       
URI format: POST /v1.0/{project_id}/kms/describe-key
For details, see "Querying Key Details".
 - Example request 
       
POST: https://{endpoint}/v1.0/53d1aefc533f4ce9a59c26b01667cbcf/kms/describe-key
Obtain {endpoint} from Regions and Endpoints.
You can use the API for Querying the List of CMKs to check key information, including key_id.
Body:
{ "key_id": "0d0466b0-e727-4d9c-b35d-f84bb474a37f" } - Example response 
       
{ "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", } } 
 - API information 
       
 - Query CMK instances.
     
     
- API information 
       
URI format: POST /v1.0/{project_id}/kms/resource_instances/action
For details, see "Querying Key Instances".
 - Example request 
       
POST: https://{endpoint}/v1.0/53d1aefc533f4ce9a59c26b01667cbcf/kms//resource_instances/action
Obtain {endpoint} from Regions and Endpoints.
Body:
{ "offset": "100", "limit": "100", "action": "filter", "matches":[ { "key": "resource_name", "value": "resource1" } ], "tags": [ { "key": "key1", "values": [ "value1", "value2" ] } ] } - Example response 
       
{ "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 } 
 - API information 
       
 - Query the tags of a key.
     
     
- API information 
       
URI format: GET /v1.0/{project_id}/kms/{key_id}/tags
For details, see "Querying Key Tags".
 - Example request 
       
GET: https://{endpoint}/v1.0/53d1aefc533f4ce9a59c26b01667cbcf/kms/94752282-805e-4032-ada8-34966f70e02f/tags
Obtain {endpoint} from Regions and Endpoints.
Body:
None
 - Example response 
       
{ "tags": [ { "key": "key1", "value": "value1" }, { "key": "key2", "value": "value3" } ], "existTagsNum":2 } 
 - API information 
       
 
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot