Skip to content

Commit

Permalink
Limiting centry manifest file extensions to yaml and yml.
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofferahl committed Oct 10, 2021
1 parent 61b11f4 commit bece583
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions internal/pkg/config/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/ghodss/yaml"
"github.com/kristofferahl/go-centry/internal/pkg/cmd"
Expand Down Expand Up @@ -78,6 +79,10 @@ type LogConfig struct {

// LoadManifest reads, parses and returns a manifest root object
func LoadManifest(manifest string) (*Manifest, error) {
if !strings.HasSuffix(manifest, ".yaml") && !strings.HasSuffix(manifest, ".yml") {
return nil, fmt.Errorf("manifest file must have a valid extension (yaml,yml)")
}

mp, _ := filepath.Abs(manifest)

if _, err := os.Stat(mp); os.IsNotExist(err) {
Expand Down
11 changes: 9 additions & 2 deletions internal/pkg/config/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@ func TestManifest(t *testing.T) {
})

g.It("returns error when path is invalid", func() {
m, err := LoadManifest("foo")
m, err := LoadManifest("foo.yaml")
g.Assert(m == nil).IsTrue("exected manifest to be nil")
g.Assert(err != nil).IsTrue("expected error")
g.Assert(err.Error()).Equal("manifest file not found (path=foo)")
g.Assert(err.Error()).Equal("manifest file not found (path=foo.yaml)")
})

g.It("returns error when path is not a yaml or yml file", func() {
m, err := LoadManifest("foo.bar")
g.Assert(m == nil).IsTrue("exected manifest to be nil")
g.Assert(err != nil).IsTrue("expected error")
g.Assert(err.Error()).Equal("manifest file must have a valid extension (yaml,yml)")
})
})

Expand Down

0 comments on commit bece583

Please sign in to comment.