public static async Task Main() { var client = new AmazonKeyManagementServiceClient(); // The identifier of the AWS KMS key to enable. 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 EnableKeyRequest { KeyId = keyId, }; var response = await client.EnableKeyAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { // Retrieve information about the key to show that it has now // been enabled. var describeResponse = await client.DescribeKeyAsync(new DescribeKeyRequest { KeyId = keyId, }); Console.WriteLine($"{describeResponse.KeyMetadata.KeyId} - state: {describeResponse.KeyMetadata.KeyState}"); } }
private static void EnableKey(KmsClient kmsClient) { try { var req = new EnableKeyRequest { VersionId = "v1.0", Body = new OperateKeyRequestBody { KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "3") } }; var resp = kmsClient.EnableKey(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 EnableKeyResponse EnableKey(EnableKeyRequest request) { var marshaller = new EnableKeyRequestMarshaller(); var unmarshaller = EnableKeyResponseUnmarshaller.Instance; return(Invoke <EnableKeyRequest, EnableKeyResponse>(request, marshaller, unmarshaller)); }
/// <summary> /// Initiates the asynchronous execution of the EnableKey operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the EnableKey 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 <EnableKeyResponse> EnableKeyAsync(EnableKeyRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new EnableKeyRequestMarshaller(); var unmarshaller = EnableKeyResponseUnmarshaller.Instance; return(InvokeAsync <EnableKeyRequest, EnableKeyResponse>(request, marshaller, unmarshaller, cancellationToken)); }
/// <summary> /// 启用密钥 /// </summary> public async Task <EnableKeyResponse> EnableKeyAsync(EnableKeyRequest enableKeyRequest) { Dictionary <string, string> urlParam = new Dictionary <string, string>(); urlParam.Add("version_id", enableKeyRequest.VersionId.ToString()); string urlPath = HttpUtils.AddUrlPath("/{version_id}/{project_id}/kms/enable-key", urlParam); SdkRequest request = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", enableKeyRequest); HttpResponseMessage response = await DoHttpRequestAsync("POST", request); return(JsonUtils.DeSerialize <EnableKeyResponse>(response)); }
private static async Task EnableKey(KmsManagementClient kmsManagementClient, string keyId) { logger.Info("Enable Key"); EnableKeyRequest enableKeyRequest = new EnableKeyRequest { KeyId = keyId }; EnableKeyResponse enableKeyResponse = await kmsManagementClient.EnableKey(enableKeyRequest); logger.Info($"Key Disabled Successfully: {enableKeyResponse.Key.DisplayName}"); }
/// <summary> /// 用于启用一个指定的CMK。 /// </summary> /// <param name="req"><see cref="EnableKeyRequest"/></param> /// <returns><see cref="EnableKeyResponse"/></returns> public EnableKeyResponse EnableKeySync(EnableKeyRequest req) { JsonResponseModel <EnableKeyResponse> rsp = null; try { var strResp = this.InternalRequestSync(req, "EnableKey"); rsp = JsonConvert.DeserializeObject <JsonResponseModel <EnableKeyResponse> >(strResp); } catch (JsonSerializationException e) { throw new TencentCloudSDKException(e.Message); } return(rsp.Response); }
protected override void ProcessRecord() { base.ProcessRecord(); EnableKeyRequest request; try { request = new EnableKeyRequest { KeyId = KeyId, IfMatch = IfMatch, OpcRequestId = OpcRequestId, OpcRetryToken = OpcRetryToken }; response = client.EnableKey(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 <EnableKeyResponse> EnableKey(EnableKeyRequest request) { return(await new EnableKeyExecutor().Client(this).Execute <EnableKeyResponse, EnableKeyResult, EnableKeyRequest>(request).ConfigureAwait(false)); }
/// <summary> /// 启用当前状态为`已禁用`的密钥 /// </summary> /// <param name="request">请求参数信息</param> /// <returns>请求结果信息</returns> public EnableKeyResponse EnableKey(EnableKeyRequest request) { return(new EnableKeyExecutor().Client(this).Execute <EnableKeyResponse, EnableKeyResult, EnableKeyRequest>(request)); }