internal TemplateLinkPipeline(PipelineContext context, PipelineWriter writer, string basePath, bool skipUnlinked) : base(context, writer) { _BasePath = PSRuleOption.GetRootedBasePath(basePath); _SkipUnlinked = skipUnlinked; _PathBuilder = new PathBuilder(writer, basePath, DEFAULT_TEMPLATESEARCH_PATTERN); }
internal PathBuilder(ILogger logger, string basePath, string searchPattern) { Logger = logger; _Source = new List <FileInfo>(); _BasePath = PSRuleOption.GetRootedBasePath(basePath); _DefaultSearchPattern = searchPattern; }
private bool TryTemplateFile(JObject metadata, string parameterFile, out string templateFile) { if (!TryStringProperty(metadata, PROPERTYNAME_TEMPLATE, out templateFile)) { if (_SkipUnlinked) { Writer.VerboseTemplateLinkNotFound(parameterFile); } return(false); } templateFile = TrimSlash(templateFile); var pathBase = IsRelative(templateFile) ? Path.GetDirectoryName(parameterFile) : PSRuleOption.GetWorkingPath(); templateFile = Path.GetFullPath(Path.Combine(pathBase, templateFile)); // Template file must be within working path if (!templateFile.StartsWith(PSRuleOption.GetRootedBasePath(""), StringComparison.Ordinal)) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, PSRuleResources.PathTraversal, templateFile)); } if (!File.Exists(templateFile)) { Writer.VerboseTemplateFileNotFound(templateFile); throw new FileNotFoundException( string.Format(CultureInfo.CurrentCulture, PSRuleResources.TemplateFileReferenceNotFound, parameterFile), new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, PSRuleResources.TemplateFileNotFound, templateFile)) ); } return(true); }