diff --git a/.gitignore b/.gitignore index 66fd13c9..4f71c0e2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.dll *.so *.dylib +cmd/validator/validator # Test binary, built with `go test -c` *.test diff --git a/README.md b/README.md index 339d602e..9a9aca99 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ How many deployments have you done that needed to be rolled back due to a missin * JSON * YAML * TOML +* INI ## Installing There are several ways to install the config file validator tool diff --git a/cmd/validator/validator.go b/cmd/validator/validator.go index 657886ab..17ba0dd9 100644 --- a/cmd/validator/validator.go +++ b/cmd/validator/validator.go @@ -2,7 +2,7 @@ Validator recusively scans a directory to search for configuration files and validates them using the go package for each configuration type. -Currently json, yaml, toml, and xml configuration file types are supported. +Currently json, yaml, toml, xml and ini configuration file types are supported. Usage: diff --git a/go.mod b/go.mod index 6fa8e7c0..3c1a249b 100644 --- a/go.mod +++ b/go.mod @@ -8,5 +8,6 @@ require ( github.com/mattn/go-isatty v0.0.14 // indirect github.com/pelletier/go-toml/v2 v2.0.6 // indirect golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect + gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 0c916345..657bc82a 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,7 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= +github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= @@ -21,6 +22,8 @@ golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/filetype/file_type.go b/pkg/filetype/file_type.go index e6a61427..649509c7 100644 --- a/pkg/filetype/file_type.go +++ b/pkg/filetype/file_type.go @@ -46,6 +46,14 @@ var TomlFileType = FileType{ validator.TomlValidator{}, } +// Instance of FileType object to +// represent a Ini file +var IniFileType = FileType{ + "ini", + []string{"ini"}, + validator.IniValidator{}, +} + // An array of files types that are supported // by the validator var FileTypes = []FileType{ @@ -53,4 +61,5 @@ var FileTypes = []FileType{ YamlFileType, XmlFileType, TomlFileType, + IniFileType, } diff --git a/pkg/validator/ini.go b/pkg/validator/ini.go new file mode 100644 index 00000000..eeac3d3a --- /dev/null +++ b/pkg/validator/ini.go @@ -0,0 +1,17 @@ +package validator + +import ( + "gopkg.in/ini.v1" +) + +type IniValidator struct{} + +// Validate implements the Validator interface by attempting to +// parse a byte array of ini +func (iv IniValidator) Validate(b []byte) (bool, error) { + _, err := ini.LoadSources(ini.LoadOptions{}, b) + if err != nil { + return false, err + } + return true, nil +} diff --git a/pkg/validator/validator_test.go b/pkg/validator/validator_test.go index 53725d59..29afbdfb 100644 --- a/pkg/validator/validator_test.go +++ b/pkg/validator/validator_test.go @@ -18,6 +18,8 @@ var testData = []struct { {"invalidXml", []byte("