diff --git a/v2/acl/convert.go b/v2/acl/convert.go index f41a28dc..bf656850 100644 --- a/v2/acl/convert.go +++ b/v2/acl/convert.go @@ -5,6 +5,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/refs" ) +// TargetToGRPCField converts unified target enum into grpc enum. func TargetToGRPCField(t Target) acl.Target { switch t { case TargetUser: @@ -18,6 +19,7 @@ func TargetToGRPCField(t Target) acl.Target { } } +// TargetFromGRPCField converts grpc enum into unified target enum. func TargetFromGRPCField(t acl.Target) Target { switch t { case acl.Target_USER: @@ -31,6 +33,7 @@ func TargetFromGRPCField(t acl.Target) Target { } } +// OperationToGRPCField converts unified operation enum into grpc enum. func OperationToGRPCField(t Operation) acl.Operation { switch t { case OperationPut: @@ -52,6 +55,7 @@ func OperationToGRPCField(t Operation) acl.Operation { } } +// OperationFromGRPCField converts grpc enum into unified operation enum. func OperationFromGRPCField(t acl.Operation) Operation { switch t { case acl.Operation_PUT: @@ -73,6 +77,7 @@ func OperationFromGRPCField(t acl.Operation) Operation { } } +// ActionToGRPCField converts unified action enum into grpc enum. func ActionToGRPCField(t Action) acl.Action { switch t { case ActionDeny: @@ -84,6 +89,7 @@ func ActionToGRPCField(t Action) acl.Action { } } +// ActionFromGRPCField converts grpc enum into unified action enum. func ActionFromGRPCField(t acl.Action) Action { switch t { case acl.Action_DENY: @@ -95,6 +101,7 @@ func ActionFromGRPCField(t acl.Action) Action { } } +// HeaderTypeToGRPCField converts unified header type enum into grpc enum. func HeaderTypeToGRPCField(t HeaderType) acl.HeaderType { switch t { case HeaderTypeRequest: @@ -106,6 +113,7 @@ func HeaderTypeToGRPCField(t HeaderType) acl.HeaderType { } } +// HeaderTypeFromGRPCField converts grpc enum into unified header type enum. func HeaderTypeFromGRPCField(t acl.HeaderType) HeaderType { switch t { case acl.HeaderType_REQUEST: @@ -117,6 +125,7 @@ func HeaderTypeFromGRPCField(t acl.HeaderType) HeaderType { } } +// MatchTypeToGRPCField converts unified match type enum into grpc enum. func MatchTypeToGRPCField(t MatchType) acl.MatchType { switch t { case MatchTypeStringEqual: @@ -128,6 +137,7 @@ func MatchTypeToGRPCField(t MatchType) acl.MatchType { } } +// MatchTypeFromGRPCField converts grpc enum into unified match type enum. func MatchTypeFromGRPCField(t acl.MatchType) MatchType { switch t { case acl.MatchType_STRING_EQUAL: @@ -139,6 +149,7 @@ func MatchTypeFromGRPCField(t acl.MatchType) MatchType { } } +// HeaderFilterToGRPCMessage converts unified header filter struct into grpc struct. func HeaderFilterToGRPCMessage(f *HeaderFilter) *acl.EACLRecord_FilterInfo { if f == nil { return nil @@ -160,6 +171,7 @@ func HeaderFilterToGRPCMessage(f *HeaderFilter) *acl.EACLRecord_FilterInfo { return m } +// HeaderFilterFromGRPCMessage converts grpc struct into unified header filter struct. func HeaderFilterFromGRPCMessage(m *acl.EACLRecord_FilterInfo) *HeaderFilter { if m == nil { return nil @@ -181,6 +193,7 @@ func HeaderFilterFromGRPCMessage(m *acl.EACLRecord_FilterInfo) *HeaderFilter { return f } +// TargetInfoToGRPCMessage converts unified target info struct into grpc struct. func TargetInfoToGRPCMessage(t *TargetInfo) *acl.EACLRecord_TargetInfo { if t == nil { return nil @@ -197,6 +210,7 @@ func TargetInfoToGRPCMessage(t *TargetInfo) *acl.EACLRecord_TargetInfo { return m } +// TargetInfoFromGRPCMessage converts grpc struct into unified target info struct. func TargetInfoFromGRPCMessage(m *acl.EACLRecord_TargetInfo) *TargetInfo { if m == nil { return nil @@ -213,6 +227,7 @@ func TargetInfoFromGRPCMessage(m *acl.EACLRecord_TargetInfo) *TargetInfo { return t } +// RecordToGRPCMessage converts unified acl record struct into grpc struct. func RecordToGRPCMessage(r *Record) *acl.EACLRecord { if r == nil { return nil @@ -249,6 +264,7 @@ func RecordToGRPCMessage(r *Record) *acl.EACLRecord { return m } +// RecordFromGRPCMessage converts grpc struct into unified acl record struct. func RecordFromGRPCMessage(m *acl.EACLRecord) *Record { if m == nil { return nil @@ -285,6 +301,7 @@ func RecordFromGRPCMessage(m *acl.EACLRecord) *Record { return r } +// TableToGRPCMessage converts unified acl table struct into grpc struct. func TableToGRPCMessage(t *Table) *acl.EACLTable { if t == nil { return nil @@ -308,6 +325,7 @@ func TableToGRPCMessage(t *Table) *acl.EACLTable { return m } +// TableFromGRPCMessage converts grpc struct into unified acl table struct. func TableFromGRPCMessage(m *acl.EACLTable) *Table { if m == nil { return nil diff --git a/v2/acl/marshal.go b/v2/acl/marshal.go index e4cb2e9d..7b9e7eaa 100644 --- a/v2/acl/marshal.go +++ b/v2/acl/marshal.go @@ -24,6 +24,8 @@ const ( tableRecordsField = 2 ) +// StableMarshal marshals unified acl table structure in a protobuf +// compatible way without field order shuffle. func (t *Table) StableMarshal(buf []byte) ([]byte, error) { if t == nil { return []byte{}, nil @@ -73,6 +75,7 @@ func (t *Table) StableMarshal(buf []byte) ([]byte, error) { return buf, nil } +// StableSize of acl table structure marshalled by StableMarshal function. func (t *Table) StableSize() (size int) { if t == nil { return 0 @@ -94,6 +97,8 @@ func (t *Table) StableSize() (size int) { return size } +// StableMarshal marshals unified acl record structure in a protobuf +// compatible way without field order shuffle. func (r *Record) StableMarshal(buf []byte) ([]byte, error) { if r == nil { return []byte{}, nil @@ -158,6 +163,7 @@ func (r *Record) StableMarshal(buf []byte) ([]byte, error) { return buf, nil } +// StableSize of acl record structure marshalled by StableMarshal function. func (r *Record) StableSize() (size int) { if r == nil { return 0 @@ -183,6 +189,8 @@ func (r *Record) StableSize() (size int) { return size } +// StableMarshal marshals unified header filter structure in a protobuf +// compatible way without field order shuffle. func (f *HeaderFilter) StableMarshal(buf []byte) ([]byte, error) { if f == nil { return []byte{}, nil @@ -218,7 +226,7 @@ func (f *HeaderFilter) StableMarshal(buf []byte) ([]byte, error) { offset += n - n, err = proto.StringMarshal(filterValueField, buf[offset:], f.value) + _, err = proto.StringMarshal(filterValueField, buf[offset:], f.value) if err != nil { return nil, err } @@ -226,6 +234,7 @@ func (f *HeaderFilter) StableMarshal(buf []byte) ([]byte, error) { return buf, nil } +// StableSize of header filter structure marshalled by StableMarshal function. func (f *HeaderFilter) StableSize() (size int) { if f == nil { return 0 @@ -239,6 +248,8 @@ func (f *HeaderFilter) StableSize() (size int) { return size } +// StableMarshal marshals unified target info structure in a protobuf +// compatible way without field order shuffle. func (t *TargetInfo) StableMarshal(buf []byte) ([]byte, error) { if t == nil { return []byte{}, nil @@ -260,7 +271,7 @@ func (t *TargetInfo) StableMarshal(buf []byte) ([]byte, error) { offset += n - n, err = proto.RepeatedBytesMarshal(targetKeysField, buf[offset:], t.keys) + _, err = proto.RepeatedBytesMarshal(targetKeysField, buf[offset:], t.keys) if err != nil { return nil, err } @@ -268,6 +279,7 @@ func (t *TargetInfo) StableMarshal(buf []byte) ([]byte, error) { return buf, nil } +// StableSize of target info structure marshalled by StableMarshal function. func (t *TargetInfo) StableSize() (size int) { if t == nil { return 0 diff --git a/v2/acl/marshal_test.go b/v2/acl/marshal_test.go index 8874ccd0..c5de1c83 100644 --- a/v2/acl/marshal_test.go +++ b/v2/acl/marshal_test.go @@ -15,6 +15,7 @@ func generateTarget(u acl.Target, k int) *acl.TargetInfo { target.SetTarget(u) keys := make([][]byte, k) + for i := 0; i < k; i++ { s := fmt.Sprintf("Public Key %d", i+1) keys[i] = []byte(s) @@ -23,10 +24,10 @@ func generateTarget(u acl.Target, k int) *acl.TargetInfo { return target } -func generateFilter(t acl.HeaderType, m acl.MatchType, k, v string) *acl.HeaderFilter { +func generateFilter(t acl.HeaderType, k, v string) *acl.HeaderFilter { filter := new(acl.HeaderFilter) filter.SetHeaderType(t) - filter.SetMatchType(m) + filter.SetMatchType(acl.MatchTypeStringEqual) filter.SetName(k) filter.SetValue(v) @@ -34,12 +35,12 @@ func generateFilter(t acl.HeaderType, m acl.MatchType, k, v string) *acl.HeaderF } func generateRecord(another bool) *acl.Record { - var record = new(acl.Record) + record := new(acl.Record) + switch another { case true: t1 := generateTarget(acl.TargetUser, 2) - f1 := generateFilter(acl.HeaderTypeObject, acl.MatchTypeStringEqual, - "OID", "ObjectID Value") + f1 := generateFilter(acl.HeaderTypeObject, "OID", "ObjectID Value") record.SetOperation(acl.OperationHead) record.SetAction(acl.ActionDeny) @@ -48,10 +49,8 @@ func generateRecord(another bool) *acl.Record { default: t1 := generateTarget(acl.TargetUser, 2) t2 := generateTarget(acl.TargetSystem, 0) - f1 := generateFilter(acl.HeaderTypeObject, acl.MatchTypeStringEqual, - "CID", "Container ID Value") - f2 := generateFilter(acl.HeaderTypeRequest, acl.MatchTypeStringEqual, - "X-Header-Key", "X-Header-Value") + f1 := generateFilter(acl.HeaderTypeObject, "CID", "Container ID Value") + f2 := generateFilter(acl.HeaderTypeRequest, "X-Header-Key", "X-Header-Value") record.SetOperation(acl.OperationPut) record.SetAction(acl.ActionAllow) @@ -63,8 +62,7 @@ func generateRecord(another bool) *acl.Record { } func TestHeaderFilter_StableMarshal(t *testing.T) { - filterFrom := generateFilter(acl.HeaderTypeObject, acl.MatchTypeStringEqual, - "CID", "Container ID Value") + filterFrom := generateFilter(acl.HeaderTypeObject, "CID", "Container ID Value") transport := new(grpc.EACLRecord_FilterInfo) t.Run("non empty", func(t *testing.T) { diff --git a/v2/acl/types.go b/v2/acl/types.go index b73eea10..5fb1b6bd 100644 --- a/v2/acl/types.go +++ b/v2/acl/types.go @@ -2,6 +2,8 @@ package acl import "github.com/nspcc-dev/neofs-api-go/v2/refs" +// HeaderFilter is a unified structure of FilterInfo +// message from proto definition. type HeaderFilter struct { hdrType HeaderType @@ -10,12 +12,16 @@ type HeaderFilter struct { name, value string } +// TargetInfo is a unified structure of TargetInfo +// message from proto definition. type TargetInfo struct { target Target keys [][]byte } +// Record is a unified structure of EACLRecord +// message from proto definition. type Record struct { op Operation @@ -26,20 +32,27 @@ type Record struct { targets []*TargetInfo } +// Table is a unified structure of EACLTable +// message from proto definition. type Table struct { cid *refs.ContainerID records []*Record } +// TargetInfo is a unified enum of MatchType enum from proto definition. type MatchType uint32 +// HeaderType is a unified enum of HeaderType enum from proto definition. type HeaderType uint32 +// Action is a unified enum of Action enum from proto definition. type Action uint32 +// Operation is a unified enum of Operation enum from proto definition. type Operation uint32 +// Target is a unified enum of Target enum from proto definition. type Target uint32 const (