internal virtual PutSecretValueResponse PutSecretValue(PutSecretValueRequest request)
        {
            var marshaller   = PutSecretValueRequestMarshaller.Instance;
            var unmarshaller = PutSecretValueResponseUnmarshaller.Instance;

            return(Invoke <PutSecretValueRequest, PutSecretValueResponse>(request, marshaller, unmarshaller));
        }
        /// <summary>
        /// Initiates the asynchronous execution of the PutSecretValue operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the PutSecretValue 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/PutSecretValue">REST API Reference for PutSecretValue Operation</seealso>
        public virtual Task <PutSecretValueResponse> PutSecretValueAsync(PutSecretValueRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = PutSecretValueRequestMarshaller.Instance;
            var unmarshaller = PutSecretValueResponseUnmarshaller.Instance;

            return(InvokeAsync <PutSecretValueRequest, PutSecretValueResponse>(request, marshaller,
                                                                               unmarshaller, cancellationToken));
        }
示例#3
0
        /// <summary>
        /// Initiates the asynchronous execution of the PutSecretValue operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the PutSecretValue 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/PutSecretValue">REST API Reference for PutSecretValue Operation</seealso>
        public virtual Task <PutSecretValueResponse> PutSecretValueAsync(PutSecretValueRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = PutSecretValueRequestMarshaller.Instance;
            options.ResponseUnmarshaller = PutSecretValueResponseUnmarshaller.Instance;

            return(InvokeAsync <PutSecretValueResponse>(request, options, cancellationToken));
        }
示例#4
0
        internal virtual PutSecretValueResponse PutSecretValue(PutSecretValueRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = PutSecretValueRequestMarshaller.Instance;
            options.ResponseUnmarshaller = PutSecretValueResponseUnmarshaller.Instance;

            return(Invoke <PutSecretValueResponse>(request, options));
        }
示例#5
0
        // *******************************************************************

        /// <inheritdoc/>
        public virtual async Task <Secret> SetByNameAsync(
            string name,
            string value,
            CancellationToken cancellationToken = default
            )
        {
            try
            {
                // Validate the parameters before attempting to use them.
                Guard.Instance().ThrowIfNullOrEmpty(name, nameof(name));

                // Create the request.
                var request = new PutSecretValueRequest
                {
                    SecretId     = name,
                    SecretString = value
                };

                // Defer to the manager.
                var response = await SecretClient.PutSecretValueAsync(
                    request,
                    cancellationToken
                    ).ConfigureAwait(false);

                // Validate the results.
                if (response.HttpStatusCode != System.Net.HttpStatusCode.OK)
                {
                    // Panic!!
                    throw new RepositoryException(
                              message: $"The call to ASWS failed with status code: {response.HttpStatusCode}"
                              );
                }

                // Wrap the results in our model.
                var model = new Secret()
                {
                    Key   = response.ARN,
                    Name  = name,
                    Value = value
                };

                // Return the result.
                return(model);
            }
            catch (Exception ex)
            {
                // Provide better context for the error.
                throw new RepositoryException(
                          message: $"Failed to set the value for a secret, by name!",
                          innerException: ex
                          ).SetCallerInfo()
                      .SetOriginator(nameof(SecretRepository))
                      .SetDateTime();
            }
        }
示例#6
0
        /// <summary>
        /// PutSecretValue接口的同步版本,该接口在指定名称的凭据下增加新版本的凭据内容,一个凭据下最多可以支持10个版本。只能对处于Enabled 和 Disabled 状态的凭据添加新的版本。
        /// </summary>
        /// <param name="req">参考<see cref="PutSecretValueRequest"/></param>
        /// <returns>参考<see cref="PutSecretValueResponse"/>实例</returns>
        public PutSecretValueResponse PutSecretValueSync(PutSecretValueRequest req)
        {
            JsonResponseModel <PutSecretValueResponse> rsp = null;

            try
            {
                var strResp = this.InternalRequestSync(req, "PutSecretValue");
                rsp = JsonConvert.DeserializeObject <JsonResponseModel <PutSecretValueResponse> >(strResp);
            }
            catch (JsonSerializationException e)
            {
                throw new TencentCloudSDKException(e.Message);
            }
            return(rsp.Response);
        }
