コード例 #1
0
 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);
 }
コード例 #2
0
 internal PathBuilder(ILogger logger, string basePath, string searchPattern)
 {
     Logger                = logger;
     _Source               = new List <FileInfo>();
     _BasePath             = PSRuleOption.GetRootedBasePath(basePath);
     _DefaultSearchPattern = searchPattern;
 }
コード例 #3
0
        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);
        }