build(deps): bump github.com/containerd/typeurl/v2 from 2.2.2 to 2.2.3

Bumps [github.com/containerd/typeurl/v2](https://github.com/containerd/typeurl) from 2.2.2 to 2.2.3.
- [Release notes](https://github.com/containerd/typeurl/releases)
- [Commits](https://github.com/containerd/typeurl/compare/v2.2.2...v2.2.3)

Signed-off-by: Derek McGowan <derek@mcg.dev>

---
updated-dependencies:
- dependency-name: github.com/containerd/typeurl/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
(cherry picked from commit 01c489141c37e27b71370ab26ab28347b17f4284)
Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
dependabot[bot] 2024-11-11 23:34:14 +00:00 committed by Derek McGowan
parent e21cb92182
commit 389e781ea1
No known key found for this signature in database
GPG Key ID: F58C5D0A4405ACDB
5 changed files with 24 additions and 22 deletions

2
go.mod
View File

@ -27,7 +27,7 @@ require (
github.com/containerd/platforms v1.0.0-rc.0
github.com/containerd/plugin v1.0.0
github.com/containerd/ttrpc v1.2.6
github.com/containerd/typeurl/v2 v2.2.2
github.com/containerd/typeurl/v2 v2.2.3
github.com/containerd/zfs/v2 v2.0.0-rc.0
github.com/containernetworking/cni v1.2.3
github.com/containernetworking/plugins v1.5.1

4
go.sum
View File

@ -698,8 +698,8 @@ github.com/containerd/plugin v1.0.0/go.mod h1:hQfJe5nmWfImiqT1q8Si3jLv3ynMUIBB47
github.com/containerd/ttrpc v1.2.2/go.mod h1:sIT6l32Ph/H9cvnJsfXM5drIVzTr5A2flTf1G5tYZak=
github.com/containerd/ttrpc v1.2.6 h1:zG+Kn5EZ6MUYCS1t2Hmt2J4tMVaLSFEJVOraDQwNPC4=
github.com/containerd/ttrpc v1.2.6/go.mod h1:YCXHsb32f+Sq5/72xHubdiJRQY9inL4a4ZQrAbN1q9o=
github.com/containerd/typeurl/v2 v2.2.2 h1:3jN/k2ysKuPCsln5Qv8bzR9cxal8XjkxPogJfSNO31k=
github.com/containerd/typeurl/v2 v2.2.2/go.mod h1:95ljDnPfD3bAbDJRugOiShd/DlAAsxGtUBhJxIn7SCk=
github.com/containerd/typeurl/v2 v2.2.3 h1:yNA/94zxWdvYACdYO8zofhrTVuQY73fFU1y++dYSw40=
github.com/containerd/typeurl/v2 v2.2.3/go.mod h1:95ljDnPfD3bAbDJRugOiShd/DlAAsxGtUBhJxIn7SCk=
github.com/containerd/zfs/v2 v2.0.0-rc.0 h1:0dRlgpoaepW7HuovtcvYQMF7NlpceQVdn7+3Udeth4M=
github.com/containerd/zfs/v2 v2.0.0-rc.0/go.mod h1:g36g/XCEGDRxUXIFdM3oWAEvmTvhfz/eKWElqg4Secw=
github.com/containernetworking/cni v1.2.3 h1:hhOcjNVUQTnzdRJ6alC5XF+wd9mfGIUaj8FuJbEslXM=

View File

@ -39,7 +39,7 @@ type handler interface {
Marshaller(interface{}) func() ([]byte, error)
Unmarshaller(interface{}) func([]byte) error
TypeURL(interface{}) string
GetType(url string) reflect.Type
GetType(url string) (reflect.Type, bool)
}
// Definitions of common error types used throughout typeurl.
@ -240,7 +240,7 @@ func MarshalAnyToProto(from interface{}) (*anypb.Any, error) {
}
func unmarshal(typeURL string, value []byte, v interface{}) (interface{}, error) {
t, err := getTypeByUrl(typeURL)
t, isProto, err := getTypeByUrl(typeURL)
if err != nil {
return nil, err
}
@ -258,6 +258,7 @@ func unmarshal(typeURL string, value []byte, v interface{}) (interface{}, error)
}
}
if isProto {
pm, ok := v.(proto.Message)
if ok {
return v, proto.Unmarshal(value, pm)
@ -268,17 +269,18 @@ func unmarshal(typeURL string, value []byte, v interface{}) (interface{}, error)
return v, unmarshal(value)
}
}
}
// fallback to json unmarshaller
return v, json.Unmarshal(value, v)
}
func getTypeByUrl(url string) (reflect.Type, error) {
func getTypeByUrl(url string) (_ reflect.Type, isProto bool, _ error) {
mu.RLock()
for t, u := range registry {
if u == url {
mu.RUnlock()
return t, nil
return t, false, nil
}
}
mu.RUnlock()
@ -286,15 +288,15 @@ func getTypeByUrl(url string) (reflect.Type, error) {
if err != nil {
if errors.Is(err, protoregistry.NotFound) {
for _, h := range handlers {
if t := h.GetType(url); t != nil {
return t, nil
if t, isProto := h.GetType(url); t != nil {
return t, isProto, nil
}
}
}
return nil, fmt.Errorf("type with url %s: %w", url, ErrNotFound)
return nil, false, fmt.Errorf("type with url %s: %w", url, ErrNotFound)
}
empty := mt.New().Interface()
return reflect.TypeOf(empty).Elem(), nil
return reflect.TypeOf(empty).Elem(), true, nil
}
func tryDereference(v interface{}) reflect.Type {

View File

@ -59,10 +59,10 @@ func (gogoHandler) TypeURL(v interface{}) string {
return gogoproto.MessageName(pm)
}
func (gogoHandler) GetType(url string) reflect.Type {
func (gogoHandler) GetType(url string) (reflect.Type, bool) {
t := gogoproto.MessageType(url)
if t == nil {
return nil
return nil, false
}
return t.Elem()
return t.Elem(), true
}

2
vendor/modules.txt vendored
View File

@ -194,7 +194,7 @@ github.com/containerd/plugin/registry
# github.com/containerd/ttrpc v1.2.6
## explicit; go 1.19
github.com/containerd/ttrpc
# github.com/containerd/typeurl/v2 v2.2.2
# github.com/containerd/typeurl/v2 v2.2.3
## explicit; go 1.21
github.com/containerd/typeurl/v2
# github.com/containerd/zfs/v2 v2.0.0-rc.0