From 25e9336d68115374ba1110ca03e31aed6e71aacd Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 7 Apr 2023 08:32:35 +0300 Subject: [PATCH] [#47] container: Make readFromV2() pass funlen Signed-off-by: Evgenii Stratonikov --- container/container.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/container/container.go b/container/container.go index 11cd097..c07e3ec 100644 --- a/container/container.go +++ b/container/container.go @@ -50,8 +50,6 @@ const ( // reads Container from the container.Container message. If checkFieldPresence is set, // returns an error on absence of any protocol-required field. -// -// nolint: funlen func (x *Container) readFromV2(m container.Container, checkFieldPresence bool) error { var err error @@ -98,6 +96,16 @@ func (x *Container) readFromV2(m container.Container, checkFieldPresence bool) e return errors.New("missing placement policy") } + if err := checkAttributes(m); err != nil { + return err + } + + x.v2 = m + + return nil +} + +func checkAttributes(m container.Container) error { attrs := m.GetAttributes() mAttr := make(map[string]struct{}, len(attrs)) var key, val string @@ -119,6 +127,7 @@ func (x *Container) readFromV2(m container.Container, checkFieldPresence bool) e return fmt.Errorf("empty attribute value %s", key) } + var err error switch key { case container.SysAttributeSubnet: err = new(subnetid.ID).DecodeString(val) @@ -132,9 +141,6 @@ func (x *Container) readFromV2(m container.Container, checkFieldPresence bool) e mAttr[key] = struct{}{} } - - x.v2 = m - return nil }