Skip to content

Commit

Permalink
Update go-ucfg (#3045)
Browse files Browse the repository at this point in the history
- Update go-ucfg
- add support for parsing lists/dictionaries from environment variables and via
  `-E` flag
  • Loading branch information
Steffen Siering authored and ruflin committed Nov 29, 2016
1 parent 4fce107 commit c963ba0
Show file tree
Hide file tree
Showing 24 changed files with 1,065 additions and 258 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ https://github.com/elastic/beats/compare/v5.0.1...master[Check the HEAD diff]
*Affecting all Beats*
- Add add_cloud_metadata processor for collecting cloud provider metadata. {pull}2728[2728]
- Added decode_json_fields processor for decoding fields containing JSON strings. {pull}2605[2605]
- Add support for passing list and dictionary settings via -E flag.
- Support for parsing list and dictionary setting from environment variables.

*Metricbeat*

Expand Down
2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import:
- package: github.com/dustin/go-humanize
version: 499693e27ee0d14ffab67c31ad065fdb3d34ea75
- package: github.com/elastic/go-ucfg
version: v0.3.7
version: v0.4.2
- package: github.com/armon/go-socks5
version: 3a873e99f5400ad7706e464e905ffcc94b3ff247
- package: github.com/pkg/errors
Expand Down
12 changes: 2 additions & 10 deletions heartbeat/monitors/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,22 +281,14 @@ func (f funcTask) annotated(start time.Time, typ string) TaskRunner {
return annotated(start, typ, f.run)
}

func (p *PingMode) Unpack(v interface{}) error {
var fail = errors.New("expecting 'any' or 'all'")
s, ok := v.(string)
if !ok {
return fail
}

func (p *PingMode) Unpack(s string) error {
switch s {
case "all":
*p = PingAll
case "any":
*p = PingAny
default:
return fail
}
return nil
return errors.New("expecting 'any' or 'all'")
}

func annotated(start time.Time, typ string, fn func() (common.MapStr, []TaskRunner, error)) TaskRunner {
Expand Down
16 changes: 4 additions & 12 deletions heartbeat/scheduler/schedule/cron/cron.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cron

import (
"errors"
"time"

"github.com/gorhill/cronexpr"
Expand All @@ -27,17 +26,10 @@ func (s *Schedule) Next(t time.Time) time.Time {
return expr.Next(t)
}

func (s *Schedule) Unpack(in interface{}) error {
str, ok := in.(string)
if !ok {
return errors.New("scheduler string required")
}

func (s *Schedule) Unpack(str string) error {
tmp, err := Parse(str)
if err != nil {
return err
if err == nil {
*s = *tmp
}

*s = *tmp
return nil
return err
}
16 changes: 4 additions & 12 deletions heartbeat/scheduler/schedule/schedule.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package schedule

import (
"errors"
"strings"
"time"

Expand Down Expand Up @@ -43,17 +42,10 @@ func (s intervalScheduler) Next(t time.Time) time.Time {
return t.Add(s.interval)
}

func (s *Schedule) Unpack(in interface{}) error {
str, ok := in.(string)
if !ok {
return errors.New("scheduler string required")
}

func (s *Schedule) Unpack(str string) error {
tmp, err := Parse(str)
if err != nil {
return err
if err == nil {
*s = *tmp
}

*s = *tmp
return nil
return err
}
76 changes: 39 additions & 37 deletions libbeat/outputs/outil/select_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package outil

import (
"strings"
"testing"

"github.com/elastic/beats/libbeat/common"
Expand Down Expand Up @@ -49,24 +50,24 @@ func TestSelector(t *testing.T) {
{
"missing format string key with default in rule",
`keys:
- key: '%{[key]}'
default: value`,
- key: '%{[key]}'
default: value`,
common.MapStr{},
"value",
},
{
"empty format string key with default in rule",
`keys:
- key: '%{[key]}'
default: value`,
- key: '%{[key]}'
default: value`,
common.MapStr{"key": ""},
"value",
},
{
"missing format string key with constant in next rule",
`keys:
- key: '%{[key]}'
- key: value`,
- key: '%{[key]}'
- key: value`,
common.MapStr{},
"value",
},
Expand All @@ -79,83 +80,83 @@ func TestSelector(t *testing.T) {
{
"apply mapping",
`keys:
- key: '%{[key]}'
mappings:
v: value`,
- key: '%{[key]}'
mappings:
v: value`,
common.MapStr{"key": "v"},
"value",
},
{
"apply mapping with default on empty key",
`keys:
- key: '%{[key]}'
default: value
mappings:
v: 'v'`,
- key: '%{[key]}'
default: value
mappings:
v: 'v'`,
common.MapStr{"key": ""},
"value",
},
{
"apply mapping with default on empty lookup",
`keys:
- key: '%{[key]}'
default: value
mappings:
v: ''`,
- key: '%{[key]}'
default: value
mappings:
v: ''`,
common.MapStr{"key": "v"},
"value",
},
{
"apply mapping without match",
`keys:
- key: '%{[key]}'
mappings:
v: ''
- key: value`,
- key: '%{[key]}'
mappings:
v: ''
- key: value`,
common.MapStr{"key": "x"},
"value",
},
{
"mapping with constant key",
`keys:
- key: k
mappings:
k: value`,
- key: k
mappings:
k: value`,
common.MapStr{},
"value",
},
{
"mapping with missing constant key",
`keys:
- key: unknown
mappings: {k: wrong}
- key: value`,
- key: unknown
mappings: {k: wrong}
- key: value`,
common.MapStr{},
"value",
},
{
"mapping with missing constant key, but default",
`keys:
- key: unknown
default: value
mappings: {k: wrong}`,
- key: unknown
default: value
mappings: {k: wrong}`,
common.MapStr{},
"value",
},
{
"matching condition",
`keys:
- key: value
when.equals.test: test`,
- key: value
when.equals.test: test`,
common.MapStr{"test": "test"},
"value",
},
{
"failing condition",
`keys:
- key: wrong
when.equals.test: test
- key: value`,
- key: wrong
when.equals.test: test
- key: value`,
common.MapStr{"test": "x"},
"value",
},
Expand All @@ -164,9 +165,10 @@ func TestSelector(t *testing.T) {
for i, test := range tests {
t.Logf("run (%v): %v", i, test.title)

cfg, err := common.NewConfigWithYAML([]byte(test.config), "test")
yaml := strings.Replace(test.config, "\t", " ", -1)
cfg, err := common.NewConfigWithYAML([]byte(yaml), "test")
if err != nil {
t.Error(err)
t.Errorf("YAML parse error: %v\n%v", err, yaml)
continue
}

Expand Down
15 changes: 2 additions & 13 deletions libbeat/outputs/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,7 @@ func loadCertificateAuthorities(CAs []string) (*x509.CertPool, []error) {
return roots, errors
}

func (cs *tlsCipherSuite) Unpack(in interface{}) error {
s, ok := in.(string)
if !ok {
return fmt.Errorf("tls cipher suite must be an identifier")
}

func (cs *tlsCipherSuite) Unpack(s string) error {
suite, found := tlsCipherSuites[s]
if !found {
return fmt.Errorf("invalid tls cipher suite '%v'", s)
Expand All @@ -284,18 +279,12 @@ func (cs *tlsCipherSuite) Unpack(in interface{}) error {
return nil
}

func (ct *tlsCurveType) Unpack(in interface{}) error {
s, ok := in.(string)
if !ok {
return fmt.Errorf("tls curve type must be an identifier")
}

func (ct *tlsCurveType) Unpack(s string) error {
t, found := tlsCurveTypes[s]
if !found {
return fmt.Errorf("invalid tls curve type '%v'", s)
}

*ct = t
return nil

}
7 changes: 1 addition & 6 deletions libbeat/outputs/transport/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,7 @@ func (v TLSVersion) String() string {
return "unknown"
}

func (v *TLSVersion) Unpack(in interface{}) error {
s, ok := in.(string)
if !ok {
return fmt.Errorf("tls version must be an identifier")
}

func (v *TLSVersion) Unpack(s string) error {
version, found := tlsProtocolVersions[s]
if !found {
return fmt.Errorf("invalid tls version '%v'", s)
Expand Down
18 changes: 6 additions & 12 deletions packetbeat/protos/cassandra/internal/gocql/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
"time"

"errors"
"strings"

"github.com/elastic/beats/libbeat/logp"
"gopkg.in/inf.v0"
"strings"
)

// TypeInfo describes a Cassandra specific data type.
Expand Down Expand Up @@ -530,19 +531,12 @@ func FrameOpFromString(s string) (FrameOp, error) {
return op, nil
}

func (f *FrameOp) Unpack(in interface{}) error {
s, ok := in.(string)
if !ok {
return errors.New("expected string")
}

func (f *FrameOp) Unpack(s string) error {
op, err := FrameOpFromString(s)
if err != nil {
return err
if err == nil {
*f = op
}

*f = op
return nil
return err
}

const (
Expand Down
27 changes: 26 additions & 1 deletion vendor/github.com/elastic/go-ucfg/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c963ba0

Please sign in to comment.