private void ExpandArmTemplateImpl(ArmTemplate armTemplate, HashSet <string> uniqueArmTemplateFullPaths) { armTemplate .ExpandedContent .SelectTokens("$..templateLink") .ToList() .ForEach(t => { var templateFilePath = ((string)((dynamic)t).uri).Replace("file://", "").Replace("/", "\\"); string templateFullPath = GetFullPath(fileSystem.Path.GetDirectoryName(armTemplate.FilePath), templateFilePath); if (string.Equals(armTemplate.FilePath, templateFullPath, StringComparison.InvariantCultureIgnoreCase)) { throw new SelfReferenceException("This template contains a link to self which will cause a neverending expansion loop."); } if (uniqueArmTemplateFullPaths.Contains(templateFullPath)) { throw new ReferenceLoopException($"This template contains a link to one of its parents. File: {templateFullPath}"); } uniqueArmTemplateFullPaths.Add(templateFullPath); var nestedTemplate = LoadArmTemplate(templateFullPath); ExpandArmTemplateImpl(nestedTemplate, uniqueArmTemplateFullPaths); t.Parent.Parent["template"] = nestedTemplate.ExpandedContent; ((JObject)t.Parent.Parent).Property("templateLink").Remove(); }); }
public string SaveExpandedTemplate(ArmTemplate armTemplate, string outputFilePath) { var acctualOutputFilePath = string.IsNullOrWhiteSpace(outputFilePath) ? fileSystem.Path.ChangeExtension(armTemplate.FilePath, "expanded.json") : outputFilePath; fileSystem.File.WriteAllText(acctualOutputFilePath, armTemplate.ExpandedContent.ToString()); return(acctualOutputFilePath); }
public string SaveExpandedTemplate(ArmTemplate armTemplate) { return(SaveExpandedTemplate(armTemplate, null)); }
public void ExpandArmTemplate(ArmTemplate armTemplate) { HashSet <string> uniqueArmTemplateFullPaths = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase); ExpandArmTemplateImpl(armTemplate, uniqueArmTemplateFullPaths); }