[#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, // reads Container from the container.Container message. If checkFieldPresence is set,
// returns an error on absence of any protocol-required field. // returns an error on absence of any protocol-required field.
//
// nolint: funlen
func (x *Container) readFromV2(m container.Container, checkFieldPresence bool) error { func (x *Container) readFromV2(m container.Container, checkFieldPresence bool) error {
var err error var err error
@ -98,6 +96,16 @@ func (x *Container) readFromV2(m container.Container, checkFieldPresence bool) e
return errors.New("missing placement policy") 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() attrs := m.GetAttributes()
mAttr := make(map[string]struct{}, len(attrs)) mAttr := make(map[string]struct{}, len(attrs))
var key, val string 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) return fmt.Errorf("empty attribute value %s", key)
} }
var err error
switch key { switch key {
case container.SysAttributeSubnet: case container.SysAttributeSubnet:
err = new(subnetid.ID).DecodeString(val) err = new(subnetid.ID).DecodeString(val)
@ -132,9 +141,6 @@ func (x *Container) readFromV2(m container.Container, checkFieldPresence bool) e
mAttr[key] = struct{}{} mAttr[key] = struct{}{}
} }
x.v2 = m
return nil return nil
} }