in src/Microsoft.Azure.WebJobs.Extensions.Dapr/Services/DaprServiceClient.cs [253:298]
public async Task<JsonDocument> GetSecretAsync(
string? daprAddress,
string secretStoreName,
string? key,
string? metadata,
CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(secretStoreName))
{
throw new ArgumentNullException(nameof(secretStoreName));
}
if (string.IsNullOrEmpty(key))
{
throw new ArgumentNullException(nameof(key));
}
try
{
this.EnsureDaprAddress(ref daprAddress);
string metadataQuery = string.Empty;
if (!string.IsNullOrEmpty(metadata))
{
metadataQuery = "?" + metadata;
}
string uri = $"{daprAddress}/v1.0/secrets/{secretStoreName}/{key}{metadataQuery}";
var response = await this.daprClient.GetAsync(this.secretInputLogger, uri, cancellationToken);
string secretPayload = await response.Content.ReadAsStringAsync();
// The response is always expected to be a JSON object
return JsonDocument.Parse(secretPayload);
}
catch (Exception ex)
{
if (ex is DaprException || ex is DaprSidecarNotPresentException)
{
throw;
}
throw new DaprException(HttpStatusCode.InternalServerError, ErrorCodes.ErrDaprRequestFailed, "An error occurred while getting secret.", ex);
}
}