From ebff07aaf2040f2ef48490ad54eee78295659e21 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 1 Feb 2021 20:57:18 +0300 Subject: [PATCH] [#254] object: Support new values of search match type Support STRING_NOT_EQUAL and NOT_PRESENT match types of object search filters. Signed-off-by: Leonard Lyubich --- pkg/object/search.go | 10 ++++++++++ pkg/object/search_test.go | 6 ++++-- v2/object/grpc/service.pb.go | 4 ++++ v2/object/grpc/types.pb.go | 25 ++++++++++++++++++------- v2/object/types.go | 2 ++ 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/pkg/object/search.go b/pkg/object/search.go index 5d59e1a8..208fcf48 100644 --- a/pkg/object/search.go +++ b/pkg/object/search.go @@ -15,12 +15,18 @@ type SearchMatchType uint32 const ( MatchUnknown SearchMatchType = iota MatchStringEqual + MatchStringNotEqual + MatchNotPresent ) func (m SearchMatchType) ToV2() v2object.MatchType { switch m { case MatchStringEqual: return v2object.MatchStringEqual + case MatchStringNotEqual: + return v2object.MatchStringNotEqual + case MatchNotPresent: + return v2object.MatchNotPresent default: return v2object.MatchUnknown } @@ -30,6 +36,10 @@ func SearchMatchFromV2(t v2object.MatchType) (m SearchMatchType) { switch t { case v2object.MatchStringEqual: m = MatchStringEqual + case v2object.MatchStringNotEqual: + m = MatchStringNotEqual + case v2object.MatchNotPresent: + m = MatchNotPresent default: m = MatchUnknown } diff --git a/pkg/object/search_test.go b/pkg/object/search_test.go index 48291060..573d06be 100644 --- a/pkg/object/search_test.go +++ b/pkg/object/search_test.go @@ -12,8 +12,10 @@ import ( var ( eqV2Matches = map[object.SearchMatchType]v2object.MatchType{ - object.MatchUnknown: v2object.MatchUnknown, - object.MatchStringEqual: v2object.MatchStringEqual, + object.MatchUnknown: v2object.MatchUnknown, + object.MatchStringEqual: v2object.MatchStringEqual, + object.MatchStringNotEqual: v2object.MatchStringNotEqual, + object.MatchNotPresent: v2object.MatchNotPresent, } ) diff --git a/v2/object/grpc/service.pb.go b/v2/object/grpc/service.pb.go index 890ac966..8f0ea63c 100644 --- a/v2/object/grpc/service.pb.go +++ b/v2/object/grpc/service.pb.go @@ -1952,6 +1952,10 @@ func (x *SearchRequest_Body) GetFilters() []*SearchRequest_Body_Filter { // * $Object:PHY \ // Returns only objects physically stored in the system. This filter is // activated if the `key` exists, disregarding the value and matcher type. +// +// Note: using filters with a key with prefix `$Object:` and match type +// `NOT_PRESENT `is not recommended since this is not a cross-version approach. +// Behavior when processing this kind of filters is undefined. type SearchRequest_Body_Filter struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache diff --git a/v2/object/grpc/types.pb.go b/v2/object/grpc/types.pb.go index 1109640a..b7fdd95a 100644 --- a/v2/object/grpc/types.pb.go +++ b/v2/object/grpc/types.pb.go @@ -96,6 +96,10 @@ const ( MatchType_MATCH_TYPE_UNSPECIFIED MatchType = 0 // Full string match MatchType_STRING_EQUAL MatchType = 1 + // Full string mismatch + MatchType_STRING_NOT_EQUAL MatchType = 2 + // Lack of key + MatchType_NOT_PRESENT MatchType = 3 ) // Enum value maps for MatchType. @@ -103,10 +107,14 @@ var ( MatchType_name = map[int32]string{ 0: "MATCH_TYPE_UNSPECIFIED", 1: "STRING_EQUAL", + 2: "STRING_NOT_EQUAL", + 3: "NOT_PRESENT", } MatchType_value = map[string]int32{ "MATCH_TYPE_UNSPECIFIED": 0, "STRING_EQUAL": 1, + "STRING_NOT_EQUAL": 2, + "NOT_PRESENT": 3, } ) @@ -839,16 +847,19 @@ var file_v2_object_grpc_types_proto_rawDesc = []byte{ 0x0a, 0x0a, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x52, 0x45, 0x47, 0x55, 0x4c, 0x41, 0x52, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x54, 0x4f, 0x4d, 0x42, 0x53, 0x54, 0x4f, 0x4e, 0x45, 0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x53, 0x54, 0x4f, 0x52, - 0x41, 0x47, 0x45, 0x5f, 0x47, 0x52, 0x4f, 0x55, 0x50, 0x10, 0x02, 0x2a, 0x39, 0x0a, 0x09, 0x4d, + 0x41, 0x47, 0x45, 0x5f, 0x47, 0x52, 0x4f, 0x55, 0x50, 0x10, 0x02, 0x2a, 0x60, 0x0a, 0x09, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x16, 0x4d, 0x41, 0x54, 0x43, 0x48, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x10, 0x0a, 0x0c, 0x53, 0x54, 0x52, 0x49, 0x4e, 0x47, 0x5f, 0x45, - 0x51, 0x55, 0x41, 0x4c, 0x10, 0x01, 0x42, 0x4f, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6e, 0x73, 0x70, 0x63, 0x63, 0x2d, 0x64, 0x65, 0x76, 0x2f, 0x6e, - 0x65, 0x6f, 0x66, 0x73, 0x2d, 0x61, 0x70, 0x69, 0x2d, 0x67, 0x6f, 0x2f, 0x76, 0x32, 0x2f, 0x6f, - 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x3b, 0x6f, 0x62, 0x6a, 0x65, 0x63, - 0x74, 0xaa, 0x02, 0x13, 0x4e, 0x65, 0x6f, 0x46, 0x53, 0x2e, 0x41, 0x50, 0x49, 0x2e, 0x76, 0x32, - 0x2e, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x51, 0x55, 0x41, 0x4c, 0x10, 0x01, 0x12, 0x14, 0x0a, 0x10, 0x53, 0x54, 0x52, 0x49, 0x4e, 0x47, + 0x5f, 0x4e, 0x4f, 0x54, 0x5f, 0x45, 0x51, 0x55, 0x41, 0x4c, 0x10, 0x02, 0x12, 0x0f, 0x0a, 0x0b, + 0x4e, 0x4f, 0x54, 0x5f, 0x50, 0x52, 0x45, 0x53, 0x45, 0x4e, 0x54, 0x10, 0x03, 0x42, 0x4f, 0x5a, + 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6e, 0x73, 0x70, 0x63, + 0x63, 0x2d, 0x64, 0x65, 0x76, 0x2f, 0x6e, 0x65, 0x6f, 0x66, 0x73, 0x2d, 0x61, 0x70, 0x69, 0x2d, + 0x67, 0x6f, 0x2f, 0x76, 0x32, 0x2f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x67, 0x72, 0x70, + 0x63, 0x3b, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0xaa, 0x02, 0x13, 0x4e, 0x65, 0x6f, 0x46, 0x53, + 0x2e, 0x41, 0x50, 0x49, 0x2e, 0x76, 0x32, 0x2e, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/v2/object/types.go b/v2/object/types.go index 3c258eb5..bed48d45 100644 --- a/v2/object/types.go +++ b/v2/object/types.go @@ -226,6 +226,8 @@ const ( const ( MatchUnknown MatchType = iota MatchStringEqual + MatchStringNotEqual + MatchNotPresent ) func (h *ShortHeader) GetVersion() *refs.Version {