mirror of
https://github.com/strongdm/comply
synced 2025-12-06 14:24:12 +00:00
Initial commit
This commit is contained in:
4
internal/path/doc.go
Normal file
4
internal/path/doc.go
Normal file
@@ -0,0 +1,4 @@
|
||||
/*
|
||||
Package path provides convenient access to comply project path conventions.
|
||||
*/
|
||||
package path
|
||||
55
internal/path/path.go
Normal file
55
internal/path/path.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package path
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// File wraps an os.FileInfo as well as the absolute path to the underlying file.
|
||||
type File struct {
|
||||
FullPath string
|
||||
Info os.FileInfo
|
||||
}
|
||||
|
||||
// Standards lists all standard files.
|
||||
func Standards() ([]File, error) {
|
||||
return filesFor("standards", "yml")
|
||||
}
|
||||
|
||||
// Narratives lists all narrative files.
|
||||
func Narratives() ([]File, error) {
|
||||
return filesFor("narratives", "md")
|
||||
}
|
||||
|
||||
// Policies lists all policy files.
|
||||
func Policies() ([]File, error) {
|
||||
return filesFor("policies", "md")
|
||||
}
|
||||
|
||||
// Procedures lists all procedure files.
|
||||
func Procedures() ([]File, error) {
|
||||
return filesFor("procedures", "md")
|
||||
}
|
||||
|
||||
func filesFor(name, extension string) ([]File, error) {
|
||||
var filtered []File
|
||||
files, err := ioutil.ReadDir(filepath.Join(".", name))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unable to load files for: "+name)
|
||||
}
|
||||
for _, f := range files {
|
||||
if !strings.HasSuffix(f.Name(), "."+extension) || strings.HasPrefix(strings.ToUpper(f.Name()), "README") {
|
||||
continue
|
||||
}
|
||||
abs, err := filepath.Abs(filepath.Join(".", name, f.Name()))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unable to load file: "+f.Name())
|
||||
}
|
||||
filtered = append(filtered, File{abs, f})
|
||||
}
|
||||
return filtered, nil
|
||||
}
|
||||
Reference in New Issue
Block a user