/// <summary> /// Creates a new secret according to the details of the request. /// <br/> /// This operation is not supported by the Oracle Cloud Infrastructure Terraform Provider. /// /// </summary> /// <param name="request">The request object containing the details to send. Required.</param> /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param> /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param> /// <returns>A response object containing details about the completed operation</returns> /// <example>Click <a href="https://docs.cloud.oracle.com/en-us/iaas/tools/dot-net-examples/latest/vault/CreateSecret.cs.html">here</a> to see an example of how to use CreateSecret API.</example> public async Task <CreateSecretResponse> CreateSecret(CreateSecretRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default) { logger.Trace("Called createSecret"); Uri uri = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/secrets".Trim('/'))); HttpMethod method = new HttpMethod("POST"); HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request); requestMessage.Headers.Add("Accept", "application/json"); GenericRetrier retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration); HttpResponseMessage responseMessage; try { if (retryingClient != null) { responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken).ConfigureAwait(false); } else { responseMessage = await this.restClient.HttpSend(requestMessage).ConfigureAwait(false); } this.restClient.CheckHttpResponseMessage(requestMessage, responseMessage); return(Converter.FromHttpResponseMessage <CreateSecretResponse>(responseMessage)); } catch (Exception e) { logger.Error($"CreateSecret failed with error: {e.Message}"); throw; } }
private async Task <string> Set(string key, string value) { var request = new CreateSecretRequest { Name = key, SecretString = value }; try { var createResponse = await _amazonSecretsManager.CreateSecretAsync(request); return(createResponse.VersionId); } catch (ResourceExistsException) { var updateRequest = new UpdateSecretRequest { SecretId = key, SecretString = value }; var response = await _amazonSecretsManager.UpdateSecretAsync(updateRequest); return(response.VersionId); } }
internal virtual CreateSecretResponse CreateSecret(CreateSecretRequest request) { var marshaller = CreateSecretRequestMarshaller.Instance; var unmarshaller = CreateSecretResponseUnmarshaller.Instance; return(Invoke <CreateSecretRequest, CreateSecretResponse>(request, marshaller, unmarshaller)); }
/// <summary> /// Initiates the asynchronous execution of the CreateSecret operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the CreateSecret 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> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/secretsmanager-2017-10-17/CreateSecret">REST API Reference for CreateSecret Operation</seealso> public virtual Task <CreateSecretResponse> CreateSecretAsync(CreateSecretRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = CreateSecretRequestMarshaller.Instance; var unmarshaller = CreateSecretResponseUnmarshaller.Instance; return(InvokeAsync <CreateSecretRequest, CreateSecretResponse>(request, marshaller, unmarshaller, cancellationToken)); }
/// <summary> /// 创建凭据 /// </summary> public async Task <CreateSecretResponse> CreateSecretAsync(CreateSecretRequest createSecretRequest) { Dictionary <string, string> urlParam = new Dictionary <string, string>(); string urlPath = HttpUtils.AddUrlPath("/v1/{project_id}/secrets", urlParam); SdkRequest request = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", createSecretRequest); HttpResponseMessage response = await DoHttpRequestAsync("POST", request); return(JsonUtils.DeSerialize <CreateSecretResponse>(response)); }
/// <summary> /// Initiates the asynchronous execution of the CreateSecret operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the CreateSecret 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> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/secretsmanager-2017-10-17/CreateSecret">REST API Reference for CreateSecret Operation</seealso> public virtual Task <CreateSecretResponse> CreateSecretAsync(CreateSecretRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var options = new InvokeOptions(); options.RequestMarshaller = CreateSecretRequestMarshaller.Instance; options.ResponseUnmarshaller = CreateSecretResponseUnmarshaller.Instance; return(InvokeAsync <CreateSecretResponse>(request, options, cancellationToken)); }
internal virtual CreateSecretResponse CreateSecret(CreateSecretRequest request) { var options = new InvokeOptions(); options.RequestMarshaller = CreateSecretRequestMarshaller.Instance; options.ResponseUnmarshaller = CreateSecretResponseUnmarshaller.Instance; return(Invoke <CreateSecretResponse>(request, options)); }
/// <summary> /// CreateSecret接口的同步版本,创建新的凭据信息,通过KMS进行加密保护。每个Region最多可创建存储1000个凭据信息。 /// </summary> /// <param name="req">参考<see cref="CreateSecretRequest"/></param> /// <returns>参考<see cref="CreateSecretResponse"/>实例</returns> public CreateSecretResponse CreateSecretSync(CreateSecretRequest req) { JsonResponseModel <CreateSecretResponse> rsp = null; try { var strResp = this.InternalRequestSync(req, "CreateSecret"); rsp = JsonConvert.DeserializeObject <JsonResponseModel <CreateSecretResponse> >(strResp); } catch (JsonSerializationException e) { throw new TencentCloudSDKException(e.Message); } return(rsp.Response); }
private Secret CreateSecret() { var secretId = RandomSecretId(); var request = new CreateSecretRequest { ParentAsProjectName = new ProjectName(s_projectId), SecretId = secretId, Secret = new Secret { Replication = new Replication { Automatic = new Replication.Types.Automatic(), }, }, }; return(_client.CreateSecret(request)); }
public void Execute() { var VONAGE_API_KEY = Environment.GetEnvironmentVariable("VONAGE_API_KEY") ?? "VONAGE_API_KEY"; var VONAGE_API_SECRET = Environment.GetEnvironmentVariable("VONAGE_API_SECRET") ?? "VONAGE_API_SECRET"; var API_KEY = Environment.GetEnvironmentVariable("API_KEY") ?? "API_KEY"; var NEW_SECRET = Environment.GetEnvironmentVariable("NEW_SECRET") ?? "NEW_SECRET"; var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET); var client = new VonageClient(credentials); var request = new CreateSecretRequest() { Secret = NEW_SECRET }; var response = client.AccountClient.CreateApiSecret(request, API_KEY); Console.WriteLine($"New Secret Created id:{response.Id}"); }
private String Setup(TestType type) { String testSecretName = TestBase.TestSecretPrefix + Guid.NewGuid().ToString(); CreateSecretRequest req = null; if (type == TestType.SecretString) { req = new CreateSecretRequest { Name = testSecretName, SecretString = testSecretString }; } else if (type == TestType.SecretBinary) { req = new CreateSecretRequest { Name = testSecretName, SecretBinary = testSecretBinary }; } TestBase.Client.CreateSecret(req); TestBase.SecretNamesToDelete.Add(testSecretName); return(testSecretName); }
protected override void ProcessRecord() { base.ProcessRecord(); CreateSecretRequest request; try { request = new CreateSecretRequest { CreateSecretDetails = CreateSecretDetails, OpcRequestId = OpcRequestId, OpcRetryToken = OpcRetryToken }; response = client.CreateSecret(request).GetAwaiter().GetResult(); WriteOutput(response, response.Secret); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
// [END secretmanager_add_secret_version] // [START secretmanager_create_secret] /// <summary> /// Create a new secret in the given project with the given name. /// </summary> /// <param name="projectId">ID of the project in which to create the secret.</param> /// <param name="secretId">ID of the secret.</param> /// <example> /// Create a secret. /// <code>CreateSecret("my-project", "my-secret")</code> /// </example> public static void CreateSecret(string projectId, string secretId) { SecretManagerServiceClient client = SecretManagerServiceClient.Create(); // Create the request. var request = new CreateSecretRequest { ParentAsProjectName = new ProjectName(projectId), SecretId = secretId, Secret = new Secret { Replication = new Replication { Automatic = new Replication.Types.Automatic(), }, }, }; // Create the secret. var secret = client.CreateSecret(request); Console.WriteLine($"Created secret {secret.Name}"); }
private bool CreateAwsAccount(string asset, string account, string password) { if (_awsClient == null || !ConfigurationIsValid) { _logger.Error("No vault connection. Make sure that the plugin has been configured."); return(false); } var name = $"{asset}-{account}"; try { var createAccountRequest = new CreateSecretRequest { Name = name, SecretString = password }; var res = Task.Run(async() => await _awsClient.CreateSecretAsync(createAccountRequest)); if (res.Result.HttpStatusCode == System.Net.HttpStatusCode.OK) { _logger.Information($"Successfully created account {name} in vault."); return(true); } else { throw new Exception($"Http Status Code {res.Result.HttpStatusCode}"); } } catch (Exception createEx) { _logger.Error(createEx, $"Failed to create account {name} in vault. Message: {createEx.Message}"); return(false); } }
public static void Main(string[] args) { // GCP project in which to store secrets in Secret Manager. string projectId = "YOUR-PROJECT-ID"; // ID of the secret to create. string secretId = "YOUR-SECRET-ID"; // [END secretmanager_quickstart] if (args.Length > 1) { projectId = args[0]; secretId = args[1]; } // [START secretmanager_quickstart] // Create a Secret Manager client. SecretManagerServiceClient client = SecretManagerServiceClient.Create(); // Create the parent secret. var createSecretRequest = new CreateSecretRequest { ParentAsProjectName = new ProjectName(projectId), SecretId = secretId, Secret = new Secret { Replication = new Replication { Automatic = new Replication.Types.Automatic(), }, }, }; var secret = client.CreateSecret(createSecretRequest); // Add a secret version. var addSecretVersionRequest = new AddSecretVersionRequest { ParentAsSecretName = secret.SecretName, Payload = new SecretPayload { Data = ByteString.CopyFrom("my super secret data", Encoding.UTF8), }, }; var version = client.AddSecretVersion(addSecretVersionRequest); // Access the secret version. var accessSecretVersionRequest = new AccessSecretVersionRequest { SecretVersionName = version.SecretVersionName, }; var result = client.AccessSecretVersion(accessSecretVersionRequest); // Print the results // // WARNING: Do not print secrets in production environments. This // snippet is for demonstration purposes only. string payload = result.Payload.Data.ToStringUtf8(); Console.WriteLine($"Plaintext: {payload}"); }
/// <summary> /// 创建机密 /// </summary> /// <param name="request">请求参数信息</param> /// <returns>请求结果信息</returns> public async Task <CreateSecretResponse> CreateSecret(CreateSecretRequest request) { return(await new CreateSecretExecutor().Client(this).Execute <CreateSecretResponse, CreateSecretResult, CreateSecretRequest>(request).ConfigureAwait(false)); }
/// <summary> /// 创建机密 /// </summary> /// <param name="request">请求参数信息</param> /// <returns>请求结果信息</returns> public CreateSecretResponse CreateSecret(CreateSecretRequest request) { return(new CreateSecretExecutor().Client(this).Execute <CreateSecretResponse, CreateSecretResult, CreateSecretRequest>(request)); }