From 8c70b4714e53cc03cdb6c11c8fcaaac4cab985e5 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 27 May 2021 14:42:12 +0300 Subject: [PATCH] [#288] pkg/eacl: Fix conversion of slices in Record.ToV2 method Nil slices of targets and filters of the `Record` should be converted to nil slices in corresponding fields of API v2 message structure. Add nil-check in `Record.ToV2` implementation. The changes fix corresponding unit test. Signed-off-by: Leonard Lyubich --- pkg/acl/eacl/record.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/pkg/acl/eacl/record.go b/pkg/acl/eacl/record.go index e8430d14..7ba97433 100644 --- a/pkg/acl/eacl/record.go +++ b/pkg/acl/eacl/record.go @@ -135,22 +135,28 @@ func (r *Record) ToV2() *v2acl.Record { return nil } - targets := make([]*v2acl.Target, 0, len(r.targets)) - for _, target := range r.targets { - targets = append(targets, target.ToV2()) - } - - filters := make([]*v2acl.HeaderFilter, 0, len(r.filters)) - for _, filter := range r.filters { - filters = append(filters, filter.ToV2()) - } - v2 := new(v2acl.Record) + if r.targets != nil { + targets := make([]*v2acl.Target, 0, len(r.targets)) + for _, target := range r.targets { + targets = append(targets, target.ToV2()) + } + + v2.SetTargets(targets) + } + + if r.filters != nil { + filters := make([]*v2acl.HeaderFilter, 0, len(r.filters)) + for _, filter := range r.filters { + filters = append(filters, filter.ToV2()) + } + + v2.SetFilters(filters) + } + v2.SetAction(r.action.ToV2()) v2.SetOperation(r.operation.ToV2()) - v2.SetTargets(targets) - v2.SetFilters(filters) return v2 }