private static void RevokeGrant(KmsClient kmsClient)
 {
     try
     {
         var request = new CancelGrantRequest
         {
             VersionId = "v1.0",
             Body      = new RevokeGrantRequestBody
             {
                 KeyId   = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2"),
                 GrantId = CreateGrant(kmsClient)
             }
         };
         var resp = kmsClient.CancelGrant(request);
         Console.WriteLine(resp);
     }
     catch (RequestTimeoutException requestTimeoutException)
     {
         Console.WriteLine(requestTimeoutException.ErrorMessage);
     }
     catch (ServiceResponseException clientRequestException)
     {
         Console.WriteLine(clientRequestException.HttpStatusCode);
         Console.WriteLine(clientRequestException.ErrorCode);
         Console.WriteLine(clientRequestException.ErrorMsg);
     }
     catch (ConnectionException connectionException)
     {
         Console.WriteLine(connectionException.ErrorMessage);
     }
 }
Beispiel #2
0
        /// <summary>
        /// 撤销授权
        /// </summary>
        public async Task <CancelGrantResponse> CancelGrantAsync(CancelGrantRequest cancelGrantRequest)
        {
            Dictionary <string, string> urlParam = new Dictionary <string, string>();

            urlParam.Add("version_id", cancelGrantRequest.VersionId.ToString());
            string              urlPath  = HttpUtils.AddUrlPath("/{version_id}/{project_id}/kms/revoke-grant", urlParam);
            SdkRequest          request  = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", cancelGrantRequest);
            HttpResponseMessage response = await DoHttpRequestAsync("POST", request);

            return(JsonUtils.DeSerializeNull <CancelGrantResponse>(response));
        }