Table of Contents

Class KeyVaultService

Namespace
arolariu.Backend.Common.Services.KeyVault
Assembly
arolariu.Backend.Common.dll

Service that handles the Azure Key Vault integration. A singleton instance of this class is registered in the service collection.

public sealed class KeyVaultService : IKeyVaultService
Inheritance
KeyVaultService
Implements
Inherited Members

Remarks

Constructor.

Constructors

KeyVaultService(IOptionsMonitor<AzureOptions>)

Service that handles the Azure Key Vault integration. A singleton instance of this class is registered in the service collection.

public KeyVaultService(IOptionsMonitor<AzureOptions> options)

Parameters

options IOptionsMonitor<AzureOptions>

The configuration instance used to retrieve the Azure Key Vault URI.

Remarks

Constructor.

Exceptions

ArgumentNullException

Thrown when the configuration is null.

Properties

_secretClient

private SecretClient _secretClient { get; init; }

Property Value

SecretClient

Exceptions

ArgumentNullException

Thrown when the configuration is null.

Methods

TryGetSecret(string)

Fetches a Key Vault secret by name synchronously. When using this method, the thread will be blocked until the secret is fetched. For asynchronous fetching, use the TryGetSecretAsync(string) method.

public string TryGetSecret(string secretName)

Parameters

secretName string

The name of the secret to fetch from Azure Key Vault.

Returns

string

The value of the secret.

Exceptions

Exception

Thrown when the retrieval of the secret fails.

TryGetSecretAsync(string)

Fetches a Key Vault secret by name asynchronously. When using this method, the thread will not be blocked until the secret is fetched. For synchronous fetching, use the TryGetSecret(string) method.

public Task<string> TryGetSecretAsync(string secretName)

Parameters

secretName string

The name of the secret to fetch from Azure Key Vault.

Returns

Task<string>

A task representing the asynchronous operation. The result of the task is the value of the secret.

Exceptions

Exception

Thrown when the retrieval of the secret fails.