Ejemplo n.º 1
0
        /// <summary>
        /// Sets a secret in the specified vault.
        /// </summary>
        /// <param name="vault">The URL for the vault containing the secrets.</param>
        /// <param name="secretName">The name the secret in the given vault.</param>
        /// <param name="value">The value of the secret.</param>
        /// <returns>A response message containing the updated secret</returns>
        public async Task <Secret> SetSecretAsync(string vault, string secretName, SecureString value)
        {
            if (string.IsNullOrEmpty(vault))
            {
                throw new ArgumentNullException("vaultAddress");
            }

            if (string.IsNullOrEmpty(secretName))
            {
                throw new ArgumentNullException("secretName");
            }

            var identifier = new SecretIdentifier(vault, secretName);
            var request    = new SecretRequestMessage()
            {
                Value = value
            };

            using (var response = await this.SendAsync <SecretRequestMessage>("PUT",
                                                                              CreateSecretUrl(identifier.BaseIdentifier), request).ConfigureAwait(false))
            {
                await EnsureSuccessStatusCode(response).ConfigureAwait(false);

                var putResponse = await DeserializeAsync <SecretResponseMessage>(response).ConfigureAwait(false);

                return(new Secret()
                {
                    Id = putResponse.Id, SecureValue = putResponse.Value
                });
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deletes a secret from the specified vault.
        /// </summary>
        /// <param name="vault">The URL for the vault containing the secrets.</param>
        /// <param name="secretName">The name the secret in the given vault.</param>
        /// <returns>The deleted secret</returns>
        public async Task <Secret> DeleteSecretAsync(string vault, string secretName)
        {
            if (string.IsNullOrEmpty(vault))
            {
                throw new ArgumentNullException("vaultAddress");
            }

            if (string.IsNullOrEmpty(secretName))
            {
                throw new ArgumentNullException("secretName");
            }

            var identifier = new SecretIdentifier(vault, secretName);

            using (var response = await this.SendAsync <HttpRequestMessage>("DELETE",
                                                                            CreateSecretUrl(identifier.BaseIdentifier)).ConfigureAwait(false))
            {
                await EnsureSuccessStatusCode(response).ConfigureAwait(false);

                return(await DeserializeAsync <Secret>(response).ConfigureAwait(false));
            }
        }