func main() { flag.Usage = func() { fmt.Fprintln(os.Stderr, `usage: check-certs ([-err DAYS] [-warn DAYS] | -verify [-ca "GLOB"]) "<GLOBS...>" -err DAYS Number of days before expiry to generate an ERROR message -warn DAYS Number of days before expiry to generate an WARNING message -verify Verify certificate chain -ca GLOB Trusted root certificates `) os.Exit(2) } flag.Parse() if flag.NArg() < 1 { util.Usage() } var bundles []string for _, arg := range flag.Args() { if b, err := doublestar.Glob(arg); err != nil { logrus.Fatal(err) } else { bundles = append(bundles, b...) } } var files = util.Files(bundles) if len(files) == 0 { os.Exit(1) } if *verify { pool := x509.NewCertPool() if *caGlob != "" { cas, err := doublestar.Glob(*caGlob) if err != nil { logrus.Fatal(err) } for _, bundle := range util.Files(cas) { if data, err := ioutil.ReadFile(bundle); err != nil { logrus.Fatal(err) } else { pool.AppendCertsFromPEM(data) } } } Run(files, ChainProcessor{pool}) } else { Run(files, DayProcessor{}) } }
func Match(pattern string, filenames []string) []string { var matched []string globbed, _ := doublestar.Glob(pattern) for _, filename := range filenames { if contains(filename, globbed) { matched = append(matched, filename) } } return matched }
func New(globs ...string) *layout { var paths []string for _, glob := range globs { matches, _ := doublestar.Glob(glob) paths = append(paths, matches...) } return &layout{ layoutKey: "Layout", contentKey: "Content", paths: paths, helpers: nil, } }
func (w *Watcher) watchGlob(glob string) error { ms, err := doublestar.Glob(glob) if err != nil { return err } for _, f := range ms { err := w.watcher.Watch(f) if err != nil { return err } logger.Println("Watching ", f, " ...") } return nil }
func (c genericCpCopier) FilteredCopyToTemp(dir string, filters []string) (string, error) { var filtersFilesToCopy []string var err error filters = c.convertDirectoriesToGlobs(dir, filters) filesToCopy := []string{} for _, filterPath := range filters { filtersFilesToCopy, err = doublestar.Glob(filterPath) if err != nil { return "", bosherr.WrapError(err, "Finding files matching filters") } for _, fileToCopy := range filtersFilesToCopy { filesToCopy = append(filesToCopy, strings.TrimPrefix(strings.TrimPrefix(fileToCopy, dir), "/")) } } return c.tryInTempDir(func(tempDir string) error { for _, relativePath := range filesToCopy { src := filepath.Join(dir, relativePath) dst := filepath.Join(tempDir, relativePath) fileInfo, err := os.Stat(src) if err != nil { return bosherr.WrapErrorf(err, "Getting file info for '%s'", src) } if !fileInfo.IsDir() { err = c.cp(src, dst, tempDir) if err != nil { c.CleanUp(tempDir) return err } } } err = os.Chmod(tempDir, os.FileMode(0755)) if err != nil { bosherr.WrapError(err, "Fixing permissions on temp dir") } return nil }) }
func (fs *osFileSystem) RecursiveGlob(pattern string) (matches []string, err error) { fs.logger.Debug(fs.logTag, "RecursiveGlob '%s'", pattern) return doublestar.Glob(pattern) }