diff --git a/internal/middleware/consistency/consistency_test.go b/internal/middleware/consistency/consistency_test.go index 58a2555246..f985ead597 100644 --- a/internal/middleware/consistency/consistency_test.go +++ b/internal/middleware/consistency/consistency_test.go @@ -169,7 +169,7 @@ func TestAddRevisionToContextWithCursor(t *testing.T) { ds.On("RevisionFromString", optimized.String()).Return(optimized, nil).Once() // cursor is at `optimized` - cursor, err := cursor.EncodeFromDispatchCursor(&dispatch.Cursor{}, "somehash", optimized) + cursor, err := cursor.EncodeFromDispatchCursor(&dispatch.Cursor{}, "somehash", optimized, nil) require.NoError(err) // revision in context is at `exact` diff --git a/internal/services/v1/permissions.go b/internal/services/v1/permissions.go index baf5062bbc..1c3118cc62 100644 --- a/internal/services/v1/permissions.go +++ b/internal/services/v1/permissions.go @@ -391,7 +391,22 @@ func TranslateExpansionTree(node *core.RelationTupleTreeNode) *v1.PermissionRela } } +const lrv2CursorFlag = "lrv2" + func (ps *permissionServer) LookupResources(req *v1.LookupResourcesRequest, resp v1.PermissionsService_LookupResourcesServer) error { + // If the cursor specifies that this is a LookupResources2 request, then that implementation must + // be used. + if req.OptionalCursor != nil { + _, ok, err := cursor.GetCursorFlag(req.OptionalCursor, lrv2CursorFlag) + if err != nil { + return ps.rewriteError(resp.Context(), err) + } + + if ok { + return ps.lookupResources2(req, resp) + } + } + if ps.config.UseExperimentalLookupResources2 { return ps.lookupResources2(req, resp) } @@ -445,7 +460,7 @@ func (ps *permissionServer) lookupResources1(req *v1.LookupResourcesRequest, res } if req.OptionalCursor != nil { - decodedCursor, err := cursor.DecodeToDispatchCursor(req.OptionalCursor, lrRequestHash) + decodedCursor, _, err := cursor.DecodeToDispatchCursor(req.OptionalCursor, lrRequestHash) if err != nil { return ps.rewriteError(ctx, err) } @@ -476,7 +491,7 @@ func (ps *permissionServer) lookupResources1(req *v1.LookupResourcesRequest, res alreadyPublishedPermissionedResourceIds[found.ResourceId] = struct{}{} } - encodedCursor, err := cursor.EncodeFromDispatchCursor(result.AfterResponseCursor, lrRequestHash, atRevision) + encodedCursor, err := cursor.EncodeFromDispatchCursor(result.AfterResponseCursor, lrRequestHash, atRevision, nil) if err != nil { return ps.rewriteError(ctx, err) } @@ -573,7 +588,7 @@ func (ps *permissionServer) lookupResources2(req *v1.LookupResourcesRequest, res } if req.OptionalCursor != nil { - decodedCursor, err := cursor.DecodeToDispatchCursor(req.OptionalCursor, lrRequestHash) + decodedCursor, _, err := cursor.DecodeToDispatchCursor(req.OptionalCursor, lrRequestHash) if err != nil { return ps.rewriteError(ctx, err) } @@ -605,7 +620,9 @@ func (ps *permissionServer) lookupResources2(req *v1.LookupResourcesRequest, res alreadyPublishedPermissionedResourceIds[found.ResourceId] = struct{}{} } - encodedCursor, err := cursor.EncodeFromDispatchCursor(result.AfterResponseCursor, lrRequestHash, atRevision) + encodedCursor, err := cursor.EncodeFromDispatchCursor(result.AfterResponseCursor, lrRequestHash, atRevision, map[string]string{ + lrv2CursorFlag: "1", + }) if err != nil { return ps.rewriteError(ctx, err) } diff --git a/internal/services/v1/relationships.go b/internal/services/v1/relationships.go index 2202ab9e56..6f6e308715 100644 --- a/internal/services/v1/relationships.go +++ b/internal/services/v1/relationships.go @@ -184,7 +184,7 @@ func (ps *permissionServer) ReadRelationships(req *v1.ReadRelationshipsRequest, } if req.OptionalCursor != nil { - decodedCursor, err := cursor.DecodeToDispatchCursor(req.OptionalCursor, rrRequestHash) + decodedCursor, _, err := cursor.DecodeToDispatchCursor(req.OptionalCursor, rrRequestHash) if err != nil { return ps.rewriteError(ctx, err) } @@ -249,7 +249,7 @@ func (ps *permissionServer) ReadRelationships(req *v1.ReadRelationshipsRequest, } dispatchCursor.Sections[0] = tuple.StringWithoutCaveat(tpl) - encodedCursor, err := cursor.EncodeFromDispatchCursor(dispatchCursor, rrRequestHash, atRevision) + encodedCursor, err := cursor.EncodeFromDispatchCursor(dispatchCursor, rrRequestHash, atRevision, nil) if err != nil { return ps.rewriteError(ctx, err) } diff --git a/pkg/cursor/cursor.go b/pkg/cursor/cursor.go index 38df2353ee..4233efaa5c 100644 --- a/pkg/cursor/cursor.go +++ b/pkg/cursor/cursor.go @@ -48,7 +48,7 @@ func Decode(encoded *v1.Cursor) (*impl.DecodedCursor, error) { // consumption, including the provided call context to ensure the API cursor reflects the calling // API method. The call hash should contain all the parameters of the calling API function, // as well as its revision and name. -func EncodeFromDispatchCursor(dispatchCursor *dispatch.Cursor, callAndParameterHash string, revision datastore.Revision) (*v1.Cursor, error) { +func EncodeFromDispatchCursor(dispatchCursor *dispatch.Cursor, callAndParameterHash string, revision datastore.Revision, flags map[string]string) (*v1.Cursor, error) { if dispatchCursor == nil { return nil, spiceerrors.MustBugf("got nil dispatch cursor") } @@ -60,34 +60,51 @@ func EncodeFromDispatchCursor(dispatchCursor *dispatch.Cursor, callAndParameterH DispatchVersion: dispatchCursor.DispatchVersion, Sections: dispatchCursor.Sections, CallAndParametersHash: callAndParameterHash, + Flags: flags, }, }, }) } +// GetCursorFlag retrieves a flag from an encoded API cursor, if any. +func GetCursorFlag(encoded *v1.Cursor, flagName string) (string, bool, error) { + decoded, err := Decode(encoded) + if err != nil { + return "", false, err + } + + v1decoded := decoded.GetV1() + if v1decoded == nil { + return "", false, NewInvalidCursorErr(ErrNilCursor) + } + + value, ok := v1decoded.Flags[flagName] + return value, ok, nil +} + // DecodeToDispatchCursor decodes an encoded API cursor into an internal dispatching cursor, // ensuring that the provided call context matches that encoded into the API cursor. The call // hash should contain all the parameters of the calling API function, as well as its revision // and name. -func DecodeToDispatchCursor(encoded *v1.Cursor, callAndParameterHash string) (*dispatch.Cursor, error) { +func DecodeToDispatchCursor(encoded *v1.Cursor, callAndParameterHash string) (*dispatch.Cursor, map[string]string, error) { decoded, err := Decode(encoded) if err != nil { - return nil, err + return nil, nil, err } v1decoded := decoded.GetV1() if v1decoded == nil { - return nil, NewInvalidCursorErr(ErrNilCursor) + return nil, nil, NewInvalidCursorErr(ErrNilCursor) } if v1decoded.CallAndParametersHash != callAndParameterHash { - return nil, NewInvalidCursorErr(ErrHashMismatch) + return nil, nil, NewInvalidCursorErr(ErrHashMismatch) } return &dispatch.Cursor{ DispatchVersion: v1decoded.DispatchVersion, Sections: v1decoded.Sections, - }, nil + }, v1decoded.Flags, nil } // DecodeToDispatchRevision decodes an encoded API cursor into an internal dispatch revision. diff --git a/pkg/cursor/cursor_test.go b/pkg/cursor/cursor_test.go index 9013fb51df..488c3d56bf 100644 --- a/pkg/cursor/cursor_test.go +++ b/pkg/cursor/cursor_test.go @@ -48,13 +48,14 @@ func TestEncodeDecode(t *testing.T) { require := require.New(t) encoded, err := EncodeFromDispatchCursor(&dispatch.Cursor{ Sections: tc.sections, - }, tc.hash, tc.revision) + }, tc.hash, tc.revision, map[string]string{"some": "flag"}) require.NoError(err) require.NotNil(encoded) - decoded, err := DecodeToDispatchCursor(encoded, tc.hash) + decoded, flags, err := DecodeToDispatchCursor(encoded, tc.hash) require.NoError(err) require.NotNil(decoded) + require.Equal(map[string]string{"some": "flag"}, flags) require.Equal(tc.sections, decoded.Sections) @@ -123,7 +124,7 @@ func TestDecode(t *testing.T) { t.Run(testName, func(t *testing.T) { require := require.New(t) - decoded, err := DecodeToDispatchCursor(&v1.Cursor{ + decoded, _, err := DecodeToDispatchCursor(&v1.Cursor{ Token: testCase.token, }, testCase.expectedHash) diff --git a/pkg/proto/impl/v1/impl.pb.go b/pkg/proto/impl/v1/impl.pb.go index 0845f44244..67ee033f1d 100644 --- a/pkg/proto/impl/v1/impl.pb.go +++ b/pkg/proto/impl/v1/impl.pb.go @@ -400,6 +400,8 @@ type V1Cursor struct { CallAndParametersHash string `protobuf:"bytes,3,opt,name=call_and_parameters_hash,json=callAndParametersHash,proto3" json:"call_and_parameters_hash,omitempty"` // dispatch_version is the version of the dispatcher which created the cursor. DispatchVersion uint32 `protobuf:"varint,4,opt,name=dispatch_version,json=dispatchVersion,proto3" json:"dispatch_version,omitempty"` + // flags are flags set by the API caller. + Flags map[string]string `protobuf:"bytes,5,rep,name=flags,proto3" json:"flags,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (x *V1Cursor) Reset() { @@ -462,6 +464,13 @@ func (x *V1Cursor) GetDispatchVersion() uint32 { return 0 } +func (x *V1Cursor) GetFlags() map[string]string { + if x != nil { + return x.Flags + } + return nil +} + type DocComment struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -896,7 +905,7 @@ var file_impl_v1_impl_proto_rawDesc = []byte{ 0x76, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x69, 0x6d, 0x70, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x31, 0x43, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x48, 0x00, 0x52, 0x02, 0x76, 0x31, 0x42, 0x0f, 0x0a, 0x0d, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x6f, 0x6e, 0x65, - 0x6f, 0x66, 0x22, 0xa6, 0x01, 0x0a, 0x08, 0x56, 0x31, 0x43, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x12, + 0x6f, 0x66, 0x22, 0x94, 0x02, 0x0a, 0x08, 0x56, 0x31, 0x43, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x73, @@ -906,39 +915,46 @@ var file_impl_v1_impl_proto_rawDesc = []byte{ 0x6e, 0x64, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x48, 0x61, 0x73, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x64, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0f, 0x64, 0x69, 0x73, 0x70, - 0x61, 0x74, 0x63, 0x68, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x26, 0x0a, 0x0a, 0x44, - 0x6f, 0x63, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, - 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, - 0x65, 0x6e, 0x74, 0x22, 0x8e, 0x01, 0x0a, 0x10, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x3a, 0x0a, 0x04, 0x6b, 0x69, 0x6e, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x26, 0x2e, 0x69, 0x6d, 0x70, 0x6c, 0x2e, 0x76, 0x31, - 0x2e, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, - 0x61, 0x2e, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4b, 0x69, 0x6e, 0x64, 0x52, 0x04, - 0x6b, 0x69, 0x6e, 0x64, 0x22, 0x3e, 0x0a, 0x0c, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x10, 0x0a, 0x0c, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x5f, - 0x4b, 0x49, 0x4e, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x52, 0x45, 0x4c, 0x41, 0x54, 0x49, - 0x4f, 0x4e, 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x50, 0x45, 0x52, 0x4d, 0x49, 0x53, 0x53, 0x49, - 0x4f, 0x4e, 0x10, 0x02, 0x22, 0x59, 0x0a, 0x14, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, - 0x65, 0x41, 0x6e, 0x64, 0x52, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x0a, 0x0e, - 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x4e, - 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x22, - 0x54, 0x0a, 0x10, 0x56, 0x31, 0x41, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x52, 0x65, 0x76, 0x69, 0x73, - 0x69, 0x6f, 0x6e, 0x12, 0x40, 0x0a, 0x0c, 0x6e, 0x73, 0x5f, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, - 0x6f, 0x6e, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x69, 0x6d, 0x70, 0x6c, - 0x2e, 0x76, 0x31, 0x2e, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x41, 0x6e, 0x64, - 0x52, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x6e, 0x73, 0x52, 0x65, 0x76, 0x69, - 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x42, 0x8a, 0x01, 0x0a, 0x0b, 0x63, 0x6f, 0x6d, 0x2e, 0x69, 0x6d, - 0x70, 0x6c, 0x2e, 0x76, 0x31, 0x42, 0x09, 0x49, 0x6d, 0x70, 0x6c, 0x50, 0x72, 0x6f, 0x74, 0x6f, - 0x50, 0x01, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, - 0x75, 0x74, 0x68, 0x7a, 0x65, 0x64, 0x2f, 0x73, 0x70, 0x69, 0x63, 0x65, 0x64, 0x62, 0x2f, 0x70, - 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x69, 0x6d, 0x70, 0x6c, 0x2f, 0x76, 0x31, - 0x3b, 0x69, 0x6d, 0x70, 0x6c, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x49, 0x58, 0x58, 0xaa, 0x02, 0x07, - 0x49, 0x6d, 0x70, 0x6c, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x07, 0x49, 0x6d, 0x70, 0x6c, 0x5c, 0x56, - 0x31, 0xe2, 0x02, 0x13, 0x49, 0x6d, 0x70, 0x6c, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, - 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x08, 0x49, 0x6d, 0x70, 0x6c, 0x3a, 0x3a, - 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x74, 0x63, 0x68, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x32, 0x0a, 0x05, 0x66, + 0x6c, 0x61, 0x67, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x69, 0x6d, 0x70, + 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x31, 0x43, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x2e, 0x46, 0x6c, + 0x61, 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x1a, + 0x38, 0x0a, 0x0a, 0x46, 0x6c, 0x61, 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x26, 0x0a, 0x0a, 0x44, 0x6f, 0x63, + 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, + 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, + 0x74, 0x22, 0x8e, 0x01, 0x0a, 0x10, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4d, 0x65, + 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x3a, 0x0a, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0e, 0x32, 0x26, 0x2e, 0x69, 0x6d, 0x70, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x52, + 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2e, + 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4b, 0x69, 0x6e, 0x64, 0x52, 0x04, 0x6b, 0x69, + 0x6e, 0x64, 0x22, 0x3e, 0x0a, 0x0c, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4b, 0x69, + 0x6e, 0x64, 0x12, 0x10, 0x0a, 0x0c, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x5f, 0x4b, 0x49, + 0x4e, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x52, 0x45, 0x4c, 0x41, 0x54, 0x49, 0x4f, 0x4e, + 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x50, 0x45, 0x52, 0x4d, 0x49, 0x53, 0x53, 0x49, 0x4f, 0x4e, + 0x10, 0x02, 0x22, 0x59, 0x0a, 0x14, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x41, + 0x6e, 0x64, 0x52, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x6e, 0x61, + 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0d, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x4e, 0x61, 0x6d, + 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x54, 0x0a, + 0x10, 0x56, 0x31, 0x41, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x52, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, + 0x6e, 0x12, 0x40, 0x0a, 0x0c, 0x6e, 0x73, 0x5f, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, + 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x69, 0x6d, 0x70, 0x6c, 0x2e, 0x76, + 0x31, 0x2e, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x41, 0x6e, 0x64, 0x52, 0x65, + 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x6e, 0x73, 0x52, 0x65, 0x76, 0x69, 0x73, 0x69, + 0x6f, 0x6e, 0x73, 0x42, 0x8a, 0x01, 0x0a, 0x0b, 0x63, 0x6f, 0x6d, 0x2e, 0x69, 0x6d, 0x70, 0x6c, + 0x2e, 0x76, 0x31, 0x42, 0x09, 0x49, 0x6d, 0x70, 0x6c, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, + 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x75, 0x74, + 0x68, 0x7a, 0x65, 0x64, 0x2f, 0x73, 0x70, 0x69, 0x63, 0x65, 0x64, 0x62, 0x2f, 0x70, 0x6b, 0x67, + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x69, 0x6d, 0x70, 0x6c, 0x2f, 0x76, 0x31, 0x3b, 0x69, + 0x6d, 0x70, 0x6c, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x49, 0x58, 0x58, 0xaa, 0x02, 0x07, 0x49, 0x6d, + 0x70, 0x6c, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x07, 0x49, 0x6d, 0x70, 0x6c, 0x5c, 0x56, 0x31, 0xe2, + 0x02, 0x13, 0x49, 0x6d, 0x70, 0x6c, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x08, 0x49, 0x6d, 0x70, 0x6c, 0x3a, 0x3a, 0x56, 0x31, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -954,7 +970,7 @@ func file_impl_v1_impl_proto_rawDescGZIP() []byte { } var file_impl_v1_impl_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_impl_v1_impl_proto_msgTypes = make([]protoimpl.MessageInfo, 13) +var file_impl_v1_impl_proto_msgTypes = make([]protoimpl.MessageInfo, 14) var file_impl_v1_impl_proto_goTypes = []any{ (RelationMetadata_RelationKind)(0), // 0: impl.v1.RelationMetadata.RelationKind (*DecodedCaveat)(nil), // 1: impl.v1.DecodedCaveat @@ -970,22 +986,24 @@ var file_impl_v1_impl_proto_goTypes = []any{ (*DecodedZookie_V2Zookie)(nil), // 11: impl.v1.DecodedZookie.V2Zookie (*DecodedZedToken_V1Zookie)(nil), // 12: impl.v1.DecodedZedToken.V1Zookie (*DecodedZedToken_V1ZedToken)(nil), // 13: impl.v1.DecodedZedToken.V1ZedToken - (*v1alpha1.CheckedExpr)(nil), // 14: google.api.expr.v1alpha1.CheckedExpr + nil, // 14: impl.v1.V1Cursor.FlagsEntry + (*v1alpha1.CheckedExpr)(nil), // 15: google.api.expr.v1alpha1.CheckedExpr } var file_impl_v1_impl_proto_depIdxs = []int32{ - 14, // 0: impl.v1.DecodedCaveat.cel:type_name -> google.api.expr.v1alpha1.CheckedExpr + 15, // 0: impl.v1.DecodedCaveat.cel:type_name -> google.api.expr.v1alpha1.CheckedExpr 10, // 1: impl.v1.DecodedZookie.v1:type_name -> impl.v1.DecodedZookie.V1Zookie 11, // 2: impl.v1.DecodedZookie.v2:type_name -> impl.v1.DecodedZookie.V2Zookie 12, // 3: impl.v1.DecodedZedToken.deprecated_v1_zookie:type_name -> impl.v1.DecodedZedToken.V1Zookie 13, // 4: impl.v1.DecodedZedToken.v1:type_name -> impl.v1.DecodedZedToken.V1ZedToken 5, // 5: impl.v1.DecodedCursor.v1:type_name -> impl.v1.V1Cursor - 0, // 6: impl.v1.RelationMetadata.kind:type_name -> impl.v1.RelationMetadata.RelationKind - 8, // 7: impl.v1.V1Alpha1Revision.ns_revisions:type_name -> impl.v1.NamespaceAndRevision - 8, // [8:8] is the sub-list for method output_type - 8, // [8:8] is the sub-list for method input_type - 8, // [8:8] is the sub-list for extension type_name - 8, // [8:8] is the sub-list for extension extendee - 0, // [0:8] is the sub-list for field type_name + 14, // 6: impl.v1.V1Cursor.flags:type_name -> impl.v1.V1Cursor.FlagsEntry + 0, // 7: impl.v1.RelationMetadata.kind:type_name -> impl.v1.RelationMetadata.RelationKind + 8, // 8: impl.v1.V1Alpha1Revision.ns_revisions:type_name -> impl.v1.NamespaceAndRevision + 9, // [9:9] is the sub-list for method output_type + 9, // [9:9] is the sub-list for method input_type + 9, // [9:9] is the sub-list for extension type_name + 9, // [9:9] is the sub-list for extension extendee + 0, // [0:9] is the sub-list for field type_name } func init() { file_impl_v1_impl_proto_init() } @@ -1171,7 +1189,7 @@ func file_impl_v1_impl_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_impl_v1_impl_proto_rawDesc, NumEnums: 1, - NumMessages: 13, + NumMessages: 14, NumExtensions: 0, NumServices: 0, }, diff --git a/pkg/proto/impl/v1/impl.pb.validate.go b/pkg/proto/impl/v1/impl.pb.validate.go index 43a753a435..dea8479bb2 100644 --- a/pkg/proto/impl/v1/impl.pb.validate.go +++ b/pkg/proto/impl/v1/impl.pb.validate.go @@ -733,6 +733,8 @@ func (m *V1Cursor) validate(all bool) error { // no validation rules for DispatchVersion + // no validation rules for Flags + if len(errors) > 0 { return V1CursorMultiError(errors) } diff --git a/pkg/proto/impl/v1/impl_vtproto.pb.go b/pkg/proto/impl/v1/impl_vtproto.pb.go index b33b124c04..951a7d19a0 100644 --- a/pkg/proto/impl/v1/impl_vtproto.pb.go +++ b/pkg/proto/impl/v1/impl_vtproto.pb.go @@ -247,6 +247,13 @@ func (m *V1Cursor) CloneVT() *V1Cursor { copy(tmpContainer, rhs) r.Sections = tmpContainer } + if rhs := m.Flags; rhs != nil { + tmpContainer := make(map[string]string, len(rhs)) + for k, v := range rhs { + tmpContainer[k] = v + } + r.Flags = tmpContainer + } if len(m.unknownFields) > 0 { r.unknownFields = make([]byte, len(m.unknownFields)) copy(r.unknownFields, m.unknownFields) @@ -707,6 +714,18 @@ func (this *V1Cursor) EqualVT(that *V1Cursor) bool { if this.DispatchVersion != that.DispatchVersion { return false } + if len(this.Flags) != len(that.Flags) { + return false + } + for i, vx := range this.Flags { + vy, ok := that.Flags[i] + if !ok { + return false + } + if vx != vy { + return false + } + } return string(this.unknownFields) == string(that.unknownFields) } @@ -1302,6 +1321,25 @@ func (m *V1Cursor) MarshalToSizedBufferVT(dAtA []byte) (int, error) { i -= len(m.unknownFields) copy(dAtA[i:], m.unknownFields) } + if len(m.Flags) > 0 { + for k := range m.Flags { + v := m.Flags[k] + baseI := i + i -= len(v) + copy(dAtA[i:], v) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(v))) + i-- + dAtA[i] = 0x12 + i -= len(k) + copy(dAtA[i:], k) + i = protohelpers.EncodeVarint(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = protohelpers.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x2a + } + } if m.DispatchVersion != 0 { i = protohelpers.EncodeVarint(dAtA, i, uint64(m.DispatchVersion)) i-- @@ -1717,6 +1755,14 @@ func (m *V1Cursor) SizeVT() (n int) { if m.DispatchVersion != 0 { n += 1 + protohelpers.SizeOfVarint(uint64(m.DispatchVersion)) } + if len(m.Flags) > 0 { + for k, v := range m.Flags { + _ = k + _ = v + mapEntrySize := 1 + len(k) + protohelpers.SizeOfVarint(uint64(len(k))) + 1 + len(v) + protohelpers.SizeOfVarint(uint64(len(v))) + n += mapEntrySize + 1 + protohelpers.SizeOfVarint(uint64(mapEntrySize)) + } + } n += len(m.unknownFields) return n } @@ -2749,6 +2795,133 @@ func (m *V1Cursor) UnmarshalVT(dAtA []byte) error { break } } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Flags", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Flags == nil { + m.Flags = make(map[string]string) + } + var mapkey string + var mapvalue string + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return protohelpers.ErrInvalidLength + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return protohelpers.ErrInvalidLength + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + var stringLenmapvalue uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapvalue |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapvalue := int(stringLenmapvalue) + if intStringLenmapvalue < 0 { + return protohelpers.ErrInvalidLength + } + postStringIndexmapvalue := iNdEx + intStringLenmapvalue + if postStringIndexmapvalue < 0 { + return protohelpers.ErrInvalidLength + } + if postStringIndexmapvalue > l { + return io.ErrUnexpectedEOF + } + mapvalue = string(dAtA[iNdEx:postStringIndexmapvalue]) + iNdEx = postStringIndexmapvalue + } else { + iNdEx = entryPreIndex + skippy, err := protohelpers.Skip(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protohelpers.ErrInvalidLength + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.Flags[mapkey] = mapvalue + iNdEx = postIndex default: iNdEx = preIndex skippy, err := protohelpers.Skip(dAtA[iNdEx:]) diff --git a/proto/internal/impl/v1/impl.proto b/proto/internal/impl/v1/impl.proto index c6e871a1ed..836d833910 100644 --- a/proto/internal/impl/v1/impl.proto +++ b/proto/internal/impl/v1/impl.proto @@ -60,6 +60,9 @@ message V1Cursor { // dispatch_version is the version of the dispatcher which created the cursor. uint32 dispatch_version = 4; + + // flags are flags set by the API caller. + map flags = 5; } message DocComment {