Files
Luna/Luna.Configuration/Extensions/ConfigurationBuilderExtensions.cs
T
darmanandClaude Opus 5 9f1e62fdbf Remove hardcoded secrets; source credentials from configuration
The Telegram bot token was a const in AddChannels(), and the Mistral API
key was baked into the embedded Provider.Mistral.toml resource.

- Wire AddChannels() through the existing (previously unused)
  AddTelegramOptions(), which binds "Channels:Telegram" and validates on
  start. TelegramOptions is resolved from IOptions<> so TelegramAdapter
  and TelegramChannel are unchanged.
- Ship the embedded provider defaults with an empty ApiKey. Ollama's
  placeholder is now a non-secret literal.
- Re-apply AddEnvironmentVariables() last in AddLunaConfiguration() so
  env vars override the TOML sources; without this the embedded defaults
  would shadow injected credentials.

Credentials are now supplied via Providers__Mistral__ApiKey and
Channels__Telegram__BotToken, or via ~/.luna/providers/*.toml overrides.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-29 07:59:05 +02:00

45 lines
1.5 KiB
C#

using Luna.Configuration.Services.Agents;
using Luna.Configuration.Services.Providers;
using Microsoft.Extensions.Configuration;
namespace Luna.Configuration.Extensions;
public static class ConfigurationBuilderExtensions
{
private static readonly string[] AgentConfigSearchPaths =
[
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".luna", "agents")
];
private static readonly string[] ProviderConfigSearchPaths =
[
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".luna", "providers")
];
extension(IConfigurationBuilder builder)
{
public IConfigurationBuilder AddLunaConfiguration()
{
builder.Add(new AgentOptionsConfigurationSource());
foreach (var searchPath in AgentConfigSearchPaths)
{
builder.Add(new AgentOptionsConfigurationSource(searchPath));
}
builder.Add(new ProviderOptionsConfigurationSource());
foreach (var searchPath in ProviderConfigSearchPaths)
{
builder.Add(new ProviderOptionsConfigurationSource(searchPath));
}
// Re-applied last so environment variables take precedence over the TOML
// sources above. This is how secrets (API keys, bot tokens) are supplied —
// the embedded defaults ship with empty credentials.
builder.AddEnvironmentVariables();
return builder;
}
}
}