From 5ed85b0909fa639c546b2b038724fd069da2d3a3 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 9 May 2020 14:32:13 +0200 Subject: [PATCH] vendor: bump containerd/typeurl v1.0.1 full diff: https://github.com/containerd/typeurl/compare/b45ef1f1f737e10bd45b25b669df25f0da8b9ba0...v1.0.1 Signed-off-by: Sebastiaan van Stijn --- vendor.conf | 2 +- vendor/github.com/containerd/typeurl/types.go | 33 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/vendor.conf b/vendor.conf index b3886d9b90..c230ff07ed 100644 --- a/vendor.conf +++ b/vendor.conf @@ -128,7 +128,7 @@ github.com/containerd/continuity 26c1120b8d4107d2471b93ad78ef github.com/containerd/cgroups 44306b6a1d46985d916b48b4199f93a378af314f github.com/containerd/console 8375c3424e4d7b114e8a90a4a40c8e1b40d1d4e6 # v1.0.0 github.com/containerd/go-runc 7016d3ce2328dd2cb1192b2076ebd565c4e8df0c -github.com/containerd/typeurl b45ef1f1f737e10bd45b25b669df25f0da8b9ba0 # v1.0.0-13-gb45ef1f +github.com/containerd/typeurl cd3ce7159eae562a4f60ceff37dada11a939d247 # v1.0.1 github.com/containerd/ttrpc 0be804eadb152bc3b3c20c5edc314c4633833398 # v1.0.0-16-g0be804e github.com/gogo/googleapis 01e0f9cca9b92166042241267ee2a5cdf5cff46c # v1.3.2 github.com/cilium/ebpf 60c3aa43f488292fe2ee50fb8b833b383ca8ebbb diff --git a/vendor/github.com/containerd/typeurl/types.go b/vendor/github.com/containerd/typeurl/types.go index b70314fda0..e912fd630e 100644 --- a/vendor/github.com/containerd/typeurl/types.go +++ b/vendor/github.com/containerd/typeurl/types.go @@ -47,14 +47,14 @@ func Register(v interface{}, args ...string) { defer mu.Unlock() if et, ok := registry[t]; ok { if et != p { - panic(errors.Errorf("type registred with alternate path %q != %q", et, p)) + panic(errors.Errorf("type registered with alternate path %q != %q", et, p)) } return } registry[t] = p } -// TypeURL returns the type url for a registred type. +// TypeURL returns the type url for a registered type. func TypeURL(v interface{}) (string, error) { mu.Lock() u, ok := registry[tryDereference(v)] @@ -120,16 +120,43 @@ func UnmarshalAny(any *types.Any) (interface{}, error) { } func UnmarshalByTypeURL(typeURL string, value []byte) (interface{}, error) { + return unmarshal(typeURL, value, nil) +} + +func UnmarshalTo(any *types.Any, out interface{}) error { + return UnmarshalToByTypeURL(any.TypeUrl, any.Value, out) +} + +func UnmarshalToByTypeURL(typeURL string, value []byte, out interface{}) error { + _, err := unmarshal(typeURL, value, out) + return err +} + +func unmarshal(typeURL string, value []byte, v interface{}) (interface{}, error) { t, err := getTypeByUrl(typeURL) if err != nil { return nil, err } - v := reflect.New(t.t).Interface() + + if v == nil { + v = reflect.New(t.t).Interface() + } else { + // Validate interface type provided by client + vURL, err := TypeURL(v) + if err != nil { + return nil, err + } + if typeURL != vURL { + return nil, errors.Errorf("can't unmarshal type %q to output %q", typeURL, vURL) + } + } + if t.isProto { err = proto.Unmarshal(value, v.(proto.Message)) } else { err = json.Unmarshal(value, v) } + return v, err }