diff --git a/NOTICE.txt b/NOTICE.txt index 1bee6d854de..09658f3904e 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -1391,8 +1391,8 @@ Apache License 2.0 -------------------------------------------------------------------- Dependency: github.com/elastic/go-ucfg -Version: v0.8.1 -Revision: 093a6898c440d2e5e93abf09850068c60428b2cd +Version: v0.8.2 +Revision: ab69586e10820006b250d04c98cc3b848e227808 License type (autodetected): Apache-2.0 ./vendor/github.com/elastic/go-ucfg/LICENSE: -------------------------------------------------------------------- diff --git a/filebeat/fileset/modules_test.go b/filebeat/fileset/modules_test.go index d82f3361865..c9a346b2fb1 100644 --- a/filebeat/fileset/modules_test.go +++ b/filebeat/fileset/modules_test.go @@ -347,8 +347,8 @@ func TestMcfgFromConfig(t *testing.T) { Filesets: map[string]*FilesetConfig{ "error": { Enabled: &falseVar, - Var: map[string]interface{}{}, - Input: map[string]interface{}{}, + Var: nil, + Input: nil, }, }, }, @@ -366,7 +366,7 @@ func TestMcfgFromConfig(t *testing.T) { Var: map[string]interface{}{ "test": false, }, - Input: map[string]interface{}{}, + Input: nil, }, }, }, diff --git a/metricbeat/mb/lightmodules_test.go b/metricbeat/mb/lightmodules_test.go index e7a933cc47a..fdc55033355 100644 --- a/metricbeat/mb/lightmodules_test.go +++ b/metricbeat/mb/lightmodules_test.go @@ -194,22 +194,22 @@ func TestNewModuleFromConfig(t *testing.T) { "normal module": { config: common.MapStr{"module": "foo", "metricsets": []string{"bar"}}, expectedOption: "default", - expectedQuery: QueryParams{}, + expectedQuery: nil, }, "light module": { config: common.MapStr{"module": "service", "metricsets": []string{"metricset"}}, expectedOption: "test", - expectedQuery: QueryParams{}, + expectedQuery: nil, }, "light module default metricset": { config: common.MapStr{"module": "service"}, expectedOption: "test", - expectedQuery: QueryParams{}, + expectedQuery: nil, }, "light module override option": { config: common.MapStr{"module": "service", "option": "overriden"}, expectedOption: "overriden", - expectedQuery: QueryParams{}, + expectedQuery: nil, }, "light module with query": { config: common.MapStr{"module": "service", "query": common.MapStr{"param": "foo"}}, @@ -220,7 +220,7 @@ func TestNewModuleFromConfig(t *testing.T) { config: common.MapStr{"module": "service", "period": "42s"}, expectedOption: "test", expectedPeriod: 42 * time.Second, - expectedQuery: QueryParams{}, + expectedQuery: nil, }, "light module is broken": { config: common.MapStr{"module": "broken"}, @@ -237,7 +237,7 @@ func TestNewModuleFromConfig(t *testing.T) { "mixed module with standard and light metricsets": { config: common.MapStr{"module": "mixed", "metricsets": []string{"standard", "light"}}, expectedOption: "default", - expectedQuery: QueryParams{}, + expectedQuery: nil, }, "mixed module with unregistered and light metricsets": { config: common.MapStr{"module": "mixedbroken", "metricsets": []string{"unregistered", "light"}}, diff --git a/metricbeat/mb/mb_test.go b/metricbeat/mb/mb_test.go index 3094e1588d6..f93721d8a81 100644 --- a/metricbeat/mb/mb_test.go +++ b/metricbeat/mb/mb_test.go @@ -81,9 +81,9 @@ func TestModuleConfig(t *testing.T) { err string }{ { - name: "missing required field", + name: "string value is not set on required field", in: map[string]interface{}{}, - err: "missing required field accessing 'module'", + err: "string value is not set accessing 'module'", }, { name: "valid config", @@ -97,7 +97,7 @@ func TestModuleConfig(t *testing.T) { Enabled: true, Period: time.Second * 10, Timeout: 0, - Query: QueryParams{}, + Query: nil, }, }, { diff --git a/metricbeat/module/prometheus/collector/_meta/data.json b/metricbeat/module/prometheus/collector/_meta/data.json index da3bc943960..dba9f7771c4 100644 --- a/metricbeat/module/prometheus/collector/_meta/data.json +++ b/metricbeat/module/prometheus/collector/_meta/data.json @@ -23,4 +23,4 @@ "address": "127.0.0.1:55555", "type": "prometheus" } -} +} \ No newline at end of file diff --git a/vendor/github.com/elastic/go-ucfg/CHANGELOG.md b/vendor/github.com/elastic/go-ucfg/CHANGELOG.md index 4349863cb7b..01a9ea1d295 100644 --- a/vendor/github.com/elastic/go-ucfg/CHANGELOG.md +++ b/vendor/github.com/elastic/go-ucfg/CHANGELOG.md @@ -14,6 +14,13 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +## [0.8.2] + +### Fixed +- Fixed nonzero validator to not fail on nil array or slice. #147 +- Fixed nonzero validator to validate maps. +- Fixed required validator to validate maps. + ## [0.8.1] ### Fixed @@ -256,7 +263,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Introduced CHANGELOG.md for documenting changes to ucfg. -[Unreleased]: https://github.com/elastic/go-ucfg/compare/v0.8.1...HEAD +[Unreleased]: https://github.com/elastic/go-ucfg/compare/v0.8.2...HEAD +[0.8.2]: https://github.com/elastic/go-ucfg/compare/v0.8.1...v0.8.2 [0.8.1]: https://github.com/elastic/go-ucfg/compare/v0.8.0...v0.8.1 [0.8.0]: https://github.com/elastic/go-ucfg/compare/v0.7.0...v0.8.0 [0.7.0]: https://github.com/elastic/go-ucfg/compare/v0.6.5...v0.7.0 diff --git a/vendor/github.com/elastic/go-ucfg/error.go b/vendor/github.com/elastic/go-ucfg/error.go index a48690e30a8..d944bac66d9 100644 --- a/vendor/github.com/elastic/go-ucfg/error.go +++ b/vendor/github.com/elastic/go-ucfg/error.go @@ -98,6 +98,14 @@ var ( ErrRequired = errors.New("missing required field") ErrEmpty = errors.New("empty field") + + ErrArrayEmpty = errors.New("empty array") + + ErrMapEmpty = errors.New("empty map") + + ErrRegexEmpty = errors.New("regex value is not set") + + ErrStringEmpty = errors.New("string value is not set") ) // Error Classes diff --git a/vendor/github.com/elastic/go-ucfg/reify.go b/vendor/github.com/elastic/go-ucfg/reify.go index ad14f95baf7..11dea0a53ad 100644 --- a/vendor/github.com/elastic/go-ucfg/reify.go +++ b/vendor/github.com/elastic/go-ucfg/reify.go @@ -167,7 +167,7 @@ func reifyInto(opts *options, to reflect.Value, from *Config) Error { switch k { case reflect.Map: - return reifyMap(opts, to, from) + return reifyMap(opts, to, from, nil) case reflect.Struct: return reifyStruct(opts, to, from) case reflect.Slice, reflect.Array: @@ -183,7 +183,7 @@ func reifyInto(opts *options, to reflect.Value, from *Config) Error { return raiseInvalidTopLevelType(to.Interface(), opts.meta) } -func reifyMap(opts *options, to reflect.Value, from *Config) Error { +func reifyMap(opts *options, to reflect.Value, from *Config, validators []validatorTag) Error { parentFields := opts.activeFields defer func() { opts.activeFields = parentFields }() @@ -198,7 +198,7 @@ func reifyMap(opts *options, to reflect.Value, from *Config) Error { fields := from.fields.dict() if len(fields) == 0 { - if err := tryRecursiveValidate(to, opts, nil); err != nil { + if err := tryRecursiveValidate(to, opts, validators); err != nil { return raiseValidation(from.ctx, from.metadata, "", err) } return nil @@ -224,6 +224,9 @@ func reifyMap(opts *options, to reflect.Value, from *Config) Error { to.SetMapIndex(key, v) } + if err := runValidators(to.Interface(), validators); err != nil { + return raiseValidation(from.ctx, from.metadata, "", err) + } if err := tryValidate(to); err != nil { return raiseValidation(from.ctx, from.metadata, "", err) } @@ -321,7 +324,7 @@ func reifyGetField( } // Primitive types return early when it doesn't implement the Initializer interface. - if fieldType.Kind() != reflect.Map && fieldType.Kind() != reflect.Struct && !hasInitDefaults(fieldType) { + if fieldType.Kind() != reflect.Struct && !hasInitDefaults(fieldType) { if err := tryRecursiveValidate(to, opts.opts, opts.validators); err != nil { return raiseValidation(cfg.ctx, cfg.metadata, name, err) } @@ -479,7 +482,7 @@ func reifyMergeValue( if err != nil { return reflect.Value{}, raiseExpectedObject(opts.opts, val) } - return old, reifyMap(opts.opts, old, sub) + return old, reifyMap(opts.opts, old, sub, opts.validators) case reflect.Struct: sub, err := val.toConfig(opts.opts) diff --git a/vendor/github.com/elastic/go-ucfg/validator.go b/vendor/github.com/elastic/go-ucfg/validator.go index b56e8835dfd..8a72abf3b33 100644 --- a/vendor/github.com/elastic/go-ucfg/validator.go +++ b/vendor/github.com/elastic/go-ucfg/validator.go @@ -392,31 +392,53 @@ func validateRequired(v interface{}, name string) error { } return nil } - if err := validateNonEmpty(v, name); err != nil { - return ErrRequired + if err := validateNonEmptyWithAllowNil(v, name, false); err != nil { + return err } return nil } -func validateNonEmpty(v interface{}, _ string) error { +func validateNonEmpty(v interface{}, name string) error { + return validateNonEmptyWithAllowNil(v, name, true) +} + +func validateNonEmptyWithAllowNil(v interface{}, _ string, allowNil bool) error { if s, ok := v.(string); ok { if s == "" { - return ErrEmpty + return ErrStringEmpty } return nil } if r, ok := v.(regexp.Regexp); ok { if r.String() == "" { - return ErrEmpty + return ErrRegexEmpty } return nil } val := reflect.ValueOf(v) if val.Kind() == reflect.Array || val.Kind() == reflect.Slice { + if val.IsNil() { + if allowNil { + return nil + } + return ErrRequired + } + if val.Len() == 0 { + return ErrArrayEmpty + } + return nil + } + if val.Kind() == reflect.Map { + if val.IsNil() { + if allowNil { + return nil + } + return ErrRequired + } if val.Len() == 0 { - return ErrEmpty + return ErrMapEmpty } return nil } diff --git a/vendor/vendor.json b/vendor/vendor.json index 4b29c2259eb..35cce37fe27 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -3268,76 +3268,76 @@ "versionExact": "v0.0.7" }, { - "checksumSHA1": "a1x0prr3ix+QFOdJpNfM3Q4G6Es=", + "checksumSHA1": "VPcK6uPDligSrbdi1yVeGivPvno=", "path": "github.com/elastic/go-ucfg", - "revision": "093a6898c440d2e5e93abf09850068c60428b2cd", - "revisionTime": "2020-01-31T13:55:22Z", - "version": "v0.8.1", - "versionExact": "v0.8.1" + "revision": "ab69586e10820006b250d04c98cc3b848e227808", + "revisionTime": "2020-02-07T21:56:35Z", + "version": "v0.8.2", + "versionExact": "v0.8.2" }, { "checksumSHA1": "X+R/CD8SokJrmlxFTx2nSevRDhQ=", "path": "github.com/elastic/go-ucfg/cfgutil", - "revision": "093a6898c440d2e5e93abf09850068c60428b2cd", - "revisionTime": "2020-01-31T13:55:22Z", - "version": "v0.8.1", - "versionExact": "v0.8.1" + "revision": "ab69586e10820006b250d04c98cc3b848e227808", + "revisionTime": "2020-02-07T21:56:35Z", + "version": "v0.8.2", + "versionExact": "v0.8.2" }, { "checksumSHA1": "B58nBBiUIstpkXfr9yaYN9GzdLE=", "path": "github.com/elastic/go-ucfg/diff", - "revision": "093a6898c440d2e5e93abf09850068c60428b2cd", - "revisionTime": "2020-01-31T13:55:22Z", - "version": "v0.8.1", - "versionExact": "v0.8.1" + "revision": "ab69586e10820006b250d04c98cc3b848e227808", + "revisionTime": "2020-02-07T21:56:35Z", + "version": "v0.8.2", + "versionExact": "v0.8.2" }, { "checksumSHA1": "E6k6DWkpI+LOKDIFRqRmNH9GORc=", "path": "github.com/elastic/go-ucfg/flag", - "revision": "093a6898c440d2e5e93abf09850068c60428b2cd", - "revisionTime": "2020-01-31T13:55:22Z", - "version": "v0.8.1", - "versionExact": "v0.8.1" + "revision": "ab69586e10820006b250d04c98cc3b848e227808", + "revisionTime": "2020-02-07T21:56:35Z", + "version": "v0.8.2", + "versionExact": "v0.8.2" }, { "checksumSHA1": "NhiQQjYMs/ViCbmEq9tll2uCaYo=", "path": "github.com/elastic/go-ucfg/hjson", - "revision": "093a6898c440d2e5e93abf09850068c60428b2cd", - "revisionTime": "2020-01-31T13:55:22Z", - "version": "v0.8.1", - "versionExact": "v0.8.1" + "revision": "ab69586e10820006b250d04c98cc3b848e227808", + "revisionTime": "2020-02-07T21:56:35Z", + "version": "v0.8.2", + "versionExact": "v0.8.2" }, { "checksumSHA1": "esXpiQlEvTOUwsE0nNesso8albo=", "path": "github.com/elastic/go-ucfg/internal/parse", "revision": "0539807037ce820e147797f051ff32b05f4f9288", "revisionTime": "2019-01-28T11:18:48Z", - "version": "v0.8.1", - "versionExact": "v0.8.1" + "version": "v0.8.2", + "versionExact": "v0.8.2" }, { "checksumSHA1": "cfMNsyQm0gZOV0hRJrBSdKDQSBo=", "path": "github.com/elastic/go-ucfg/json", - "revision": "093a6898c440d2e5e93abf09850068c60428b2cd", - "revisionTime": "2020-01-31T13:55:22Z", - "version": "v0.8.1", - "versionExact": "v0.8.1" + "revision": "ab69586e10820006b250d04c98cc3b848e227808", + "revisionTime": "2020-02-07T21:56:35Z", + "version": "v0.8.2", + "versionExact": "v0.8.2" }, { "checksumSHA1": "ZISq+zzSb0OLzvwLlf1ObdgnFmM=", "path": "github.com/elastic/go-ucfg/parse", - "revision": "093a6898c440d2e5e93abf09850068c60428b2cd", - "revisionTime": "2020-01-31T13:55:22Z", - "version": "v0.8.1", - "versionExact": "v0.8.1" + "revision": "ab69586e10820006b250d04c98cc3b848e227808", + "revisionTime": "2020-02-07T21:56:35Z", + "version": "v0.8.2", + "versionExact": "v0.8.2" }, { "checksumSHA1": "cnJVnptTvXNLzxVhd266k19/pQg=", "path": "github.com/elastic/go-ucfg/yaml", - "revision": "093a6898c440d2e5e93abf09850068c60428b2cd", - "revisionTime": "2020-01-31T13:55:22Z", - "version": "v0.8.1", - "versionExact": "v0.8.1" + "revision": "ab69586e10820006b250d04c98cc3b848e227808", + "revisionTime": "2020-02-07T21:56:35Z", + "version": "v0.8.2", + "versionExact": "v0.8.2" }, { "checksumSHA1": "iI1JCWsrAPpoKcEo/i6G3lRLIVs=",