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 }