From 91fa727c74f73f881d6df3e2b471bcc4716d7e05 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Mon, 12 Feb 2018 16:42:02 +0100 Subject: [PATCH] Update Staert. --- Gopkg.lock | 6 +-- Gopkg.toml | 2 +- vendor/github.com/containous/staert/kv.go | 47 ++++++++++++++++++++--- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 07b526c58..4cc719e22 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -243,8 +243,8 @@ [[projects]] name = "github.com/containous/staert" packages = ["."] - revision = "dbb7c840f31daec0d863ada6829d075a8dbb7469" - version = "v3.0.0" + revision = "cc00c303ccbd2491ddc1dccc9eb7ccadd807557e" + version = "v3.1.0" [[projects]] name = "github.com/containous/traefik-extra-service-fabric" @@ -1496,6 +1496,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "865659187f3824cb57b8ff8805e3114b806c67ee0ffe9cbc6db237e4038edee6" + inputs-digest = "17cefac15e170ca9d73093cad7a8f1fb6874cd03eeb67ccc3f8fe4d239f6e9aa" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index d14276bad..44ca3a4c3 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -62,7 +62,7 @@ [[constraint]] name = "github.com/containous/staert" - version = "3.0.0" + version = "3.1.0" [[constraint]] name = "github.com/containous/traefik-extra-service-fabric" diff --git a/vendor/github.com/containous/staert/kv.go b/vendor/github.com/containous/staert/kv.go index 898000cc3..bec34d173 100644 --- a/vendor/github.com/containous/staert/kv.go +++ b/vendor/github.com/containous/staert/kv.go @@ -1,10 +1,14 @@ package staert import ( + "bytes" + "compress/gzip" "encoding" "encoding/base64" "errors" "fmt" + "io" + "io/ioutil" "reflect" "sort" "strconv" @@ -155,16 +159,32 @@ func decodeHook(fromType reflect.Type, toType reflect.Type, data interface{}) (i return dataOutput, nil } else if fromType.Kind() == reflect.String { - b, err := base64.StdEncoding.DecodeString(data.(string)) - if err != nil { - return nil, err - } - return b, nil + return readCompressedData(data.(string), gzipReader, base64Reader) } } return data, nil } +func readCompressedData(data string, fs ...func(io.Reader) (io.Reader, error)) ([]byte, error) { + var err error + for _, f := range fs { + var reader io.Reader + reader, err = f(bytes.NewBufferString(data)) + if err == nil { + return ioutil.ReadAll(reader) + } + } + return nil, err +} + +func base64Reader(r io.Reader) (io.Reader, error) { + return base64.NewDecoder(base64.StdEncoding, r), nil +} + +func gzipReader(r io.Reader) (io.Reader, error) { + return gzip.NewReader(r) +} + // StoreConfig stores the config into the KV Store func (kv *KvSource) StoreConfig(config interface{}) error { kvMap := map[string]string{} @@ -263,7 +283,11 @@ func collateKvRecursive(objValue reflect.Value, kv map[string]string, key string case reflect.Array, reflect.Slice: // Byte slices get special treatment if objValue.Type().Elem().Kind() == reflect.Uint8 { - kv[name] = base64.StdEncoding.EncodeToString(objValue.Bytes()) + compressedData, err := writeCompressedData(objValue.Bytes()) + if err != nil { + return err + } + kv[name] = compressedData } else { for i := 0; i < objValue.Len(); i++ { name = key + "/" + strconv.Itoa(i) @@ -286,6 +310,17 @@ func collateKvRecursive(objValue reflect.Value, kv map[string]string, key string return nil } +func writeCompressedData(data []byte) (string, error) { + var buffer bytes.Buffer + gzipWriter := gzip.NewWriter(&buffer) + _, err := gzipWriter.Write(data) + if err != nil { + return "", err + } + gzipWriter.Close() + return buffer.String(), nil +} + // ListRecursive lists all key value children under key func (kv *KvSource) ListRecursive(key string, pairs map[string][]byte) error { pairsN1, err := kv.List(key, nil)