public void Resolve(ConfigDocument includeDoc) { if (includeDoc == null) { throw new ArgumentNullException(nameof(includeDoc)); } if (includeDoc.GetXDocument()?.Root == null) { return; } var payloadElements = includeDoc.GetXDocument().Root .Descendants() .Where(e => !e.HasElements); var addElements = new List <XElement>(); foreach (var pe in payloadElements) { var pathItems = new List <XElement>(); GetElementPath(pe, pathItems); var newElement = BuildPathElements(_includeComment.Parent, pathItems.ToArray(), pe.Name.LocalName, addElements); if (string.IsNullOrEmpty(newElement.Value)) { newElement.Value = pe.Value; } } _includeComment.Remove(); }
public async Task <ConfigDocument> GetInclude(string id) { var filePath = Path.Combine(BasePath, id + ".json"); var content = File.Exists(filePath) ? await File.ReadAllTextAsync(filePath) : await Task.FromResult <string>(null); return(ConfigDocument.Load(content)); }
public IEnumerable <ConfigSecret> GetSecrets(ConfigDocument confDoc) { foreach (var secret in confDoc.GetSecrets()) { yield return(new ConfigSecret { FieldPath = secret.Path, SecretKey = secret.Key, Resolved = _resolvedKeys.Contains(secret.Key) }); } }
public static Task ApplyIncludes(this ConfigDocument doc, IIncludesProvider includeProvider) { if (doc == null) { throw new ArgumentNullException(nameof(doc)); } if (includeProvider == null) { throw new ArgumentNullException(nameof(includeProvider)); } return(ResolveIncludes(doc, 0, includeProvider)); }
public static void ApplyOverride(this ConfigDocument doc, ConfigDocument ovrd) { if (doc == null) { throw new ArgumentNullException(nameof(doc)); } if (ovrd == null) { throw new ArgumentNullException(nameof(ovrd)); } var overrides = ovrd.CreateOverrides(); doc.ApplyOverrides(overrides); }
static async Task ResolveIncludes(ConfigDocument confDoc, int deepCount, IIncludesProvider includeProvider) { if (deepCount >= 2) { return; } foreach (var include in confDoc.GetIncludes()) { var includeContent = await includeProvider.GetInclude(include.Link); await ResolveIncludes(includeContent, deepCount + 1, includeProvider); include.Resolve(includeContent); } }
public static void ApplySecrets(this ConfigDocument doc, ISecretsProvider secretsProvider) { if (doc == null) { throw new ArgumentNullException(nameof(doc)); } if (secretsProvider == null) { throw new ArgumentNullException(nameof(secretsProvider)); } var secretMap = secretsProvider.Provide(); foreach (var secret in doc.GetSecrets()) { if (secretMap.TryGetValue(secret.Key, out var secretVal)) { secret.Resolve(secretVal); } } }