forked from admin/VolcanicAgenticCore
37 lines
2.1 KiB
C#
37 lines
2.1 KiB
C#
using Volcanic.AgenticCore.Extensions.GoogleCalendar;
|
|
using Volcanic.AgenticCore.Features.Processes;
|
|
|
|
namespace Volcanic.AgenticCore.Telegram;
|
|
|
|
/// <summary>The Telegram host's process environment: section, <c>PROCESS_ENV_ALLOW</c> and the host's secret values.</summary>
|
|
public static class TelegramProcessEnvironment
|
|
{
|
|
public const string AllowVariable = "PROCESS_ENV_ALLOW";
|
|
|
|
/// <summary>Adds the section's lists, <c>PROCESS_ENV_ALLOW</c>, the bot token, the speech and OpenRouter API keys and the Google client secret to <paramref name="target"/>.</summary>
|
|
public static void Configure(ProcessEnvironmentOptions target, TelegramOptions telegram, ProcessEnvironmentSection section, Func<string, string?> getEnv,
|
|
GoogleCalendarOptions? calendar = null)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(target);
|
|
ArgumentNullException.ThrowIfNull(telegram);
|
|
ArgumentNullException.ThrowIfNull(section);
|
|
ArgumentNullException.ThrowIfNull(getEnv);
|
|
target.Deny.AddRange(section.Deny);
|
|
target.Allow.AddRange(section.Allow);
|
|
if (getEnv(AllowVariable) is { Length: > 0 } allow)
|
|
target.Allow.AddRange(allow.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries));
|
|
target.HardenHostProcess = section.HardenHostProcess;
|
|
if (!string.IsNullOrWhiteSpace(telegram.BotToken)) target.SecretValues.Add(telegram.BotToken);
|
|
if (!string.IsNullOrWhiteSpace(telegram.Speech?.ApiKey)) target.SecretValues.Add(telegram.Speech.ApiKey);
|
|
if (!string.IsNullOrWhiteSpace(telegram.Triggers?.ApiKey)) target.SecretValues.Add(telegram.Triggers.ApiKey);
|
|
if (!string.IsNullOrWhiteSpace(calendar?.ClientSecret)) target.SecretValues.Add(calendar.ClientSecret);
|
|
}
|
|
|
|
/// <summary>The startup log line: names only, never values.</summary>
|
|
public static string Describe(ProcessEnvironmentOptions options)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(options);
|
|
return $"Process environment: {options.Deny.Count} deny rules, allow: {(options.Allow.Count == 0 ? "none" : string.Join(", ", options.Allow))}";
|
|
}
|
|
}
|