[#338] v2/acl: add Service filter type

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-09-14 13:51:20 +03:00 committed by Alex Vanin
parent da89c2b71f
commit 520a065dd2
5 changed files with 16 additions and 3 deletions

View file

@ -96,6 +96,9 @@ const (
// HeaderFromObject is a FilterHeaderType for object header. // HeaderFromObject is a FilterHeaderType for object header.
HeaderFromObject HeaderFromObject
// HeaderFromService is a FilterHeaderType for service header.
HeaderFromService
) )
// ToV2 converts Action to v2 Action enum value. // ToV2 converts Action to v2 Action enum value.
@ -343,6 +346,8 @@ func (h FilterHeaderType) ToV2() v2acl.HeaderType {
return v2acl.HeaderTypeRequest return v2acl.HeaderTypeRequest
case HeaderFromObject: case HeaderFromObject:
return v2acl.HeaderTypeObject return v2acl.HeaderTypeObject
case HeaderFromService:
return v2acl.HeaderTypeService
default: default:
return v2acl.HeaderTypeUnknown return v2acl.HeaderTypeUnknown
} }
@ -355,6 +360,8 @@ func FilterHeaderTypeFromV2(header v2acl.HeaderType) (h FilterHeaderType) {
h = HeaderFromRequest h = HeaderFromRequest
case v2acl.HeaderTypeObject: case v2acl.HeaderTypeObject:
h = HeaderFromObject h = HeaderFromObject
case v2acl.HeaderTypeService:
h = HeaderFromService
default: default:
h = HeaderTypeUnknown h = HeaderTypeUnknown
} }

View file

@ -43,6 +43,7 @@ var (
eacl.HeaderTypeUnknown: v2acl.HeaderTypeUnknown, eacl.HeaderTypeUnknown: v2acl.HeaderTypeUnknown,
eacl.HeaderFromRequest: v2acl.HeaderTypeRequest, eacl.HeaderFromRequest: v2acl.HeaderTypeRequest,
eacl.HeaderFromObject: v2acl.HeaderTypeObject, eacl.HeaderFromObject: v2acl.HeaderTypeObject,
eacl.HeaderFromService: v2acl.HeaderTypeService,
} }
) )
@ -104,15 +105,15 @@ func TestMatch(t *testing.T) {
func TestFilterHeaderType(t *testing.T) { func TestFilterHeaderType(t *testing.T) {
t.Run("known header types", func(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, eqV2HeaderTypes[i], i.ToV2())
require.Equal(t, eacl.FilterHeaderTypeFromV2(i.ToV2()), i) require.Equal(t, eacl.FilterHeaderTypeFromV2(i.ToV2()), i)
} }
}) })
t.Run("unknown header types", func(t *testing.T) { t.Run("unknown header types", func(t *testing.T) {
require.Equal(t, (eacl.HeaderFromObject + 1).ToV2(), v2acl.HeaderTypeUnknown) require.Equal(t, (eacl.HeaderFromService + 1).ToV2(), v2acl.HeaderTypeUnknown)
require.Equal(t, eacl.FilterHeaderTypeFromV2(v2acl.HeaderTypeObject+1), eacl.HeaderTypeUnknown) require.Equal(t, eacl.FilterHeaderTypeFromV2(v2acl.HeaderTypeService+1), eacl.HeaderTypeUnknown)
}) })
} }

View file

@ -111,6 +111,8 @@ func HeaderTypeToGRPCField(t HeaderType) acl.HeaderType {
return acl.HeaderType_REQUEST return acl.HeaderType_REQUEST
case HeaderTypeObject: case HeaderTypeObject:
return acl.HeaderType_OBJECT return acl.HeaderType_OBJECT
case HeaderTypeService:
return acl.HeaderType_SERVICE
default: default:
return acl.HeaderType_HEADER_UNSPECIFIED return acl.HeaderType_HEADER_UNSPECIFIED
} }
@ -123,6 +125,8 @@ func HeaderTypeFromGRPCField(t acl.HeaderType) HeaderType {
return HeaderTypeRequest return HeaderTypeRequest
case acl.HeaderType_OBJECT: case acl.HeaderType_OBJECT:
return HeaderTypeObject return HeaderTypeObject
case acl.HeaderType_SERVICE:
return HeaderTypeService
default: default:
return HeaderTypeUnknown return HeaderTypeUnknown
} }

BIN
v2/acl/grpc/types.pb.go generated

Binary file not shown.

View file

@ -85,6 +85,7 @@ const (
HeaderTypeUnknown HeaderType = iota HeaderTypeUnknown HeaderType = iota
HeaderTypeRequest HeaderTypeRequest
HeaderTypeObject HeaderTypeObject
HeaderTypeService
) )
const ( const (