public Secret UpdateSecret(string vaultName, string secretName, string secretVersion, SecretAttributes secretAttributes)
        {
            if (string.IsNullOrEmpty(vaultName))
                throw new ArgumentNullException("vaultName");
            if (string.IsNullOrEmpty(secretName))
                throw new ArgumentNullException("secretName");
            if (secretAttributes == null)
                throw new ArgumentNullException("secretAttributes");

            var secretIdentifier = new SecretIdentifier(this.vaultUriHelper.CreateVaultAddress(vaultName), secretName, secretVersion);

            Azure.KeyVault.Models.SecretAttributes attributes = (Azure.KeyVault.Models.SecretAttributes)secretAttributes;

            SecretBundle secret;
            try
            {
                secret = this.keyVaultClient.UpdateSecretAsync(secretIdentifier.Identifier,
                    secretAttributes.ContentType, attributes, secretAttributes.TagsDictionary).GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                throw GetInnerException(ex);
            }

            return new Secret(secret, this.vaultUriHelper);
        }
        public Secret GetSecret(string vaultName, string secretName, string secretVersion)
        {
            if (string.IsNullOrEmpty(vaultName))
            {
                throw new ArgumentNullException("vaultName");
            }
            if (string.IsNullOrEmpty(secretName))
            {
                throw new ArgumentNullException("secretName");
            }

            var secretIdentifier = new Microsoft.Azure.KeyVault.SecretIdentifier(this.vaultUriHelper.CreateVaultAddress(vaultName), secretName, secretVersion);

            Microsoft.Azure.KeyVault.Secret secret;
            try
            {
                secret = this.keyVaultClient.GetSecretAsync(secretIdentifier.Identifier).GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                throw GetInnerException(ex);
            }

            return(new Secret(secret, this.vaultUriHelper));
        }
        public Secret UpdateSecret(string vaultName, string secretName, string secretVersion, SecretAttributes secretAttributes)
        {
            if (string.IsNullOrEmpty(vaultName))
            {
                throw new ArgumentNullException("vaultName");
            }
            if (string.IsNullOrEmpty(secretName))
            {
                throw new ArgumentNullException("secretName");
            }
            if (secretAttributes == null)
            {
                throw new ArgumentNullException("secretAttributes");
            }

            var secretIdentifier = new Microsoft.Azure.KeyVault.SecretIdentifier(this.vaultUriHelper.CreateVaultAddress(vaultName), secretName, secretVersion);

            Microsoft.Azure.KeyVault.SecretAttributes attributes = (Microsoft.Azure.KeyVault.SecretAttributes)secretAttributes;

            Microsoft.Azure.KeyVault.Secret secret;
            try
            {
                secret = this.keyVaultClient.UpdateSecretAsync(secretIdentifier.Identifier,
                                                               secretAttributes.ContentType, attributes, secretAttributes.TagsDictionary).GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                throw GetInnerException(ex);
            }

            return(new Secret(secret, this.vaultUriHelper));
        }
Exemple #4
0
        /// <summary>
        /// Provides an IKey implementation for the specified key or secret identifier.
        /// </summary>
        /// <param name="kid">The key or secret identifier to resolve</param>
        /// <param name="token">Cancellation token</param>
        /// <returns>The resolved IKey implementation or null</returns>
        public async Task <IKey> ResolveKeyAsync(string kid, CancellationToken token)
        {
            if (string.IsNullOrWhiteSpace(kid))
            {
                throw new ArgumentNullException("kid");
            }

            // If the resolver has a name prefix, only handle kid that have that prefix.
            if (_name != null)
            {
                var vaultUrl = new Uri(_name);
                var keyUrl   = new Uri(kid);

                if (string.Compare(vaultUrl.Scheme, keyUrl.Scheme, true) != 0 || string.Compare(vaultUrl.Authority, keyUrl.Authority, true) != 0 || vaultUrl.Port != keyUrl.Port)
                {
                    return(null);
                }
            }

            if (KeyIdentifier.IsKeyIdentifier(kid))
            {
                return(await ResolveKeyFromKeyAsync(kid, token).ConfigureAwait(false));
            }

            if (SecretIdentifier.IsSecretIdentifier(kid))
            {
                return(await ResolveKeyFromSecretAsync(kid, token).ConfigureAwait(false));
            }

            // Return null rather than throw an exception here
            return(null);
        }
