diff --git a/dsl/matcher.go b/dsl/matcher.go index 160a25651..d63a5e5c0 100644 --- a/dsl/matcher.go +++ b/dsl/matcher.go @@ -3,8 +3,45 @@ package dsl import ( "encoding/json" "log" + "time" ) +// Matcher regexes +const ( + hexadecimal = `[0-9a-fA-F]+` + ipAddress = `(\d{1,3}\.)+\d{1,3}` + ipv6Address = `(\A([0-9a-f]{1,4}:){1,1}(:[0-9a-f]{1,4}){1,6}\Z)|(\A([0-9a-f]{1,4}:){1,2}(:[0-9a-f]{1,4}){1,5}\Z)|(\A([0-9a-f]{1,4}:){1,3}(:[0-9a-f]{1,4}){1,4}\Z)|(\A([0-9a-f]{1,4}:){1,4}(:[0-9a-f]{1,4}){1,3}\Z)|(\A([0-9a-f]{1,4}:){1,5}(:[0-9a-f]{1,4}){1,2}\Z)|(\A([0-9a-f]{1,4}:){1,6}(:[0-9a-f]{1,4}){1,1}\Z)|(\A(([0-9a-f]{1,4}:){1,7}|:):\Z)|(\A:(:[0-9a-f]{1,4}){1,7}\Z)|(\A((([0-9a-f]{1,4}:){6})(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})\Z)|(\A(([0-9a-f]{1,4}:){5}[0-9a-f]{1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})\Z)|(\A([0-9a-f]{1,4}:){5}:[0-9a-f]{1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|(\A([0-9a-f]{1,4}:){1,1}(:[0-9a-f]{1,4}){1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|(\A([0-9a-f]{1,4}:){1,2}(:[0-9a-f]{1,4}){1,3}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|(\A([0-9a-f]{1,4}:){1,3}(:[0-9a-f]{1,4}){1,2}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|(\A([0-9a-f]{1,4}:){1,4}(:[0-9a-f]{1,4}){1,1}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|(\A(([0-9a-f]{1,4}:){1,5}|:):(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|(\A:(:[0-9a-f]{1,4}){1,5}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)` + uuid = `[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}` + timestamp = `^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$` + date = `^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))?)` + timeRegex = `^(T\d\d:\d\d(:\d\d)?(\.\d+)?(([+-]\d\d:\d\d)|Z)?)?$` +) + +var timeExample = time.Date(2000, 2, 1, 12, 30, 0, 0, time.UTC) + +type eachLike struct { + Type string `json:"json_class"` + Contents interface{} `json:"contents"` + Min int `json:"min"` +} + +type like struct { + Type string `json:"json_class"` + Contents interface{} `json:"contents"` +} + +type term struct { + Type string `json:"json_class"` + Data struct { + Generate interface{} `json:"generate"` + Matcher struct { + Type string `json:"json_class"` + O int `json:"o"` + Regex interface{} `json:"s"` + } `json:"matcher"` + } `json:"data"` +} + // EachLike specifies that a given element in a JSON body can be repeated // "minRequired" times. Number needs to be 1 or greater func EachLike(content interface{}, minRequired int) Matcher { @@ -40,6 +77,60 @@ func Term(generate string, matcher string) Matcher { } } +// HexValue defines a matcher that accepts hexidecimal values. +func HexValue() Matcher { + return Regex("3F", hexadecimal) +} + +// Identifier defines a matcher that accepts integer values. +func Identifier() Matcher { + return Like(42) +} + +// Integer defines a matcher that accepts ints. Identical to Identifier. +var Integer = Identifier + +// IPAddress defines a matcher that accepts valid IPv4 addresses. +func IPAddress() Matcher { + return Regex("127.0.0.1", ipAddress) +} + +// IPv4Address matches valid IPv4 addresses. +var IPv4Address = IPAddress + +// IPv6Address defines a matcher that accepts IP addresses. +func IPv6Address() Matcher { + return Regex("::ffff:192.0.2.128", ipAddress) +} + +// Decimal defines a matcher that accepts any decimal value. +func Decimal() Matcher { + return Like(42.0) +} + +// Timestamp matches a pattern corresponding to the ISO_DATETIME_FORMAT, which +// is "yyyy-MM-dd'T'HH:mm:ss". The current date and time is used as the eaxmple. +func Timestamp() Matcher { + return Regex(timeExample.Format(time.RFC3339), timestamp) +} + +// Date matches a pattern corresponding to the ISO_DATE_FORMAT, which +// is "yyyy-MM-dd". The current date is used as the eaxmple. +func Date() Matcher { + return Regex(timeExample.Format("2006-01-02"), date) +} + +// Time matches a pattern corresponding to the ISO_DATE_FORMAT, which +// is "'T'HH:mm:ss". The current tem is used as the eaxmple. +func Time() Matcher { + return Regex(timeExample.Format("T15:04:05"), timeRegex) +} + +// UUID defines a matcher that accepts UUIDs. Produces a v4 UUID as the example. +func UUID() Matcher { + return Regex("fc763eba-0905-41c5-a27f-3934ab26786c", uuid) +} + // Regex is a more appropriately named alias for the "Term" matcher var Regex = Term diff --git a/dsl/matcher_test.go b/dsl/matcher_test.go index 02dbe06af..435bafea1 100644 --- a/dsl/matcher_test.go +++ b/dsl/matcher_test.go @@ -5,6 +5,8 @@ import ( "encoding/json" "fmt" "log" + "reflect" + "regexp" "testing" ) @@ -331,8 +333,6 @@ func formatJSON(object interface{}) interface{} { switch content := object.(type) { case string: json.Indent(&out, []byte(content), "", "\t") - // case StringMatcher: - // json.Indent(&out, []byte(content), "", "\t") default: jsonString, err := json.Marshal(object) if err != nil { @@ -344,6 +344,151 @@ func formatJSON(object interface{}) interface{} { return string(out.Bytes()) } +// Instrument the Matcher type to be able to assert the +// values and regexs contained within! +func (m Matcher) getValue() interface{} { + mString := objectToString(m) + + // try like + likeValue := &like{} + err := json.Unmarshal([]byte(mString), likeValue) + if err == nil && likeValue.Contents != nil { + return likeValue.Contents + } + + // try term + termValue := &term{} + err = json.Unmarshal([]byte(mString), termValue) + if err == nil && termValue != nil { + return termValue.Data.Generate + } + + return "no value found" +} + +func TestMatcher_SugarMatchers(t *testing.T) { + + type matcherTestCase struct { + matcher Matcher + testCase func(val interface{}) error + } + matchers := map[string]matcherTestCase{ + "HexValue": matcherTestCase{ + matcher: HexValue(), + testCase: func(v interface{}) (err error) { + if v.(string) != "3F" { + err = fmt.Errorf("want '3F', got '%v'", reflect.TypeOf(v)) + } + return + }, + }, + "Identifier": matcherTestCase{ + matcher: Identifier(), + testCase: func(v interface{}) (err error) { + _, valid := v.(float64) // JSON converts numbers to float64 in anonymous structs + if !valid { + err = fmt.Errorf("want int, got '%v'", reflect.TypeOf(v)) + } + return + }, + }, + "Integer": matcherTestCase{ + matcher: Integer(), + testCase: func(v interface{}) (err error) { + _, valid := v.(float64) // JSON converts numbers to float64 in anonymous structs + if !valid { + err = fmt.Errorf("want int, got '%v'", reflect.TypeOf(v)) + } + return + }, + }, + "IPAddress": matcherTestCase{ + matcher: IPAddress(), + testCase: func(v interface{}) (err error) { + if v.(string) != "127.0.0.1" { + err = fmt.Errorf("want '127.0.0.1', got '%v'", reflect.TypeOf(v)) + } + return + }, + }, + "IPv4Address": matcherTestCase{ + matcher: IPv4Address(), + testCase: func(v interface{}) (err error) { + if v.(string) != "127.0.0.1" { + err = fmt.Errorf("want '127.0.0.1', got '%v'", reflect.TypeOf(v)) + } + return + }, + }, + "IPv6Address": matcherTestCase{ + matcher: IPv6Address(), + testCase: func(v interface{}) (err error) { + if v.(string) != "::ffff:192.0.2.128" { + err = fmt.Errorf("want '::ffff:192.0.2.128', got '%v'", reflect.TypeOf(v)) + } + return + }, + }, + "Decimal": matcherTestCase{ + matcher: Decimal(), + testCase: func(v interface{}) (err error) { + _, valid := v.(float64) + if !valid { + err = fmt.Errorf("want float64, got '%v'", reflect.TypeOf(v)) + } + return + }, + }, + "Timestamp": matcherTestCase{ + matcher: Timestamp(), + testCase: func(v interface{}) (err error) { + _, valid := v.(string) + if !valid { + err = fmt.Errorf("want string, got '%v'", reflect.TypeOf(v)) + } + return + }, + }, + "Date": matcherTestCase{ + matcher: Date(), + testCase: func(v interface{}) (err error) { + _, valid := v.(string) + if !valid { + err = fmt.Errorf("want string, got '%v'", reflect.TypeOf(v)) + } + return + }, + }, + "Time": matcherTestCase{ + matcher: Time(), + testCase: func(v interface{}) (err error) { + _, valid := v.(string) + if !valid { + err = fmt.Errorf("want string, got '%v'", reflect.TypeOf(v)) + } + return + }, + }, + "UUID": matcherTestCase{ + matcher: UUID(), + testCase: func(v interface{}) (err error) { + match, err := regexp.MatchString(uuid, v.(string)) + + if !match { + err = fmt.Errorf("want string, got '%v'. Err: %v", v, err) + } + return + }, + }, + } + var err error + for k, v := range matchers { + if err = v.testCase(v.matcher.getValue()); err != nil { + t.Fatalf("error validating matcher '%s': %v", k, err) + } + } +} + func ExampleLike_string() { match := Like("myspecialvalue") fmt.Println(formatJSON(match)) diff --git a/vendor/github.com/gin-gonic/gin/README.md b/vendor/github.com/gin-gonic/gin/README.md index b51aa10c5..63e8b2c5d 100644 --- a/vendor/github.com/gin-gonic/gin/README.md +++ b/vendor/github.com/gin-gonic/gin/README.md @@ -1324,8 +1324,13 @@ func main() { go func() { // service connections +<<<<<<< HEAD if err := srv.ListenAndServe(); err != nil { log.Printf("listen: %s\n", err) +======= + if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { + log.Fatalf("listen: %s\n", err) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ } }() diff --git a/vendor/github.com/gin-gonic/gin/examples/graceful-shutdown/graceful-shutdown/server.go b/vendor/github.com/gin-gonic/gin/examples/graceful-shutdown/graceful-shutdown/server.go index 6debe7f59..d62c8ed83 100644 --- a/vendor/github.com/gin-gonic/gin/examples/graceful-shutdown/graceful-shutdown/server.go +++ b/vendor/github.com/gin-gonic/gin/examples/graceful-shutdown/graceful-shutdown/server.go @@ -27,8 +27,13 @@ func main() { go func() { // service connections +<<<<<<< HEAD if err := srv.ListenAndServe(); err != nil { log.Printf("listen: %s\n", err) +======= + if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { + log.Fatalf("listen: %s\n", err) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ } }() diff --git a/vendor/github.com/gin-gonic/gin/recovery.go b/vendor/github.com/gin-gonic/gin/recovery.go index 89b39fecd..3880c78b6 100644 --- a/vendor/github.com/gin-gonic/gin/recovery.go +++ b/vendor/github.com/gin-gonic/gin/recovery.go @@ -12,6 +12,10 @@ import ( "log" "net/http/httputil" "runtime" +<<<<<<< HEAD +======= + "time" +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ ) var ( @@ -38,7 +42,11 @@ func RecoveryWithWriter(out io.Writer) HandlerFunc { if logger != nil { stack := stack(3) httprequest, _ := httputil.DumpRequest(c.Request, false) +<<<<<<< HEAD logger.Printf("[Recovery] panic recovered:\n%s\n%s\n%s%s", string(httprequest), err, stack, reset) +======= + logger.Printf("[Recovery] %s panic recovered:\n%s\n%s\n%s%s", timeFormat(time.Now()), string(httprequest), err, stack, reset) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ } c.AbortWithStatus(500) } @@ -107,3 +115,11 @@ func function(pc uintptr) []byte { name = bytes.Replace(name, centerDot, dot, -1) return name } +<<<<<<< HEAD +======= + +func timeFormat(t time.Time) string { + var timeString = t.Format("2006/01/02 - 15:04:05") + return timeString +} +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ diff --git a/vendor/github.com/go-kit/kit/transport/http/encode_decode.go b/vendor/github.com/go-kit/kit/transport/http/encode_decode.go index 3076e4d2a..d12f05566 100644 --- a/vendor/github.com/go-kit/kit/transport/http/encode_decode.go +++ b/vendor/github.com/go-kit/kit/transport/http/encode_decode.go @@ -8,12 +8,20 @@ import ( // DecodeRequestFunc extracts a user-domain request object from an HTTP // request object. It's designed to be used in HTTP servers, for server-side // endpoints. One straightforward DecodeRequestFunc could be something that +<<<<<<< HEAD // JSON decodes from the request body to the concrete response type. +======= +// JSON decodes from the request body to the concrete request type. +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ type DecodeRequestFunc func(context.Context, *http.Request) (request interface{}, err error) // EncodeRequestFunc encodes the passed request object into the HTTP request // object. It's designed to be used in HTTP clients, for client-side +<<<<<<< HEAD // endpoints. One straightforward EncodeRequestFunc could something that JSON +======= +// endpoints. One straightforward EncodeRequestFunc could be something that JSON +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ // encodes the object directly to the request body. type EncodeRequestFunc func(context.Context, *http.Request, interface{}) error diff --git a/vendor/github.com/json-iterator/go/reflect_struct_decoder.go b/vendor/github.com/json-iterator/go/reflect_struct_decoder.go index e718722af..5a5056193 100644 --- a/vendor/github.com/json-iterator/go/reflect_struct_decoder.go +++ b/vendor/github.com/json-iterator/go/reflect_struct_decoder.go @@ -31,6 +31,14 @@ func decoderOfStruct(ctx *ctx, typ reflect2.Type) ValDecoder { for k, binding := range bindings { fields[k] = binding.Decoder.(*structFieldDecoder) } +<<<<<<< HEAD +======= + for k, binding := range bindings { + if _, found := fields[strings.ToLower(k)]; !found { + fields[strings.ToLower(k)] = binding.Decoder.(*structFieldDecoder) + } + } +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ return createStructDecoder(ctx, typ, fields) } diff --git a/vendor/github.com/json-iterator/go/value_tests/struct_test.go b/vendor/github.com/json-iterator/go/value_tests/struct_test.go index 2335d0786..4872424b0 100644 --- a/vendor/github.com/json-iterator/go/value_tests/struct_test.go +++ b/vendor/github.com/json-iterator/go/value_tests/struct_test.go @@ -63,6 +63,24 @@ func init() { d *time.Timer })(nil), input: `{"a": 444, "b":"bad", "C":256, "d":{"not":"a timer"}}`, +<<<<<<< HEAD +======= + }, unmarshalCase{ + ptr: (*struct { + A string + B string + C string + D string + E string + F string + G string + H string + I string + J string + K string + })(nil), + input: `{"a":"1","b":"2","c":"3","d":"4","e":"5","f":"6","g":"7","h":"8","i":"9","j":"10","k":"11"}`, +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ }) marshalCases = append(marshalCases, struct { diff --git a/vendor/github.com/magiconair/properties/.travis.yml b/vendor/github.com/magiconair/properties/.travis.yml deleted file mode 100644 index 5ef5d72f3..000000000 --- a/vendor/github.com/magiconair/properties/.travis.yml +++ /dev/null @@ -1,6 +0,0 @@ -language: go -go: - - 1.4.3 - - 1.5.3 - - 1.6 - - tip diff --git a/vendor/github.com/magiconair/properties/CHANGELOG.md b/vendor/github.com/magiconair/properties/CHANGELOG.md deleted file mode 100644 index bf49a1376..000000000 --- a/vendor/github.com/magiconair/properties/CHANGELOG.md +++ /dev/null @@ -1,81 +0,0 @@ -## Changelog - -### [1.7.0](https://github.com/magiconair/properties/tags/v1.7.0) - 20 Mar 2016 - - * [Issue #10](https://github.com/magiconair/properties/issues/10): Add [LoadURL,LoadURLs,MustLoadURL,MustLoadURLs](http://godoc.org/github.com/magiconair/properties#Properties.LoadURL) method to load properties from a URL. - * [Issue #11](https://github.com/magiconair/properties/issues/11): Add [LoadString,MustLoadString](http://godoc.org/github.com/magiconair/properties#Properties.LoadString) method to load properties from an UTF8 string. - * [PR #8](https://github.com/magiconair/properties/pull/8): Add [MustFlag](http://godoc.org/github.com/magiconair/properties#Properties.MustFlag) method to provide overrides via command line flags. (@pascaldekloe) - -### [1.6.0](https://github.com/magiconair/properties/tags/v1.6.0) - 11 Dec 2015 - - * Add [Decode](http://godoc.org/github.com/magiconair/properties#Properties.Decode) method to populate struct from properties via tags. - -### [1.5.6](https://github.com/magiconair/properties/tags/v1.5.6) - 18 Oct 2015 - - * Vendored in gopkg.in/check.v1 - -### [1.5.5](https://github.com/magiconair/properties/tags/v1.5.5) - 31 Jul 2015 - - * [PR #6](https://github.com/magiconair/properties/pull/6): Add [Delete](http://godoc.org/github.com/magiconair/properties#Properties.Delete) method to remove keys including comments. (@gerbenjacobs) - -### [1.5.4](https://github.com/magiconair/properties/tags/v1.5.4) - 23 Jun 2015 - - * [Issue #5](https://github.com/magiconair/properties/issues/5): Allow disabling of property expansion [DisableExpansion](http://godoc.org/github.com/magiconair/properties#Properties.DisableExpansion). When property expansion is disabled Properties become a simple key/value store and don't check for circular references. - -### [1.5.3](https://github.com/magiconair/properties/tags/v1.5.3) - 02 Jun 2015 - - * [Issue #4](https://github.com/magiconair/properties/issues/4): Maintain key order in [Filter()](http://godoc.org/github.com/magiconair/properties#Properties.Filter), [FilterPrefix()](http://godoc.org/github.com/magiconair/properties#Properties.FilterPrefix) and [FilterRegexp()](http://godoc.org/github.com/magiconair/properties#Properties.FilterRegexp) - -### [1.5.2](https://github.com/magiconair/properties/tags/v1.5.2) - 10 Apr 2015 - - * [Issue #3](https://github.com/magiconair/properties/issues/3): Don't print comments in [WriteComment()](http://godoc.org/github.com/magiconair/properties#Properties.WriteComment) if they are all empty - * Add clickable links to README - -### [1.5.1](https://github.com/magiconair/properties/tags/v1.5.1) - 08 Dec 2014 - - * Added [GetParsedDuration()](http://godoc.org/github.com/magiconair/properties#Properties.GetParsedDuration) and [MustGetParsedDuration()](http://godoc.org/github.com/magiconair/properties#Properties.MustGetParsedDuration) for values specified compatible with - [time.ParseDuration()](http://golang.org/pkg/time/#ParseDuration). - -### [1.5.0](https://github.com/magiconair/properties/tags/v1.5.0) - 18 Nov 2014 - - * Added support for single and multi-line comments (reading, writing and updating) - * The order of keys is now preserved - * Calling [Set()](http://godoc.org/github.com/magiconair/properties#Properties.Set) with an empty key now silently ignores the call and does not create a new entry - * Added a [MustSet()](http://godoc.org/github.com/magiconair/properties#Properties.MustSet) method - * Migrated test library from launchpad.net/gocheck to [gopkg.in/check.v1](http://gopkg.in/check.v1) - -### [1.4.2](https://github.com/magiconair/properties/tags/v1.4.2) - 15 Nov 2014 - - * [Issue #2](https://github.com/magiconair/properties/issues/2): Fixed goroutine leak in parser which created two lexers but cleaned up only one - -### [1.4.1](https://github.com/magiconair/properties/tags/v1.4.1) - 13 Nov 2014 - - * [Issue #1](https://github.com/magiconair/properties/issues/1): Fixed bug in Keys() method which returned an empty string - -### [1.4.0](https://github.com/magiconair/properties/tags/v1.4.0) - 23 Sep 2014 - - * Added [Keys()](http://godoc.org/github.com/magiconair/properties#Properties.Keys) to get the keys - * Added [Filter()](http://godoc.org/github.com/magiconair/properties#Properties.Filter), [FilterRegexp()](http://godoc.org/github.com/magiconair/properties#Properties.FilterRegexp) and [FilterPrefix()](http://godoc.org/github.com/magiconair/properties#Properties.FilterPrefix) to get a subset of the properties - -### [1.3.0](https://github.com/magiconair/properties/tags/v1.3.0) - 18 Mar 2014 - -* Added support for time.Duration -* Made MustXXX() failure beha[ior configurable (log.Fatal, panic](https://github.com/magiconair/properties/tags/vior configurable (log.Fatal, panic) - custom) -* Changed default of MustXXX() failure from panic to log.Fatal - -### [1.2.0](https://github.com/magiconair/properties/tags/v1.2.0) - 05 Mar 2014 - -* Added MustGet... functions -* Added support for int and uint with range checks on 32 bit platforms - -### [1.1.0](https://github.com/magiconair/properties/tags/v1.1.0) - 20 Jan 2014 - -* Renamed from goproperties to properties -* Added support for expansion of environment vars in - filenames and value expressions -* Fixed bug where value expressions were not at the - start of the string - -### [1.0.0](https://github.com/magiconair/properties/tags/v1.0.0) - 7 Jan 2014 - -* Initial release diff --git a/vendor/github.com/magiconair/properties/LICENSE b/vendor/github.com/magiconair/properties/LICENSE deleted file mode 100644 index 7eab43b6b..000000000 --- a/vendor/github.com/magiconair/properties/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ -goproperties - properties file decoder for Go - -Copyright (c) 2013-2014 - Frank Schroeder - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/magiconair/properties/README.md b/vendor/github.com/magiconair/properties/README.md deleted file mode 100644 index 1ae0035a0..000000000 --- a/vendor/github.com/magiconair/properties/README.md +++ /dev/null @@ -1,81 +0,0 @@ -Overview [![Build Status](https://travis-ci.org/magiconair/properties.svg?branch=master)](https://travis-ci.org/magiconair/properties) -======== - -#### Current version: 1.7.0 - -properties is a Go library for reading and writing properties files. - -It supports reading from multiple files or URLs and Spring style recursive -property expansion of expressions like `${key}` to their corresponding value. -Value expressions can refer to other keys like in `${key}` or to environment -variables like in `${USER}`. Filenames can also contain environment variables -like in `/home/${USER}/myapp.properties`. - -Properties can be decoded into structs, maps, arrays and values through -struct tags. - -Comments and the order of keys are preserved. Comments can be modified -and can be written to the output. - -The properties library supports both ISO-8859-1 and UTF-8 encoded data. - -Starting from version 1.3.0 the behavior of the MustXXX() functions is -configurable by providing a custom `ErrorHandler` function. The default has -changed from `panic` to `log.Fatal` but this is configurable and custom -error handling functions can be provided. See the package documentation for -details. - -Getting Started ---------------- - -```go -import ( - "flag" - "github.com/magiconair/properties" -) - -func main() { - p := properties.MustLoadFile("${HOME}/config.properties", properties.UTF8) - - // via getters - host := p.MustGetString("host") - port := p.GetInt("port", 8080) - - // or via decode - type Config struct { - Host string `properties:"host"` - Port int `properties:"port,default=9000"` - Accept []string `properties:"accept,default=image/png;image;gif"` - Timeout time.Duration `properties:"timeout,default=5s"` - } - var cfg Config - if err := p.Decode(&cfg); err != nil { - log.Fatal(err) - } - - // or via flags - p.MustFlag(flag.CommandLine) - - // or via url - p = properties.MustLoadURL("http://host/path") -} - -``` - -Read the full documentation on [GoDoc](https://godoc.org/github.com/magiconair/properties) [![GoDoc](https://godoc.org/github.com/magiconair/properties?status.png)](https://godoc.org/github.com/magiconair/properties) - -Installation and Upgrade ------------------------- - -``` -$ go get -u github.com/magiconair/properties -``` - -License -------- - -2 clause BSD license. See [LICENSE](https://github.com/magiconair/properties/blob/master/LICENSE) file for details. - -ToDo ----- -* Dump contents with passwords and secrets obscured diff --git a/vendor/github.com/magiconair/properties/benchmark_test.go b/vendor/github.com/magiconair/properties/benchmark_test.go deleted file mode 100644 index b2019e103..000000000 --- a/vendor/github.com/magiconair/properties/benchmark_test.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2013-2014 Frank Schroeder. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package properties - -import ( - "fmt" - "testing" -) - -// Benchmarks the decoder by creating a property file with 1000 key/value pairs. -func BenchmarkLoad(b *testing.B) { - input := "" - for i := 0; i < 1000; i++ { - input += fmt.Sprintf("key%d=value%d\n", i, i) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - Load([]byte(input), ISO_8859_1) - } -} diff --git a/vendor/github.com/magiconair/properties/decode.go b/vendor/github.com/magiconair/properties/decode.go deleted file mode 100644 index b989e6397..000000000 --- a/vendor/github.com/magiconair/properties/decode.go +++ /dev/null @@ -1,290 +0,0 @@ -// Copyright 2016 Frank Schroeder. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package properties - -import ( - "fmt" - "reflect" - "strconv" - "strings" - "time" -) - -// Decode assigns property values to exported fields of a struct. -// -// Decode traverses v recursively and returns an error if a value cannot be -// converted to the field type or a required value is missing for a field. -// -// The following type dependent decodings are used: -// -// String, boolean, numeric fields have the value of the property key assigned. -// The property key name is the name of the field. A different key and a default -// value can be set in the field's tag. Fields without default value are -// required. If the value cannot be converted to the field type an error is -// returned. -// -// time.Duration fields have the result of time.ParseDuration() assigned. -// -// time.Time fields have the vaule of time.Parse() assigned. The default layout -// is time.RFC3339 but can be set in the field's tag. -// -// Arrays and slices of string, boolean, numeric, time.Duration and time.Time -// fields have the value interpreted as a comma separated list of values. The -// individual values are trimmed of whitespace and empty values are ignored. A -// default value can be provided as a semicolon separated list in the field's -// tag. -// -// Struct fields are decoded recursively using the field name plus "." as -// prefix. The prefix (without dot) can be overridden in the field's tag. -// Default values are not supported in the field's tag. Specify them on the -// fields of the inner struct instead. -// -// Map fields must have a key of type string and are decoded recursively by -// using the field's name plus ".' as prefix and the next element of the key -// name as map key. The prefix (without dot) can be overridden in the field's -// tag. Default values are not supported. -// -// Examples: -// -// // Field is ignored. -// Field int `properties:"-"` -// -// // Field is assigned value of 'Field'. -// Field int -// -// // Field is assigned value of 'myName'. -// Field int `properties:"myName"` -// -// // Field is assigned value of key 'myName' and has a default -// // value 15 if the key does not exist. -// Field int `properties:"myName,default=15"` -// -// // Field is assigned value of key 'Field' and has a default -// // value 15 if the key does not exist. -// Field int `properties:",default=15"` -// -// // Field is assigned value of key 'date' and the date -// // is in format 2006-01-02 -// Field time.Time `properties:"date,layout=2006-01-02"` -// -// // Field is assigned the non-empty and whitespace trimmed -// // values of key 'Field' split by commas. -// Field []string -// -// // Field is assigned the non-empty and whitespace trimmed -// // values of key 'Field' split by commas and has a default -// // value ["a", "b", "c"] if the key does not exist. -// Field []string `properties:",default=a;b;c"` -// -// // Field is decoded recursively with "Field." as key prefix. -// Field SomeStruct -// -// // Field is decoded recursively with "myName." as key prefix. -// Field SomeStruct `properties:"myName"` -// -// // Field is decoded recursively with "Field." as key prefix -// // and the next dotted element of the key as map key. -// Field map[string]string -// -// // Field is decoded recursively with "myName." as key prefix -// // and the next dotted element of the key as map key. -// Field map[string]string `properties:"myName"` -func (p *Properties) Decode(x interface{}) error { - t, v := reflect.TypeOf(x), reflect.ValueOf(x) - if t.Kind() != reflect.Ptr || v.Elem().Type().Kind() != reflect.Struct { - return fmt.Errorf("not a pointer to struct: %s", t) - } - if err := dec(p, "", nil, nil, v); err != nil { - return err - } - return nil -} - -func dec(p *Properties, key string, def *string, opts map[string]string, v reflect.Value) error { - t := v.Type() - - // value returns the property value for key or the default if provided. - value := func() (string, error) { - if val, ok := p.Get(key); ok { - return val, nil - } - if def != nil { - return *def, nil - } - return "", fmt.Errorf("missing required key %s", key) - } - - // conv converts a string to a value of the given type. - conv := func(s string, t reflect.Type) (val reflect.Value, err error) { - var v interface{} - - switch { - case isDuration(t): - v, err = time.ParseDuration(s) - - case isTime(t): - layout := opts["layout"] - if layout == "" { - layout = time.RFC3339 - } - v, err = time.Parse(layout, s) - - case isBool(t): - v, err = boolVal(s), nil - - case isString(t): - v, err = s, nil - - case isFloat(t): - v, err = strconv.ParseFloat(s, 64) - - case isInt(t): - v, err = strconv.ParseInt(s, 10, 64) - - case isUint(t): - v, err = strconv.ParseUint(s, 10, 64) - - default: - return reflect.Zero(t), fmt.Errorf("unsupported type %s", t) - } - if err != nil { - return reflect.Zero(t), err - } - return reflect.ValueOf(v).Convert(t), nil - } - - // keydef returns the property key and the default value based on the - // name of the struct field and the options in the tag. - keydef := func(f reflect.StructField) (string, *string, map[string]string) { - key, opts := parseTag(f.Tag.Get("properties")) - - var def *string - if d, ok := opts["default"]; ok { - def = &d - } - if key != "" { - return key, def, opts - } - return f.Name, def, opts - } - - switch { - case isDuration(t) || isTime(t) || isBool(t) || isString(t) || isFloat(t) || isInt(t) || isUint(t): - s, err := value() - if err != nil { - return err - } - val, err := conv(s, t) - if err != nil { - return err - } - v.Set(val) - - case isPtr(t): - return dec(p, key, def, opts, v.Elem()) - - case isStruct(t): - for i := 0; i < v.NumField(); i++ { - fv := v.Field(i) - fk, def, opts := keydef(t.Field(i)) - if !fv.CanSet() { - return fmt.Errorf("cannot set ", t.Field(i).Name) - } - if fk == "-" { - continue - } - if key != "" { - fk = key + "." + fk - } - if err := dec(p, fk, def, opts, fv); err != nil { - return err - } - } - return nil - - case isArray(t): - val, err := value() - if err != nil { - return err - } - vals := split(val, ";") - a := reflect.MakeSlice(t, 0, len(vals)) - for _, s := range vals { - val, err := conv(s, t.Elem()) - if err != nil { - return err - } - a = reflect.Append(a, val) - } - v.Set(a) - - case isMap(t): - valT := t.Elem() - m := reflect.MakeMap(t) - for postfix, _ := range p.FilterStripPrefix(key + ".").m { - pp := strings.SplitN(postfix, ".", 2) - mk, mv := pp[0], reflect.New(valT) - if err := dec(p, key+"."+mk, nil, nil, mv); err != nil { - return err - } - m.SetMapIndex(reflect.ValueOf(mk), mv.Elem()) - } - v.Set(m) - - default: - return fmt.Errorf("unsupported type %s", t) - } - return nil -} - -// split splits a string on sep, trims whitespace of elements -// and omits empty elements -func split(s string, sep string) []string { - var a []string - for _, v := range strings.Split(s, sep) { - if v = strings.TrimSpace(v); v != "" { - a = append(a, v) - } - } - return a -} - -// parseTag parses a "key,k=v,k=v,..." -func parseTag(tag string) (key string, opts map[string]string) { - opts = map[string]string{} - for i, s := range strings.Split(tag, ",") { - if i == 0 { - key = s - continue - } - - pp := strings.SplitN(s, "=", 2) - if len(pp) == 1 { - opts[pp[0]] = "" - } else { - opts[pp[0]] = pp[1] - } - } - return key, opts -} - -func isArray(t reflect.Type) bool { return t.Kind() == reflect.Array || t.Kind() == reflect.Slice } -func isBool(t reflect.Type) bool { return t.Kind() == reflect.Bool } -func isDuration(t reflect.Type) bool { return t == reflect.TypeOf(time.Second) } -func isMap(t reflect.Type) bool { return t.Kind() == reflect.Map } -func isNumeric(t reflect.Type) bool { return isInt(t) || isUint(t) || isFloat(t) } -func isPtr(t reflect.Type) bool { return t.Kind() == reflect.Ptr } -func isString(t reflect.Type) bool { return t.Kind() == reflect.String } -func isStruct(t reflect.Type) bool { return t.Kind() == reflect.Struct } -func isTime(t reflect.Type) bool { return t == reflect.TypeOf(time.Time{}) } -func isFloat(t reflect.Type) bool { - return t.Kind() == reflect.Float32 || t.Kind() == reflect.Float64 -} -func isInt(t reflect.Type) bool { - return t.Kind() == reflect.Int || t.Kind() == reflect.Int8 || t.Kind() == reflect.Int16 || t.Kind() == reflect.Int32 || t.Kind() == reflect.Int64 -} -func isUint(t reflect.Type) bool { - return t.Kind() == reflect.Uint || t.Kind() == reflect.Uint8 || t.Kind() == reflect.Uint16 || t.Kind() == reflect.Uint32 || t.Kind() == reflect.Uint64 -} diff --git a/vendor/github.com/magiconair/properties/decode_test.go b/vendor/github.com/magiconair/properties/decode_test.go deleted file mode 100644 index a12f1e208..000000000 --- a/vendor/github.com/magiconair/properties/decode_test.go +++ /dev/null @@ -1,299 +0,0 @@ -// Copyright 2016 Frank Schroeder. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package properties - -import ( - "reflect" - "testing" - "time" -) - -func TestDecodeValues(t *testing.T) { - type S struct { - S string - BT bool - BF bool - I int - I8 int8 - I16 int16 - I32 int32 - I64 int64 - U uint - U8 uint8 - U16 uint16 - U32 uint32 - U64 uint64 - F32 float32 - F64 float64 - D time.Duration - TM time.Time - } - in := ` - S=abc - BT=true - BF=false - I=-1 - I8=-8 - I16=-16 - I32=-32 - I64=-64 - U=1 - U8=8 - U16=16 - U32=32 - U64=64 - F32=3.2 - F64=6.4 - D=5s - TM=2015-01-02T12:34:56Z - ` - out := &S{ - S: "abc", - BT: true, - BF: false, - I: -1, - I8: -8, - I16: -16, - I32: -32, - I64: -64, - U: 1, - U8: 8, - U16: 16, - U32: 32, - U64: 64, - F32: 3.2, - F64: 6.4, - D: 5 * time.Second, - TM: tm(t, time.RFC3339, "2015-01-02T12:34:56Z"), - } - testDecode(t, in, &S{}, out) -} - -func TestDecodeValueDefaults(t *testing.T) { - type S struct { - S string `properties:",default=abc"` - BT bool `properties:",default=true"` - BF bool `properties:",default=false"` - I int `properties:",default=-1"` - I8 int8 `properties:",default=-8"` - I16 int16 `properties:",default=-16"` - I32 int32 `properties:",default=-32"` - I64 int64 `properties:",default=-64"` - U uint `properties:",default=1"` - U8 uint8 `properties:",default=8"` - U16 uint16 `properties:",default=16"` - U32 uint32 `properties:",default=32"` - U64 uint64 `properties:",default=64"` - F32 float32 `properties:",default=3.2"` - F64 float64 `properties:",default=6.4"` - D time.Duration `properties:",default=5s"` - TM time.Time `properties:",default=2015-01-02T12:34:56Z"` - } - out := &S{ - S: "abc", - BT: true, - BF: false, - I: -1, - I8: -8, - I16: -16, - I32: -32, - I64: -64, - U: 1, - U8: 8, - U16: 16, - U32: 32, - U64: 64, - F32: 3.2, - F64: 6.4, - D: 5 * time.Second, - TM: tm(t, time.RFC3339, "2015-01-02T12:34:56Z"), - } - testDecode(t, "", &S{}, out) -} - -func TestDecodeArrays(t *testing.T) { - type S struct { - S []string - B []bool - I []int - I8 []int8 - I16 []int16 - I32 []int32 - I64 []int64 - U []uint - U8 []uint8 - U16 []uint16 - U32 []uint32 - U64 []uint64 - F32 []float32 - F64 []float64 - D []time.Duration - TM []time.Time - } - in := ` - S=a;b - B=true;false - I=-1;-2 - I8=-8;-9 - I16=-16;-17 - I32=-32;-33 - I64=-64;-65 - U=1;2 - U8=8;9 - U16=16;17 - U32=32;33 - U64=64;65 - F32=3.2;3.3 - F64=6.4;6.5 - D=4s;5s - TM=2015-01-01T00:00:00Z;2016-01-01T00:00:00Z - ` - out := &S{ - S: []string{"a", "b"}, - B: []bool{true, false}, - I: []int{-1, -2}, - I8: []int8{-8, -9}, - I16: []int16{-16, -17}, - I32: []int32{-32, -33}, - I64: []int64{-64, -65}, - U: []uint{1, 2}, - U8: []uint8{8, 9}, - U16: []uint16{16, 17}, - U32: []uint32{32, 33}, - U64: []uint64{64, 65}, - F32: []float32{3.2, 3.3}, - F64: []float64{6.4, 6.5}, - D: []time.Duration{4 * time.Second, 5 * time.Second}, - TM: []time.Time{tm(t, time.RFC3339, "2015-01-01T00:00:00Z"), tm(t, time.RFC3339, "2016-01-01T00:00:00Z")}, - } - testDecode(t, in, &S{}, out) -} - -func TestDecodeArrayDefaults(t *testing.T) { - type S struct { - S []string `properties:",default=a;b"` - B []bool `properties:",default=true;false"` - I []int `properties:",default=-1;-2"` - I8 []int8 `properties:",default=-8;-9"` - I16 []int16 `properties:",default=-16;-17"` - I32 []int32 `properties:",default=-32;-33"` - I64 []int64 `properties:",default=-64;-65"` - U []uint `properties:",default=1;2"` - U8 []uint8 `properties:",default=8;9"` - U16 []uint16 `properties:",default=16;17"` - U32 []uint32 `properties:",default=32;33"` - U64 []uint64 `properties:",default=64;65"` - F32 []float32 `properties:",default=3.2;3.3"` - F64 []float64 `properties:",default=6.4;6.5"` - D []time.Duration `properties:",default=4s;5s"` - TM []time.Time `properties:",default=2015-01-01T00:00:00Z;2016-01-01T00:00:00Z"` - } - out := &S{ - S: []string{"a", "b"}, - B: []bool{true, false}, - I: []int{-1, -2}, - I8: []int8{-8, -9}, - I16: []int16{-16, -17}, - I32: []int32{-32, -33}, - I64: []int64{-64, -65}, - U: []uint{1, 2}, - U8: []uint8{8, 9}, - U16: []uint16{16, 17}, - U32: []uint32{32, 33}, - U64: []uint64{64, 65}, - F32: []float32{3.2, 3.3}, - F64: []float64{6.4, 6.5}, - D: []time.Duration{4 * time.Second, 5 * time.Second}, - TM: []time.Time{tm(t, time.RFC3339, "2015-01-01T00:00:00Z"), tm(t, time.RFC3339, "2016-01-01T00:00:00Z")}, - } - testDecode(t, "", &S{}, out) -} - -func TestDecodeSkipUndef(t *testing.T) { - type S struct { - X string `properties:"-"` - Undef string `properties:",default=some value"` - } - in := `X=ignore` - out := &S{"", "some value"} - testDecode(t, in, &S{}, out) -} - -func TestDecodeStruct(t *testing.T) { - type A struct { - S string - T string `properties:"t"` - U string `properties:"u,default=uuu"` - } - type S struct { - A A - B A `properties:"b"` - } - in := ` - A.S=sss - A.t=ttt - b.S=SSS - b.t=TTT - ` - out := &S{ - A{S: "sss", T: "ttt", U: "uuu"}, - A{S: "SSS", T: "TTT", U: "uuu"}, - } - testDecode(t, in, &S{}, out) -} - -func TestDecodeMap(t *testing.T) { - type S struct { - A string `properties:"a"` - } - type X struct { - A map[string]string - B map[string][]string - C map[string]map[string]string - D map[string]S - E map[string]int - F map[string]int `properties:"-"` - } - in := ` - A.foo=bar - A.bar=bang - B.foo=a;b;c - B.bar=1;2;3 - C.foo.one=1 - C.foo.two=2 - C.bar.three=3 - C.bar.four=4 - D.foo.a=bar - ` - out := &X{ - A: map[string]string{"foo": "bar", "bar": "bang"}, - B: map[string][]string{"foo": []string{"a", "b", "c"}, "bar": []string{"1", "2", "3"}}, - C: map[string]map[string]string{"foo": map[string]string{"one": "1", "two": "2"}, "bar": map[string]string{"three": "3", "four": "4"}}, - D: map[string]S{"foo": S{"bar"}}, - E: map[string]int{}, - } - testDecode(t, in, &X{}, out) -} - -func testDecode(t *testing.T, in string, v, out interface{}) { - p, err := parse(in) - if err != nil { - t.Fatalf("got %v want nil", err) - } - if err := p.Decode(v); err != nil { - t.Fatalf("got %v want nil", err) - } - if got, want := v, out; !reflect.DeepEqual(got, want) { - t.Fatalf("\ngot %+v\nwant %+v", got, want) - } -} - -func tm(t *testing.T, layout, s string) time.Time { - tm, err := time.Parse(layout, s) - if err != nil { - t.Fatalf("got %v want nil", err) - } - return tm -} diff --git a/vendor/github.com/magiconair/properties/doc.go b/vendor/github.com/magiconair/properties/doc.go deleted file mode 100644 index ed1ff510a..000000000 --- a/vendor/github.com/magiconair/properties/doc.go +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright 2016 Frank Schroeder. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package properties provides functions for reading and writing -// ISO-8859-1 and UTF-8 encoded .properties files and has -// support for recursive property expansion. -// -// Java properties files are ISO-8859-1 encoded and use Unicode -// literals for characters outside the ISO character set. Unicode -// literals can be used in UTF-8 encoded properties files but -// aren't necessary. -// -// To load a single properties file use MustLoadFile(): -// -// p := properties.MustLoadFile(filename, properties.UTF8) -// -// To load multiple properties files use MustLoadFiles() -// which loads the files in the given order and merges the -// result. Missing properties files can be ignored if the -// 'ignoreMissing' flag is set to true. -// -// Filenames can contain environment variables which are expanded -// before loading. -// -// f1 := "/etc/myapp/myapp.conf" -// f2 := "/home/${USER}/myapp.conf" -// p := MustLoadFiles([]string{f1, f2}, properties.UTF8, true) -// -// All of the different key/value delimiters ' ', ':' and '=' are -// supported as well as the comment characters '!' and '#' and -// multi-line values. -// -// ! this is a comment -// # and so is this -// -// # the following expressions are equal -// key value -// key=value -// key:value -// key = value -// key : value -// key = val\ -// ue -// -// Properties stores all comments preceding a key and provides -// GetComments() and SetComments() methods to retrieve and -// update them. The convenience functions GetComment() and -// SetComment() allow access to the last comment. The -// WriteComment() method writes properties files including -// the comments and with the keys in the original order. -// This can be used for sanitizing properties files. -// -// Property expansion is recursive and circular references -// and malformed expressions are not allowed and cause an -// error. Expansion of environment variables is supported. -// -// # standard property -// key = value -// -// # property expansion: key2 = value -// key2 = ${key} -// -// # recursive expansion: key3 = value -// key3 = ${key2} -// -// # circular reference (error) -// key = ${key} -// -// # malformed expression (error) -// key = ${ke -// -// # refers to the users' home dir -// home = ${HOME} -// -// # local key takes precendence over env var: u = foo -// USER = foo -// u = ${USER} -// -// The default property expansion format is ${key} but can be -// changed by setting different pre- and postfix values on the -// Properties object. -// -// p := properties.NewProperties() -// p.Prefix = "#[" -// p.Postfix = "]#" -// -// Properties provides convenience functions for getting typed -// values with default values if the key does not exist or the -// type conversion failed. -// -// # Returns true if the value is either "1", "on", "yes" or "true" -// # Returns false for every other value and the default value if -// # the key does not exist. -// v = p.GetBool("key", false) -// -// # Returns the value if the key exists and the format conversion -// # was successful. Otherwise, the default value is returned. -// v = p.GetInt64("key", 999) -// v = p.GetUint64("key", 999) -// v = p.GetFloat64("key", 123.0) -// v = p.GetString("key", "def") -// v = p.GetDuration("key", 999) -// -// As an alterantive properties may be applied with the standard -// library's flag implementation at any time. -// -// # Standard configuration -// v = flag.Int("key", 999, "help message") -// flag.Parse() -// -// # Merge p into the flag set -// p.MustFlag(flag.CommandLine) -// -// Properties provides several MustXXX() convenience functions -// which will terminate the app if an error occurs. The behavior -// of the failure is configurable and the default is to call -// log.Fatal(err). To have the MustXXX() functions panic instead -// of logging the error set a different ErrorHandler before -// you use the Properties package. -// -// properties.ErrorHandler = properties.PanicHandler -// -// # Will panic instead of logging an error -// p := properties.MustLoadFile("config.properties") -// -// You can also provide your own ErrorHandler function. The only requirement -// is that the error handler function must exit after handling the error. -// -// properties.ErrorHandler = func(err error) { -// fmt.Println(err) -// os.Exit(1) -// } -// -// # Will write to stdout and then exit -// p := properties.MustLoadFile("config.properties") -// -// Properties can also be loaded into a struct via the `Decode` -// method, e.g. -// -// type S struct { -// A string `properties:"a,default=foo"` -// D time.Duration `properties:"timeout,default=5s"` -// E time.Time `properties:"expires,layout=2006-01-02,default=2015-01-01"` -// } -// -// See `Decode()` method for the full documentation. -// -// The following documents provide a description of the properties -// file format. -// -// http://en.wikipedia.org/wiki/.properties -// -// http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html#load%28java.io.Reader%29 -// -package properties diff --git a/vendor/github.com/magiconair/properties/example_test.go b/vendor/github.com/magiconair/properties/example_test.go deleted file mode 100644 index 3601217e2..000000000 --- a/vendor/github.com/magiconair/properties/example_test.go +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2016 Frank Schroeder. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package properties - -import ( - "fmt" - "log" -) - -func ExampleLoad_iso88591() { - buf := []byte("key = ISO-8859-1 value with unicode literal \\u2318 and umlaut \xE4") // 0xE4 == รค - p, _ := Load(buf, ISO_8859_1) - v, ok := p.Get("key") - fmt.Println(ok) - fmt.Println(v) - // Output: - // true - // ISO-8859-1 value with unicode literal โŒ˜ and umlaut รค -} - -func ExampleLoad_utf8() { - p, _ := Load([]byte("key = UTF-8 value with unicode character โŒ˜ and umlaut รค"), UTF8) - v, ok := p.Get("key") - fmt.Println(ok) - fmt.Println(v) - // Output: - // true - // UTF-8 value with unicode character โŒ˜ and umlaut รค -} - -func ExampleProperties_GetBool() { - var input = ` - key=1 - key2=On - key3=YES - key4=true` - p, _ := Load([]byte(input), ISO_8859_1) - fmt.Println(p.GetBool("key", false)) - fmt.Println(p.GetBool("key2", false)) - fmt.Println(p.GetBool("key3", false)) - fmt.Println(p.GetBool("key4", false)) - fmt.Println(p.GetBool("keyX", false)) - // Output: - // true - // true - // true - // true - // false -} - -func ExampleProperties_GetString() { - p, _ := Load([]byte("key=value"), ISO_8859_1) - v := p.GetString("another key", "default value") - fmt.Println(v) - // Output: - // default value -} - -func Example() { - // Decode some key/value pairs with expressions - p, err := Load([]byte("key=value\nkey2=${key}"), ISO_8859_1) - if err != nil { - log.Fatal(err) - } - - // Get a valid key - if v, ok := p.Get("key"); ok { - fmt.Println(v) - } - - // Get an invalid key - if _, ok := p.Get("does not exist"); !ok { - fmt.Println("invalid key") - } - - // Get a key with a default value - v := p.GetString("does not exist", "some value") - fmt.Println(v) - - // Dump the expanded key/value pairs of the Properties - fmt.Println("Expanded key/value pairs") - fmt.Println(p) - - // Output: - // value - // invalid key - // some value - // Expanded key/value pairs - // key = value - // key2 = value -} diff --git a/vendor/github.com/magiconair/properties/integrate.go b/vendor/github.com/magiconair/properties/integrate.go deleted file mode 100644 index 37baaad95..000000000 --- a/vendor/github.com/magiconair/properties/integrate.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2016 Frank Schroeder. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package properties - -import "flag" - -// MustFlag sets flags that are skipped by dst.Parse when p contains -// the respective key for flag.Flag.Name. -// -// It's use is recommended with command line arguments as in: -// flag.Parse() -// p.MustFlag(flag.CommandLine) -func (p *Properties) MustFlag(dst *flag.FlagSet) { - m := make(map[string]*flag.Flag) - dst.VisitAll(func(f *flag.Flag) { - m[f.Name] = f - }) - dst.Visit(func(f *flag.Flag) { - delete(m, f.Name) // overridden - }) - - for name, f := range m { - v, ok := p.Get(name) - if !ok { - continue - } - - if err := f.Value.Set(v); err != nil { - ErrorHandler(err) - } - } -} diff --git a/vendor/github.com/magiconair/properties/integrate_test.go b/vendor/github.com/magiconair/properties/integrate_test.go deleted file mode 100644 index 2daaf8ab6..000000000 --- a/vendor/github.com/magiconair/properties/integrate_test.go +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2016 Frank Schroeder. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package properties - -import ( - "flag" - "fmt" - "testing" -) - -// TestFlag verifies Properties.MustFlag without flag.FlagSet.Parse -func TestFlag(t *testing.T) { - f := flag.NewFlagSet("src", flag.PanicOnError) - gotS := f.String("s", "?", "string flag") - gotI := f.Int("i", -1, "int flag") - - p := NewProperties() - p.Set("s", "t") - p.Set("i", "9") - p.MustFlag(f) - - if want := "t"; *gotS != want { - t.Errorf("Got string s=%q, want %q", *gotS, want) - } - if want := 9; *gotI != want { - t.Errorf("Got int i=%d, want %d", *gotI, want) - } -} - -// TestFlagOverride verifies Properties.MustFlag with flag.FlagSet.Parse. -func TestFlagOverride(t *testing.T) { - f := flag.NewFlagSet("src", flag.PanicOnError) - gotA := f.Int("a", 1, "remain default") - gotB := f.Int("b", 2, "customized") - gotC := f.Int("c", 3, "overridden") - - f.Parse([]string{"-c", "4"}) - - p := NewProperties() - p.Set("b", "5") - p.Set("c", "6") - p.MustFlag(f) - - if want := 1; *gotA != want { - t.Errorf("Got remain default a=%d, want %d", *gotA, want) - } - if want := 5; *gotB != want { - t.Errorf("Got customized b=%d, want %d", *gotB, want) - } - if want := 4; *gotC != want { - t.Errorf("Got overriden c=%d, want %d", *gotC, want) - } -} - -func ExampleProperties_MustFlag() { - x := flag.Int("x", 0, "demo customize") - y := flag.Int("y", 0, "demo override") - - // Demo alternative for flag.Parse(): - flag.CommandLine.Parse([]string{"-y", "10"}) - fmt.Printf("flagged as x=%d, y=%d\n", *x, *y) - - p := NewProperties() - p.Set("x", "7") - p.Set("y", "42") // note discard - p.MustFlag(flag.CommandLine) - fmt.Printf("configured to x=%d, y=%d\n", *x, *y) - - // Output: - // flagged as x=0, y=10 - // configured to x=7, y=10 -} diff --git a/vendor/github.com/magiconair/properties/lex.go b/vendor/github.com/magiconair/properties/lex.go deleted file mode 100644 index 014e63f0e..000000000 --- a/vendor/github.com/magiconair/properties/lex.go +++ /dev/null @@ -1,409 +0,0 @@ -// Copyright 2016 Frank Schroeder. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -// -// Parts of the lexer are from the template/text/parser package -// For these parts the following applies: -// -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file of the go 1.2 -// distribution. - -package properties - -import ( - "fmt" - "strconv" - "strings" - "unicode/utf8" -) - -// item represents a token or text string returned from the scanner. -type item struct { - typ itemType // The type of this item. - pos int // The starting position, in bytes, of this item in the input string. - val string // The value of this item. -} - -func (i item) String() string { - switch { - case i.typ == itemEOF: - return "EOF" - case i.typ == itemError: - return i.val - case len(i.val) > 10: - return fmt.Sprintf("%.10q...", i.val) - } - return fmt.Sprintf("%q", i.val) -} - -// itemType identifies the type of lex items. -type itemType int - -const ( - itemError itemType = iota // error occurred; value is text of error - itemEOF - itemKey // a key - itemValue // a value - itemComment // a comment -) - -// defines a constant for EOF -const eof = -1 - -// permitted whitespace characters space, FF and TAB -const whitespace = " \f\t" - -// stateFn represents the state of the scanner as a function that returns the next state. -type stateFn func(*lexer) stateFn - -// lexer holds the state of the scanner. -type lexer struct { - input string // the string being scanned - state stateFn // the next lexing function to enter - pos int // current position in the input - start int // start position of this item - width int // width of last rune read from input - lastPos int // position of most recent item returned by nextItem - runes []rune // scanned runes for this item - items chan item // channel of scanned items -} - -// next returns the next rune in the input. -func (l *lexer) next() rune { - if int(l.pos) >= len(l.input) { - l.width = 0 - return eof - } - r, w := utf8.DecodeRuneInString(l.input[l.pos:]) - l.width = w - l.pos += l.width - return r -} - -// peek returns but does not consume the next rune in the input. -func (l *lexer) peek() rune { - r := l.next() - l.backup() - return r -} - -// backup steps back one rune. Can only be called once per call of next. -func (l *lexer) backup() { - l.pos -= l.width -} - -// emit passes an item back to the client. -func (l *lexer) emit(t itemType) { - item := item{t, l.start, string(l.runes)} - l.items <- item - l.start = l.pos - l.runes = l.runes[:0] -} - -// ignore skips over the pending input before this point. -func (l *lexer) ignore() { - l.start = l.pos -} - -// appends the rune to the current value -func (l *lexer) appendRune(r rune) { - l.runes = append(l.runes, r) -} - -// accept consumes the next rune if it's from the valid set. -func (l *lexer) accept(valid string) bool { - if strings.IndexRune(valid, l.next()) >= 0 { - return true - } - l.backup() - return false -} - -// acceptRun consumes a run of runes from the valid set. -func (l *lexer) acceptRun(valid string) { - for strings.IndexRune(valid, l.next()) >= 0 { - } - l.backup() -} - -// acceptRunUntil consumes a run of runes up to a terminator. -func (l *lexer) acceptRunUntil(term rune) { - for term != l.next() { - } - l.backup() -} - -// hasText returns true if the current parsed text is not empty. -func (l *lexer) isNotEmpty() bool { - return l.pos > l.start -} - -// lineNumber reports which line we're on, based on the position of -// the previous item returned by nextItem. Doing it this way -// means we don't have to worry about peek double counting. -func (l *lexer) lineNumber() int { - return 1 + strings.Count(l.input[:l.lastPos], "\n") -} - -// errorf returns an error token and terminates the scan by passing -// back a nil pointer that will be the next state, terminating l.nextItem. -func (l *lexer) errorf(format string, args ...interface{}) stateFn { - l.items <- item{itemError, l.start, fmt.Sprintf(format, args...)} - return nil -} - -// nextItem returns the next item from the input. -func (l *lexer) nextItem() item { - item := <-l.items - l.lastPos = item.pos - return item -} - -// lex creates a new scanner for the input string. -func lex(input string) *lexer { - l := &lexer{ - input: input, - items: make(chan item), - runes: make([]rune, 0, 32), - } - go l.run() - return l -} - -// run runs the state machine for the lexer. -func (l *lexer) run() { - for l.state = lexBeforeKey(l); l.state != nil; { - l.state = l.state(l) - } -} - -// state functions - -// lexBeforeKey scans until a key begins. -func lexBeforeKey(l *lexer) stateFn { - switch r := l.next(); { - case isEOF(r): - l.emit(itemEOF) - return nil - - case isEOL(r): - l.ignore() - return lexBeforeKey - - case isComment(r): - return lexComment - - case isWhitespace(r): - l.acceptRun(whitespace) - l.ignore() - return lexKey - - default: - l.backup() - return lexKey - } -} - -// lexComment scans a comment line. The comment character has already been scanned. -func lexComment(l *lexer) stateFn { - l.acceptRun(whitespace) - l.ignore() - for { - switch r := l.next(); { - case isEOF(r): - l.ignore() - l.emit(itemEOF) - return nil - case isEOL(r): - l.emit(itemComment) - return lexBeforeKey - default: - l.appendRune(r) - } - } -} - -// lexKey scans the key up to a delimiter -func lexKey(l *lexer) stateFn { - var r rune - -Loop: - for { - switch r = l.next(); { - - case isEscape(r): - err := l.scanEscapeSequence() - if err != nil { - return l.errorf(err.Error()) - } - - case isEndOfKey(r): - l.backup() - break Loop - - case isEOF(r): - break Loop - - default: - l.appendRune(r) - } - } - - if len(l.runes) > 0 { - l.emit(itemKey) - } - - if isEOF(r) { - l.emit(itemEOF) - return nil - } - - return lexBeforeValue -} - -// lexBeforeValue scans the delimiter between key and value. -// Leading and trailing whitespace is ignored. -// We expect to be just after the key. -func lexBeforeValue(l *lexer) stateFn { - l.acceptRun(whitespace) - l.accept(":=") - l.acceptRun(whitespace) - l.ignore() - return lexValue -} - -// lexValue scans text until the end of the line. We expect to be just after the delimiter. -func lexValue(l *lexer) stateFn { - for { - switch r := l.next(); { - case isEscape(r): - r := l.peek() - if isEOL(r) { - l.next() - l.acceptRun(whitespace) - } else { - err := l.scanEscapeSequence() - if err != nil { - return l.errorf(err.Error()) - } - } - - case isEOL(r): - l.emit(itemValue) - l.ignore() - return lexBeforeKey - - case isEOF(r): - l.emit(itemValue) - l.emit(itemEOF) - return nil - - default: - l.appendRune(r) - } - } -} - -// scanEscapeSequence scans either one of the escaped characters -// or a unicode literal. We expect to be after the escape character. -func (l *lexer) scanEscapeSequence() error { - switch r := l.next(); { - - case isEscapedCharacter(r): - l.appendRune(decodeEscapedCharacter(r)) - return nil - - case atUnicodeLiteral(r): - return l.scanUnicodeLiteral() - - case isEOF(r): - return fmt.Errorf("premature EOF") - - // silently drop the escape character and append the rune as is - default: - l.appendRune(r) - return nil - } -} - -// scans a unicode literal in the form \uXXXX. We expect to be after the \u. -func (l *lexer) scanUnicodeLiteral() error { - // scan the digits - d := make([]rune, 4) - for i := 0; i < 4; i++ { - d[i] = l.next() - if d[i] == eof || !strings.ContainsRune("0123456789abcdefABCDEF", d[i]) { - return fmt.Errorf("invalid unicode literal") - } - } - - // decode the digits into a rune - r, err := strconv.ParseInt(string(d), 16, 0) - if err != nil { - return err - } - - l.appendRune(rune(r)) - return nil -} - -// decodeEscapedCharacter returns the unescaped rune. We expect to be after the escape character. -func decodeEscapedCharacter(r rune) rune { - switch r { - case 'f': - return '\f' - case 'n': - return '\n' - case 'r': - return '\r' - case 't': - return '\t' - default: - return r - } -} - -// atUnicodeLiteral reports whether we are at a unicode literal. -// The escape character has already been consumed. -func atUnicodeLiteral(r rune) bool { - return r == 'u' -} - -// isComment reports whether we are at the start of a comment. -func isComment(r rune) bool { - return r == '#' || r == '!' -} - -// isEndOfKey reports whether the rune terminates the current key. -func isEndOfKey(r rune) bool { - return strings.ContainsRune(" \f\t\r\n:=", r) -} - -// isEOF reports whether we are at EOF. -func isEOF(r rune) bool { - return r == eof -} - -// isEOL reports whether we are at a new line character. -func isEOL(r rune) bool { - return r == '\n' || r == '\r' -} - -// isEscape reports whether the rune is the escape character which -// prefixes unicode literals and other escaped characters. -func isEscape(r rune) bool { - return r == '\\' -} - -// isEscapedCharacter reports whether we are at one of the characters that need escaping. -// The escape character has already been consumed. -func isEscapedCharacter(r rune) bool { - return strings.ContainsRune(" :=fnrt", r) -} - -// isWhitespace reports whether the rune is a whitespace character. -func isWhitespace(r rune) bool { - return strings.ContainsRune(whitespace, r) -} diff --git a/vendor/github.com/magiconair/properties/load.go b/vendor/github.com/magiconair/properties/load.go deleted file mode 100644 index 3915c7397..000000000 --- a/vendor/github.com/magiconair/properties/load.go +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright 2016 Frank Schroeder. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package properties - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "os" - "strings" -) - -// Encoding specifies encoding of the input data. -type Encoding uint - -const ( - // UTF8 interprets the input data as UTF-8. - UTF8 Encoding = 1 << iota - - // ISO_8859_1 interprets the input data as ISO-8859-1. - ISO_8859_1 -) - -// Load reads a buffer into a Properties struct. -func Load(buf []byte, enc Encoding) (*Properties, error) { - return loadBuf(buf, enc) -} - -// LoadString reads an UTF8 string into a properties struct. -func LoadString(s string) (*Properties, error) { - return loadBuf([]byte(s), UTF8) -} - -// LoadFile reads a file into a Properties struct. -func LoadFile(filename string, enc Encoding) (*Properties, error) { - return loadFiles([]string{filename}, enc, false) -} - -// LoadFiles reads multiple files in the given order into -// a Properties struct. If 'ignoreMissing' is true then -// non-existent files will not be reported as error. -func LoadFiles(filenames []string, enc Encoding, ignoreMissing bool) (*Properties, error) { - return loadFiles(filenames, enc, ignoreMissing) -} - -// LoadURL reads the content of the URL into a Properties struct. -// -// The encoding is determined via the Content-Type header which -// should be set to 'text/plain'. If the 'charset' parameter is -// missing, 'iso-8859-1' or 'latin1' the encoding is set to -// ISO-8859-1. If the 'charset' parameter is set to 'utf-8' the -// encoding is set to UTF-8. A missing content type header is -// interpreted as 'text/plain; charset=utf-8'. -func LoadURL(url string) (*Properties, error) { - return loadURLs([]string{url}, false) -} - -// LoadURLs reads the content of multiple URLs in the given order into a -// Properties struct. If 'ignoreMissing' is true then a 404 status code will -// not be reported as error. See LoadURL for the Content-Type header -// and the encoding. -func LoadURLs(urls []string, ignoreMissing bool) (*Properties, error) { - return loadURLs(urls, ignoreMissing) -} - -// MustLoadString reads an UTF8 string into a Properties struct and -// panics on error. -func MustLoadString(s string) *Properties { - return must(LoadString(s)) -} - -// MustLoadFile reads a file into a Properties struct and -// panics on error. -func MustLoadFile(filename string, enc Encoding) *Properties { - return must(LoadFile(filename, enc)) -} - -// MustLoadFiles reads multiple files in the given order into -// a Properties struct and panics on error. If 'ignoreMissing' -// is true then non-existent files will not be reported as error. -func MustLoadFiles(filenames []string, enc Encoding, ignoreMissing bool) *Properties { - return must(LoadFiles(filenames, enc, ignoreMissing)) -} - -// MustLoadURL reads the content of a URL into a Properties struct and -// panics on error. -func MustLoadURL(url string) *Properties { - return must(LoadURL(url)) -} - -// MustLoadFiles reads the content of multiple URLs in the given order into a -// Properties struct and panics on error. If 'ignoreMissing' is true then a 404 -// status code will not be reported as error. -func MustLoadURLs(urls []string, ignoreMissing bool) *Properties { - return must(LoadURLs(urls, ignoreMissing)) -} - -func loadBuf(buf []byte, enc Encoding) (*Properties, error) { - p, err := parse(convert(buf, enc)) - if err != nil { - return nil, err - } - return p, p.check() -} - -func loadFiles(filenames []string, enc Encoding, ignoreMissing bool) (*Properties, error) { - var buf bytes.Buffer - for _, filename := range filenames { - f, err := expandFilename(filename) - if err != nil { - return nil, err - } - - data, err := ioutil.ReadFile(f) - if err != nil { - if ignoreMissing && os.IsNotExist(err) { - LogPrintf("properties: %s not found. skipping", filename) - continue - } - return nil, err - } - - // concatenate the buffers and add a new line in case - // the previous file didn't end with a new line - buf.Write(data) - buf.WriteRune('\n') - } - return loadBuf(buf.Bytes(), enc) -} - -func loadURLs(urls []string, ignoreMissing bool) (*Properties, error) { - var buf bytes.Buffer - for _, u := range urls { - resp, err := http.Get(u) - if err != nil { - return nil, fmt.Errorf("properties: error fetching %q. %s", u, err) - } - if resp.StatusCode == 404 && ignoreMissing { - LogPrintf("properties: %s returned %d. skipping", u, resp.StatusCode) - continue - } - if resp.StatusCode != 200 { - return nil, fmt.Errorf("properties: %s returned %d", u, resp.StatusCode) - } - body, err := ioutil.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - return nil, fmt.Errorf("properties: %s error reading response. %s", u, err) - } - - ct := resp.Header.Get("Content-Type") - var enc Encoding - switch strings.ToLower(ct) { - case "text/plain", "text/plain; charset=iso-8859-1", "text/plain; charset=latin1": - enc = ISO_8859_1 - case "", "text/plain; charset=utf-8": - enc = UTF8 - default: - return nil, fmt.Errorf("properties: invalid content type %s", ct) - } - - buf.WriteString(convert(body, enc)) - buf.WriteRune('\n') - } - return loadBuf(buf.Bytes(), UTF8) -} - -func must(p *Properties, err error) *Properties { - if err != nil { - ErrorHandler(err) - } - return p -} - -// expandFilename expands ${ENV_VAR} expressions in a filename. -// If the environment variable does not exist then it will be replaced -// with an empty string. Malformed expressions like "${ENV_VAR" will -// be reported as error. -func expandFilename(filename string) (string, error) { - return expand(filename, make(map[string]bool), "${", "}", make(map[string]string)) -} - -// Interprets a byte buffer either as an ISO-8859-1 or UTF-8 encoded string. -// For ISO-8859-1 we can convert each byte straight into a rune since the -// first 256 unicode code points cover ISO-8859-1. -func convert(buf []byte, enc Encoding) string { - switch enc { - case UTF8: - return string(buf) - case ISO_8859_1: - runes := make([]rune, len(buf)) - for i, b := range buf { - runes[i] = rune(b) - } - return string(runes) - default: - ErrorHandler(fmt.Errorf("unsupported encoding %v", enc)) - } - panic("ErrorHandler should exit") -} diff --git a/vendor/github.com/magiconair/properties/load_test.go b/vendor/github.com/magiconair/properties/load_test.go deleted file mode 100644 index f95b94838..000000000 --- a/vendor/github.com/magiconair/properties/load_test.go +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright 2016 Frank Schroeder. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package properties - -import ( - "fmt" - "io/ioutil" - "net/http" - "net/http/httptest" - "os" - "strings" - - . "github.com/magiconair/properties/_third_party/gopkg.in/check.v1" -) - -type LoadSuite struct { - tempFiles []string -} - -var _ = Suite(&LoadSuite{}) - -func (s *LoadSuite) TestLoadFailsWithNotExistingFile(c *C) { - _, err := LoadFile("doesnotexist.properties", ISO_8859_1) - c.Assert(err, NotNil) - c.Assert(err, ErrorMatches, "open.*no such file or directory") -} - -func (s *LoadSuite) TestLoadFilesFailsOnNotExistingFile(c *C) { - _, err := LoadFiles([]string{"doesnotexist.properties"}, ISO_8859_1, false) - c.Assert(err, NotNil) - c.Assert(err, ErrorMatches, "open.*no such file or directory") -} - -func (s *LoadSuite) TestLoadFilesDoesNotFailOnNotExistingFileAndIgnoreMissing(c *C) { - p, err := LoadFiles([]string{"doesnotexist.properties"}, ISO_8859_1, true) - c.Assert(err, IsNil) - c.Assert(p.Len(), Equals, 0) -} - -func (s *LoadSuite) TestLoadString(c *C) { - x := "key=รครผรถ" - p1 := MustLoadString(x) - p2 := must(Load([]byte(x), UTF8)) - c.Assert(p1, DeepEquals, p2) -} - -func (s *LoadSuite) TestLoadFile(c *C) { - filename := s.makeFile(c, "key=value") - p := MustLoadFile(filename, ISO_8859_1) - - c.Assert(p.Len(), Equals, 1) - assertKeyValues(c, "", p, "key", "value") -} - -func (s *LoadSuite) TestLoadFiles(c *C) { - filename := s.makeFile(c, "key=value") - filename2 := s.makeFile(c, "key2=value2") - p := MustLoadFiles([]string{filename, filename2}, ISO_8859_1, false) - assertKeyValues(c, "", p, "key", "value", "key2", "value2") -} - -func (s *LoadSuite) TestLoadExpandedFile(c *C) { - filename := s.makeFilePrefix(c, os.Getenv("USER"), "key=value") - filename = strings.Replace(filename, os.Getenv("USER"), "${USER}", -1) - p := MustLoadFile(filename, ISO_8859_1) - assertKeyValues(c, "", p, "key", "value") -} - -func (s *LoadSuite) TestLoadFilesAndIgnoreMissing(c *C) { - filename := s.makeFile(c, "key=value") - filename2 := s.makeFile(c, "key2=value2") - p := MustLoadFiles([]string{filename, filename + "foo", filename2, filename2 + "foo"}, ISO_8859_1, true) - assertKeyValues(c, "", p, "key", "value", "key2", "value2") -} - -func (s *LoadSuite) TestLoadURL(c *C) { - srv := testServer() - defer srv.Close() - p := MustLoadURL(srv.URL + "/a") - assertKeyValues(c, "", p, "key", "value") -} - -func (s *LoadSuite) TestLoadURLs(c *C) { - srv := testServer() - defer srv.Close() - p := MustLoadURLs([]string{srv.URL + "/a", srv.URL + "/b"}, false) - assertKeyValues(c, "", p, "key", "value", "key2", "value2") -} - -func (s *LoadSuite) TestLoadURLsAndFailMissing(c *C) { - srv := testServer() - defer srv.Close() - p, err := LoadURLs([]string{srv.URL + "/a", srv.URL + "/c"}, false) - c.Assert(p, IsNil) - c.Assert(err, ErrorMatches, ".*returned 404.*") -} - -func (s *LoadSuite) TestLoadURLsAndIgnoreMissing(c *C) { - srv := testServer() - defer srv.Close() - p := MustLoadURLs([]string{srv.URL + "/a", srv.URL + "/b", srv.URL + "/c"}, true) - assertKeyValues(c, "", p, "key", "value", "key2", "value2") -} - -func (s *LoadSuite) TestLoadURLEncoding(c *C) { - srv := testServer() - defer srv.Close() - - uris := []string{"/none", "/utf8", "/plain", "/latin1", "/iso88591"} - for i, uri := range uris { - p := MustLoadURL(srv.URL + uri) - c.Assert(p.GetString("key", ""), Equals, "รครถรผ", Commentf("%d", i)) - } -} - -func (s *LoadSuite) TestLoadURLFailInvalidEncoding(c *C) { - srv := testServer() - defer srv.Close() - - p, err := LoadURL(srv.URL + "/json") - c.Assert(p, IsNil) - c.Assert(err, ErrorMatches, ".*invalid content type.*") -} - -func (s *LoadSuite) SetUpSuite(c *C) { - s.tempFiles = make([]string, 0) -} - -func (s *LoadSuite) TearDownSuite(c *C) { - for _, path := range s.tempFiles { - err := os.Remove(path) - if err != nil { - fmt.Printf("os.Remove: %v", err) - } - } -} - -func (s *LoadSuite) makeFile(c *C, data string) string { - return s.makeFilePrefix(c, "properties", data) -} - -func (s *LoadSuite) makeFilePrefix(c *C, prefix, data string) string { - f, err := ioutil.TempFile("", prefix) - if err != nil { - fmt.Printf("ioutil.TempFile: %v", err) - c.FailNow() - } - - // remember the temp file so that we can remove it later - s.tempFiles = append(s.tempFiles, f.Name()) - - n, err := fmt.Fprint(f, data) - if err != nil { - fmt.Printf("fmt.Fprintln: %v", err) - c.FailNow() - } - if n != len(data) { - fmt.Printf("Data size mismatch. expected=%d wrote=%d\n", len(data), n) - c.FailNow() - } - - err = f.Close() - if err != nil { - fmt.Printf("f.Close: %v", err) - c.FailNow() - } - - return f.Name() -} - -func testServer() *httptest.Server { - return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - send := func(data []byte, contentType string) { - w.Header().Set("Content-Type", contentType) - w.Write(data) - } - - utf8 := []byte("key=รครถรผ") - iso88591 := []byte{0x6b, 0x65, 0x79, 0x3d, 0xe4, 0xf6, 0xfc} // key=รครถรผ - - switch r.RequestURI { - case "/a": - send([]byte("key=value"), "") - case "/b": - send([]byte("key2=value2"), "") - case "/none": - send(utf8, "") - case "/utf8": - send(utf8, "text/plain; charset=utf-8") - case "/json": - send(utf8, "application/json; charset=utf-8") - case "/plain": - send(iso88591, "text/plain") - case "/latin1": - send(iso88591, "text/plain; charset=latin1") - case "/iso88591": - send(iso88591, "text/plain; charset=iso-8859-1") - default: - w.WriteHeader(404) - } - })) -} diff --git a/vendor/github.com/magiconair/properties/parser.go b/vendor/github.com/magiconair/properties/parser.go deleted file mode 100644 index ff0e1e157..000000000 --- a/vendor/github.com/magiconair/properties/parser.go +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2016 Frank Schroeder. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package properties - -import ( - "fmt" - "runtime" -) - -type parser struct { - lex *lexer -} - -func parse(input string) (properties *Properties, err error) { - p := &parser{lex: lex(input)} - defer p.recover(&err) - - properties = NewProperties() - key := "" - comments := []string{} - - for { - token := p.expectOneOf(itemComment, itemKey, itemEOF) - switch token.typ { - case itemEOF: - goto done - case itemComment: - comments = append(comments, token.val) - continue - case itemKey: - key = token.val - if _, ok := properties.m[key]; !ok { - properties.k = append(properties.k, key) - } - } - - token = p.expectOneOf(itemValue, itemEOF) - if len(comments) > 0 { - properties.c[key] = comments - comments = []string{} - } - switch token.typ { - case itemEOF: - properties.m[key] = "" - goto done - case itemValue: - properties.m[key] = token.val - } - } - -done: - return properties, nil -} - -func (p *parser) errorf(format string, args ...interface{}) { - format = fmt.Sprintf("properties: Line %d: %s", p.lex.lineNumber(), format) - panic(fmt.Errorf(format, args...)) -} - -func (p *parser) expect(expected itemType) (token item) { - token = p.lex.nextItem() - if token.typ != expected { - p.unexpected(token) - } - return token -} - -func (p *parser) expectOneOf(expected ...itemType) (token item) { - token = p.lex.nextItem() - for _, v := range expected { - if token.typ == v { - return token - } - } - p.unexpected(token) - panic("unexpected token") -} - -func (p *parser) unexpected(token item) { - p.errorf(token.String()) -} - -// recover is the handler that turns panics into returns from the top level of Parse. -func (p *parser) recover(errp *error) { - e := recover() - if e != nil { - if _, ok := e.(runtime.Error); ok { - panic(e) - } - *errp = e.(error) - } - return -} diff --git a/vendor/github.com/magiconair/properties/properties.go b/vendor/github.com/magiconair/properties/properties.go deleted file mode 100644 index 884ef4e07..000000000 --- a/vendor/github.com/magiconair/properties/properties.go +++ /dev/null @@ -1,750 +0,0 @@ -// Copyright 2016 Frank Schroeder. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package properties - -// BUG(frank): Set() does not check for invalid unicode literals since this is currently handled by the lexer. -// BUG(frank): Write() does not allow to configure the newline character. Therefore, on Windows LF is used. - -import ( - "fmt" - "io" - "log" - "os" - "regexp" - "strconv" - "strings" - "time" - "unicode/utf8" -) - -// ErrorHandlerFunc defines the type of function which handles failures -// of the MustXXX() functions. An error handler function must exit -// the application after handling the error. -type ErrorHandlerFunc func(error) - -// ErrorHandler is the function which handles failures of the MustXXX() -// functions. The default is LogFatalHandler. -var ErrorHandler ErrorHandlerFunc = LogFatalHandler - -type LogHandlerFunc func(fmt string, args ...interface{}) - -var LogPrintf LogHandlerFunc = log.Printf - -// LogFatalHandler handles the error by logging a fatal error and exiting. -func LogFatalHandler(err error) { - log.Fatal(err) -} - -// PanicHandler handles the error by panicking. -func PanicHandler(err error) { - panic(err) -} - -// ----------------------------------------------------------------------------- - -// A Properties contains the key/value pairs from the properties input. -// All values are stored in unexpanded form and are expanded at runtime -type Properties struct { - // Pre-/Postfix for property expansion. - Prefix string - Postfix string - - // DisableExpansion controls the expansion of properties on Get() - // and the check for circular references on Set(). When set to - // true Properties behaves like a simple key/value store and does - // not check for circular references on Get() or on Set(). - DisableExpansion bool - - // Stores the key/value pairs - m map[string]string - - // Stores the comments per key. - c map[string][]string - - // Stores the keys in order of appearance. - k []string -} - -// NewProperties creates a new Properties struct with the default -// configuration for "${key}" expressions. -func NewProperties() *Properties { - return &Properties{ - Prefix: "${", - Postfix: "}", - m: map[string]string{}, - c: map[string][]string{}, - k: []string{}, - } -} - -// Get returns the expanded value for the given key if exists. -// Otherwise, ok is false. -func (p *Properties) Get(key string) (value string, ok bool) { - v, ok := p.m[key] - if p.DisableExpansion { - return v, ok - } - if !ok { - return "", false - } - - expanded, err := p.expand(v) - - // we guarantee that the expanded value is free of - // circular references and malformed expressions - // so we panic if we still get an error here. - if err != nil { - ErrorHandler(fmt.Errorf("%s in %q", err, key+" = "+v)) - } - - return expanded, true -} - -// MustGet returns the expanded value for the given key if exists. -// Otherwise, it panics. -func (p *Properties) MustGet(key string) string { - if v, ok := p.Get(key); ok { - return v - } - ErrorHandler(invalidKeyError(key)) - panic("ErrorHandler should exit") -} - -// ---------------------------------------------------------------------------- - -// ClearComments removes the comments for all keys. -func (p *Properties) ClearComments() { - p.c = map[string][]string{} -} - -// ---------------------------------------------------------------------------- - -// GetComment returns the last comment before the given key or an empty string. -func (p *Properties) GetComment(key string) string { - comments, ok := p.c[key] - if !ok || len(comments) == 0 { - return "" - } - return comments[len(comments)-1] -} - -// ---------------------------------------------------------------------------- - -// GetComments returns all comments that appeared before the given key or nil. -func (p *Properties) GetComments(key string) []string { - if comments, ok := p.c[key]; ok { - return comments - } - return nil -} - -// ---------------------------------------------------------------------------- - -// SetComment sets the comment for the key. -func (p *Properties) SetComment(key, comment string) { - p.c[key] = []string{comment} -} - -// ---------------------------------------------------------------------------- - -// SetComments sets the comments for the key. If the comments are nil then -// all comments for this key are deleted. -func (p *Properties) SetComments(key string, comments []string) { - if comments == nil { - delete(p.c, key) - return - } - p.c[key] = comments -} - -// ---------------------------------------------------------------------------- - -// GetBool checks if the expanded value is one of '1', 'yes', -// 'true' or 'on' if the key exists. The comparison is case-insensitive. -// If the key does not exist the default value is returned. -func (p *Properties) GetBool(key string, def bool) bool { - v, err := p.getBool(key) - if err != nil { - return def - } - return v -} - -// MustGetBool checks if the expanded value is one of '1', 'yes', -// 'true' or 'on' if the key exists. The comparison is case-insensitive. -// If the key does not exist the function panics. -func (p *Properties) MustGetBool(key string) bool { - v, err := p.getBool(key) - if err != nil { - ErrorHandler(err) - } - return v -} - -func (p *Properties) getBool(key string) (value bool, err error) { - if v, ok := p.Get(key); ok { - return boolVal(v), nil - } - return false, invalidKeyError(key) -} - -func boolVal(v string) bool { - v = strings.ToLower(v) - return v == "1" || v == "true" || v == "yes" || v == "on" -} - -// ---------------------------------------------------------------------------- - -// GetDuration parses the expanded value as an time.Duration (in ns) if the -// key exists. If key does not exist or the value cannot be parsed the default -// value is returned. In almost all cases you want to use GetParsedDuration(). -func (p *Properties) GetDuration(key string, def time.Duration) time.Duration { - v, err := p.getInt64(key) - if err != nil { - return def - } - return time.Duration(v) -} - -// MustGetDuration parses the expanded value as an time.Duration (in ns) if -// the key exists. If key does not exist or the value cannot be parsed the -// function panics. In almost all cases you want to use MustGetParsedDuration(). -func (p *Properties) MustGetDuration(key string) time.Duration { - v, err := p.getInt64(key) - if err != nil { - ErrorHandler(err) - } - return time.Duration(v) -} - -// ---------------------------------------------------------------------------- - -// GetParsedDuration parses the expanded value with time.ParseDuration() if the key exists. -// If key does not exist or the value cannot be parsed the default -// value is returned. -func (p *Properties) GetParsedDuration(key string, def time.Duration) time.Duration { - s, ok := p.Get(key) - if !ok { - return def - } - v, err := time.ParseDuration(s) - if err != nil { - return def - } - return v -} - -// MustGetParsedDuration parses the expanded value with time.ParseDuration() if the key exists. -// If key does not exist or the value cannot be parsed the function panics. -func (p *Properties) MustGetParsedDuration(key string) time.Duration { - s, ok := p.Get(key) - if !ok { - ErrorHandler(invalidKeyError(key)) - } - v, err := time.ParseDuration(s) - if err != nil { - ErrorHandler(err) - } - return v -} - -// ---------------------------------------------------------------------------- - -// GetFloat64 parses the expanded value as a float64 if the key exists. -// If key does not exist or the value cannot be parsed the default -// value is returned. -func (p *Properties) GetFloat64(key string, def float64) float64 { - v, err := p.getFloat64(key) - if err != nil { - return def - } - return v -} - -// MustGetFloat64 parses the expanded value as a float64 if the key exists. -// If key does not exist or the value cannot be parsed the function panics. -func (p *Properties) MustGetFloat64(key string) float64 { - v, err := p.getFloat64(key) - if err != nil { - ErrorHandler(err) - } - return v -} - -func (p *Properties) getFloat64(key string) (value float64, err error) { - if v, ok := p.Get(key); ok { - value, err = strconv.ParseFloat(v, 64) - if err != nil { - return 0, err - } - return value, nil - } - return 0, invalidKeyError(key) -} - -// ---------------------------------------------------------------------------- - -// GetInt parses the expanded value as an int if the key exists. -// If key does not exist or the value cannot be parsed the default -// value is returned. If the value does not fit into an int the -// function panics with an out of range error. -func (p *Properties) GetInt(key string, def int) int { - v, err := p.getInt64(key) - if err != nil { - return def - } - return intRangeCheck(key, v) -} - -// MustGetInt parses the expanded value as an int if the key exists. -// If key does not exist or the value cannot be parsed the function panics. -// If the value does not fit into an int the function panics with -// an out of range error. -func (p *Properties) MustGetInt(key string) int { - v, err := p.getInt64(key) - if err != nil { - ErrorHandler(err) - } - return intRangeCheck(key, v) -} - -// ---------------------------------------------------------------------------- - -// GetInt64 parses the expanded value as an int64 if the key exists. -// If key does not exist or the value cannot be parsed the default -// value is returned. -func (p *Properties) GetInt64(key string, def int64) int64 { - v, err := p.getInt64(key) - if err != nil { - return def - } - return v -} - -// MustGetInt64 parses the expanded value as an int if the key exists. -// If key does not exist or the value cannot be parsed the function panics. -func (p *Properties) MustGetInt64(key string) int64 { - v, err := p.getInt64(key) - if err != nil { - ErrorHandler(err) - } - return v -} - -func (p *Properties) getInt64(key string) (value int64, err error) { - if v, ok := p.Get(key); ok { - value, err = strconv.ParseInt(v, 10, 64) - if err != nil { - return 0, err - } - return value, nil - } - return 0, invalidKeyError(key) -} - -// ---------------------------------------------------------------------------- - -// GetUint parses the expanded value as an uint if the key exists. -// If key does not exist or the value cannot be parsed the default -// value is returned. If the value does not fit into an int the -// function panics with an out of range error. -func (p *Properties) GetUint(key string, def uint) uint { - v, err := p.getUint64(key) - if err != nil { - return def - } - return uintRangeCheck(key, v) -} - -// MustGetUint parses the expanded value as an int if the key exists. -// If key does not exist or the value cannot be parsed the function panics. -// If the value does not fit into an int the function panics with -// an out of range error. -func (p *Properties) MustGetUint(key string) uint { - v, err := p.getUint64(key) - if err != nil { - ErrorHandler(err) - } - return uintRangeCheck(key, v) -} - -// ---------------------------------------------------------------------------- - -// GetUint64 parses the expanded value as an uint64 if the key exists. -// If key does not exist or the value cannot be parsed the default -// value is returned. -func (p *Properties) GetUint64(key string, def uint64) uint64 { - v, err := p.getUint64(key) - if err != nil { - return def - } - return v -} - -// MustGetUint64 parses the expanded value as an int if the key exists. -// If key does not exist or the value cannot be parsed the function panics. -func (p *Properties) MustGetUint64(key string) uint64 { - v, err := p.getUint64(key) - if err != nil { - ErrorHandler(err) - } - return v -} - -func (p *Properties) getUint64(key string) (value uint64, err error) { - if v, ok := p.Get(key); ok { - value, err = strconv.ParseUint(v, 10, 64) - if err != nil { - return 0, err - } - return value, nil - } - return 0, invalidKeyError(key) -} - -// ---------------------------------------------------------------------------- - -// GetString returns the expanded value for the given key if exists or -// the default value otherwise. -func (p *Properties) GetString(key, def string) string { - if v, ok := p.Get(key); ok { - return v - } - return def -} - -// MustGetString returns the expanded value for the given key if exists or -// panics otherwise. -func (p *Properties) MustGetString(key string) string { - if v, ok := p.Get(key); ok { - return v - } - ErrorHandler(invalidKeyError(key)) - panic("ErrorHandler should exit") -} - -// ---------------------------------------------------------------------------- - -// Filter returns a new properties object which contains all properties -// for which the key matches the pattern. -func (p *Properties) Filter(pattern string) (*Properties, error) { - re, err := regexp.Compile(pattern) - if err != nil { - return nil, err - } - - return p.FilterRegexp(re), nil -} - -// FilterRegexp returns a new properties object which contains all properties -// for which the key matches the regular expression. -func (p *Properties) FilterRegexp(re *regexp.Regexp) *Properties { - pp := NewProperties() - for _, k := range p.k { - if re.MatchString(k) { - pp.Set(k, p.m[k]) - } - } - return pp -} - -// FilterPrefix returns a new properties object with a subset of all keys -// with the given prefix. -func (p *Properties) FilterPrefix(prefix string) *Properties { - pp := NewProperties() - for _, k := range p.k { - if strings.HasPrefix(k, prefix) { - pp.Set(k, p.m[k]) - } - } - return pp -} - -// FilterStripPrefix returns a new properties object with a subset of all keys -// with the given prefix and the prefix removed from the keys. -func (p *Properties) FilterStripPrefix(prefix string) *Properties { - pp := NewProperties() - n := len(prefix) - for _, k := range p.k { - if len(k) > len(prefix) && strings.HasPrefix(k, prefix) { - pp.Set(k[n:], p.m[k]) - } - } - return pp -} - -// Len returns the number of keys. -func (p *Properties) Len() int { - return len(p.m) -} - -// Keys returns all keys in the same order as in the input. -func (p *Properties) Keys() []string { - keys := make([]string, len(p.k)) - for i, k := range p.k { - keys[i] = k - } - return keys -} - -// Set sets the property key to the corresponding value. -// If a value for key existed before then ok is true and prev -// contains the previous value. If the value contains a -// circular reference or a malformed expression then -// an error is returned. -// An empty key is silently ignored. -func (p *Properties) Set(key, value string) (prev string, ok bool, err error) { - if key == "" { - return "", false, nil - } - - // if expansion is disabled we allow circular references - if p.DisableExpansion { - prev, ok = p.Get(key) - p.m[key] = value - return prev, ok, nil - } - - // to check for a circular reference we temporarily need - // to set the new value. If there is an error then revert - // to the previous state. Only if all tests are successful - // then we add the key to the p.k list. - prev, ok = p.Get(key) - p.m[key] = value - - // now check for a circular reference - _, err = p.expand(value) - if err != nil { - - // revert to the previous state - if ok { - p.m[key] = prev - } else { - delete(p.m, key) - } - - return "", false, err - } - - if !ok { - p.k = append(p.k, key) - } - - return prev, ok, nil -} - -// MustSet sets the property key to the corresponding value. -// If a value for key existed before then ok is true and prev -// contains the previous value. An empty key is silently ignored. -func (p *Properties) MustSet(key, value string) (prev string, ok bool) { - prev, ok, err := p.Set(key, value) - if err != nil { - ErrorHandler(err) - } - return prev, ok -} - -// String returns a string of all expanded 'key = value' pairs. -func (p *Properties) String() string { - var s string - for _, key := range p.k { - value, _ := p.Get(key) - s = fmt.Sprintf("%s%s = %s\n", s, key, value) - } - return s -} - -// Write writes all unexpanded 'key = value' pairs to the given writer. -// Write returns the number of bytes written and any write error encountered. -func (p *Properties) Write(w io.Writer, enc Encoding) (n int, err error) { - return p.WriteComment(w, "", enc) -} - -// WriteComment writes all unexpanced 'key = value' pairs to the given writer. -// If prefix is not empty then comments are written with a blank line and the -// given prefix. The prefix should be either "# " or "! " to be compatible with -// the properties file format. Otherwise, the properties parser will not be -// able to read the file back in. It returns the number of bytes written and -// any write error encountered. -func (p *Properties) WriteComment(w io.Writer, prefix string, enc Encoding) (n int, err error) { - var x int - - for _, key := range p.k { - value := p.m[key] - - if prefix != "" { - if comments, ok := p.c[key]; ok { - // don't print comments if they are all empty - allEmpty := true - for _, c := range comments { - if c != "" { - allEmpty = false - break - } - } - - if !allEmpty { - // add a blank line between entries but not at the top - if len(comments) > 0 && n > 0 { - x, err = fmt.Fprintln(w) - if err != nil { - return - } - n += x - } - - for _, c := range comments { - x, err = fmt.Fprintf(w, "%s%s\n", prefix, encode(c, "", enc)) - if err != nil { - return - } - n += x - } - } - } - } - - x, err = fmt.Fprintf(w, "%s = %s\n", encode(key, " :", enc), encode(value, "", enc)) - if err != nil { - return - } - n += x - } - return -} - -// ---------------------------------------------------------------------------- - -// Delete removes the key and its comments. -func (p *Properties) Delete(key string) { - delete(p.m, key) - delete(p.c, key) - newKeys := []string{} - for _, k := range p.k { - if k != key { - newKeys = append(newKeys, key) - } - } - p.k = newKeys -} - -// ---------------------------------------------------------------------------- - -// check expands all values and returns an error if a circular reference or -// a malformed expression was found. -func (p *Properties) check() error { - for _, value := range p.m { - if _, err := p.expand(value); err != nil { - return err - } - } - return nil -} - -func (p *Properties) expand(input string) (string, error) { - // no pre/postfix -> nothing to expand - if p.Prefix == "" && p.Postfix == "" { - return input, nil - } - - return expand(input, make(map[string]bool), p.Prefix, p.Postfix, p.m) -} - -// expand recursively expands expressions of '(prefix)key(postfix)' to their corresponding values. -// The function keeps track of the keys that were already expanded and stops if it -// detects a circular reference or a malformed expression of the form '(prefix)key'. -func expand(s string, keys map[string]bool, prefix, postfix string, values map[string]string) (string, error) { - start := strings.Index(s, prefix) - if start == -1 { - return s, nil - } - - keyStart := start + len(prefix) - keyLen := strings.Index(s[keyStart:], postfix) - if keyLen == -1 { - return "", fmt.Errorf("malformed expression") - } - - end := keyStart + keyLen + len(postfix) - 1 - key := s[keyStart : keyStart+keyLen] - - // fmt.Printf("s:%q pp:%q start:%d end:%d keyStart:%d keyLen:%d key:%q\n", s, prefix + "..." + postfix, start, end, keyStart, keyLen, key) - - if _, ok := keys[key]; ok { - return "", fmt.Errorf("circular reference") - } - - val, ok := values[key] - if !ok { - val = os.Getenv(key) - } - - // remember that we've seen the key - keys[key] = true - - return expand(s[:start]+val+s[end+1:], keys, prefix, postfix, values) -} - -// encode encodes a UTF-8 string to ISO-8859-1 and escapes some characters. -func encode(s string, special string, enc Encoding) string { - switch enc { - case UTF8: - return encodeUtf8(s, special) - case ISO_8859_1: - return encodeIso(s, special) - default: - panic(fmt.Sprintf("unsupported encoding %v", enc)) - } -} - -func encodeUtf8(s string, special string) string { - v := "" - for pos := 0; pos < len(s); { - r, w := utf8.DecodeRuneInString(s[pos:]) - pos += w - v += escape(r, special) - } - return v -} - -func encodeIso(s string, special string) string { - var r rune - var w int - var v string - for pos := 0; pos < len(s); { - switch r, w = utf8.DecodeRuneInString(s[pos:]); { - case r < 1<<8: // single byte rune -> escape special chars only - v += escape(r, special) - case r < 1<<16: // two byte rune -> unicode literal - v += fmt.Sprintf("\\u%04x", r) - default: // more than two bytes per rune -> can't encode - v += "?" - } - pos += w - } - return v -} - -func escape(r rune, special string) string { - switch r { - case '\f': - return "\\f" - case '\n': - return "\\n" - case '\r': - return "\\r" - case '\t': - return "\\t" - default: - if strings.ContainsRune(special, r) { - return "\\" + string(r) - } - return string(r) - } -} - -func invalidKeyError(key string) error { - return fmt.Errorf("unknown property: %s", key) -} diff --git a/vendor/github.com/magiconair/properties/properties_test.go b/vendor/github.com/magiconair/properties/properties_test.go deleted file mode 100644 index c0af16e7e..000000000 --- a/vendor/github.com/magiconair/properties/properties_test.go +++ /dev/null @@ -1,906 +0,0 @@ -// Copyright 2016 Frank Schroeder. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package properties - -import ( - "bytes" - "flag" - "fmt" - "math" - "os" - "strings" - "testing" - "time" - - . "github.com/magiconair/properties/_third_party/gopkg.in/check.v1" -) - -func Test(t *testing.T) { TestingT(t) } - -type TestSuite struct { - prevHandler ErrorHandlerFunc -} - -var ( - _ = Suite(&TestSuite{}) - verbose = flag.Bool("verbose", false, "Verbose output") -) - -// -------------------------------------------------------------------- - -func (s *TestSuite) SetUpSuite(c *C) { - s.prevHandler = ErrorHandler - ErrorHandler = PanicHandler -} - -// -------------------------------------------------------------------- - -func (s *TestSuite) TearDownSuite(c *C) { - ErrorHandler = s.prevHandler -} - -// ---------------------------------------------------------------------------- - -// define test cases in the form of -// {"input", "key1", "value1", "key2", "value2", ...} -var complexTests = [][]string{ - // whitespace prefix - {" key=value", "key", "value"}, // SPACE prefix - {"\fkey=value", "key", "value"}, // FF prefix - {"\tkey=value", "key", "value"}, // TAB prefix - {" \f\tkey=value", "key", "value"}, // mix prefix - - // multiple keys - {"key1=value1\nkey2=value2\n", "key1", "value1", "key2", "value2"}, - {"key1=value1\rkey2=value2\r", "key1", "value1", "key2", "value2"}, - {"key1=value1\r\nkey2=value2\r\n", "key1", "value1", "key2", "value2"}, - - // blank lines - {"\nkey=value\n", "key", "value"}, - {"\rkey=value\r", "key", "value"}, - {"\r\nkey=value\r\n", "key", "value"}, - - // escaped chars in key - {"k\\ ey = value", "k ey", "value"}, - {"k\\:ey = value", "k:ey", "value"}, - {"k\\=ey = value", "k=ey", "value"}, - {"k\\fey = value", "k\fey", "value"}, - {"k\\ney = value", "k\ney", "value"}, - {"k\\rey = value", "k\rey", "value"}, - {"k\\tey = value", "k\tey", "value"}, - - // escaped chars in value - {"key = v\\ alue", "key", "v alue"}, - {"key = v\\:alue", "key", "v:alue"}, - {"key = v\\=alue", "key", "v=alue"}, - {"key = v\\falue", "key", "v\falue"}, - {"key = v\\nalue", "key", "v\nalue"}, - {"key = v\\ralue", "key", "v\ralue"}, - {"key = v\\talue", "key", "v\talue"}, - - // silently dropped escape character - {"k\\zey = value", "kzey", "value"}, - {"key = v\\zalue", "key", "vzalue"}, - - // unicode literals - {"key\\u2318 = value", "keyโŒ˜", "value"}, - {"k\\u2318ey = value", "kโŒ˜ey", "value"}, - {"key = value\\u2318", "key", "valueโŒ˜"}, - {"key = valu\\u2318e", "key", "valuโŒ˜e"}, - - // multiline values - {"key = valueA,\\\n valueB", "key", "valueA,valueB"}, // SPACE indent - {"key = valueA,\\\n\f\f\fvalueB", "key", "valueA,valueB"}, // FF indent - {"key = valueA,\\\n\t\t\tvalueB", "key", "valueA,valueB"}, // TAB indent - {"key = valueA,\\\n \f\tvalueB", "key", "valueA,valueB"}, // mix indent - - // comments - {"# this is a comment\n! and so is this\nkey1=value1\nkey#2=value#2\n\nkey!3=value!3\n# and another one\n! and the final one", "key1", "value1", "key#2", "value#2", "key!3", "value!3"}, - - // expansion tests - {"key=value\nkey2=${key}", "key", "value", "key2", "value"}, - {"key=value\nkey2=aa${key}", "key", "value", "key2", "aavalue"}, - {"key=value\nkey2=${key}bb", "key", "value", "key2", "valuebb"}, - {"key=value\nkey2=aa${key}bb", "key", "value", "key2", "aavaluebb"}, - {"key=value\nkey2=${key}\nkey3=${key2}", "key", "value", "key2", "value", "key3", "value"}, - {"key=${USER}", "key", os.Getenv("USER")}, - {"key=${USER}\nUSER=value", "key", "value", "USER", "value"}, -} - -// ---------------------------------------------------------------------------- - -var commentTests = []struct { - input, key, value string - comments []string -}{ - {"key=value", "key", "value", nil}, - {"#\nkey=value", "key", "value", []string{""}}, - {"#comment\nkey=value", "key", "value", []string{"comment"}}, - {"# comment\nkey=value", "key", "value", []string{"comment"}}, - {"# comment\nkey=value", "key", "value", []string{"comment"}}, - {"# comment\n\nkey=value", "key", "value", []string{"comment"}}, - {"# comment1\n# comment2\nkey=value", "key", "value", []string{"comment1", "comment2"}}, - {"# comment1\n\n# comment2\n\nkey=value", "key", "value", []string{"comment1", "comment2"}}, - {"!comment\nkey=value", "key", "value", []string{"comment"}}, - {"! comment\nkey=value", "key", "value", []string{"comment"}}, - {"! comment\nkey=value", "key", "value", []string{"comment"}}, - {"! comment\n\nkey=value", "key", "value", []string{"comment"}}, - {"! comment1\n! comment2\nkey=value", "key", "value", []string{"comment1", "comment2"}}, - {"! comment1\n\n! comment2\n\nkey=value", "key", "value", []string{"comment1", "comment2"}}, -} - -// ---------------------------------------------------------------------------- - -var errorTests = []struct { - input, msg string -}{ - // unicode literals - {"key\\u1 = value", "invalid unicode literal"}, - {"key\\u12 = value", "invalid unicode literal"}, - {"key\\u123 = value", "invalid unicode literal"}, - {"key\\u123g = value", "invalid unicode literal"}, - {"key\\u123", "invalid unicode literal"}, - - // circular references - {"key=${key}", "circular reference"}, - {"key1=${key2}\nkey2=${key1}", "circular reference"}, - - // malformed expressions - {"key=${ke", "malformed expression"}, - {"key=valu${ke", "malformed expression"}, -} - -// ---------------------------------------------------------------------------- - -var writeTests = []struct { - input, output, encoding string -}{ - // ISO-8859-1 tests - {"key = value", "key = value\n", "ISO-8859-1"}, - {"key = value \\\n continued", "key = value continued\n", "ISO-8859-1"}, - {"keyโŒ˜ = value", "key\\u2318 = value\n", "ISO-8859-1"}, - {"ke\\ \\:y = value", "ke\\ \\:y = value\n", "ISO-8859-1"}, - - // UTF-8 tests - {"key = value", "key = value\n", "UTF-8"}, - {"key = value \\\n continued", "key = value continued\n", "UTF-8"}, - {"keyโŒ˜ = valueโŒ˜", "keyโŒ˜ = valueโŒ˜\n", "UTF-8"}, - {"ke\\ \\:y = value", "ke\\ \\:y = value\n", "UTF-8"}, -} - -// ---------------------------------------------------------------------------- - -var writeCommentTests = []struct { - input, output, encoding string -}{ - // ISO-8859-1 tests - {"key = value", "key = value\n", "ISO-8859-1"}, - {"#\nkey = value", "key = value\n", "ISO-8859-1"}, - {"#\n#\n#\nkey = value", "key = value\n", "ISO-8859-1"}, - {"# comment\nkey = value", "# comment\nkey = value\n", "ISO-8859-1"}, - {"\n# comment\nkey = value", "# comment\nkey = value\n", "ISO-8859-1"}, - {"# comment\n\nkey = value", "# comment\nkey = value\n", "ISO-8859-1"}, - {"# comment1\n# comment2\nkey = value", "# comment1\n# comment2\nkey = value\n", "ISO-8859-1"}, - {"#comment1\nkey1 = value1\n#comment2\nkey2 = value2", "# comment1\nkey1 = value1\n\n# comment2\nkey2 = value2\n", "ISO-8859-1"}, - - // UTF-8 tests - {"key = value", "key = value\n", "UTF-8"}, - {"# commentโŒ˜\nkey = valueโŒ˜", "# commentโŒ˜\nkey = valueโŒ˜\n", "UTF-8"}, - {"\n# commentโŒ˜\nkey = valueโŒ˜", "# commentโŒ˜\nkey = valueโŒ˜\n", "UTF-8"}, - {"# commentโŒ˜\n\nkey = valueโŒ˜", "# commentโŒ˜\nkey = valueโŒ˜\n", "UTF-8"}, - {"# comment1โŒ˜\n# comment2โŒ˜\nkey = valueโŒ˜", "# comment1โŒ˜\n# comment2โŒ˜\nkey = valueโŒ˜\n", "UTF-8"}, - {"#comment1โŒ˜\nkey1 = value1โŒ˜\n#comment2โŒ˜\nkey2 = value2โŒ˜", "# comment1โŒ˜\nkey1 = value1โŒ˜\n\n# comment2โŒ˜\nkey2 = value2โŒ˜\n", "UTF-8"}, -} - -// ---------------------------------------------------------------------------- - -var boolTests = []struct { - input, key string - def, value bool -}{ - // valid values for TRUE - {"key = 1", "key", false, true}, - {"key = on", "key", false, true}, - {"key = On", "key", false, true}, - {"key = ON", "key", false, true}, - {"key = true", "key", false, true}, - {"key = True", "key", false, true}, - {"key = TRUE", "key", false, true}, - {"key = yes", "key", false, true}, - {"key = Yes", "key", false, true}, - {"key = YES", "key", false, true}, - - // valid values for FALSE (all other) - {"key = 0", "key", true, false}, - {"key = off", "key", true, false}, - {"key = false", "key", true, false}, - {"key = no", "key", true, false}, - - // non existent key - {"key = true", "key2", false, false}, -} - -// ---------------------------------------------------------------------------- - -var durationTests = []struct { - input, key string - def, value time.Duration -}{ - // valid values - {"key = 1", "key", 999, 1}, - {"key = 0", "key", 999, 0}, - {"key = -1", "key", 999, -1}, - {"key = 0123", "key", 999, 123}, - - // invalid values - {"key = 0xff", "key", 999, 999}, - {"key = 1.0", "key", 999, 999}, - {"key = a", "key", 999, 999}, - - // non existent key - {"key = 1", "key2", 999, 999}, -} - -// ---------------------------------------------------------------------------- - -var parsedDurationTests = []struct { - input, key string - def, value time.Duration -}{ - // valid values - {"key = -1ns", "key", 999, -1 * time.Nanosecond}, - {"key = 300ms", "key", 999, 300 * time.Millisecond}, - {"key = 5s", "key", 999, 5 * time.Second}, - {"key = 3h", "key", 999, 3 * time.Hour}, - {"key = 2h45m", "key", 999, 2*time.Hour + 45*time.Minute}, - - // invalid values - {"key = 0xff", "key", 999, 999}, - {"key = 1.0", "key", 999, 999}, - {"key = a", "key", 999, 999}, - {"key = 1", "key", 999, 999}, - {"key = 0", "key", 999, 0}, - - // non existent key - {"key = 1", "key2", 999, 999}, -} - -// ---------------------------------------------------------------------------- - -var floatTests = []struct { - input, key string - def, value float64 -}{ - // valid values - {"key = 1.0", "key", 999, 1.0}, - {"key = 0.0", "key", 999, 0.0}, - {"key = -1.0", "key", 999, -1.0}, - {"key = 1", "key", 999, 1}, - {"key = 0", "key", 999, 0}, - {"key = -1", "key", 999, -1}, - {"key = 0123", "key", 999, 123}, - - // invalid values - {"key = 0xff", "key", 999, 999}, - {"key = a", "key", 999, 999}, - - // non existent key - {"key = 1", "key2", 999, 999}, -} - -// ---------------------------------------------------------------------------- - -var int64Tests = []struct { - input, key string - def, value int64 -}{ - // valid values - {"key = 1", "key", 999, 1}, - {"key = 0", "key", 999, 0}, - {"key = -1", "key", 999, -1}, - {"key = 0123", "key", 999, 123}, - - // invalid values - {"key = 0xff", "key", 999, 999}, - {"key = 1.0", "key", 999, 999}, - {"key = a", "key", 999, 999}, - - // non existent key - {"key = 1", "key2", 999, 999}, -} - -// ---------------------------------------------------------------------------- - -var uint64Tests = []struct { - input, key string - def, value uint64 -}{ - // valid values - {"key = 1", "key", 999, 1}, - {"key = 0", "key", 999, 0}, - {"key = 0123", "key", 999, 123}, - - // invalid values - {"key = -1", "key", 999, 999}, - {"key = 0xff", "key", 999, 999}, - {"key = 1.0", "key", 999, 999}, - {"key = a", "key", 999, 999}, - - // non existent key - {"key = 1", "key2", 999, 999}, -} - -// ---------------------------------------------------------------------------- - -var stringTests = []struct { - input, key string - def, value string -}{ - // valid values - {"key = abc", "key", "def", "abc"}, - - // non existent key - {"key = abc", "key2", "def", "def"}, -} - -// ---------------------------------------------------------------------------- - -var keysTests = []struct { - input string - keys []string -}{ - {"", []string{}}, - {"key = abc", []string{"key"}}, - {"key = abc\nkey2=def", []string{"key", "key2"}}, - {"key2 = abc\nkey=def", []string{"key2", "key"}}, - {"key = abc\nkey=def", []string{"key"}}, -} - -// ---------------------------------------------------------------------------- - -var filterTests = []struct { - input string - pattern string - keys []string - err string -}{ - {"", "", []string{}, ""}, - {"", "abc", []string{}, ""}, - {"key=value", "", []string{"key"}, ""}, - {"key=value", "key=", []string{}, ""}, - {"key=value\nfoo=bar", "", []string{"foo", "key"}, ""}, - {"key=value\nfoo=bar", "f", []string{"foo"}, ""}, - {"key=value\nfoo=bar", "fo", []string{"foo"}, ""}, - {"key=value\nfoo=bar", "foo", []string{"foo"}, ""}, - {"key=value\nfoo=bar", "fooo", []string{}, ""}, - {"key=value\nkey2=value2\nfoo=bar", "ey", []string{"key", "key2"}, ""}, - {"key=value\nkey2=value2\nfoo=bar", "key", []string{"key", "key2"}, ""}, - {"key=value\nkey2=value2\nfoo=bar", "^key", []string{"key", "key2"}, ""}, - {"key=value\nkey2=value2\nfoo=bar", "^(key|foo)", []string{"foo", "key", "key2"}, ""}, - {"key=value\nkey2=value2\nfoo=bar", "[ abc", nil, "error parsing regexp.*"}, -} - -// ---------------------------------------------------------------------------- - -var filterPrefixTests = []struct { - input string - prefix string - keys []string -}{ - {"", "", []string{}}, - {"", "abc", []string{}}, - {"key=value", "", []string{"key"}}, - {"key=value", "key=", []string{}}, - {"key=value\nfoo=bar", "", []string{"foo", "key"}}, - {"key=value\nfoo=bar", "f", []string{"foo"}}, - {"key=value\nfoo=bar", "fo", []string{"foo"}}, - {"key=value\nfoo=bar", "foo", []string{"foo"}}, - {"key=value\nfoo=bar", "fooo", []string{}}, - {"key=value\nkey2=value2\nfoo=bar", "key", []string{"key", "key2"}}, -} - -// ---------------------------------------------------------------------------- - -var filterStripPrefixTests = []struct { - input string - prefix string - keys []string -}{ - {"", "", []string{}}, - {"", "abc", []string{}}, - {"key=value", "", []string{"key"}}, - {"key=value", "key=", []string{}}, - {"key=value\nfoo=bar", "", []string{"foo", "key"}}, - {"key=value\nfoo=bar", "f", []string{"foo"}}, - {"key=value\nfoo=bar", "fo", []string{"foo"}}, - {"key=value\nfoo=bar", "foo", []string{"foo"}}, - {"key=value\nfoo=bar", "fooo", []string{}}, - {"key=value\nkey2=value2\nfoo=bar", "key", []string{"key", "key2"}}, -} - -// ---------------------------------------------------------------------------- - -var setTests = []struct { - input string - key, value string - prev string - ok bool - err string - keys []string -}{ - {"", "", "", "", false, "", []string{}}, - {"", "key", "value", "", false, "", []string{"key"}}, - {"key=value", "key2", "value2", "", false, "", []string{"key", "key2"}}, - {"key=value", "abc", "value3", "", false, "", []string{"key", "abc"}}, - {"key=value", "key", "value3", "value", true, "", []string{"key"}}, -} - -// ---------------------------------------------------------------------------- - -// TestBasic tests basic single key/value combinations with all possible -// whitespace, delimiter and newline permutations. -func (s *TestSuite) TestBasic(c *C) { - testWhitespaceAndDelimiterCombinations(c, "key", "") - testWhitespaceAndDelimiterCombinations(c, "key", "value") - testWhitespaceAndDelimiterCombinations(c, "key", "value ") -} - -func (s *TestSuite) TestComplex(c *C) { - for _, test := range complexTests { - testKeyValue(c, test[0], test[1:]...) - } -} - -func (s *TestSuite) TestErrors(c *C) { - for _, test := range errorTests { - _, err := Load([]byte(test.input), ISO_8859_1) - c.Assert(err, NotNil) - c.Assert(strings.Contains(err.Error(), test.msg), Equals, true, Commentf("Expected %q got %q", test.msg, err.Error())) - } -} - -func (s *TestSuite) TestDisableExpansion(c *C) { - input := "key=value\nkey2=${key}" - p, err := parse(input) - p.DisableExpansion = true - c.Assert(err, IsNil) - c.Assert(p.MustGet("key"), Equals, "value") - c.Assert(p.MustGet("key2"), Equals, "${key}") - - // with expansion disabled we can introduce circular references - p.Set("keyA", "${keyB}") - p.Set("keyB", "${keyA}") - c.Assert(p.MustGet("keyA"), Equals, "${keyB}") - c.Assert(p.MustGet("keyB"), Equals, "${keyA}") -} - -func (s *TestSuite) TestMustGet(c *C) { - input := "key = value\nkey2 = ghi" - p, err := parse(input) - c.Assert(err, IsNil) - c.Assert(p.MustGet("key"), Equals, "value") - c.Assert(func() { p.MustGet("invalid") }, PanicMatches, "unknown property: invalid") -} - -func (s *TestSuite) TestGetBool(c *C) { - for _, test := range boolTests { - p, err := parse(test.input) - c.Assert(err, IsNil) - c.Assert(p.Len(), Equals, 1) - c.Assert(p.GetBool(test.key, test.def), Equals, test.value) - } -} - -func (s *TestSuite) TestMustGetBool(c *C) { - input := "key = true\nkey2 = ghi" - p, err := parse(input) - c.Assert(err, IsNil) - c.Assert(p.MustGetBool("key"), Equals, true) - c.Assert(func() { p.MustGetBool("invalid") }, PanicMatches, "unknown property: invalid") -} - -func (s *TestSuite) TestGetDuration(c *C) { - for _, test := range durationTests { - p, err := parse(test.input) - c.Assert(err, IsNil) - c.Assert(p.Len(), Equals, 1) - c.Assert(p.GetDuration(test.key, test.def), Equals, test.value) - } -} - -func (s *TestSuite) TestMustGetDuration(c *C) { - input := "key = 123\nkey2 = ghi" - p, err := parse(input) - c.Assert(err, IsNil) - c.Assert(p.MustGetDuration("key"), Equals, time.Duration(123)) - c.Assert(func() { p.MustGetDuration("key2") }, PanicMatches, "strconv.ParseInt: parsing.*") - c.Assert(func() { p.MustGetDuration("invalid") }, PanicMatches, "unknown property: invalid") -} - -func (s *TestSuite) TestGetParsedDuration(c *C) { - for _, test := range parsedDurationTests { - p, err := parse(test.input) - c.Assert(err, IsNil) - c.Assert(p.Len(), Equals, 1) - c.Assert(p.GetParsedDuration(test.key, test.def), Equals, test.value) - } -} - -func (s *TestSuite) TestMustGetParsedDuration(c *C) { - input := "key = 123ms\nkey2 = ghi" - p, err := parse(input) - c.Assert(err, IsNil) - c.Assert(p.MustGetParsedDuration("key"), Equals, 123*time.Millisecond) - c.Assert(func() { p.MustGetParsedDuration("key2") }, PanicMatches, "time: invalid duration ghi") - c.Assert(func() { p.MustGetParsedDuration("invalid") }, PanicMatches, "unknown property: invalid") -} - -func (s *TestSuite) TestGetFloat64(c *C) { - for _, test := range floatTests { - p, err := parse(test.input) - c.Assert(err, IsNil) - c.Assert(p.Len(), Equals, 1) - c.Assert(p.GetFloat64(test.key, test.def), Equals, test.value) - } -} - -func (s *TestSuite) TestMustGetFloat64(c *C) { - input := "key = 123\nkey2 = ghi" - p, err := parse(input) - c.Assert(err, IsNil) - c.Assert(p.MustGetFloat64("key"), Equals, float64(123)) - c.Assert(func() { p.MustGetFloat64("key2") }, PanicMatches, "strconv.ParseFloat: parsing.*") - c.Assert(func() { p.MustGetFloat64("invalid") }, PanicMatches, "unknown property: invalid") -} - -func (s *TestSuite) TestGetInt(c *C) { - for _, test := range int64Tests { - p, err := parse(test.input) - c.Assert(err, IsNil) - c.Assert(p.Len(), Equals, 1) - c.Assert(p.GetInt(test.key, int(test.def)), Equals, int(test.value)) - } -} - -func (s *TestSuite) TestMustGetInt(c *C) { - input := "key = 123\nkey2 = ghi" - p, err := parse(input) - c.Assert(err, IsNil) - c.Assert(p.MustGetInt("key"), Equals, int(123)) - c.Assert(func() { p.MustGetInt("key2") }, PanicMatches, "strconv.ParseInt: parsing.*") - c.Assert(func() { p.MustGetInt("invalid") }, PanicMatches, "unknown property: invalid") -} - -func (s *TestSuite) TestGetInt64(c *C) { - for _, test := range int64Tests { - p, err := parse(test.input) - c.Assert(err, IsNil) - c.Assert(p.Len(), Equals, 1) - c.Assert(p.GetInt64(test.key, test.def), Equals, test.value) - } -} - -func (s *TestSuite) TestMustGetInt64(c *C) { - input := "key = 123\nkey2 = ghi" - p, err := parse(input) - c.Assert(err, IsNil) - c.Assert(p.MustGetInt64("key"), Equals, int64(123)) - c.Assert(func() { p.MustGetInt64("key2") }, PanicMatches, "strconv.ParseInt: parsing.*") - c.Assert(func() { p.MustGetInt64("invalid") }, PanicMatches, "unknown property: invalid") -} - -func (s *TestSuite) TestGetUint(c *C) { - for _, test := range uint64Tests { - p, err := parse(test.input) - c.Assert(err, IsNil) - c.Assert(p.Len(), Equals, 1) - c.Assert(p.GetUint(test.key, uint(test.def)), Equals, uint(test.value)) - } -} - -func (s *TestSuite) TestMustGetUint(c *C) { - input := "key = 123\nkey2 = ghi" - p, err := parse(input) - c.Assert(err, IsNil) - c.Assert(p.MustGetUint("key"), Equals, uint(123)) - c.Assert(func() { p.MustGetUint64("key2") }, PanicMatches, "strconv.ParseUint: parsing.*") - c.Assert(func() { p.MustGetUint64("invalid") }, PanicMatches, "unknown property: invalid") -} - -func (s *TestSuite) TestGetUint64(c *C) { - for _, test := range uint64Tests { - p, err := parse(test.input) - c.Assert(err, IsNil) - c.Assert(p.Len(), Equals, 1) - c.Assert(p.GetUint64(test.key, test.def), Equals, test.value) - } -} - -func (s *TestSuite) TestMustGetUint64(c *C) { - input := "key = 123\nkey2 = ghi" - p, err := parse(input) - c.Assert(err, IsNil) - c.Assert(p.MustGetUint64("key"), Equals, uint64(123)) - c.Assert(func() { p.MustGetUint64("key2") }, PanicMatches, "strconv.ParseUint: parsing.*") - c.Assert(func() { p.MustGetUint64("invalid") }, PanicMatches, "unknown property: invalid") -} - -func (s *TestSuite) TestGetString(c *C) { - for _, test := range stringTests { - p, err := parse(test.input) - c.Assert(err, IsNil) - c.Assert(p.Len(), Equals, 1) - c.Assert(p.GetString(test.key, test.def), Equals, test.value) - } -} - -func (s *TestSuite) TestMustGetString(c *C) { - input := `key = value` - p, err := parse(input) - c.Assert(err, IsNil) - c.Assert(p.MustGetString("key"), Equals, "value") - c.Assert(func() { p.MustGetString("invalid") }, PanicMatches, "unknown property: invalid") -} - -func (s *TestSuite) TestComment(c *C) { - for _, test := range commentTests { - p, err := parse(test.input) - c.Assert(err, IsNil) - c.Assert(p.MustGetString(test.key), Equals, test.value) - c.Assert(p.GetComments(test.key), DeepEquals, test.comments) - if test.comments != nil { - c.Assert(p.GetComment(test.key), Equals, test.comments[len(test.comments)-1]) - } else { - c.Assert(p.GetComment(test.key), Equals, "") - } - - // test setting comments - if len(test.comments) > 0 { - // set single comment - p.ClearComments() - c.Assert(len(p.c), Equals, 0) - p.SetComment(test.key, test.comments[0]) - c.Assert(p.GetComment(test.key), Equals, test.comments[0]) - - // set multiple comments - p.ClearComments() - c.Assert(len(p.c), Equals, 0) - p.SetComments(test.key, test.comments) - c.Assert(p.GetComments(test.key), DeepEquals, test.comments) - - // clear comments for a key - p.SetComments(test.key, nil) - c.Assert(p.GetComment(test.key), Equals, "") - c.Assert(p.GetComments(test.key), IsNil) - } - } -} - -func (s *TestSuite) TestFilter(c *C) { - for _, test := range filterTests { - p, err := parse(test.input) - c.Assert(err, IsNil) - pp, err := p.Filter(test.pattern) - if err != nil { - c.Assert(err, ErrorMatches, test.err) - continue - } - c.Assert(pp, NotNil) - c.Assert(pp.Len(), Equals, len(test.keys)) - for _, key := range test.keys { - v1, ok1 := p.Get(key) - v2, ok2 := pp.Get(key) - c.Assert(ok1, Equals, true) - c.Assert(ok2, Equals, true) - c.Assert(v1, Equals, v2) - } - } -} - -func (s *TestSuite) TestFilterPrefix(c *C) { - for _, test := range filterPrefixTests { - p, err := parse(test.input) - c.Assert(err, IsNil) - pp := p.FilterPrefix(test.prefix) - c.Assert(pp, NotNil) - c.Assert(pp.Len(), Equals, len(test.keys)) - for _, key := range test.keys { - v1, ok1 := p.Get(key) - v2, ok2 := pp.Get(key) - c.Assert(ok1, Equals, true) - c.Assert(ok2, Equals, true) - c.Assert(v1, Equals, v2) - } - } -} - -func (s *TestSuite) TestKeys(c *C) { - for _, test := range keysTests { - p, err := parse(test.input) - c.Assert(err, IsNil) - c.Assert(p.Len(), Equals, len(test.keys)) - c.Assert(len(p.Keys()), Equals, len(test.keys)) - c.Assert(p.Keys(), DeepEquals, test.keys) - } -} - -func (s *TestSuite) TestSet(c *C) { - for _, test := range setTests { - p, err := parse(test.input) - c.Assert(err, IsNil) - prev, ok, err := p.Set(test.key, test.value) - if test.err != "" { - c.Assert(err, ErrorMatches, test.err) - continue - } - - c.Assert(err, IsNil) - c.Assert(ok, Equals, test.ok) - if ok { - c.Assert(prev, Equals, test.prev) - } - c.Assert(p.Keys(), DeepEquals, test.keys) - } -} - -func (s *TestSuite) TestMustSet(c *C) { - input := "key=${key}" - p, err := parse(input) - c.Assert(err, IsNil) - c.Assert(func() { p.MustSet("key", "${key}") }, PanicMatches, "circular reference .*") -} - -func (s *TestSuite) TestWrite(c *C) { - for _, test := range writeTests { - p, err := parse(test.input) - - buf := new(bytes.Buffer) - var n int - switch test.encoding { - case "UTF-8": - n, err = p.Write(buf, UTF8) - case "ISO-8859-1": - n, err = p.Write(buf, ISO_8859_1) - } - c.Assert(err, IsNil) - s := string(buf.Bytes()) - c.Assert(n, Equals, len(test.output), Commentf("input=%q expected=%q obtained=%q", test.input, test.output, s)) - c.Assert(s, Equals, test.output, Commentf("input=%q expected=%q obtained=%q", test.input, test.output, s)) - } -} - -func (s *TestSuite) TestWriteComment(c *C) { - for _, test := range writeCommentTests { - p, err := parse(test.input) - - buf := new(bytes.Buffer) - var n int - switch test.encoding { - case "UTF-8": - n, err = p.WriteComment(buf, "# ", UTF8) - case "ISO-8859-1": - n, err = p.WriteComment(buf, "# ", ISO_8859_1) - } - c.Assert(err, IsNil) - s := string(buf.Bytes()) - c.Assert(n, Equals, len(test.output), Commentf("input=%q expected=%q obtained=%q", test.input, test.output, s)) - c.Assert(s, Equals, test.output, Commentf("input=%q expected=%q obtained=%q", test.input, test.output, s)) - } -} - -func (s *TestSuite) TestCustomExpansionExpression(c *C) { - testKeyValuePrePostfix(c, "*[", "]*", "key=value\nkey2=*[key]*", "key", "value", "key2", "value") -} - -func (s *TestSuite) TestPanicOn32BitIntOverflow(c *C) { - is32Bit = true - var min, max int64 = math.MinInt32 - 1, math.MaxInt32 + 1 - input := fmt.Sprintf("min=%d\nmax=%d", min, max) - p, err := parse(input) - c.Assert(err, IsNil) - c.Assert(p.MustGetInt64("min"), Equals, min) - c.Assert(p.MustGetInt64("max"), Equals, max) - c.Assert(func() { p.MustGetInt("min") }, PanicMatches, ".* out of range") - c.Assert(func() { p.MustGetInt("max") }, PanicMatches, ".* out of range") -} - -func (s *TestSuite) TestPanicOn32BitUintOverflow(c *C) { - is32Bit = true - var max uint64 = math.MaxUint32 + 1 - input := fmt.Sprintf("max=%d", max) - p, err := parse(input) - c.Assert(err, IsNil) - c.Assert(p.MustGetUint64("max"), Equals, max) - c.Assert(func() { p.MustGetUint("max") }, PanicMatches, ".* out of range") -} - -func (s *TestSuite) TestDeleteKey(c *C) { - input := "#comments should also be gone\nkey=to-be-deleted\nsecond=key" - p, err := parse(input) - c.Assert(err, IsNil) - c.Check(len(p.m), Equals, 2) - c.Check(len(p.c), Equals, 1) - c.Check(len(p.k), Equals, 2) - p.Delete("key") - c.Check(len(p.m), Equals, 1) - c.Check(len(p.c), Equals, 0) - c.Check(len(p.k), Equals, 1) -} - -func (s *TestSuite) TestDeleteUnknownKey(c *C) { - input := "#comments should also be gone\nkey=to-be-deleted" - p, err := parse(input) - c.Assert(err, IsNil) - c.Check(len(p.m), Equals, 1) - c.Check(len(p.c), Equals, 1) - c.Check(len(p.k), Equals, 1) - p.Delete("wrong-key") - c.Check(len(p.m), Equals, 1) - c.Check(len(p.c), Equals, 1) - c.Check(len(p.k), Equals, 1) -} - -// ---------------------------------------------------------------------------- - -// tests all combinations of delimiters, leading and/or trailing whitespace and newlines. -func testWhitespaceAndDelimiterCombinations(c *C, key, value string) { - whitespace := []string{"", " ", "\f", "\t"} - delimiters := []string{"", " ", "=", ":"} - newlines := []string{"", "\r", "\n", "\r\n"} - for _, dl := range delimiters { - for _, ws1 := range whitespace { - for _, ws2 := range whitespace { - for _, nl := range newlines { - // skip the one case where there is nothing between a key and a value - if ws1 == "" && dl == "" && ws2 == "" && value != "" { - continue - } - - input := fmt.Sprintf("%s%s%s%s%s%s", key, ws1, dl, ws2, value, nl) - testKeyValue(c, input, key, value) - } - } - } - } -} - -// tests whether key/value pairs exist for a given input. -// keyvalues is expected to be an even number of strings of "key", "value", ... -func testKeyValue(c *C, input string, keyvalues ...string) { - testKeyValuePrePostfix(c, "${", "}", input, keyvalues...) -} - -// tests whether key/value pairs exist for a given input. -// keyvalues is expected to be an even number of strings of "key", "value", ... -func testKeyValuePrePostfix(c *C, prefix, postfix, input string, keyvalues ...string) { - printf("%q\n", input) - - p, err := Load([]byte(input), ISO_8859_1) - c.Assert(err, IsNil) - p.Prefix = prefix - p.Postfix = postfix - assertKeyValues(c, input, p, keyvalues...) -} - -// tests whether key/value pairs exist for a given input. -// keyvalues is expected to be an even number of strings of "key", "value", ... -func assertKeyValues(c *C, input string, p *Properties, keyvalues ...string) { - c.Assert(p, NotNil) - c.Assert(2*p.Len(), Equals, len(keyvalues), Commentf("Odd number of key/value pairs.")) - - for i := 0; i < len(keyvalues); i += 2 { - key, value := keyvalues[i], keyvalues[i+1] - v, ok := p.Get(key) - c.Assert(ok, Equals, true, Commentf("No key %q found (input=%q)", key, input)) - c.Assert(v, Equals, value, Commentf("Value %q does not match %q (input=%q)", v, value, input)) - } -} - -// prints to stderr if the -verbose flag was given. -func printf(format string, args ...interface{}) { - if *verbose { - fmt.Fprintf(os.Stderr, format, args...) - } -} diff --git a/vendor/github.com/magiconair/properties/rangecheck.go b/vendor/github.com/magiconair/properties/rangecheck.go deleted file mode 100644 index d9ce2806b..000000000 --- a/vendor/github.com/magiconair/properties/rangecheck.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2016 Frank Schroeder. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package properties - -import ( - "fmt" - "math" -) - -// make this a var to overwrite it in a test -var is32Bit = ^uint(0) == math.MaxUint32 - -// intRangeCheck checks if the value fits into the int type and -// panics if it does not. -func intRangeCheck(key string, v int64) int { - if is32Bit && (v < math.MinInt32 || v > math.MaxInt32) { - panic(fmt.Sprintf("Value %d for key %s out of range", v, key)) - } - return int(v) -} - -// uintRangeCheck checks if the value fits into the uint type and -// panics if it does not. -func uintRangeCheck(key string, v uint64) uint { - if is32Bit && v > math.MaxUint32 { - panic(fmt.Sprintf("Value %d for key %s out of range", v, key)) - } - return uint(v) -} diff --git a/vendor/github.com/modern-go/reflect2/reflect2.go b/vendor/github.com/modern-go/reflect2/reflect2.go index ac13ad615..ffb02fe41 100644 --- a/vendor/github.com/modern-go/reflect2/reflect2.go +++ b/vendor/github.com/modern-go/reflect2/reflect2.go @@ -283,3 +283,16 @@ func NoEscape(p unsafe.Pointer) unsafe.Pointer { x := uintptr(p) return unsafe.Pointer(x ^ 0) } +<<<<<<< HEAD +======= + +func UnsafeCastString(str string) []byte { + stringHeader := (*reflect.StringHeader)(unsafe.Pointer(&str)) + sliceHeader := &reflect.SliceHeader{ + Data: stringHeader.Data, + Cap: stringHeader.Len, + Len: stringHeader.Len, + } + return *(*[]byte)(unsafe.Pointer(sliceHeader)) +} +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ diff --git a/vendor/golang.org/x/net/icmp/diag_test.go b/vendor/golang.org/x/net/icmp/diag_test.go new file mode 100644 index 000000000..2ecd465a1 --- /dev/null +++ b/vendor/golang.org/x/net/icmp/diag_test.go @@ -0,0 +1,274 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package icmp_test + +import ( + "errors" + "fmt" + "net" + "os" + "runtime" + "sync" + "testing" + "time" + + "golang.org/x/net/icmp" + "golang.org/x/net/internal/iana" + "golang.org/x/net/internal/nettest" + "golang.org/x/net/ipv4" + "golang.org/x/net/ipv6" +) + +type diagTest struct { + network, address string + protocol int + m icmp.Message +} + +func TestDiag(t *testing.T) { + if testing.Short() { + t.Skip("avoid external network") + } + + t.Run("Ping/NonPrivileged", func(t *testing.T) { + switch runtime.GOOS { + case "darwin": + case "linux": + t.Log("you may need to adjust the net.ipv4.ping_group_range kernel state") + default: + t.Logf("not supported on %s", runtime.GOOS) + return + } + for i, dt := range []diagTest{ + { + "udp4", "0.0.0.0", iana.ProtocolICMP, + icmp.Message{ + Type: ipv4.ICMPTypeEcho, Code: 0, + Body: &icmp.Echo{ + ID: os.Getpid() & 0xffff, + Data: []byte("HELLO-R-U-THERE"), + }, + }, + }, + + { + "udp6", "::", iana.ProtocolIPv6ICMP, + icmp.Message{ + Type: ipv6.ICMPTypeEchoRequest, Code: 0, + Body: &icmp.Echo{ + ID: os.Getpid() & 0xffff, + Data: []byte("HELLO-R-U-THERE"), + }, + }, + }, + } { + if err := doDiag(dt, i); err != nil { + t.Error(err) + } + } + }) + t.Run("Ping/Privileged", func(t *testing.T) { + if m, ok := nettest.SupportsRawIPSocket(); !ok { + t.Skip(m) + } + for i, dt := range []diagTest{ + { + "ip4:icmp", "0.0.0.0", iana.ProtocolICMP, + icmp.Message{ + Type: ipv4.ICMPTypeEcho, Code: 0, + Body: &icmp.Echo{ + ID: os.Getpid() & 0xffff, + Data: []byte("HELLO-R-U-THERE"), + }, + }, + }, + + { + "ip6:ipv6-icmp", "::", iana.ProtocolIPv6ICMP, + icmp.Message{ + Type: ipv6.ICMPTypeEchoRequest, Code: 0, + Body: &icmp.Echo{ + ID: os.Getpid() & 0xffff, + Data: []byte("HELLO-R-U-THERE"), + }, + }, + }, + } { + if err := doDiag(dt, i); err != nil { + t.Error(err) + } + } + }) + t.Run("Probe/Privileged", func(t *testing.T) { + if m, ok := nettest.SupportsRawIPSocket(); !ok { + t.Skip(m) + } + for i, dt := range []diagTest{ + { + "ip4:icmp", "0.0.0.0", iana.ProtocolICMP, + icmp.Message{ + Type: ipv4.ICMPTypeExtendedEchoRequest, Code: 0, + Body: &icmp.ExtendedEchoRequest{ + ID: os.Getpid() & 0xffff, + Local: true, + Extensions: []icmp.Extension{ + &icmp.InterfaceIdent{ + Class: 3, Type: 1, + Name: "doesnotexist", + }, + }, + }, + }, + }, + + { + "ip6:ipv6-icmp", "::", iana.ProtocolIPv6ICMP, + icmp.Message{ + Type: ipv6.ICMPTypeExtendedEchoRequest, Code: 0, + Body: &icmp.ExtendedEchoRequest{ + ID: os.Getpid() & 0xffff, + Local: true, + Extensions: []icmp.Extension{ + &icmp.InterfaceIdent{ + Class: 3, Type: 1, + Name: "doesnotexist", + }, + }, + }, + }, + }, + } { + if err := doDiag(dt, i); err != nil { + t.Error(err) + } + } + }) +} + +func doDiag(dt diagTest, seq int) error { + c, err := icmp.ListenPacket(dt.network, dt.address) + if err != nil { + return err + } + defer c.Close() + + dst, err := googleAddr(c, dt.protocol) + if err != nil { + return err + } + + if dt.network != "udp6" && dt.protocol == iana.ProtocolIPv6ICMP { + var f ipv6.ICMPFilter + f.SetAll(true) + f.Accept(ipv6.ICMPTypeDestinationUnreachable) + f.Accept(ipv6.ICMPTypePacketTooBig) + f.Accept(ipv6.ICMPTypeTimeExceeded) + f.Accept(ipv6.ICMPTypeParameterProblem) + f.Accept(ipv6.ICMPTypeEchoReply) + f.Accept(ipv6.ICMPTypeExtendedEchoReply) + if err := c.IPv6PacketConn().SetICMPFilter(&f); err != nil { + return err + } + } + + switch m := dt.m.Body.(type) { + case *icmp.Echo: + m.Seq = 1 << uint(seq) + case *icmp.ExtendedEchoRequest: + m.Seq = 1 << uint(seq) + } + wb, err := dt.m.Marshal(nil) + if err != nil { + return err + } + if n, err := c.WriteTo(wb, dst); err != nil { + return err + } else if n != len(wb) { + return fmt.Errorf("got %v; want %v", n, len(wb)) + } + + rb := make([]byte, 1500) + if err := c.SetReadDeadline(time.Now().Add(3 * time.Second)); err != nil { + return err + } + n, peer, err := c.ReadFrom(rb) + if err != nil { + return err + } + rm, err := icmp.ParseMessage(dt.protocol, rb[:n]) + if err != nil { + return err + } + switch { + case dt.m.Type == ipv4.ICMPTypeEcho && rm.Type == ipv4.ICMPTypeEchoReply: + fallthrough + case dt.m.Type == ipv6.ICMPTypeEchoRequest && rm.Type == ipv6.ICMPTypeEchoReply: + fallthrough + case dt.m.Type == ipv4.ICMPTypeExtendedEchoRequest && rm.Type == ipv4.ICMPTypeExtendedEchoReply: + fallthrough + case dt.m.Type == ipv6.ICMPTypeExtendedEchoRequest && rm.Type == ipv6.ICMPTypeExtendedEchoReply: + return nil + default: + return fmt.Errorf("got %+v from %v; want echo reply or extended echo reply", rm, peer) + } +} + +func googleAddr(c *icmp.PacketConn, protocol int) (net.Addr, error) { + host := "ipv4.google.com" + if protocol == iana.ProtocolIPv6ICMP { + host = "ipv6.google.com" + } + ips, err := net.LookupIP(host) + if err != nil { + return nil, err + } + netaddr := func(ip net.IP) (net.Addr, error) { + switch c.LocalAddr().(type) { + case *net.UDPAddr: + return &net.UDPAddr{IP: ip}, nil + case *net.IPAddr: + return &net.IPAddr{IP: ip}, nil + default: + return nil, errors.New("neither UDPAddr nor IPAddr") + } + } + if len(ips) > 0 { + return netaddr(ips[0]) + } + return nil, errors.New("no A or AAAA record") +} + +func TestConcurrentNonPrivilegedListenPacket(t *testing.T) { + if testing.Short() { + t.Skip("avoid external network") + } + switch runtime.GOOS { + case "darwin": + case "linux": + t.Log("you may need to adjust the net.ipv4.ping_group_range kernel state") + default: + t.Skipf("not supported on %s", runtime.GOOS) + } + + network, address := "udp4", "127.0.0.1" + if !nettest.SupportsIPv4() { + network, address = "udp6", "::1" + } + const N = 1000 + var wg sync.WaitGroup + wg.Add(N) + for i := 0; i < N; i++ { + go func() { + defer wg.Done() + c, err := icmp.ListenPacket(network, address) + if err != nil { + t.Error(err) + return + } + c.Close() + }() + } + wg.Wait() +} diff --git a/vendor/golang.org/x/net/icmp/dstunreach.go b/vendor/golang.org/x/net/icmp/dstunreach.go index 75db991df..9318460fe 100644 --- a/vendor/golang.org/x/net/icmp/dstunreach.go +++ b/vendor/golang.org/x/net/icmp/dstunreach.go @@ -16,24 +16,40 @@ func (p *DstUnreach) Len(proto int) int { if p == nil { return 0 } +<<<<<<< HEAD l, _ := multipartMessageBodyDataLen(proto, p.Data, p.Extensions) +======= + l, _ := multipartMessageBodyDataLen(proto, true, p.Data, p.Extensions) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ return 4 + l } // Marshal implements the Marshal method of MessageBody interface. func (p *DstUnreach) Marshal(proto int) ([]byte, error) { +<<<<<<< HEAD return marshalMultipartMessageBody(proto, p.Data, p.Extensions) +======= + return marshalMultipartMessageBody(proto, true, p.Data, p.Extensions) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ } // parseDstUnreach parses b as an ICMP destination unreachable message // body. +<<<<<<< HEAD func parseDstUnreach(proto int, b []byte) (MessageBody, error) { +======= +func parseDstUnreach(proto int, typ Type, b []byte) (MessageBody, error) { +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ if len(b) < 4 { return nil, errMessageTooShort } p := &DstUnreach{} var err error +<<<<<<< HEAD p.Data, p.Extensions, err = parseMultipartMessageBody(proto, b) +======= + p.Data, p.Extensions, err = parseMultipartMessageBody(proto, typ, b) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ if err != nil { return nil, err } diff --git a/vendor/golang.org/x/net/icmp/echo.go b/vendor/golang.org/x/net/icmp/echo.go index e6f15efd7..21c00bb63 100644 --- a/vendor/golang.org/x/net/icmp/echo.go +++ b/vendor/golang.org/x/net/icmp/echo.go @@ -31,7 +31,11 @@ func (p *Echo) Marshal(proto int) ([]byte, error) { } // parseEcho parses b as an ICMP echo request or reply message body. +<<<<<<< HEAD func parseEcho(proto int, b []byte) (MessageBody, error) { +======= +func parseEcho(proto int, _ Type, b []byte) (MessageBody, error) { +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ bodyLen := len(b) if bodyLen < 4 { return nil, errMessageTooShort @@ -43,3 +47,118 @@ func parseEcho(proto int, b []byte) (MessageBody, error) { } return p, nil } +<<<<<<< HEAD +======= + +// An ExtendedEchoRequest represents an ICMP extended echo request +// message body. +type ExtendedEchoRequest struct { + ID int // identifier + Seq int // sequence number + Local bool // must be true when identifying by name or index + Extensions []Extension // extensions +} + +// Len implements the Len method of MessageBody interface. +func (p *ExtendedEchoRequest) Len(proto int) int { + if p == nil { + return 0 + } + l, _ := multipartMessageBodyDataLen(proto, false, nil, p.Extensions) + return 4 + l +} + +// Marshal implements the Marshal method of MessageBody interface. +func (p *ExtendedEchoRequest) Marshal(proto int) ([]byte, error) { + b, err := marshalMultipartMessageBody(proto, false, nil, p.Extensions) + if err != nil { + return nil, err + } + bb := make([]byte, 4) + binary.BigEndian.PutUint16(bb[:2], uint16(p.ID)) + bb[2] = byte(p.Seq) + if p.Local { + bb[3] |= 0x01 + } + bb = append(bb, b...) + return bb, nil +} + +// parseExtendedEchoRequest parses b as an ICMP extended echo request +// message body. +func parseExtendedEchoRequest(proto int, typ Type, b []byte) (MessageBody, error) { + if len(b) < 4+4 { + return nil, errMessageTooShort + } + p := &ExtendedEchoRequest{ID: int(binary.BigEndian.Uint16(b[:2])), Seq: int(b[2])} + if b[3]&0x01 != 0 { + p.Local = true + } + var err error + _, p.Extensions, err = parseMultipartMessageBody(proto, typ, b[4:]) + if err != nil { + return nil, err + } + return p, nil +} + +// An ExtendedEchoReply represents an ICMP extended echo reply message +// body. +type ExtendedEchoReply struct { + ID int // identifier + Seq int // sequence number + State int // 3-bit state working together with Message.Code + Active bool // probed interface is active + IPv4 bool // probed interface runs IPv4 + IPv6 bool // probed interface runs IPv6 +} + +// Len implements the Len method of MessageBody interface. +func (p *ExtendedEchoReply) Len(proto int) int { + if p == nil { + return 0 + } + return 4 +} + +// Marshal implements the Marshal method of MessageBody interface. +func (p *ExtendedEchoReply) Marshal(proto int) ([]byte, error) { + b := make([]byte, 4) + binary.BigEndian.PutUint16(b[:2], uint16(p.ID)) + b[2] = byte(p.Seq) + b[3] = byte(p.State<<5) & 0xe0 + if p.Active { + b[3] |= 0x04 + } + if p.IPv4 { + b[3] |= 0x02 + } + if p.IPv6 { + b[3] |= 0x01 + } + return b, nil +} + +// parseExtendedEchoReply parses b as an ICMP extended echo reply +// message body. +func parseExtendedEchoReply(proto int, _ Type, b []byte) (MessageBody, error) { + if len(b) < 4 { + return nil, errMessageTooShort + } + p := &ExtendedEchoReply{ + ID: int(binary.BigEndian.Uint16(b[:2])), + Seq: int(b[2]), + State: int(b[3]) >> 5, + } + if b[3]&0x04 != 0 { + p.Active = true + } + if b[3]&0x02 != 0 { + p.IPv4 = true + } + if b[3]&0x01 != 0 { + p.IPv6 = true + } + return p, nil +} +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ diff --git a/vendor/golang.org/x/net/icmp/extension.go b/vendor/golang.org/x/net/icmp/extension.go index 402a7514b..f56ec2782 100644 --- a/vendor/golang.org/x/net/icmp/extension.go +++ b/vendor/golang.org/x/net/icmp/extension.go @@ -4,7 +4,16 @@ package icmp +<<<<<<< HEAD import "encoding/binary" +======= +import ( + "encoding/binary" + + "golang.org/x/net/ipv4" + "golang.org/x/net/ipv6" +) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ // An Extension represents an ICMP extension. type Extension interface { @@ -38,7 +47,11 @@ func validExtensionHeader(b []byte) bool { // It will return a list of ICMP extensions and an adjusted length // attribute that represents the length of the padded original // datagram field. Otherwise, it returns an error. +<<<<<<< HEAD func parseExtensions(b []byte, l int) ([]Extension, int, error) { +======= +func parseExtensions(typ Type, b []byte, l int) ([]Extension, int, error) { +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ // Still a lot of non-RFC 4884 compliant implementations are // out there. Set the length attribute l to 128 when it looks // inappropriate for backwards compatibility. @@ -48,6 +61,7 @@ func parseExtensions(b []byte, l int) ([]Extension, int, error) { // header. // // See RFC 4884 for further information. +<<<<<<< HEAD if 128 > l || l+8 > len(b) { l = 128 } @@ -62,6 +76,30 @@ func parseExtensions(b []byte, l int) ([]Extension, int, error) { if !validExtensionHeader(b[l:]) { return nil, -1, errNoExtension } +======= + switch typ { + case ipv4.ICMPTypeExtendedEchoRequest, ipv6.ICMPTypeExtendedEchoRequest: + if len(b) < 8 || !validExtensionHeader(b) { + return nil, -1, errNoExtension + } + l = 0 + default: + if 128 > l || l+8 > len(b) { + l = 128 + } + if l+8 > len(b) { + return nil, -1, errNoExtension + } + if !validExtensionHeader(b[l:]) { + if l == 128 { + return nil, -1, errNoExtension + } + l = 128 + if !validExtensionHeader(b[l:]) { + return nil, -1, errNoExtension + } + } +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ } var exts []Extension for b = b[l+4:]; len(b) >= 4; { @@ -82,6 +120,15 @@ func parseExtensions(b []byte, l int) ([]Extension, int, error) { return nil, -1, err } exts = append(exts, ext) +<<<<<<< HEAD +======= + case classInterfaceIdent: + ext, err := parseInterfaceIdent(b[:ol]) + if err != nil { + return nil, -1, err + } + exts = append(exts, ext) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ } b = b[ol:] } diff --git a/vendor/golang.org/x/net/icmp/extension_test.go b/vendor/golang.org/x/net/icmp/extension_test.go index 0b3f7b9e1..b186ea964 100644 --- a/vendor/golang.org/x/net/icmp/extension_test.go +++ b/vendor/golang.org/x/net/icmp/extension_test.go @@ -5,11 +5,16 @@ package icmp import ( +<<<<<<< HEAD +======= + "fmt" +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ "net" "reflect" "testing" "golang.org/x/net/internal/iana" +<<<<<<< HEAD ) var marshalAndParseExtensionTests = []struct { @@ -247,11 +252,327 @@ var parseInterfaceNameTests = []struct { {[]byte{4, 'e', 'n', '0'}, nil}, {[]byte{7, 'e', 'n', '0', 0xff, 0xff, 0xff, 0xff}, errInvalidExtension}, {[]byte{8, 'e', 'n', '0', 0xff, 0xff, 0xff}, errMessageTooShort}, +======= + "golang.org/x/net/ipv4" + "golang.org/x/net/ipv6" +) + +func TestMarshalAndParseExtension(t *testing.T) { + fn := func(t *testing.T, proto int, typ Type, hdr, obj []byte, te Extension) error { + b, err := te.Marshal(proto) + if err != nil { + return err + } + if !reflect.DeepEqual(b, obj) { + return fmt.Errorf("got %#v; want %#v", b, obj) + } + switch typ { + case ipv4.ICMPTypeExtendedEchoRequest, ipv6.ICMPTypeExtendedEchoRequest: + exts, l, err := parseExtensions(typ, append(hdr, obj...), 0) + if err != nil { + return err + } + if l != 0 { + return fmt.Errorf("got %d; want 0", l) + } + if !reflect.DeepEqual(exts, []Extension{te}) { + return fmt.Errorf("got %#v; want %#v", exts[0], te) + } + default: + for i, wire := range []struct { + data []byte // original datagram + inlattr int // length of padded original datagram, a hint + outlattr int // length of padded original datagram, a want + err error + }{ + {nil, 0, -1, errNoExtension}, + {make([]byte, 127), 128, -1, errNoExtension}, + + {make([]byte, 128), 127, -1, errNoExtension}, + {make([]byte, 128), 128, -1, errNoExtension}, + {make([]byte, 128), 129, -1, errNoExtension}, + + {append(make([]byte, 128), append(hdr, obj...)...), 127, 128, nil}, + {append(make([]byte, 128), append(hdr, obj...)...), 128, 128, nil}, + {append(make([]byte, 128), append(hdr, obj...)...), 129, 128, nil}, + + {append(make([]byte, 512), append(hdr, obj...)...), 511, -1, errNoExtension}, + {append(make([]byte, 512), append(hdr, obj...)...), 512, 512, nil}, + {append(make([]byte, 512), append(hdr, obj...)...), 513, -1, errNoExtension}, + } { + exts, l, err := parseExtensions(typ, wire.data, wire.inlattr) + if err != wire.err { + return fmt.Errorf("#%d: got %v; want %v", i, err, wire.err) + } + if wire.err != nil { + continue + } + if l != wire.outlattr { + return fmt.Errorf("#%d: got %d; want %d", i, l, wire.outlattr) + } + if !reflect.DeepEqual(exts, []Extension{te}) { + return fmt.Errorf("#%d: got %#v; want %#v", i, exts[0], te) + } + } + } + return nil + } + + t.Run("MPLSLabelStack", func(t *testing.T) { + for _, et := range []struct { + proto int + typ Type + hdr []byte + obj []byte + ext Extension + }{ + // MPLS label stack with no label + { + proto: iana.ProtocolICMP, + typ: ipv4.ICMPTypeDestinationUnreachable, + hdr: []byte{ + 0x20, 0x00, 0x00, 0x00, + }, + obj: []byte{ + 0x00, 0x04, 0x01, 0x01, + }, + ext: &MPLSLabelStack{ + Class: classMPLSLabelStack, + Type: typeIncomingMPLSLabelStack, + }, + }, + // MPLS label stack with a single label + { + proto: iana.ProtocolIPv6ICMP, + typ: ipv6.ICMPTypeDestinationUnreachable, + hdr: []byte{ + 0x20, 0x00, 0x00, 0x00, + }, + obj: []byte{ + 0x00, 0x08, 0x01, 0x01, + 0x03, 0xe8, 0xe9, 0xff, + }, + ext: &MPLSLabelStack{ + Class: classMPLSLabelStack, + Type: typeIncomingMPLSLabelStack, + Labels: []MPLSLabel{ + { + Label: 16014, + TC: 0x4, + S: true, + TTL: 255, + }, + }, + }, + }, + // MPLS label stack with multiple labels + { + proto: iana.ProtocolICMP, + typ: ipv4.ICMPTypeDestinationUnreachable, + hdr: []byte{ + 0x20, 0x00, 0x00, 0x00, + }, + obj: []byte{ + 0x00, 0x0c, 0x01, 0x01, + 0x03, 0xe8, 0xde, 0xfe, + 0x03, 0xe8, 0xe1, 0xff, + }, + ext: &MPLSLabelStack{ + Class: classMPLSLabelStack, + Type: typeIncomingMPLSLabelStack, + Labels: []MPLSLabel{ + { + Label: 16013, + TC: 0x7, + S: false, + TTL: 254, + }, + { + Label: 16014, + TC: 0, + S: true, + TTL: 255, + }, + }, + }, + }, + } { + if err := fn(t, et.proto, et.typ, et.hdr, et.obj, et.ext); err != nil { + t.Error(err) + } + } + }) + t.Run("InterfaceInfo", func(t *testing.T) { + for _, et := range []struct { + proto int + typ Type + hdr []byte + obj []byte + ext Extension + }{ + // Interface information with no attribute + { + proto: iana.ProtocolICMP, + typ: ipv4.ICMPTypeDestinationUnreachable, + hdr: []byte{ + 0x20, 0x00, 0x00, 0x00, + }, + obj: []byte{ + 0x00, 0x04, 0x02, 0x00, + }, + ext: &InterfaceInfo{ + Class: classInterfaceInfo, + }, + }, + // Interface information with ifIndex and name + { + proto: iana.ProtocolICMP, + typ: ipv4.ICMPTypeDestinationUnreachable, + hdr: []byte{ + 0x20, 0x00, 0x00, 0x00, + }, + obj: []byte{ + 0x00, 0x10, 0x02, 0x0a, + 0x00, 0x00, 0x00, 0x10, + 0x08, byte('e'), byte('n'), byte('1'), + byte('0'), byte('1'), 0x00, 0x00, + }, + ext: &InterfaceInfo{ + Class: classInterfaceInfo, + Type: 0x0a, + Interface: &net.Interface{ + Index: 16, + Name: "en101", + }, + }, + }, + // Interface information with ifIndex, IPAddr, name and MTU + { + proto: iana.ProtocolIPv6ICMP, + typ: ipv6.ICMPTypeDestinationUnreachable, + hdr: []byte{ + 0x20, 0x00, 0x00, 0x00, + }, + obj: []byte{ + 0x00, 0x28, 0x02, 0x0f, + 0x00, 0x00, 0x00, 0x0f, + 0x00, 0x02, 0x00, 0x00, + 0xfe, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, + 0x08, byte('e'), byte('n'), byte('1'), + byte('0'), byte('1'), 0x00, 0x00, + 0x00, 0x00, 0x20, 0x00, + }, + ext: &InterfaceInfo{ + Class: classInterfaceInfo, + Type: 0x0f, + Interface: &net.Interface{ + Index: 15, + Name: "en101", + MTU: 8192, + }, + Addr: &net.IPAddr{ + IP: net.ParseIP("fe80::1"), + Zone: "en101", + }, + }, + }, + } { + if err := fn(t, et.proto, et.typ, et.hdr, et.obj, et.ext); err != nil { + t.Error(err) + } + } + }) + t.Run("InterfaceIdent", func(t *testing.T) { + for _, et := range []struct { + proto int + typ Type + hdr []byte + obj []byte + ext Extension + }{ + // Interface identification by name + { + proto: iana.ProtocolICMP, + typ: ipv4.ICMPTypeExtendedEchoRequest, + hdr: []byte{ + 0x20, 0x00, 0x00, 0x00, + }, + obj: []byte{ + 0x00, 0x0c, 0x03, 0x01, + byte('e'), byte('n'), byte('1'), byte('0'), + byte('1'), 0x00, 0x00, 0x00, + }, + ext: &InterfaceIdent{ + Class: classInterfaceIdent, + Type: typeInterfaceByName, + Name: "en101", + }, + }, + // Interface identification by index + { + proto: iana.ProtocolIPv6ICMP, + typ: ipv6.ICMPTypeExtendedEchoRequest, + hdr: []byte{ + 0x20, 0x00, 0x00, 0x00, + }, + obj: []byte{ + 0x00, 0x0c, 0x03, 0x02, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x03, 0x8f, + }, + ext: &InterfaceIdent{ + Class: classInterfaceIdent, + Type: typeInterfaceByIndex, + Index: 911, + }, + }, + // Interface identification by address + { + proto: iana.ProtocolICMP, + typ: ipv4.ICMPTypeExtendedEchoRequest, + hdr: []byte{ + 0x20, 0x00, 0x00, 0x00, + }, + obj: []byte{ + 0x00, 0x10, 0x03, 0x03, + byte(iana.AddrFamily48bitMAC >> 8), byte(iana.AddrFamily48bitMAC & 0x0f), 0x06, 0x00, + 0x01, 0x23, 0x45, 0x67, + 0x89, 0xab, 0x00, 0x00, + }, + ext: &InterfaceIdent{ + Class: classInterfaceIdent, + Type: typeInterfaceByAddress, + AFI: iana.AddrFamily48bitMAC, + Addr: []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab}, + }, + }, + } { + if err := fn(t, et.proto, et.typ, et.hdr, et.obj, et.ext); err != nil { + t.Error(err) + } + } + }) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ } func TestParseInterfaceName(t *testing.T) { ifi := InterfaceInfo{Interface: &net.Interface{}} +<<<<<<< HEAD for i, tt := range parseInterfaceNameTests { +======= + for i, tt := range []struct { + b []byte + error + }{ + {[]byte{0, 'e', 'n', '0'}, errInvalidExtension}, + {[]byte{4, 'e', 'n', '0'}, nil}, + {[]byte{7, 'e', 'n', '0', 0xff, 0xff, 0xff, 0xff}, errInvalidExtension}, + {[]byte{8, 'e', 'n', '0', 0xff, 0xff, 0xff}, errMessageTooShort}, + } { +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ if _, err := ifi.parseName(tt.b); err != tt.error { t.Errorf("#%d: got %v; want %v", i, err, tt.error) } diff --git a/vendor/golang.org/x/net/icmp/interface.go b/vendor/golang.org/x/net/icmp/interface.go index 78b5b98bf..ca542ecf2 100644 --- a/vendor/golang.org/x/net/icmp/interface.go +++ b/vendor/golang.org/x/net/icmp/interface.go @@ -14,9 +14,12 @@ import ( const ( classInterfaceInfo = 2 +<<<<<<< HEAD afiIPv4 = 1 afiIPv6 = 2 +======= +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ ) const ( @@ -127,11 +130,19 @@ func (ifi *InterfaceInfo) parseIfIndex(b []byte) ([]byte, error) { func (ifi *InterfaceInfo) marshalIPAddr(proto int, b []byte) []byte { switch proto { case iana.ProtocolICMP: +<<<<<<< HEAD binary.BigEndian.PutUint16(b[:2], uint16(afiIPv4)) copy(b[4:4+net.IPv4len], ifi.Addr.IP.To4()) b = b[4+net.IPv4len:] case iana.ProtocolIPv6ICMP: binary.BigEndian.PutUint16(b[:2], uint16(afiIPv6)) +======= + binary.BigEndian.PutUint16(b[:2], uint16(iana.AddrFamilyIPv4)) + copy(b[4:4+net.IPv4len], ifi.Addr.IP.To4()) + b = b[4+net.IPv4len:] + case iana.ProtocolIPv6ICMP: + binary.BigEndian.PutUint16(b[:2], uint16(iana.AddrFamilyIPv6)) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ copy(b[4:4+net.IPv6len], ifi.Addr.IP.To16()) b = b[4+net.IPv6len:] } @@ -145,14 +156,22 @@ func (ifi *InterfaceInfo) parseIPAddr(b []byte) ([]byte, error) { afi := int(binary.BigEndian.Uint16(b[:2])) b = b[4:] switch afi { +<<<<<<< HEAD case afiIPv4: +======= + case iana.AddrFamilyIPv4: +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ if len(b) < net.IPv4len { return nil, errMessageTooShort } ifi.Addr.IP = make(net.IP, net.IPv4len) copy(ifi.Addr.IP, b[:net.IPv4len]) b = b[net.IPv4len:] +<<<<<<< HEAD case afiIPv6: +======= + case iana.AddrFamilyIPv6: +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ if len(b) < net.IPv6len { return nil, errMessageTooShort } @@ -234,3 +253,95 @@ func parseInterfaceInfo(b []byte) (Extension, error) { } return ifi, nil } +<<<<<<< HEAD +======= + +const ( + classInterfaceIdent = 3 + typeInterfaceByName = 1 + typeInterfaceByIndex = 2 + typeInterfaceByAddress = 3 +) + +// An InterfaceIdent represents interface identification. +type InterfaceIdent struct { + Class int // extension object class number + Type int // extension object sub-type + Name string // interface name + Index int // interface index + AFI int // address family identifier; see address family numbers in IANA registry + Addr []byte // address +} + +// Len implements the Len method of Extension interface. +func (ifi *InterfaceIdent) Len(_ int) int { + switch ifi.Type { + case typeInterfaceByName: + l := len(ifi.Name) + if l > 255 { + l = 255 + } + return 4 + (l+3)&^3 + case typeInterfaceByIndex: + return 4 + 8 + case typeInterfaceByAddress: + return 4 + 4 + (len(ifi.Addr)+3)&^3 + default: + return 4 + } +} + +// Marshal implements the Marshal method of Extension interface. +func (ifi *InterfaceIdent) Marshal(proto int) ([]byte, error) { + b := make([]byte, ifi.Len(proto)) + if err := ifi.marshal(proto, b); err != nil { + return nil, err + } + return b, nil +} + +func (ifi *InterfaceIdent) marshal(proto int, b []byte) error { + l := ifi.Len(proto) + binary.BigEndian.PutUint16(b[:2], uint16(l)) + b[2], b[3] = classInterfaceIdent, byte(ifi.Type) + switch ifi.Type { + case typeInterfaceByName: + copy(b[4:], ifi.Name) + case typeInterfaceByIndex: + binary.BigEndian.PutUint64(b[4:4+8], uint64(ifi.Index)) + case typeInterfaceByAddress: + binary.BigEndian.PutUint16(b[4:4+2], uint16(ifi.AFI)) + b[4+2] = byte(len(ifi.Addr)) + copy(b[4+4:], ifi.Addr) + } + return nil +} + +func parseInterfaceIdent(b []byte) (Extension, error) { + ifi := &InterfaceIdent{ + Class: int(b[2]), + Type: int(b[3]), + } + switch ifi.Type { + case typeInterfaceByName: + ifi.Name = strings.Trim(string(b[4:]), string(0)) + case typeInterfaceByIndex: + if len(b[4:]) < 8 { + return nil, errInvalidExtension + } + ifi.Index = int(binary.BigEndian.Uint64(b[4 : 4+8])) + case typeInterfaceByAddress: + if len(b[4:]) < 4 { + return nil, errInvalidExtension + } + ifi.AFI = int(binary.BigEndian.Uint16(b[4 : 4+2])) + l := int(b[4+2]) + if len(b[4+4:]) < l { + return nil, errInvalidExtension + } + ifi.Addr = make([]byte, l) + copy(ifi.Addr, b[4+4:]) + } + return ifi, nil +} +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ diff --git a/vendor/golang.org/x/net/icmp/ipv4_test.go b/vendor/golang.org/x/net/icmp/ipv4_test.go index 058953f43..df3fb5ecb 100644 --- a/vendor/golang.org/x/net/icmp/ipv4_test.go +++ b/vendor/golang.org/x/net/icmp/ipv4_test.go @@ -15,6 +15,7 @@ import ( "golang.org/x/net/ipv4" ) +<<<<<<< HEAD type ipv4HeaderTest struct { wireHeaderFromKernel [ipv4.HeaderLen]byte wireHeaderFromTradBSDKernel [ipv4.HeaderLen]byte @@ -79,5 +80,63 @@ func TestParseIPv4Header(t *testing.T) { } if !reflect.DeepEqual(h, tt.Header) { t.Fatalf("got %#v; want %#v", h, tt.Header) +======= +func TestParseIPv4Header(t *testing.T) { + switch socket.NativeEndian { + case binary.LittleEndian: + t.Run("LittleEndian", func(t *testing.T) { + // TODO(mikio): Add platform dependent wire + // header formats when we support new + // platforms. + wireHeaderFromKernel := [ipv4.HeaderLen]byte{ + 0x45, 0x01, 0xbe, 0xef, + 0xca, 0xfe, 0x45, 0xdc, + 0xff, 0x01, 0xde, 0xad, + 172, 16, 254, 254, + 192, 168, 0, 1, + } + wireHeaderFromTradBSDKernel := [ipv4.HeaderLen]byte{ + 0x45, 0x01, 0xef, 0xbe, + 0xca, 0xfe, 0x45, 0xdc, + 0xff, 0x01, 0xde, 0xad, + 172, 16, 254, 254, + 192, 168, 0, 1, + } + th := &ipv4.Header{ + Version: ipv4.Version, + Len: ipv4.HeaderLen, + TOS: 1, + TotalLen: 0xbeef, + ID: 0xcafe, + Flags: ipv4.DontFragment, + FragOff: 1500, + TTL: 255, + Protocol: 1, + Checksum: 0xdead, + Src: net.IPv4(172, 16, 254, 254), + Dst: net.IPv4(192, 168, 0, 1), + } + var wh []byte + switch runtime.GOOS { + case "darwin": + wh = wireHeaderFromTradBSDKernel[:] + case "freebsd": + if freebsdVersion >= 1000000 { + wh = wireHeaderFromKernel[:] + } else { + wh = wireHeaderFromTradBSDKernel[:] + } + default: + wh = wireHeaderFromKernel[:] + } + h, err := ParseIPv4Header(wh) + if err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(h, th) { + t.Fatalf("got %#v; want %#v", h, th) + } + }) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ } } diff --git a/vendor/golang.org/x/net/icmp/message.go b/vendor/golang.org/x/net/icmp/message.go index 81140b0df..aad9ab0be 100644 --- a/vendor/golang.org/x/net/icmp/message.go +++ b/vendor/golang.org/x/net/icmp/message.go @@ -11,6 +11,10 @@ // ICMP extensions for MPLS are defined in RFC 4950. // ICMP extensions for interface and next-hop identification are // defined in RFC 5837. +<<<<<<< HEAD +======= +// PROBE: A utility for probing interfaces is defined in RFC 8335. +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ package icmp // import "golang.org/x/net/icmp" import ( @@ -107,21 +111,39 @@ func (m *Message) Marshal(psh []byte) ([]byte, error) { return b[len(psh):], nil } +<<<<<<< HEAD var parseFns = map[Type]func(int, []byte) (MessageBody, error){ +======= +var parseFns = map[Type]func(int, Type, []byte) (MessageBody, error){ +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ ipv4.ICMPTypeDestinationUnreachable: parseDstUnreach, ipv4.ICMPTypeTimeExceeded: parseTimeExceeded, ipv4.ICMPTypeParameterProblem: parseParamProb, +<<<<<<< HEAD ipv4.ICMPTypeEcho: parseEcho, ipv4.ICMPTypeEchoReply: parseEcho, +======= + ipv4.ICMPTypeEcho: parseEcho, + ipv4.ICMPTypeEchoReply: parseEcho, + ipv4.ICMPTypeExtendedEchoRequest: parseExtendedEchoRequest, + ipv4.ICMPTypeExtendedEchoReply: parseExtendedEchoReply, +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ ipv6.ICMPTypeDestinationUnreachable: parseDstUnreach, ipv6.ICMPTypePacketTooBig: parsePacketTooBig, ipv6.ICMPTypeTimeExceeded: parseTimeExceeded, ipv6.ICMPTypeParameterProblem: parseParamProb, +<<<<<<< HEAD ipv6.ICMPTypeEchoRequest: parseEcho, ipv6.ICMPTypeEchoReply: parseEcho, +======= + ipv6.ICMPTypeEchoRequest: parseEcho, + ipv6.ICMPTypeEchoReply: parseEcho, + ipv6.ICMPTypeExtendedEchoRequest: parseExtendedEchoRequest, + ipv6.ICMPTypeExtendedEchoReply: parseExtendedEchoReply, +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ } // ParseMessage parses b as an ICMP message. @@ -143,7 +165,11 @@ func ParseMessage(proto int, b []byte) (*Message, error) { if fn, ok := parseFns[m.Type]; !ok { m.Body, err = parseDefaultMessageBody(proto, b[4:]) } else { +<<<<<<< HEAD m.Body, err = fn(proto, b[4:]) +======= + m.Body, err = fn(proto, m.Type, b[4:]) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ } if err != nil { return nil, err diff --git a/vendor/golang.org/x/net/icmp/message_test.go b/vendor/golang.org/x/net/icmp/message_test.go index 5d2605f8d..b8afa8dfb 100644 --- a/vendor/golang.org/x/net/icmp/message_test.go +++ b/vendor/golang.org/x/net/icmp/message_test.go @@ -15,6 +15,7 @@ import ( "golang.org/x/net/ipv6" ) +<<<<<<< HEAD var marshalAndParseMessageForIPv4Tests = []icmp.Message{ { Type: ipv4.ICMPTypeDestinationUnreachable, Code: 15, @@ -131,4 +132,143 @@ func TestMarshalAndParseMessageForIPv6(t *testing.T) { } } } +======= +func TestMarshalAndParseMessage(t *testing.T) { + fn := func(t *testing.T, proto int, tms []icmp.Message) { + var pshs [][]byte + switch proto { + case iana.ProtocolICMP: + pshs = [][]byte{nil} + case iana.ProtocolIPv6ICMP: + pshs = [][]byte{ + icmp.IPv6PseudoHeader(net.ParseIP("fe80::1"), net.ParseIP("ff02::1")), + nil, + } + } + for i, tm := range tms { + for _, psh := range pshs { + b, err := tm.Marshal(psh) + if err != nil { + t.Fatal(err) + } + m, err := icmp.ParseMessage(proto, b) + if err != nil { + t.Fatal(err) + } + if m.Type != tm.Type || m.Code != tm.Code { + t.Errorf("#%d: got %#v; want %#v", i, m, &tm) + } + if !reflect.DeepEqual(m.Body, tm.Body) { + t.Errorf("#%d: got %#v; want %#v", i, m.Body, tm.Body) + } + } + } + } + + t.Run("IPv4", func(t *testing.T) { + fn(t, iana.ProtocolICMP, + []icmp.Message{ + { + Type: ipv4.ICMPTypeDestinationUnreachable, Code: 15, + Body: &icmp.DstUnreach{ + Data: []byte("ERROR-INVOKING-PACKET"), + }, + }, + { + Type: ipv4.ICMPTypeTimeExceeded, Code: 1, + Body: &icmp.TimeExceeded{ + Data: []byte("ERROR-INVOKING-PACKET"), + }, + }, + { + Type: ipv4.ICMPTypeParameterProblem, Code: 2, + Body: &icmp.ParamProb{ + Pointer: 8, + Data: []byte("ERROR-INVOKING-PACKET"), + }, + }, + { + Type: ipv4.ICMPTypeEcho, Code: 0, + Body: &icmp.Echo{ + ID: 1, Seq: 2, + Data: []byte("HELLO-R-U-THERE"), + }, + }, + { + Type: ipv4.ICMPTypeExtendedEchoRequest, Code: 0, + Body: &icmp.ExtendedEchoRequest{ + ID: 1, Seq: 2, + }, + }, + { + Type: ipv4.ICMPTypeExtendedEchoReply, Code: 0, + Body: &icmp.ExtendedEchoReply{ + State: 4 /* Delay */, Active: true, IPv4: true, + }, + }, + { + Type: ipv4.ICMPTypePhoturis, + Body: &icmp.DefaultMessageBody{ + Data: []byte{0x80, 0x40, 0x20, 0x10}, + }, + }, + }) + }) + t.Run("IPv6", func(t *testing.T) { + fn(t, iana.ProtocolIPv6ICMP, + []icmp.Message{ + { + Type: ipv6.ICMPTypeDestinationUnreachable, Code: 6, + Body: &icmp.DstUnreach{ + Data: []byte("ERROR-INVOKING-PACKET"), + }, + }, + { + Type: ipv6.ICMPTypePacketTooBig, Code: 0, + Body: &icmp.PacketTooBig{ + MTU: 1<<16 - 1, + Data: []byte("ERROR-INVOKING-PACKET"), + }, + }, + { + Type: ipv6.ICMPTypeTimeExceeded, Code: 1, + Body: &icmp.TimeExceeded{ + Data: []byte("ERROR-INVOKING-PACKET"), + }, + }, + { + Type: ipv6.ICMPTypeParameterProblem, Code: 2, + Body: &icmp.ParamProb{ + Pointer: 8, + Data: []byte("ERROR-INVOKING-PACKET"), + }, + }, + { + Type: ipv6.ICMPTypeEchoRequest, Code: 0, + Body: &icmp.Echo{ + ID: 1, Seq: 2, + Data: []byte("HELLO-R-U-THERE"), + }, + }, + { + Type: ipv6.ICMPTypeExtendedEchoRequest, Code: 0, + Body: &icmp.ExtendedEchoRequest{ + ID: 1, Seq: 2, + }, + }, + { + Type: ipv6.ICMPTypeExtendedEchoReply, Code: 0, + Body: &icmp.ExtendedEchoReply{ + State: 5 /* Probe */, Active: true, IPv6: true, + }, + }, + { + Type: ipv6.ICMPTypeDuplicateAddressConfirmation, + Body: &icmp.DefaultMessageBody{ + Data: []byte{0x80, 0x40, 0x20, 0x10}, + }, + }, + }) + }) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ } diff --git a/vendor/golang.org/x/net/icmp/multipart.go b/vendor/golang.org/x/net/icmp/multipart.go index f27135660..bd233c545 100644 --- a/vendor/golang.org/x/net/icmp/multipart.go +++ b/vendor/golang.org/x/net/icmp/multipart.go @@ -10,12 +10,22 @@ import "golang.org/x/net/internal/iana" // exts as extensions, and returns a required length for message body // and a required length for a padded original datagram in wire // format. +<<<<<<< HEAD func multipartMessageBodyDataLen(proto int, b []byte, exts []Extension) (bodyLen, dataLen int) { +======= +func multipartMessageBodyDataLen(proto int, withOrigDgram bool, b []byte, exts []Extension) (bodyLen, dataLen int) { +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ for _, ext := range exts { bodyLen += ext.Len(proto) } if bodyLen > 0 { +<<<<<<< HEAD dataLen = multipartMessageOrigDatagramLen(proto, b) +======= + if withOrigDgram { + dataLen = multipartMessageOrigDatagramLen(proto, b) + } +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ bodyLen += 4 // length of extension header } else { dataLen = len(b) @@ -50,8 +60,13 @@ func multipartMessageOrigDatagramLen(proto int, b []byte) int { // marshalMultipartMessageBody takes data as an original datagram and // exts as extesnsions, and returns a binary encoding of message body. // It can be used for non-multipart message bodies when exts is nil. +<<<<<<< HEAD func marshalMultipartMessageBody(proto int, data []byte, exts []Extension) ([]byte, error) { bodyLen, dataLen := multipartMessageBodyDataLen(proto, data, exts) +======= +func marshalMultipartMessageBody(proto int, withOrigDgram bool, data []byte, exts []Extension) ([]byte, error) { + bodyLen, dataLen := multipartMessageBodyDataLen(proto, withOrigDgram, data, exts) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ b := make([]byte, 4+bodyLen) copy(b[4:], data) off := dataLen + 4 @@ -71,16 +86,34 @@ func marshalMultipartMessageBody(proto int, data []byte, exts []Extension) ([]by return nil, err } off += ext.Len(proto) +<<<<<<< HEAD +======= + case *InterfaceIdent: + if err := ext.marshal(proto, b[off:]); err != nil { + return nil, err + } + off += ext.Len(proto) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ } } s := checksum(b[dataLen+4:]) b[dataLen+4+2] ^= byte(s) b[dataLen+4+3] ^= byte(s >> 8) +<<<<<<< HEAD switch proto { case iana.ProtocolICMP: b[1] = byte(dataLen / 4) case iana.ProtocolIPv6ICMP: b[0] = byte(dataLen / 8) +======= + if withOrigDgram { + switch proto { + case iana.ProtocolICMP: + b[1] = byte(dataLen / 4) + case iana.ProtocolIPv6ICMP: + b[0] = byte(dataLen / 8) + } +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ } } return b, nil @@ -88,7 +121,11 @@ func marshalMultipartMessageBody(proto int, data []byte, exts []Extension) ([]by // parseMultipartMessageBody parses b as either a non-multipart // message body or a multipart message body. +<<<<<<< HEAD func parseMultipartMessageBody(proto int, b []byte) ([]byte, []Extension, error) { +======= +func parseMultipartMessageBody(proto int, typ Type, b []byte) ([]byte, []Extension, error) { +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ var l int switch proto { case iana.ProtocolICMP: @@ -99,11 +136,23 @@ func parseMultipartMessageBody(proto int, b []byte) ([]byte, []Extension, error) if len(b) == 4 { return nil, nil, nil } +<<<<<<< HEAD exts, l, err := parseExtensions(b[4:], l) if err != nil { l = len(b) - 4 } data := make([]byte, l) copy(data, b[4:]) +======= + exts, l, err := parseExtensions(typ, b[4:], l) + if err != nil { + l = len(b) - 4 + } + var data []byte + if l > 0 { + data = make([]byte, l) + copy(data, b[4:]) + } +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ return data, exts, nil } diff --git a/vendor/golang.org/x/net/icmp/multipart_test.go b/vendor/golang.org/x/net/icmp/multipart_test.go index 966ccb8da..b8dc27422 100644 --- a/vendor/golang.org/x/net/icmp/multipart_test.go +++ b/vendor/golang.org/x/net/icmp/multipart_test.go @@ -5,6 +5,10 @@ package icmp_test import ( +<<<<<<< HEAD +======= + "errors" +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ "fmt" "net" "reflect" @@ -16,6 +20,7 @@ import ( "golang.org/x/net/ipv6" ) +<<<<<<< HEAD var marshalAndParseMultipartMessageForIPv4Tests = []icmp.Message{ { Type: ipv4.ICMPTypeDestinationUnreachable, Code: 15, @@ -435,6 +440,559 @@ var multipartMessageBodyLenTests = []struct { func TestMultipartMessageBodyLen(t *testing.T) { for i, tt := range multipartMessageBodyLenTests { +======= +func TestMarshalAndParseMultipartMessage(t *testing.T) { + fn := func(t *testing.T, proto int, tm icmp.Message) error { + b, err := tm.Marshal(nil) + if err != nil { + return err + } + switch tm.Type { + case ipv4.ICMPTypeExtendedEchoRequest, ipv6.ICMPTypeExtendedEchoRequest: + default: + switch proto { + case iana.ProtocolICMP: + if b[5] != 32 { + return fmt.Errorf("got %d; want 32", b[5]) + } + case iana.ProtocolIPv6ICMP: + if b[4] != 16 { + return fmt.Errorf("got %d; want 16", b[4]) + } + default: + return fmt.Errorf("unknown protocol: %d", proto) + } + } + m, err := icmp.ParseMessage(proto, b) + if err != nil { + return err + } + if m.Type != tm.Type || m.Code != tm.Code { + return fmt.Errorf("got %v; want %v", m, &tm) + } + switch m.Type { + case ipv4.ICMPTypeExtendedEchoRequest, ipv6.ICMPTypeExtendedEchoRequest: + got, want := m.Body.(*icmp.ExtendedEchoRequest), tm.Body.(*icmp.ExtendedEchoRequest) + if !reflect.DeepEqual(got.Extensions, want.Extensions) { + return errors.New(dumpExtensions(got.Extensions, want.Extensions)) + } + case ipv4.ICMPTypeDestinationUnreachable: + got, want := m.Body.(*icmp.DstUnreach), tm.Body.(*icmp.DstUnreach) + if !reflect.DeepEqual(got.Extensions, want.Extensions) { + return errors.New(dumpExtensions(got.Extensions, want.Extensions)) + } + if len(got.Data) != 128 { + return fmt.Errorf("got %d; want 128", len(got.Data)) + } + case ipv4.ICMPTypeTimeExceeded: + got, want := m.Body.(*icmp.TimeExceeded), tm.Body.(*icmp.TimeExceeded) + if !reflect.DeepEqual(got.Extensions, want.Extensions) { + return errors.New(dumpExtensions(got.Extensions, want.Extensions)) + } + if len(got.Data) != 128 { + return fmt.Errorf("got %d; want 128", len(got.Data)) + } + case ipv4.ICMPTypeParameterProblem: + got, want := m.Body.(*icmp.ParamProb), tm.Body.(*icmp.ParamProb) + if !reflect.DeepEqual(got.Extensions, want.Extensions) { + return errors.New(dumpExtensions(got.Extensions, want.Extensions)) + } + if len(got.Data) != 128 { + return fmt.Errorf("got %d; want 128", len(got.Data)) + } + case ipv6.ICMPTypeDestinationUnreachable: + got, want := m.Body.(*icmp.DstUnreach), tm.Body.(*icmp.DstUnreach) + if !reflect.DeepEqual(got.Extensions, want.Extensions) { + return errors.New(dumpExtensions(got.Extensions, want.Extensions)) + } + if len(got.Data) != 128 { + return fmt.Errorf("got %d; want 128", len(got.Data)) + } + case ipv6.ICMPTypeTimeExceeded: + got, want := m.Body.(*icmp.TimeExceeded), tm.Body.(*icmp.TimeExceeded) + if !reflect.DeepEqual(got.Extensions, want.Extensions) { + return errors.New(dumpExtensions(got.Extensions, want.Extensions)) + } + if len(got.Data) != 128 { + return fmt.Errorf("got %d; want 128", len(got.Data)) + } + default: + return fmt.Errorf("unknown message type: %v", m.Type) + } + return nil + } + + t.Run("IPv4", func(t *testing.T) { + for i, tm := range []icmp.Message{ + { + Type: ipv4.ICMPTypeDestinationUnreachable, Code: 15, + Body: &icmp.DstUnreach{ + Data: []byte("ERROR-INVOKING-PACKET"), + Extensions: []icmp.Extension{ + &icmp.MPLSLabelStack{ + Class: 1, + Type: 1, + Labels: []icmp.MPLSLabel{ + { + Label: 16014, + TC: 0x4, + S: true, + TTL: 255, + }, + }, + }, + &icmp.InterfaceInfo{ + Class: 2, + Type: 0x0f, + Interface: &net.Interface{ + Index: 15, + Name: "en101", + MTU: 8192, + }, + Addr: &net.IPAddr{ + IP: net.IPv4(192, 168, 0, 1).To4(), + }, + }, + }, + }, + }, + { + Type: ipv4.ICMPTypeTimeExceeded, Code: 1, + Body: &icmp.TimeExceeded{ + Data: []byte("ERROR-INVOKING-PACKET"), + Extensions: []icmp.Extension{ + &icmp.InterfaceInfo{ + Class: 2, + Type: 0x0f, + Interface: &net.Interface{ + Index: 15, + Name: "en101", + MTU: 8192, + }, + Addr: &net.IPAddr{ + IP: net.IPv4(192, 168, 0, 1).To4(), + }, + }, + &icmp.MPLSLabelStack{ + Class: 1, + Type: 1, + Labels: []icmp.MPLSLabel{ + { + Label: 16014, + TC: 0x4, + S: true, + TTL: 255, + }, + }, + }, + }, + }, + }, + { + Type: ipv4.ICMPTypeParameterProblem, Code: 2, + Body: &icmp.ParamProb{ + Pointer: 8, + Data: []byte("ERROR-INVOKING-PACKET"), + Extensions: []icmp.Extension{ + &icmp.MPLSLabelStack{ + Class: 1, + Type: 1, + Labels: []icmp.MPLSLabel{ + { + Label: 16014, + TC: 0x4, + S: true, + TTL: 255, + }, + }, + }, + &icmp.InterfaceInfo{ + Class: 2, + Type: 0x0f, + Interface: &net.Interface{ + Index: 15, + Name: "en101", + MTU: 8192, + }, + Addr: &net.IPAddr{ + IP: net.IPv4(192, 168, 0, 1).To4(), + }, + }, + &icmp.InterfaceInfo{ + Class: 2, + Type: 0x2f, + Interface: &net.Interface{ + Index: 16, + Name: "en102", + MTU: 8192, + }, + Addr: &net.IPAddr{ + IP: net.IPv4(192, 168, 0, 2).To4(), + }, + }, + }, + }, + }, + { + Type: ipv4.ICMPTypeExtendedEchoRequest, Code: 0, + Body: &icmp.ExtendedEchoRequest{ + ID: 1, Seq: 2, Local: true, + Extensions: []icmp.Extension{ + &icmp.InterfaceIdent{ + Class: 3, + Type: 1, + Name: "en101", + }, + }, + }, + }, + { + Type: ipv4.ICMPTypeExtendedEchoRequest, Code: 0, + Body: &icmp.ExtendedEchoRequest{ + ID: 1, Seq: 2, Local: true, + Extensions: []icmp.Extension{ + &icmp.InterfaceIdent{ + Class: 3, + Type: 2, + Index: 911, + }, + &icmp.InterfaceIdent{ + Class: 3, + Type: 1, + Name: "en101", + }, + }, + }, + }, + { + Type: ipv4.ICMPTypeExtendedEchoRequest, Code: 0, + Body: &icmp.ExtendedEchoRequest{ + ID: 1, Seq: 2, + Extensions: []icmp.Extension{ + &icmp.InterfaceIdent{ + Class: 3, + Type: 3, + AFI: iana.AddrFamily48bitMAC, + Addr: []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab}, + }, + }, + }, + }, + } { + if err := fn(t, iana.ProtocolICMP, tm); err != nil { + t.Errorf("#%d: %v", i, err) + } + } + }) + t.Run("IPv6", func(t *testing.T) { + for i, tm := range []icmp.Message{ + { + Type: ipv6.ICMPTypeDestinationUnreachable, Code: 6, + Body: &icmp.DstUnreach{ + Data: []byte("ERROR-INVOKING-PACKET"), + Extensions: []icmp.Extension{ + &icmp.MPLSLabelStack{ + Class: 1, + Type: 1, + Labels: []icmp.MPLSLabel{ + { + Label: 16014, + TC: 0x4, + S: true, + TTL: 255, + }, + }, + }, + &icmp.InterfaceInfo{ + Class: 2, + Type: 0x0f, + Interface: &net.Interface{ + Index: 15, + Name: "en101", + MTU: 8192, + }, + Addr: &net.IPAddr{ + IP: net.ParseIP("fe80::1"), + Zone: "en101", + }, + }, + }, + }, + }, + { + Type: ipv6.ICMPTypeTimeExceeded, Code: 1, + Body: &icmp.TimeExceeded{ + Data: []byte("ERROR-INVOKING-PACKET"), + Extensions: []icmp.Extension{ + &icmp.InterfaceInfo{ + Class: 2, + Type: 0x0f, + Interface: &net.Interface{ + Index: 15, + Name: "en101", + MTU: 8192, + }, + Addr: &net.IPAddr{ + IP: net.ParseIP("fe80::1"), + Zone: "en101", + }, + }, + &icmp.MPLSLabelStack{ + Class: 1, + Type: 1, + Labels: []icmp.MPLSLabel{ + { + Label: 16014, + TC: 0x4, + S: true, + TTL: 255, + }, + }, + }, + &icmp.InterfaceInfo{ + Class: 2, + Type: 0x2f, + Interface: &net.Interface{ + Index: 16, + Name: "en102", + MTU: 8192, + }, + Addr: &net.IPAddr{ + IP: net.ParseIP("fe80::1"), + Zone: "en102", + }, + }, + }, + }, + }, + { + Type: ipv6.ICMPTypeExtendedEchoRequest, Code: 0, + Body: &icmp.ExtendedEchoRequest{ + ID: 1, Seq: 2, Local: true, + Extensions: []icmp.Extension{ + &icmp.InterfaceIdent{ + Class: 3, + Type: 1, + Name: "en101", + }, + }, + }, + }, + { + Type: ipv6.ICMPTypeExtendedEchoRequest, Code: 0, + Body: &icmp.ExtendedEchoRequest{ + ID: 1, Seq: 2, Local: true, + Extensions: []icmp.Extension{ + &icmp.InterfaceIdent{ + Class: 3, + Type: 1, + Name: "en101", + }, + &icmp.InterfaceIdent{ + Class: 3, + Type: 2, + Index: 911, + }, + }, + }, + }, + { + Type: ipv6.ICMPTypeExtendedEchoRequest, Code: 0, + Body: &icmp.ExtendedEchoRequest{ + ID: 1, Seq: 2, + Extensions: []icmp.Extension{ + &icmp.InterfaceIdent{ + Class: 3, + Type: 3, + AFI: iana.AddrFamilyIPv4, + Addr: []byte{192, 0, 2, 1}, + }, + }, + }, + }, + } { + if err := fn(t, iana.ProtocolIPv6ICMP, tm); err != nil { + t.Errorf("#%d: %v", i, err) + } + } + }) +} + +func dumpExtensions(gotExts, wantExts []icmp.Extension) string { + var s string + for i, got := range gotExts { + switch got := got.(type) { + case *icmp.MPLSLabelStack: + want := wantExts[i].(*icmp.MPLSLabelStack) + if !reflect.DeepEqual(got, want) { + s += fmt.Sprintf("#%d: got %#v; want %#v\n", i, got, want) + } + case *icmp.InterfaceInfo: + want := wantExts[i].(*icmp.InterfaceInfo) + if !reflect.DeepEqual(got, want) { + s += fmt.Sprintf("#%d: got %#v, %#v, %#v; want %#v, %#v, %#v\n", i, got, got.Interface, got.Addr, want, want.Interface, want.Addr) + } + case *icmp.InterfaceIdent: + want := wantExts[i].(*icmp.InterfaceIdent) + if !reflect.DeepEqual(got, want) { + s += fmt.Sprintf("#%d: got %#v; want %#v\n", i, got, want) + } + } + } + if len(s) == 0 { + return "" + } + return s[:len(s)-1] +} + +func TestMultipartMessageBodyLen(t *testing.T) { + for i, tt := range []struct { + proto int + in icmp.MessageBody + out int + }{ + { + iana.ProtocolICMP, + &icmp.DstUnreach{ + Data: make([]byte, ipv4.HeaderLen), + }, + 4 + ipv4.HeaderLen, // unused and original datagram + }, + { + iana.ProtocolICMP, + &icmp.TimeExceeded{ + Data: make([]byte, ipv4.HeaderLen), + }, + 4 + ipv4.HeaderLen, // unused and original datagram + }, + { + iana.ProtocolICMP, + &icmp.ParamProb{ + Data: make([]byte, ipv4.HeaderLen), + }, + 4 + ipv4.HeaderLen, // [pointer, unused] and original datagram + }, + + { + iana.ProtocolICMP, + &icmp.ParamProb{ + Data: make([]byte, ipv4.HeaderLen), + Extensions: []icmp.Extension{ + &icmp.MPLSLabelStack{}, + }, + }, + 4 + 4 + 4 + 0 + 128, // [pointer, length, unused], extension header, object header, object payload, original datagram + }, + { + iana.ProtocolICMP, + &icmp.ParamProb{ + Data: make([]byte, 128), + Extensions: []icmp.Extension{ + &icmp.MPLSLabelStack{}, + }, + }, + 4 + 4 + 4 + 0 + 128, // [pointer, length, unused], extension header, object header, object payload and original datagram + }, + { + iana.ProtocolICMP, + &icmp.ParamProb{ + Data: make([]byte, 129), + Extensions: []icmp.Extension{ + &icmp.MPLSLabelStack{}, + }, + }, + 4 + 4 + 4 + 0 + 132, // [pointer, length, unused], extension header, object header, object payload and original datagram + }, + + { + iana.ProtocolIPv6ICMP, + &icmp.DstUnreach{ + Data: make([]byte, ipv6.HeaderLen), + }, + 4 + ipv6.HeaderLen, // unused and original datagram + }, + { + iana.ProtocolIPv6ICMP, + &icmp.PacketTooBig{ + Data: make([]byte, ipv6.HeaderLen), + }, + 4 + ipv6.HeaderLen, // mtu and original datagram + }, + { + iana.ProtocolIPv6ICMP, + &icmp.TimeExceeded{ + Data: make([]byte, ipv6.HeaderLen), + }, + 4 + ipv6.HeaderLen, // unused and original datagram + }, + { + iana.ProtocolIPv6ICMP, + &icmp.ParamProb{ + Data: make([]byte, ipv6.HeaderLen), + }, + 4 + ipv6.HeaderLen, // pointer and original datagram + }, + + { + iana.ProtocolIPv6ICMP, + &icmp.DstUnreach{ + Data: make([]byte, 127), + Extensions: []icmp.Extension{ + &icmp.MPLSLabelStack{}, + }, + }, + 4 + 4 + 4 + 0 + 128, // [length, unused], extension header, object header, object payload and original datagram + }, + { + iana.ProtocolIPv6ICMP, + &icmp.DstUnreach{ + Data: make([]byte, 128), + Extensions: []icmp.Extension{ + &icmp.MPLSLabelStack{}, + }, + }, + 4 + 4 + 4 + 0 + 128, // [length, unused], extension header, object header, object payload and original datagram + }, + { + iana.ProtocolIPv6ICMP, + &icmp.DstUnreach{ + Data: make([]byte, 129), + Extensions: []icmp.Extension{ + &icmp.MPLSLabelStack{}, + }, + }, + 4 + 4 + 4 + 0 + 136, // [length, unused], extension header, object header, object payload and original datagram + }, + + { + iana.ProtocolICMP, + &icmp.ExtendedEchoRequest{}, + 4, // [id, seq, l-bit] + }, + { + iana.ProtocolICMP, + &icmp.ExtendedEchoRequest{ + Extensions: []icmp.Extension{ + &icmp.InterfaceIdent{}, + }, + }, + 4 + 4 + 4, // [id, seq, l-bit], extension header, object header + }, + { + iana.ProtocolIPv6ICMP, + &icmp.ExtendedEchoRequest{ + Extensions: []icmp.Extension{ + &icmp.InterfaceIdent{ + Type: 3, + AFI: iana.AddrFamilyNSAP, + Addr: []byte{0x49, 0x00, 0x01, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0x00}, + }, + }, + }, + 4 + 4 + 4 + 16, // [id, seq, l-bit], extension header, object header, object payload + }, + } { +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ if out := tt.in.Len(tt.proto); out != tt.out { t.Errorf("#%d: got %d; want %d", i, out, tt.out) } diff --git a/vendor/golang.org/x/net/icmp/packettoobig.go b/vendor/golang.org/x/net/icmp/packettoobig.go index a1c9df7bf..58c348451 100644 --- a/vendor/golang.org/x/net/icmp/packettoobig.go +++ b/vendor/golang.org/x/net/icmp/packettoobig.go @@ -29,7 +29,11 @@ func (p *PacketTooBig) Marshal(proto int) ([]byte, error) { } // parsePacketTooBig parses b as an ICMP packet too big message body. +<<<<<<< HEAD func parsePacketTooBig(proto int, b []byte) (MessageBody, error) { +======= +func parsePacketTooBig(proto int, _ Type, b []byte) (MessageBody, error) { +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ bodyLen := len(b) if bodyLen < 4 { return nil, errMessageTooShort diff --git a/vendor/golang.org/x/net/icmp/paramprob.go b/vendor/golang.org/x/net/icmp/paramprob.go index 0a2548daa..29fa6622b 100644 --- a/vendor/golang.org/x/net/icmp/paramprob.go +++ b/vendor/golang.org/x/net/icmp/paramprob.go @@ -21,7 +21,11 @@ func (p *ParamProb) Len(proto int) int { if p == nil { return 0 } +<<<<<<< HEAD l, _ := multipartMessageBodyDataLen(proto, p.Data, p.Extensions) +======= + l, _ := multipartMessageBodyDataLen(proto, true, p.Data, p.Extensions) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ return 4 + l } @@ -33,7 +37,11 @@ func (p *ParamProb) Marshal(proto int) ([]byte, error) { copy(b[4:], p.Data) return b, nil } +<<<<<<< HEAD b, err := marshalMultipartMessageBody(proto, p.Data, p.Extensions) +======= + b, err := marshalMultipartMessageBody(proto, true, p.Data, p.Extensions) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ if err != nil { return nil, err } @@ -42,7 +50,11 @@ func (p *ParamProb) Marshal(proto int) ([]byte, error) { } // parseParamProb parses b as an ICMP parameter problem message body. +<<<<<<< HEAD func parseParamProb(proto int, b []byte) (MessageBody, error) { +======= +func parseParamProb(proto int, typ Type, b []byte) (MessageBody, error) { +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ if len(b) < 4 { return nil, errMessageTooShort } @@ -55,7 +67,11 @@ func parseParamProb(proto int, b []byte) (MessageBody, error) { } p.Pointer = uintptr(b[0]) var err error +<<<<<<< HEAD p.Data, p.Extensions, err = parseMultipartMessageBody(proto, b) +======= + p.Data, p.Extensions, err = parseMultipartMessageBody(proto, typ, b) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ if err != nil { return nil, err } diff --git a/vendor/golang.org/x/net/icmp/timeexceeded.go b/vendor/golang.org/x/net/icmp/timeexceeded.go index 344e15848..9fdd82328 100644 --- a/vendor/golang.org/x/net/icmp/timeexceeded.go +++ b/vendor/golang.org/x/net/icmp/timeexceeded.go @@ -15,23 +15,39 @@ func (p *TimeExceeded) Len(proto int) int { if p == nil { return 0 } +<<<<<<< HEAD l, _ := multipartMessageBodyDataLen(proto, p.Data, p.Extensions) +======= + l, _ := multipartMessageBodyDataLen(proto, true, p.Data, p.Extensions) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ return 4 + l } // Marshal implements the Marshal method of MessageBody interface. func (p *TimeExceeded) Marshal(proto int) ([]byte, error) { +<<<<<<< HEAD return marshalMultipartMessageBody(proto, p.Data, p.Extensions) } // parseTimeExceeded parses b as an ICMP time exceeded message body. func parseTimeExceeded(proto int, b []byte) (MessageBody, error) { +======= + return marshalMultipartMessageBody(proto, true, p.Data, p.Extensions) +} + +// parseTimeExceeded parses b as an ICMP time exceeded message body. +func parseTimeExceeded(proto int, typ Type, b []byte) (MessageBody, error) { +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ if len(b) < 4 { return nil, errMessageTooShort } p := &TimeExceeded{} var err error +<<<<<<< HEAD p.Data, p.Extensions, err = parseMultipartMessageBody(proto, b) +======= + p.Data, p.Extensions, err = parseMultipartMessageBody(proto, typ, b) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ if err != nil { return nil, err } diff --git a/vendor/golang.org/x/net/internal/iana/const.go b/vendor/golang.org/x/net/internal/iana/const.go index c9df24d95..fc3b5016b 100644 --- a/vendor/golang.org/x/net/internal/iana/const.go +++ b/vendor/golang.org/x/net/internal/iana/const.go @@ -1,5 +1,9 @@ // go generate gen.go +<<<<<<< HEAD // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT +======= +// Code generated by the command above; DO NOT EDIT. +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ // Package iana provides protocol number resources managed by the Internet Assigned Numbers Authority (IANA). package iana // import "golang.org/x/net/internal/iana" @@ -38,7 +42,11 @@ const ( CongestionExperienced = 0x3 // CE (Congestion Experienced) ) +<<<<<<< HEAD // Protocol Numbers, Updated: 2016-06-22 +======= +// Protocol Numbers, Updated: 2017-10-13 +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ const ( ProtocolIP = 0 // IPv4 encapsulation, pseudo protocol number ProtocolHOPOPT = 0 // IPv6 Hop-by-Hop Option @@ -178,3 +186,53 @@ const ( ProtocolROHC = 142 // Robust Header Compression ProtocolReserved = 255 // Reserved ) +<<<<<<< HEAD +======= + +// Address Family Numbers, Updated: 2016-10-25 +const ( + AddrFamilyIPv4 = 1 // IP (IP version 4) + AddrFamilyIPv6 = 2 // IP6 (IP version 6) + AddrFamilyNSAP = 3 // NSAP + AddrFamilyHDLC = 4 // HDLC (8-bit multidrop) + AddrFamilyBBN1822 = 5 // BBN 1822 + AddrFamily802 = 6 // 802 (includes all 802 media plus Ethernet "canonical format") + AddrFamilyE163 = 7 // E.163 + AddrFamilyE164 = 8 // E.164 (SMDS, Frame Relay, ATM) + AddrFamilyF69 = 9 // F.69 (Telex) + AddrFamilyX121 = 10 // X.121 (X.25, Frame Relay) + AddrFamilyIPX = 11 // IPX + AddrFamilyAppletalk = 12 // Appletalk + AddrFamilyDecnetIV = 13 // Decnet IV + AddrFamilyBanyanVines = 14 // Banyan Vines + AddrFamilyE164withSubaddress = 15 // E.164 with NSAP format subaddress + AddrFamilyDNS = 16 // DNS (Domain Name System) + AddrFamilyDistinguishedName = 17 // Distinguished Name + AddrFamilyASNumber = 18 // AS Number + AddrFamilyXTPoverIPv4 = 19 // XTP over IP version 4 + AddrFamilyXTPoverIPv6 = 20 // XTP over IP version 6 + AddrFamilyXTPnativemodeXTP = 21 // XTP native mode XTP + AddrFamilyFibreChannelWorldWidePortName = 22 // Fibre Channel World-Wide Port Name + AddrFamilyFibreChannelWorldWideNodeName = 23 // Fibre Channel World-Wide Node Name + AddrFamilyGWID = 24 // GWID + AddrFamilyL2VPN = 25 // AFI for L2VPN information + AddrFamilyMPLSTPSectionEndpointID = 26 // MPLS-TP Section Endpoint Identifier + AddrFamilyMPLSTPLSPEndpointID = 27 // MPLS-TP LSP Endpoint Identifier + AddrFamilyMPLSTPPseudowireEndpointID = 28 // MPLS-TP Pseudowire Endpoint Identifier + AddrFamilyMTIPv4 = 29 // MT IP: Multi-Topology IP version 4 + AddrFamilyMTIPv6 = 30 // MT IPv6: Multi-Topology IP version 6 + AddrFamilyEIGRPCommonServiceFamily = 16384 // EIGRP Common Service Family + AddrFamilyEIGRPIPv4ServiceFamily = 16385 // EIGRP IPv4 Service Family + AddrFamilyEIGRPIPv6ServiceFamily = 16386 // EIGRP IPv6 Service Family + AddrFamilyLISPCanonicalAddressFormat = 16387 // LISP Canonical Address Format (LCAF) + AddrFamilyBGPLS = 16388 // BGP-LS + AddrFamily48bitMAC = 16389 // 48-bit MAC + AddrFamily64bitMAC = 16390 // 64-bit MAC + AddrFamilyOUI = 16391 // OUI + AddrFamilyMACFinal24bits = 16392 // MAC/24 + AddrFamilyMACFinal40bits = 16393 // MAC/40 + AddrFamilyIPv6Initial64bits = 16394 // IPv6/64 + AddrFamilyRBridgePortID = 16395 // RBridge Port ID + AddrFamilyTRILLNickname = 16396 // TRILL Nickname +) +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ diff --git a/vendor/golang.org/x/net/internal/iana/gen.go b/vendor/golang.org/x/net/internal/iana/gen.go index 2a5c310c2..8a19b59dc 100644 --- a/vendor/golang.org/x/net/internal/iana/gen.go +++ b/vendor/golang.org/x/net/internal/iana/gen.go @@ -39,12 +39,23 @@ var registries = []struct { "https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml", parseProtocolNumbers, }, +<<<<<<< HEAD +======= + { + "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xml", + parseAddrFamilyNumbers, + }, +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ } func main() { var bb bytes.Buffer fmt.Fprintf(&bb, "// go generate gen.go\n") +<<<<<<< HEAD fmt.Fprintf(&bb, "// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT\n\n") +======= + fmt.Fprintf(&bb, "// Code generated by the command above; DO NOT EDIT.\n\n") +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ fmt.Fprintf(&bb, "// Package iana provides protocol number resources managed by the Internet Assigned Numbers Authority (IANA).\n") fmt.Fprintf(&bb, `package iana // import "golang.org/x/net/internal/iana"`+"\n\n") for _, r := range registries { @@ -291,3 +302,96 @@ func (pn *protocolNumbers) escape() []canonProtocolRecord { } return prs } +<<<<<<< HEAD +======= + +func parseAddrFamilyNumbers(w io.Writer, r io.Reader) error { + dec := xml.NewDecoder(r) + var afn addrFamilylNumbers + if err := dec.Decode(&afn); err != nil { + return err + } + afrs := afn.escape() + fmt.Fprintf(w, "// %s, Updated: %s\n", afn.Title, afn.Updated) + fmt.Fprintf(w, "const (\n") + for _, afr := range afrs { + if afr.Name == "" { + continue + } + fmt.Fprintf(w, "AddrFamily%s = %d", afr.Name, afr.Value) + fmt.Fprintf(w, "// %s\n", afr.Descr) + } + fmt.Fprintf(w, ")\n") + return nil +} + +type addrFamilylNumbers struct { + XMLName xml.Name `xml:"registry"` + Title string `xml:"title"` + Updated string `xml:"updated"` + RegTitle string `xml:"registry>title"` + Note string `xml:"registry>note"` + Records []struct { + Value string `xml:"value"` + Descr string `xml:"description"` + } `xml:"registry>record"` +} + +type canonAddrFamilyRecord struct { + Name string + Descr string + Value int +} + +func (afn *addrFamilylNumbers) escape() []canonAddrFamilyRecord { + afrs := make([]canonAddrFamilyRecord, len(afn.Records)) + sr := strings.NewReplacer( + "IP version 4", "IPv4", + "IP version 6", "IPv6", + "Identifier", "ID", + "-", "", + "-", "", + "/", "", + ".", "", + " ", "", + ) + for i, afr := range afn.Records { + if strings.Contains(afr.Descr, "Unassigned") || + strings.Contains(afr.Descr, "Reserved") { + continue + } + afrs[i].Descr = afr.Descr + s := strings.TrimSpace(afr.Descr) + switch s { + case "IP (IP version 4)": + afrs[i].Name = "IPv4" + case "IP6 (IP version 6)": + afrs[i].Name = "IPv6" + case "AFI for L2VPN information": + afrs[i].Name = "L2VPN" + case "E.164 with NSAP format subaddress": + afrs[i].Name = "E164withSubaddress" + case "MT IP: Multi-Topology IP version 4": + afrs[i].Name = "MTIPv4" + case "MAC/24": + afrs[i].Name = "MACFinal24bits" + case "MAC/40": + afrs[i].Name = "MACFinal40bits" + case "IPv6/64": + afrs[i].Name = "IPv6Initial64bits" + default: + n := strings.Index(s, "(") + if n > 0 { + s = s[:n] + } + n = strings.Index(s, ":") + if n > 0 { + s = s[:n] + } + afrs[i].Name = sr.Replace(s) + } + afrs[i].Value, _ = strconv.Atoi(afr.Value) + } + return afrs +} +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ diff --git a/vendor/golang.org/x/net/ipv4/gen.go b/vendor/golang.org/x/net/ipv4/gen.go index 9d490fac9..259dc6bf1 100644 --- a/vendor/golang.org/x/net/ipv4/gen.go +++ b/vendor/golang.org/x/net/ipv4/gen.go @@ -80,7 +80,11 @@ var registries = []struct { func geniana() error { var bb bytes.Buffer fmt.Fprintf(&bb, "// go generate gen.go\n") +<<<<<<< HEAD fmt.Fprintf(&bb, "// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT\n\n") +======= + fmt.Fprintf(&bb, "// Code generated by the command above; DO NOT EDIT.\n\n") +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ fmt.Fprintf(&bb, "package ipv4\n\n") for _, r := range registries { resp, err := http.Get(r.url) diff --git a/vendor/golang.org/x/net/ipv4/iana.go b/vendor/golang.org/x/net/ipv4/iana.go index be10c9488..2ec33c886 100644 --- a/vendor/golang.org/x/net/ipv4/iana.go +++ b/vendor/golang.org/x/net/ipv4/iana.go @@ -1,9 +1,17 @@ // go generate gen.go +<<<<<<< HEAD // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT package ipv4 // Internet Control Message Protocol (ICMP) Parameters, Updated: 2013-04-19 +======= +// Code generated by the command above; DO NOT EDIT. + +package ipv4 + +// Internet Control Message Protocol (ICMP) Parameters, Updated: 2018-02-26 +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ const ( ICMPTypeEchoReply ICMPType = 0 // Echo Reply ICMPTypeDestinationUnreachable ICMPType = 3 // Destination Unreachable @@ -16,9 +24,17 @@ const ( ICMPTypeTimestamp ICMPType = 13 // Timestamp ICMPTypeTimestampReply ICMPType = 14 // Timestamp Reply ICMPTypePhoturis ICMPType = 40 // Photuris +<<<<<<< HEAD ) // Internet Control Message Protocol (ICMP) Parameters, Updated: 2013-04-19 +======= + ICMPTypeExtendedEchoRequest ICMPType = 42 // Extended Echo Request + ICMPTypeExtendedEchoReply ICMPType = 43 // Extended Echo Reply +) + +// Internet Control Message Protocol (ICMP) Parameters, Updated: 2018-02-26 +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ var icmpTypes = map[ICMPType]string{ 0: "echo reply", 3: "destination unreachable", @@ -31,4 +47,9 @@ var icmpTypes = map[ICMPType]string{ 13: "timestamp", 14: "timestamp reply", 40: "photuris", +<<<<<<< HEAD +======= + 42: "extended echo request", + 43: "extended echo reply", +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ } diff --git a/vendor/golang.org/x/net/ipv6/gen.go b/vendor/golang.org/x/net/ipv6/gen.go index 47b7e9f0a..273afd38a 100644 --- a/vendor/golang.org/x/net/ipv6/gen.go +++ b/vendor/golang.org/x/net/ipv6/gen.go @@ -80,7 +80,11 @@ var registries = []struct { func geniana() error { var bb bytes.Buffer fmt.Fprintf(&bb, "// go generate gen.go\n") +<<<<<<< HEAD fmt.Fprintf(&bb, "// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT\n\n") +======= + fmt.Fprintf(&bb, "// Code generated by the command above; DO NOT EDIT.\n\n") +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ fmt.Fprintf(&bb, "package ipv6\n\n") for _, r := range registries { resp, err := http.Get(r.url) diff --git a/vendor/golang.org/x/net/ipv6/iana.go b/vendor/golang.org/x/net/ipv6/iana.go index 3c6214fb6..16dee0819 100644 --- a/vendor/golang.org/x/net/ipv6/iana.go +++ b/vendor/golang.org/x/net/ipv6/iana.go @@ -1,9 +1,17 @@ // go generate gen.go +<<<<<<< HEAD // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT package ipv6 // Internet Control Message Protocol version 6 (ICMPv6) Parameters, Updated: 2015-07-07 +======= +// Code generated by the command above; DO NOT EDIT. + +package ipv6 + +// Internet Control Message Protocol version 6 (ICMPv6) Parameters, Updated: 2018-03-09 +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ const ( ICMPTypeDestinationUnreachable ICMPType = 1 // Destination Unreachable ICMPTypePacketTooBig ICMPType = 2 // Packet Too Big @@ -40,9 +48,17 @@ const ( ICMPTypeDuplicateAddressRequest ICMPType = 157 // Duplicate Address Request ICMPTypeDuplicateAddressConfirmation ICMPType = 158 // Duplicate Address Confirmation ICMPTypeMPLControl ICMPType = 159 // MPL Control Message +<<<<<<< HEAD ) // Internet Control Message Protocol version 6 (ICMPv6) Parameters, Updated: 2015-07-07 +======= + ICMPTypeExtendedEchoRequest ICMPType = 160 // Extended Echo Request + ICMPTypeExtendedEchoReply ICMPType = 161 // Extended Echo Reply +) + +// Internet Control Message Protocol version 6 (ICMPv6) Parameters, Updated: 2018-03-09 +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ var icmpTypes = map[ICMPType]string{ 1: "destination unreachable", 2: "packet too big", @@ -79,4 +95,9 @@ var icmpTypes = map[ICMPType]string{ 157: "duplicate address request", 158: "duplicate address confirmation", 159: "mpl control message", +<<<<<<< HEAD +======= + 160: "extended echo request", + 161: "extended echo reply", +>>>>>>> feat(matchers): add more matchers for more fun ๐ŸŽ‰ }