Ejemplo n.º 1
0
        /// <summary>
        /// Gets a secret identified by a Key Vault reference.
        /// </summary>
        /// <param name="reference">The Key Vault reference that identifies the secret to get.</param>
        /// <returns>The secret identified by <paramref name="reference"/>.</returns>
        public Task <string> GetSecretAsync(KeyVaultReference reference)
        {
            if (reference == null)
            {
                throw new ArgumentNullException(nameof(reference));
            }

            return(this.GetSecretAsync(
                       reference.VaultName,
                       reference.SecretName,
                       reference.SecretVersion));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets a secret identified by a Key Vault reference.
        /// </summary>
        /// <param name="referenceString">The Key Vault reference string that identifies the secret to get.</param>
        /// <returns>The secret identified by a Key Vault reference.</returns>
        public Task <string> GetSecretAsync(string referenceString)
        {
            var reference = KeyVaultReference.TryParse(referenceString);

            if (reference == null)
            {
                throw new FormatException("Invalid key vault reference.");
            }

            var secretClient = this.secretClients.GetOrAdd(reference.VaultName, this.CreateSecretClient);

            return(this.GetSecretAsync(reference));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Tries to parse a Key Vault reference string.
        /// </summary>
        /// <param name="referenceString">The reference string to parse.</param>
        /// <returns>
        /// The <see cref="KeyVaultReference"/> object parsed from <paramref name="referenceString"/>.
        /// Or <c>null</c> if <paramref name="referenceString"/> is not a valid Key Vault reference string.
        /// </returns>
        public static KeyVaultReference?TryParse(string referenceString)
        {
            var match = ReferenceRegex.Match(referenceString ?? string.Empty);

            if (!match.Success)
            {
                return(null);
            }

            var secretVersionGroup = match.Groups["secretVersion"];
            var reference          = new KeyVaultReference(
                match.Groups["vaultName"].Value,
                match.Groups["secretName"].Value,
                secretVersionGroup.Success ? secretVersionGroup.Value : null);

            return(reference);
        }