Skip to content

Commit

Permalink
feat(compliance): Support loading spec by filepath (#1078)
Browse files Browse the repository at this point in the history
  • Loading branch information
simar7 authored Nov 23, 2022
1 parent c4d019e commit 8a7f5ca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ vendor/
*.iml
.vscode/
bundle/
bundle.tar.gz
bundle.tar.gz
.DS_Store
10 changes: 9 additions & 1 deletion internal/specs/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"embed"
"fmt"
"io"
"os"
"strings"

"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -49,5 +50,12 @@ func init() {

// GetSpec returns the spec content
func GetSpec(name string) string {
return complianceSpecMap[name]
if spec, ok := complianceSpecMap[name]; ok { // use embedded spec
return spec
}
spec, err := os.ReadFile(strings.TrimPrefix(name, "@")) // use custom spec by filepath
if err != nil {
return ""
}
return string(spec)
}
1 change: 1 addition & 0 deletions internal/specs/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestLoadSpecs(t *testing.T) {
{name: "nsa spec", specName: "nsa", wantSpecPath: "./compliance/nsa-1.0.yaml"},
{name: "awscis1.2", specName: "awscis1.2", wantSpecPath: "./compliance/aws-cis-1.2.yaml"},
{name: "awscis1.4", specName: "awscis1.4", wantSpecPath: "./compliance/aws-cis-1.4.yaml"},
{name: "awscis1.2 by filepath", specName: "@./compliance/aws-cis-1.2.yaml", wantSpecPath: "./compliance/aws-cis-1.2.yaml"},
{name: "bogus spec", specName: "foobarbaz"},
}

Expand Down

0 comments on commit 8a7f5ca

Please sign in to comment.