[#47] container: Make readFromV2() pass funlen

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-04-07 08:32:35 +03:00
parent 4cd755877c
commit 25e9336d68

View file

@ -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
}