[#338] v2/acl: add Service
filter type
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
da89c2b71f
commit
520a065dd2
5 changed files with 16 additions and 3 deletions
|
@ -96,6 +96,9 @@ const (
|
|||
|
||||
// HeaderFromObject is a FilterHeaderType for object header.
|
||||
HeaderFromObject
|
||||
|
||||
// HeaderFromService is a FilterHeaderType for service header.
|
||||
HeaderFromService
|
||||
)
|
||||
|
||||
// ToV2 converts Action to v2 Action enum value.
|
||||
|
@ -343,6 +346,8 @@ func (h FilterHeaderType) ToV2() v2acl.HeaderType {
|
|||
return v2acl.HeaderTypeRequest
|
||||
case HeaderFromObject:
|
||||
return v2acl.HeaderTypeObject
|
||||
case HeaderFromService:
|
||||
return v2acl.HeaderTypeService
|
||||
default:
|
||||
return v2acl.HeaderTypeUnknown
|
||||
}
|
||||
|
@ -355,6 +360,8 @@ func FilterHeaderTypeFromV2(header v2acl.HeaderType) (h FilterHeaderType) {
|
|||
h = HeaderFromRequest
|
||||
case v2acl.HeaderTypeObject:
|
||||
h = HeaderFromObject
|
||||
case v2acl.HeaderTypeService:
|
||||
h = HeaderFromService
|
||||
default:
|
||||
h = HeaderTypeUnknown
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ var (
|
|||
eacl.HeaderTypeUnknown: v2acl.HeaderTypeUnknown,
|
||||
eacl.HeaderFromRequest: v2acl.HeaderTypeRequest,
|
||||
eacl.HeaderFromObject: v2acl.HeaderTypeObject,
|
||||
eacl.HeaderFromService: v2acl.HeaderTypeService,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -104,15 +105,15 @@ func TestMatch(t *testing.T) {
|
|||
|
||||
func TestFilterHeaderType(t *testing.T) {
|
||||
t.Run("known header types", func(t *testing.T) {
|
||||
for i := eacl.HeaderTypeUnknown; i <= eacl.HeaderFromObject; i++ {
|
||||
for i := eacl.HeaderTypeUnknown; i <= eacl.HeaderFromService; i++ {
|
||||
require.Equal(t, eqV2HeaderTypes[i], i.ToV2())
|
||||
require.Equal(t, eacl.FilterHeaderTypeFromV2(i.ToV2()), i)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("unknown header types", func(t *testing.T) {
|
||||
require.Equal(t, (eacl.HeaderFromObject + 1).ToV2(), v2acl.HeaderTypeUnknown)
|
||||
require.Equal(t, eacl.FilterHeaderTypeFromV2(v2acl.HeaderTypeObject+1), eacl.HeaderTypeUnknown)
|
||||
require.Equal(t, (eacl.HeaderFromService + 1).ToV2(), v2acl.HeaderTypeUnknown)
|
||||
require.Equal(t, eacl.FilterHeaderTypeFromV2(v2acl.HeaderTypeService+1), eacl.HeaderTypeUnknown)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -111,6 +111,8 @@ func HeaderTypeToGRPCField(t HeaderType) acl.HeaderType {
|
|||
return acl.HeaderType_REQUEST
|
||||
case HeaderTypeObject:
|
||||
return acl.HeaderType_OBJECT
|
||||
case HeaderTypeService:
|
||||
return acl.HeaderType_SERVICE
|
||||
default:
|
||||
return acl.HeaderType_HEADER_UNSPECIFIED
|
||||
}
|
||||
|
@ -123,6 +125,8 @@ func HeaderTypeFromGRPCField(t acl.HeaderType) HeaderType {
|
|||
return HeaderTypeRequest
|
||||
case acl.HeaderType_OBJECT:
|
||||
return HeaderTypeObject
|
||||
case acl.HeaderType_SERVICE:
|
||||
return HeaderTypeService
|
||||
default:
|
||||
return HeaderTypeUnknown
|
||||
}
|
||||
|
|
BIN
v2/acl/grpc/types.pb.go
generated
BIN
v2/acl/grpc/types.pb.go
generated
Binary file not shown.
|
@ -85,6 +85,7 @@ const (
|
|||
HeaderTypeUnknown HeaderType = iota
|
||||
HeaderTypeRequest
|
||||
HeaderTypeObject
|
||||
HeaderTypeService
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
Loading…
Reference in a new issue