using System; using System.Linq; namespace StellaOps.Configuration; /// /// Helper utilities for bootstrapping StellaOps Authority configuration. /// public static class StellaOpsAuthorityConfiguration { private static readonly string[] _defaultAuthorityYamlFiles = { "authority.yaml", "authority.local.yaml", "etc/authority.yaml", "etc/authority.local.yaml" }; /// /// Builds using the shared configuration bootstrapper. /// /// Optional hook to customise bootstrap behaviour. public static StellaOpsConfigurationContext Build( Action>? configure = null) { return StellaOpsConfigurationBootstrapper.Build(options => { options.BindingSection ??= "Authority"; options.EnvironmentPrefix ??= "STELLAOPS_AUTHORITY_"; configure?.Invoke(options); AppendDefaultYamlFiles(options); var previousPostBind = options.PostBind; options.PostBind = (authorityOptions, configuration) => { previousPostBind?.Invoke(authorityOptions, configuration); authorityOptions.Validate(); }; }); } private static void AppendDefaultYamlFiles(StellaOpsBootstrapOptions options) { foreach (var path in _defaultAuthorityYamlFiles) { var alreadyPresent = options.YamlFiles.Any(file => string.Equals(file.Path, path, StringComparison.OrdinalIgnoreCase)); if (!alreadyPresent) { options.YamlFiles.Add(new YamlConfigurationFile(path, Optional: true)); } } } }