Exemple #5
0
        /// <summary>
        /// Provides an IKey implementation for the specified key or secret identifier.
        /// </summary>
        /// <param name="kid">The key or secret identifier to resolve</param>
        /// <param name="token">Cancellation token</param>
        /// <returns>The resolved IKey implementation or null</returns>
        public async Task <IKey> ResolveKeyAsync(string kid, CancellationToken token)
        {
            if (string.IsNullOrWhiteSpace(kid))
            {
                throw new ArgumentNullException("kid");
            }

            // If the resolver has a name prefix, only handle kid that have that prefix
            if (!string.IsNullOrEmpty(_name) && !kid.StartsWith(_name, StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            if (KeyIdentifier.IsKeyIdentifier(kid))
            {
                return(await ResolveKeyFromKeyAsync(kid, token).ConfigureAwait(false));
            }

            if (SecretIdentifier.IsSecretIdentifier(kid))
            {
                return(await ResolveKeyFromSecretAsync(kid, token).ConfigureAwait(false));
            }

            // Return null rather than throw an exception here
            return(null);
        }
Exemple #6
0
        /// <summary>
        /// Updates the attributes associated with the specified secret
        /// </summary>
        /// <param name="secretIdentifier">The URL of the secret</param>
        /// <param name="contentType">Type of the secret value such as password.</param>
        /// <param name="tags">Application-specific metadata in the form of key-value pairs</param>
        /// <param name="secretAttributes">Attributes for the secret. For more information on possible attributes, see SecretAttributes.</param>
        /// <param name="cancellationToken">Optional cancellation token</param>
        /// <returns>A response message containing the updated secret</returns>
        public static async Task <SecretBundle> UpdateSecretAsync(this IKeyVaultClient operations, string secretIdentifier, string contentType = null, SecretAttributes secretAttributes = null, Dictionary <string, string> tags = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(secretIdentifier))
            {
                throw new ArgumentNullException(nameof(secretIdentifier));
            }

            var secretId = new SecretIdentifier(secretIdentifier);

            using (var _result = await operations.UpdateSecretWithHttpMessagesAsync(secretId.Vault, secretId.Name, secretId.Version, contentType, secretAttributes, tags, null, cancellationToken).ConfigureAwait(false))
            {
                return(_result.Body);
            }
        }
Exemple #7
0
        /// <summary>
        /// Gets a secret.
        /// </summary>
        /// <param name="secretIdentifier">The URL for the secret.</param>
        /// <param name="cancellationToken">Optional cancellation token</param>
        /// <returns>A response message containing the secret</returns>
        public static async Task <SecretBundle> GetSecretAsync(this IKeyVaultClient operations, string secretIdentifier, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(secretIdentifier))
            {
                throw new ArgumentNullException(nameof(secretIdentifier));
            }

            var secretId = new SecretIdentifier(secretIdentifier);

            using (var _result = await operations.GetSecretWithHttpMessagesAsync(secretId.Vault, secretId.Name, secretId.Version ?? string.Empty, null, cancellationToken).ConfigureAwait(false))
            {
                return(_result.Body);
            }
        }
        public Secret GetSecret(string vaultName, string secretName, string secretVersion)
        {
            if (string.IsNullOrEmpty(vaultName))
                throw new ArgumentNullException("vaultName");
            if (string.IsNullOrEmpty(secretName))
                throw new ArgumentNullException("secretName");

            var secretIdentifier = new SecretIdentifier(this.vaultUriHelper.CreateVaultAddress(vaultName), secretName, secretVersion);
            SecretBundle secret;
            try
            {
                secret = this.keyVaultClient.GetSecretAsync(secretIdentifier.Identifier).GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                throw GetInnerException(ex);
            }

            return new Secret(secret, this.vaultUriHelper);
        }