示例#7
0
        public bool SetPassword(string asset, string account, string password, string altAccountName = null)
        {
            if (_awsClient == null || !ConfigurationIsValid)
            {
                _logger.Error("No vault connection. Make sure that the plugin has been configured.");
                return(false);
            }

            try
            {
                var name = altAccountName ?? $"{asset}-{account}";

                var request = new PutSecretValueRequest()
                {
                    SecretId     = name,
                    SecretString = password
                };

                var res = Task.Run(async() => await _awsClient.PutSecretValueAsync(request));

                if (res.Result.HttpStatusCode == System.Net.HttpStatusCode.OK)
                {
                    _logger.Information($"Successfully set the secret for {name}");
                    return(true);
                }
                else
                {
                    throw new Exception($"HTTP error: {res.Result.HttpStatusCode}");
                }
            }

            catch (Exception ex)
            {
                if (ex.Message.Contains("Secrets Manager can't find the specified secret"))
                {
                    _logger.Information(ex, "Account does not exist in vault; attempting to create account.");
                    return(CreateAwsAccount(asset, altAccountName ?? account, password));
                }
                else
                {
                    _logger.Error(ex, $"Failed to set the secret for {asset}-{altAccountName ?? account}: {ex.Message}.");
                    return(false);
                }
            }
        }
示例#8
0
        /// <summary>
        /// Writes the text value of a particular key, to a given secret ARN
        /// </summary>
        /// <param name="key">The field within the secret to update</param>
        /// <param name="value">The value to update for the given key</param>
        /// <param name="secretVaultIdentifier">The full secret ARN</param>
        /// <returns>A status code with the result of the request</returns>
        public override async Task <HttpStatusCode> WriteValuesToSecretAsync(IDictionary <string, string> fieldsToInsertOrUpdate, string secretVaultIdentifier)
        {
            string originalSecretJson = await GetJsonFromSecretAsync(secretVaultIdentifier);

            // for each value in the dictionary, try to update the JSON
            string sbUpdatedSecretJson = originalSecretJson;

            foreach (var field in fieldsToInsertOrUpdate)
            {
                sbUpdatedSecretJson = UpdateJsonForSecret(secretVaultIdentifier, sbUpdatedSecretJson, field.Key, field.Value);
            }

            PutSecretValueResponse response = null;

            // Now update the secret
            if (!string.IsNullOrEmpty(sbUpdatedSecretJson))
            {
                PutSecretValueRequest request = new PutSecretValueRequest();
                request.SecretId     = secretVaultIdentifier;
                request.SecretString = sbUpdatedSecretJson;
                try
                {
                    response = await SecretClient.PutSecretValueAsync(request);
                }
                catch (EncryptionFailureException e)
                {
                    // Secrets Manager can't encrypt the protected secret text using the provided KMS key.\
                    _logger.Error(string.Format(DeploySoftware_LaunchPad_AWS_Resources.Logger_Error_WriteValueToSecret_Exception, secretVaultIdentifier, e.Message));
                    throw;
                }
                catch (InternalServiceErrorException e)
                {
                    // An error occurred on the server side.
                    _logger.Error(string.Format(DeploySoftware_LaunchPad_AWS_Resources.Logger_Error_WriteValueToSecret_Exception, secretVaultIdentifier, e.Message));
                    throw;
                }
                catch (InvalidParameterException e)
                {
                    // You provided an invalid value for a parameter.
                    _logger.Error(string.Format(DeploySoftware_LaunchPad_AWS_Resources.Logger_Error_WriteValueToSecret_Exception, secretVaultIdentifier, e.Message));
                    throw;
                }
                catch (InvalidRequestException e)
                {
                    // You provided a parameter value that is not valid for the current state of the resource.
                    _logger.Error(string.Format(DeploySoftware_LaunchPad_AWS_Resources.Logger_Error_WriteValueToSecret_Exception, secretVaultIdentifier, e.Message));
                    throw;
                }
                catch (ResourceNotFoundException e)
                {
                    // We can't find the resource that you asked for.
                    _logger.Error(string.Format(DeploySoftware_LaunchPad_AWS_Resources.Logger_Error_WriteValueToSecret_Exception, secretVaultIdentifier, e.Message));
                    throw;
                }
                catch (ResourceExistsException e)
                {
                    // A resource with the ID you requested already exists.
                    _logger.Error(string.Format(DeploySoftware_LaunchPad_AWS_Resources.Logger_Error_WriteValueToSecret_Exception, secretVaultIdentifier, e.Message));
                    throw;
                }
                catch (AggregateException e)
                {
                    // More than one of the above exceptions were triggered.
                    _logger.Error(string.Format(DeploySoftware_LaunchPad_AWS_Resources.Logger_Error_WriteValueToSecret_Exception, secretVaultIdentifier, e.Message));
                    throw;
                }
            }
            return(response.HttpStatusCode);
        }