public static async Task Main() { var client = new AmazonKeyManagementServiceClient(); // The identifier of the AWS KMS key to disable. You can use the // key Id or the Amazon Resource Name (ARN) of the AWS KMS key. var keyId = "1234abcd-12ab-34cd-56ef-1234567890ab"; var request = new DisableKeyRequest { KeyId = keyId, }; var response = await client.DisableKeyAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { // Retrieve information about the key to show that it has now // been disabled. var describeResponse = await client.DescribeKeyAsync(new DescribeKeyRequest { KeyId = keyId, }); Console.WriteLine($"{describeResponse.KeyMetadata.KeyId} - state: {describeResponse.KeyMetadata.KeyState}"); } }
private static void DisableKey(KmsClient kmsClient) { try { var req = new DisableKeyRequest { VersionId = "v1.0", Body = new OperateKeyRequestBody { KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2") } }; var resp = kmsClient.DisableKey(req); Console.WriteLine(resp.ToString()); } 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); } }
internal DisableKeyResponse DisableKey(DisableKeyRequest request) { var marshaller = new DisableKeyRequestMarshaller(); var unmarshaller = DisableKeyResponseUnmarshaller.Instance; return(Invoke <DisableKeyRequest, DisableKeyResponse>(request, marshaller, unmarshaller)); }
/// <summary> /// Initiates the asynchronous execution of the DisableKey operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DisableKey operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task <DisableKeyResponse> DisableKeyAsync(DisableKeyRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new DisableKeyRequestMarshaller(); var unmarshaller = DisableKeyResponseUnmarshaller.Instance; return(InvokeAsync <DisableKeyRequest, DisableKeyResponse>(request, marshaller, unmarshaller, cancellationToken)); }
/// <summary> /// 禁用密钥 /// </summary> public async Task <DisableKeyResponse> DisableKeyAsync(DisableKeyRequest disableKeyRequest) { Dictionary <string, string> urlParam = new Dictionary <string, string>(); urlParam.Add("version_id", disableKeyRequest.VersionId.ToString()); string urlPath = HttpUtils.AddUrlPath("/{version_id}/{project_id}/kms/disable-key", urlParam); SdkRequest request = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", disableKeyRequest); HttpResponseMessage response = await DoHttpRequestAsync("POST", request); return(JsonUtils.DeSerialize <DisableKeyResponse>(response)); }
private static async Task DisableKey(KmsManagementClient kmsManagementClient, string keyId) { logger.Info("Disable Key"); DisableKeyRequest disableKeyRequest = new DisableKeyRequest { KeyId = keyId }; DisableKeyResponse disableKeyResponse = await kmsManagementClient.DisableKey(disableKeyRequest); logger.Info($"Key Disabled Successfully: {disableKeyResponse.Key.DisplayName}"); }
/// <summary> /// 本接口用于禁用一个主密钥,处于禁用状态的Key无法用于加密、解密操作。 /// </summary> /// <param name="req"><see cref="DisableKeyRequest"/></param> /// <returns><see cref="DisableKeyResponse"/></returns> public DisableKeyResponse DisableKeySync(DisableKeyRequest req) { JsonResponseModel <DisableKeyResponse> rsp = null; try { var strResp = this.InternalRequestSync(req, "DisableKey"); rsp = JsonConvert.DeserializeObject <JsonResponseModel <DisableKeyResponse> >(strResp); } catch (JsonSerializationException e) { throw new TencentCloudSDKException(e.Message); } return(rsp.Response); }
protected override void ProcessRecord() { base.ProcessRecord(); DisableKeyRequest request; try { request = new DisableKeyRequest { KeyId = KeyId, IfMatch = IfMatch, OpcRequestId = OpcRequestId, OpcRetryToken = OpcRetryToken }; response = client.DisableKey(request).GetAwaiter().GetResult(); WriteOutput(response, response.Key); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
/// <summary> /// 禁用当前状态为`已启用`的密钥 /// </summary> /// <param name="request">请求参数信息</param> /// <returns>请求结果信息</returns> public async Task <DisableKeyResponse> DisableKey(DisableKeyRequest request) { return(await new DisableKeyExecutor().Client(this).Execute <DisableKeyResponse, DisableKeyResult, DisableKeyRequest>(request).ConfigureAwait(false)); }
/// <summary> /// 禁用当前状态为`已启用`的密钥 /// </summary> /// <param name="request">请求参数信息</param> /// <returns>请求结果信息</returns> public DisableKeyResponse DisableKey(DisableKeyRequest request) { return(new DisableKeyExecutor().Client(this).Execute <DisableKeyResponse, DisableKeyResult, DisableKeyRequest>(request)); }