forked from TrueCloudLab/frostfs-api-go
Fix some lint warnings
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
ddbeaa93b3
commit
d7c4dc333c
4 changed files with 54 additions and 13 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TargetToGRPCField converts unified target enum into grpc enum.
|
||||||
func TargetToGRPCField(t Target) acl.Target {
|
func TargetToGRPCField(t Target) acl.Target {
|
||||||
switch t {
|
switch t {
|
||||||
case TargetUser:
|
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 {
|
func TargetFromGRPCField(t acl.Target) Target {
|
||||||
switch t {
|
switch t {
|
||||||
case acl.Target_USER:
|
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 {
|
func OperationToGRPCField(t Operation) acl.Operation {
|
||||||
switch t {
|
switch t {
|
||||||
case OperationPut:
|
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 {
|
func OperationFromGRPCField(t acl.Operation) Operation {
|
||||||
switch t {
|
switch t {
|
||||||
case acl.Operation_PUT:
|
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 {
|
func ActionToGRPCField(t Action) acl.Action {
|
||||||
switch t {
|
switch t {
|
||||||
case ActionDeny:
|
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 {
|
func ActionFromGRPCField(t acl.Action) Action {
|
||||||
switch t {
|
switch t {
|
||||||
case acl.Action_DENY:
|
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 {
|
func HeaderTypeToGRPCField(t HeaderType) acl.HeaderType {
|
||||||
switch t {
|
switch t {
|
||||||
case HeaderTypeRequest:
|
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 {
|
func HeaderTypeFromGRPCField(t acl.HeaderType) HeaderType {
|
||||||
switch t {
|
switch t {
|
||||||
case acl.HeaderType_REQUEST:
|
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 {
|
func MatchTypeToGRPCField(t MatchType) acl.MatchType {
|
||||||
switch t {
|
switch t {
|
||||||
case MatchTypeStringEqual:
|
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 {
|
func MatchTypeFromGRPCField(t acl.MatchType) MatchType {
|
||||||
switch t {
|
switch t {
|
||||||
case acl.MatchType_STRING_EQUAL:
|
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 {
|
func HeaderFilterToGRPCMessage(f *HeaderFilter) *acl.EACLRecord_FilterInfo {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -160,6 +171,7 @@ func HeaderFilterToGRPCMessage(f *HeaderFilter) *acl.EACLRecord_FilterInfo {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HeaderFilterFromGRPCMessage converts grpc struct into unified header filter struct.
|
||||||
func HeaderFilterFromGRPCMessage(m *acl.EACLRecord_FilterInfo) *HeaderFilter {
|
func HeaderFilterFromGRPCMessage(m *acl.EACLRecord_FilterInfo) *HeaderFilter {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -181,6 +193,7 @@ func HeaderFilterFromGRPCMessage(m *acl.EACLRecord_FilterInfo) *HeaderFilter {
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TargetInfoToGRPCMessage converts unified target info struct into grpc struct.
|
||||||
func TargetInfoToGRPCMessage(t *TargetInfo) *acl.EACLRecord_TargetInfo {
|
func TargetInfoToGRPCMessage(t *TargetInfo) *acl.EACLRecord_TargetInfo {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -197,6 +210,7 @@ func TargetInfoToGRPCMessage(t *TargetInfo) *acl.EACLRecord_TargetInfo {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TargetInfoFromGRPCMessage converts grpc struct into unified target info struct.
|
||||||
func TargetInfoFromGRPCMessage(m *acl.EACLRecord_TargetInfo) *TargetInfo {
|
func TargetInfoFromGRPCMessage(m *acl.EACLRecord_TargetInfo) *TargetInfo {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -213,6 +227,7 @@ func TargetInfoFromGRPCMessage(m *acl.EACLRecord_TargetInfo) *TargetInfo {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RecordToGRPCMessage converts unified acl record struct into grpc struct.
|
||||||
func RecordToGRPCMessage(r *Record) *acl.EACLRecord {
|
func RecordToGRPCMessage(r *Record) *acl.EACLRecord {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -249,6 +264,7 @@ func RecordToGRPCMessage(r *Record) *acl.EACLRecord {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RecordFromGRPCMessage converts grpc struct into unified acl record struct.
|
||||||
func RecordFromGRPCMessage(m *acl.EACLRecord) *Record {
|
func RecordFromGRPCMessage(m *acl.EACLRecord) *Record {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -285,6 +301,7 @@ func RecordFromGRPCMessage(m *acl.EACLRecord) *Record {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TableToGRPCMessage converts unified acl table struct into grpc struct.
|
||||||
func TableToGRPCMessage(t *Table) *acl.EACLTable {
|
func TableToGRPCMessage(t *Table) *acl.EACLTable {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -308,6 +325,7 @@ func TableToGRPCMessage(t *Table) *acl.EACLTable {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TableFromGRPCMessage converts grpc struct into unified acl table struct.
|
||||||
func TableFromGRPCMessage(m *acl.EACLTable) *Table {
|
func TableFromGRPCMessage(m *acl.EACLTable) *Table {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -24,6 +24,8 @@ const (
|
||||||
tableRecordsField = 2
|
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) {
|
func (t *Table) StableMarshal(buf []byte) ([]byte, error) {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return []byte{}, nil
|
return []byte{}, nil
|
||||||
|
@ -73,6 +75,7 @@ func (t *Table) StableMarshal(buf []byte) ([]byte, error) {
|
||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StableSize of acl table structure marshalled by StableMarshal function.
|
||||||
func (t *Table) StableSize() (size int) {
|
func (t *Table) StableSize() (size int) {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return 0
|
return 0
|
||||||
|
@ -94,6 +97,8 @@ func (t *Table) StableSize() (size int) {
|
||||||
return size
|
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) {
|
func (r *Record) StableMarshal(buf []byte) ([]byte, error) {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return []byte{}, nil
|
return []byte{}, nil
|
||||||
|
@ -158,6 +163,7 @@ func (r *Record) StableMarshal(buf []byte) ([]byte, error) {
|
||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StableSize of acl record structure marshalled by StableMarshal function.
|
||||||
func (r *Record) StableSize() (size int) {
|
func (r *Record) StableSize() (size int) {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return 0
|
return 0
|
||||||
|
@ -183,6 +189,8 @@ func (r *Record) StableSize() (size int) {
|
||||||
return size
|
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) {
|
func (f *HeaderFilter) StableMarshal(buf []byte) ([]byte, error) {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return []byte{}, nil
|
return []byte{}, nil
|
||||||
|
@ -218,7 +226,7 @@ func (f *HeaderFilter) StableMarshal(buf []byte) ([]byte, error) {
|
||||||
|
|
||||||
offset += n
|
offset += n
|
||||||
|
|
||||||
n, err = proto.StringMarshal(filterValueField, buf[offset:], f.value)
|
_, err = proto.StringMarshal(filterValueField, buf[offset:], f.value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -226,6 +234,7 @@ func (f *HeaderFilter) StableMarshal(buf []byte) ([]byte, error) {
|
||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StableSize of header filter structure marshalled by StableMarshal function.
|
||||||
func (f *HeaderFilter) StableSize() (size int) {
|
func (f *HeaderFilter) StableSize() (size int) {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return 0
|
return 0
|
||||||
|
@ -239,6 +248,8 @@ func (f *HeaderFilter) StableSize() (size int) {
|
||||||
return size
|
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) {
|
func (t *TargetInfo) StableMarshal(buf []byte) ([]byte, error) {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return []byte{}, nil
|
return []byte{}, nil
|
||||||
|
@ -260,7 +271,7 @@ func (t *TargetInfo) StableMarshal(buf []byte) ([]byte, error) {
|
||||||
|
|
||||||
offset += n
|
offset += n
|
||||||
|
|
||||||
n, err = proto.RepeatedBytesMarshal(targetKeysField, buf[offset:], t.keys)
|
_, err = proto.RepeatedBytesMarshal(targetKeysField, buf[offset:], t.keys)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -268,6 +279,7 @@ func (t *TargetInfo) StableMarshal(buf []byte) ([]byte, error) {
|
||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StableSize of target info structure marshalled by StableMarshal function.
|
||||||
func (t *TargetInfo) StableSize() (size int) {
|
func (t *TargetInfo) StableSize() (size int) {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -15,6 +15,7 @@ func generateTarget(u acl.Target, k int) *acl.TargetInfo {
|
||||||
target.SetTarget(u)
|
target.SetTarget(u)
|
||||||
|
|
||||||
keys := make([][]byte, k)
|
keys := make([][]byte, k)
|
||||||
|
|
||||||
for i := 0; i < k; i++ {
|
for i := 0; i < k; i++ {
|
||||||
s := fmt.Sprintf("Public Key %d", i+1)
|
s := fmt.Sprintf("Public Key %d", i+1)
|
||||||
keys[i] = []byte(s)
|
keys[i] = []byte(s)
|
||||||
|
@ -23,10 +24,10 @@ func generateTarget(u acl.Target, k int) *acl.TargetInfo {
|
||||||
return target
|
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 := new(acl.HeaderFilter)
|
||||||
filter.SetHeaderType(t)
|
filter.SetHeaderType(t)
|
||||||
filter.SetMatchType(m)
|
filter.SetMatchType(acl.MatchTypeStringEqual)
|
||||||
filter.SetName(k)
|
filter.SetName(k)
|
||||||
filter.SetValue(v)
|
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 {
|
func generateRecord(another bool) *acl.Record {
|
||||||
var record = new(acl.Record)
|
record := new(acl.Record)
|
||||||
|
|
||||||
switch another {
|
switch another {
|
||||||
case true:
|
case true:
|
||||||
t1 := generateTarget(acl.TargetUser, 2)
|
t1 := generateTarget(acl.TargetUser, 2)
|
||||||
f1 := generateFilter(acl.HeaderTypeObject, acl.MatchTypeStringEqual,
|
f1 := generateFilter(acl.HeaderTypeObject, "OID", "ObjectID Value")
|
||||||
"OID", "ObjectID Value")
|
|
||||||
|
|
||||||
record.SetOperation(acl.OperationHead)
|
record.SetOperation(acl.OperationHead)
|
||||||
record.SetAction(acl.ActionDeny)
|
record.SetAction(acl.ActionDeny)
|
||||||
|
@ -48,10 +49,8 @@ func generateRecord(another bool) *acl.Record {
|
||||||
default:
|
default:
|
||||||
t1 := generateTarget(acl.TargetUser, 2)
|
t1 := generateTarget(acl.TargetUser, 2)
|
||||||
t2 := generateTarget(acl.TargetSystem, 0)
|
t2 := generateTarget(acl.TargetSystem, 0)
|
||||||
f1 := generateFilter(acl.HeaderTypeObject, acl.MatchTypeStringEqual,
|
f1 := generateFilter(acl.HeaderTypeObject, "CID", "Container ID Value")
|
||||||
"CID", "Container ID Value")
|
f2 := generateFilter(acl.HeaderTypeRequest, "X-Header-Key", "X-Header-Value")
|
||||||
f2 := generateFilter(acl.HeaderTypeRequest, acl.MatchTypeStringEqual,
|
|
||||||
"X-Header-Key", "X-Header-Value")
|
|
||||||
|
|
||||||
record.SetOperation(acl.OperationPut)
|
record.SetOperation(acl.OperationPut)
|
||||||
record.SetAction(acl.ActionAllow)
|
record.SetAction(acl.ActionAllow)
|
||||||
|
@ -63,8 +62,7 @@ func generateRecord(another bool) *acl.Record {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHeaderFilter_StableMarshal(t *testing.T) {
|
func TestHeaderFilter_StableMarshal(t *testing.T) {
|
||||||
filterFrom := generateFilter(acl.HeaderTypeObject, acl.MatchTypeStringEqual,
|
filterFrom := generateFilter(acl.HeaderTypeObject, "CID", "Container ID Value")
|
||||||
"CID", "Container ID Value")
|
|
||||||
transport := new(grpc.EACLRecord_FilterInfo)
|
transport := new(grpc.EACLRecord_FilterInfo)
|
||||||
|
|
||||||
t.Run("non empty", func(t *testing.T) {
|
t.Run("non empty", func(t *testing.T) {
|
||||||
|
|
|
@ -2,6 +2,8 @@ package acl
|
||||||
|
|
||||||
import "github.com/nspcc-dev/neofs-api-go/v2/refs"
|
import "github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||||
|
|
||||||
|
// HeaderFilter is a unified structure of FilterInfo
|
||||||
|
// message from proto definition.
|
||||||
type HeaderFilter struct {
|
type HeaderFilter struct {
|
||||||
hdrType HeaderType
|
hdrType HeaderType
|
||||||
|
|
||||||
|
@ -10,12 +12,16 @@ type HeaderFilter struct {
|
||||||
name, value string
|
name, value string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TargetInfo is a unified structure of TargetInfo
|
||||||
|
// message from proto definition.
|
||||||
type TargetInfo struct {
|
type TargetInfo struct {
|
||||||
target Target
|
target Target
|
||||||
|
|
||||||
keys [][]byte
|
keys [][]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Record is a unified structure of EACLRecord
|
||||||
|
// message from proto definition.
|
||||||
type Record struct {
|
type Record struct {
|
||||||
op Operation
|
op Operation
|
||||||
|
|
||||||
|
@ -26,20 +32,27 @@ type Record struct {
|
||||||
targets []*TargetInfo
|
targets []*TargetInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Table is a unified structure of EACLTable
|
||||||
|
// message from proto definition.
|
||||||
type Table struct {
|
type Table struct {
|
||||||
cid *refs.ContainerID
|
cid *refs.ContainerID
|
||||||
|
|
||||||
records []*Record
|
records []*Record
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TargetInfo is a unified enum of MatchType enum from proto definition.
|
||||||
type MatchType uint32
|
type MatchType uint32
|
||||||
|
|
||||||
|
// HeaderType is a unified enum of HeaderType enum from proto definition.
|
||||||
type HeaderType uint32
|
type HeaderType uint32
|
||||||
|
|
||||||
|
// Action is a unified enum of Action enum from proto definition.
|
||||||
type Action uint32
|
type Action uint32
|
||||||
|
|
||||||
|
// Operation is a unified enum of Operation enum from proto definition.
|
||||||
type Operation uint32
|
type Operation uint32
|
||||||
|
|
||||||
|
// Target is a unified enum of Target enum from proto definition.
|
||||||
type Target uint32
|
type Target uint32
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
Loading…
Reference in a new issue