namespace Moli.Desktop.Llm;
|
|
public sealed class EnvironmentCredentialStore : ICredentialStore
|
{
|
public Task<string?> ResolveSecretAsync(string? authRef, CancellationToken cancellationToken = default)
|
{
|
cancellationToken.ThrowIfCancellationRequested();
|
if (string.IsNullOrWhiteSpace(authRef))
|
{
|
return Task.FromResult<string?>(null);
|
}
|
|
var direct = Environment.GetEnvironmentVariable(authRef);
|
if (!string.IsNullOrWhiteSpace(direct))
|
{
|
return Task.FromResult<string?>(direct);
|
}
|
|
var normalized = "MOLI_" + new string(authRef
|
.Select(ch => char.IsLetterOrDigit(ch) ? char.ToUpperInvariant(ch) : '_')
|
.ToArray());
|
|
return Task.FromResult(Environment.GetEnvironmentVariable(normalized));
|
}
|
}
|