diff --git a/internal/app/archied/bootstrap.go b/internal/app/archied/bootstrap.go index 5281d21dd..14e207ee1 100644 --- a/internal/app/archied/bootstrap.go +++ b/internal/app/archied/bootstrap.go @@ -1349,6 +1349,9 @@ func (b *boot) buildDaemon() { if bd, ok := b.stateStore.(storecontract.BindingDispatcher); ok { b.d.BindingDispatcher = bd } + if mm, ok := b.stateStore.(storecontract.MappingMatchRecorder); ok { + b.d.MappingMatches = mm + } if btc, ok := b.stateStore.(storecontract.BindingTaskCreator); ok { b.d.BindingTaskCreator = btc } diff --git a/internal/app/archied/state_store.go b/internal/app/archied/state_store.go index c2052b4aa..7060ab87e 100644 --- a/internal/app/archied/state_store.go +++ b/internal/app/archied/state_store.go @@ -258,6 +258,9 @@ func (b *boot) stateStoreDeps(grants *staterpc.TaskGrants) staterpc.Deps { if eventTypes, ok := any(b.eda).(storecontract.EventTypeStore); ok { deps.EventTypes = eventTypes } + if matches, ok := any(b.eda).(storecontract.MappingMatchRecorder); ok { + deps.MappingMatches = matches + } } // tool_call events project into the tool_calls collection on the same // event-capture store: this process legitimately owns both, so the diff --git a/internal/contracts/state/v1/state.pb.go b/internal/contracts/state/v1/state.pb.go index b163b6fd5..20dbad703 100644 --- a/internal/contracts/state/v1/state.pb.go +++ b/internal/contracts/state/v1/state.pb.go @@ -2143,13 +2143,17 @@ func (x *MappingField) GetRequired() bool { // Mapping mirrors internal/domain/mapping.Mapping. type Mapping struct { - state protoimpl.MessageState `protogen:"open.v1"` - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` - SourceHint string `protobuf:"bytes,3,opt,name=source_hint,json=sourceHint,proto3" json:"source_hint,omitempty"` - Fields []*MappingField `protobuf:"bytes,4,rep,name=fields,proto3" json:"fields,omitempty"` - CreatedAt *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` - UpdatedAt *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"` + state protoimpl.MessageState `protogen:"open.v1"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + SourceHint string `protobuf:"bytes,3,opt,name=source_hint,json=sourceHint,proto3" json:"source_hint,omitempty"` + Fields []*MappingField `protobuf:"bytes,4,rep,name=fields,proto3" json:"fields,omitempty"` + CreatedAt *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` + UpdatedAt *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"` + EventTypeId string `protobuf:"bytes,7,opt,name=event_type_id,json=eventTypeId,proto3" json:"event_type_id,omitempty"` + // match_count and last_matched_at are read-only: the store counts them. + MatchCount int64 `protobuf:"varint,8,opt,name=match_count,json=matchCount,proto3" json:"match_count,omitempty"` + LastMatchedAt *timestamppb.Timestamp `protobuf:"bytes,9,opt,name=last_matched_at,json=lastMatchedAt,proto3" json:"last_matched_at,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -2226,6 +2230,27 @@ func (x *Mapping) GetUpdatedAt() *timestamppb.Timestamp { return nil } +func (x *Mapping) GetEventTypeId() string { + if x != nil { + return x.EventTypeId + } + return "" +} + +func (x *Mapping) GetMatchCount() int64 { + if x != nil { + return x.MatchCount + } + return 0 +} + +func (x *Mapping) GetLastMatchedAt() *timestamppb.Timestamp { + if x != nil { + return x.LastMatchedAt + } + return nil +} + // BindingMatcher mirrors internal/domain/binding.Matcher. type BindingMatcher struct { state protoimpl.MessageState `protogen:"open.v1"` @@ -2286,6 +2311,7 @@ type Binding struct { Secret string `protobuf:"bytes,10,opt,name=secret,proto3" json:"secret,omitempty"` CreatedAt *timestamppb.Timestamp `protobuf:"bytes,11,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` UpdatedAt *timestamppb.Timestamp `protobuf:"bytes,12,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"` + Filter string `protobuf:"bytes,13,opt,name=filter,proto3" json:"filter,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -2404,6 +2430,13 @@ func (x *Binding) GetUpdatedAt() *timestamppb.Timestamp { return nil } +func (x *Binding) GetFilter() string { + if x != nil { + return x.Filter + } + return "" +} + // WorkflowStat mirrors internal/store.WorkflowStat. type WorkflowStat struct { state protoimpl.MessageState `protogen:"open.v1"` @@ -7050,6 +7083,94 @@ func (*DeleteMappingResponse) Descriptor() ([]byte, []int) { return file_state_v1_state_proto_rawDescGZIP(), []int{126} } +type RecordMappingMatchRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + MappingId string `protobuf:"bytes,1,opt,name=mapping_id,json=mappingId,proto3" json:"mapping_id,omitempty"` + CaptureId string `protobuf:"bytes,2,opt,name=capture_id,json=captureId,proto3" json:"capture_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *RecordMappingMatchRequest) Reset() { + *x = RecordMappingMatchRequest{} + mi := &file_state_v1_state_proto_msgTypes[127] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *RecordMappingMatchRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RecordMappingMatchRequest) ProtoMessage() {} + +func (x *RecordMappingMatchRequest) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[127] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RecordMappingMatchRequest.ProtoReflect.Descriptor instead. +func (*RecordMappingMatchRequest) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{127} +} + +func (x *RecordMappingMatchRequest) GetMappingId() string { + if x != nil { + return x.MappingId + } + return "" +} + +func (x *RecordMappingMatchRequest) GetCaptureId() string { + if x != nil { + return x.CaptureId + } + return "" +} + +type RecordMappingMatchResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *RecordMappingMatchResponse) Reset() { + *x = RecordMappingMatchResponse{} + mi := &file_state_v1_state_proto_msgTypes[128] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *RecordMappingMatchResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RecordMappingMatchResponse) ProtoMessage() {} + +func (x *RecordMappingMatchResponse) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[128] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RecordMappingMatchResponse.ProtoReflect.Descriptor instead. +func (*RecordMappingMatchResponse) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{128} +} + type InsertEventTypeRequest struct { state protoimpl.MessageState `protogen:"open.v1"` EventType *EventType `protobuf:"bytes,1,opt,name=event_type,json=eventType,proto3" json:"event_type,omitempty"` @@ -7059,7 +7180,7 @@ type InsertEventTypeRequest struct { func (x *InsertEventTypeRequest) Reset() { *x = InsertEventTypeRequest{} - mi := &file_state_v1_state_proto_msgTypes[127] + mi := &file_state_v1_state_proto_msgTypes[129] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7071,7 +7192,7 @@ func (x *InsertEventTypeRequest) String() string { func (*InsertEventTypeRequest) ProtoMessage() {} func (x *InsertEventTypeRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[127] + mi := &file_state_v1_state_proto_msgTypes[129] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7084,7 +7205,7 @@ func (x *InsertEventTypeRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use InsertEventTypeRequest.ProtoReflect.Descriptor instead. func (*InsertEventTypeRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{127} + return file_state_v1_state_proto_rawDescGZIP(), []int{129} } func (x *InsertEventTypeRequest) GetEventType() *EventType { @@ -7103,7 +7224,7 @@ type InsertEventTypeResponse struct { func (x *InsertEventTypeResponse) Reset() { *x = InsertEventTypeResponse{} - mi := &file_state_v1_state_proto_msgTypes[128] + mi := &file_state_v1_state_proto_msgTypes[130] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7115,7 +7236,7 @@ func (x *InsertEventTypeResponse) String() string { func (*InsertEventTypeResponse) ProtoMessage() {} func (x *InsertEventTypeResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[128] + mi := &file_state_v1_state_proto_msgTypes[130] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7128,7 +7249,7 @@ func (x *InsertEventTypeResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use InsertEventTypeResponse.ProtoReflect.Descriptor instead. func (*InsertEventTypeResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{128} + return file_state_v1_state_proto_rawDescGZIP(), []int{130} } func (x *InsertEventTypeResponse) GetId() string { @@ -7147,7 +7268,7 @@ type UpdateEventTypeRequest struct { func (x *UpdateEventTypeRequest) Reset() { *x = UpdateEventTypeRequest{} - mi := &file_state_v1_state_proto_msgTypes[129] + mi := &file_state_v1_state_proto_msgTypes[131] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7159,7 +7280,7 @@ func (x *UpdateEventTypeRequest) String() string { func (*UpdateEventTypeRequest) ProtoMessage() {} func (x *UpdateEventTypeRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[129] + mi := &file_state_v1_state_proto_msgTypes[131] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7172,7 +7293,7 @@ func (x *UpdateEventTypeRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use UpdateEventTypeRequest.ProtoReflect.Descriptor instead. func (*UpdateEventTypeRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{129} + return file_state_v1_state_proto_rawDescGZIP(), []int{131} } func (x *UpdateEventTypeRequest) GetEventType() *EventType { @@ -7190,7 +7311,7 @@ type UpdateEventTypeResponse struct { func (x *UpdateEventTypeResponse) Reset() { *x = UpdateEventTypeResponse{} - mi := &file_state_v1_state_proto_msgTypes[130] + mi := &file_state_v1_state_proto_msgTypes[132] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7202,7 +7323,7 @@ func (x *UpdateEventTypeResponse) String() string { func (*UpdateEventTypeResponse) ProtoMessage() {} func (x *UpdateEventTypeResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[130] + mi := &file_state_v1_state_proto_msgTypes[132] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7215,7 +7336,7 @@ func (x *UpdateEventTypeResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use UpdateEventTypeResponse.ProtoReflect.Descriptor instead. func (*UpdateEventTypeResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{130} + return file_state_v1_state_proto_rawDescGZIP(), []int{132} } type DeleteEventTypeRequest struct { @@ -7227,7 +7348,7 @@ type DeleteEventTypeRequest struct { func (x *DeleteEventTypeRequest) Reset() { *x = DeleteEventTypeRequest{} - mi := &file_state_v1_state_proto_msgTypes[131] + mi := &file_state_v1_state_proto_msgTypes[133] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7239,7 +7360,7 @@ func (x *DeleteEventTypeRequest) String() string { func (*DeleteEventTypeRequest) ProtoMessage() {} func (x *DeleteEventTypeRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[131] + mi := &file_state_v1_state_proto_msgTypes[133] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7252,7 +7373,7 @@ func (x *DeleteEventTypeRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use DeleteEventTypeRequest.ProtoReflect.Descriptor instead. func (*DeleteEventTypeRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{131} + return file_state_v1_state_proto_rawDescGZIP(), []int{133} } func (x *DeleteEventTypeRequest) GetId() string { @@ -7270,7 +7391,7 @@ type DeleteEventTypeResponse struct { func (x *DeleteEventTypeResponse) Reset() { *x = DeleteEventTypeResponse{} - mi := &file_state_v1_state_proto_msgTypes[132] + mi := &file_state_v1_state_proto_msgTypes[134] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7282,7 +7403,7 @@ func (x *DeleteEventTypeResponse) String() string { func (*DeleteEventTypeResponse) ProtoMessage() {} func (x *DeleteEventTypeResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[132] + mi := &file_state_v1_state_proto_msgTypes[134] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7295,7 +7416,7 @@ func (x *DeleteEventTypeResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use DeleteEventTypeResponse.ProtoReflect.Descriptor instead. func (*DeleteEventTypeResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{132} + return file_state_v1_state_proto_rawDescGZIP(), []int{134} } type ListEventTypesRequest struct { @@ -7306,7 +7427,7 @@ type ListEventTypesRequest struct { func (x *ListEventTypesRequest) Reset() { *x = ListEventTypesRequest{} - mi := &file_state_v1_state_proto_msgTypes[133] + mi := &file_state_v1_state_proto_msgTypes[135] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7318,7 +7439,7 @@ func (x *ListEventTypesRequest) String() string { func (*ListEventTypesRequest) ProtoMessage() {} func (x *ListEventTypesRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[133] + mi := &file_state_v1_state_proto_msgTypes[135] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7331,7 +7452,7 @@ func (x *ListEventTypesRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ListEventTypesRequest.ProtoReflect.Descriptor instead. func (*ListEventTypesRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{133} + return file_state_v1_state_proto_rawDescGZIP(), []int{135} } type ListEventTypesResponse struct { @@ -7343,7 +7464,7 @@ type ListEventTypesResponse struct { func (x *ListEventTypesResponse) Reset() { *x = ListEventTypesResponse{} - mi := &file_state_v1_state_proto_msgTypes[134] + mi := &file_state_v1_state_proto_msgTypes[136] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7355,7 +7476,7 @@ func (x *ListEventTypesResponse) String() string { func (*ListEventTypesResponse) ProtoMessage() {} func (x *ListEventTypesResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[134] + mi := &file_state_v1_state_proto_msgTypes[136] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7368,7 +7489,7 @@ func (x *ListEventTypesResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ListEventTypesResponse.ProtoReflect.Descriptor instead. func (*ListEventTypesResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{134} + return file_state_v1_state_proto_rawDescGZIP(), []int{136} } func (x *ListEventTypesResponse) GetEventTypes() []*EventType { @@ -7387,7 +7508,7 @@ type InsertBindingRequest struct { func (x *InsertBindingRequest) Reset() { *x = InsertBindingRequest{} - mi := &file_state_v1_state_proto_msgTypes[135] + mi := &file_state_v1_state_proto_msgTypes[137] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7399,7 +7520,7 @@ func (x *InsertBindingRequest) String() string { func (*InsertBindingRequest) ProtoMessage() {} func (x *InsertBindingRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[135] + mi := &file_state_v1_state_proto_msgTypes[137] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7412,7 +7533,7 @@ func (x *InsertBindingRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use InsertBindingRequest.ProtoReflect.Descriptor instead. func (*InsertBindingRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{135} + return file_state_v1_state_proto_rawDescGZIP(), []int{137} } func (x *InsertBindingRequest) GetBinding() *Binding { @@ -7431,7 +7552,7 @@ type InsertBindingResponse struct { func (x *InsertBindingResponse) Reset() { *x = InsertBindingResponse{} - mi := &file_state_v1_state_proto_msgTypes[136] + mi := &file_state_v1_state_proto_msgTypes[138] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7443,7 +7564,7 @@ func (x *InsertBindingResponse) String() string { func (*InsertBindingResponse) ProtoMessage() {} func (x *InsertBindingResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[136] + mi := &file_state_v1_state_proto_msgTypes[138] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7456,7 +7577,7 @@ func (x *InsertBindingResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use InsertBindingResponse.ProtoReflect.Descriptor instead. func (*InsertBindingResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{136} + return file_state_v1_state_proto_rawDescGZIP(), []int{138} } func (x *InsertBindingResponse) GetId() string { @@ -7475,7 +7596,7 @@ type GetBindingRequest struct { func (x *GetBindingRequest) Reset() { *x = GetBindingRequest{} - mi := &file_state_v1_state_proto_msgTypes[137] + mi := &file_state_v1_state_proto_msgTypes[139] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7487,7 +7608,7 @@ func (x *GetBindingRequest) String() string { func (*GetBindingRequest) ProtoMessage() {} func (x *GetBindingRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[137] + mi := &file_state_v1_state_proto_msgTypes[139] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7500,7 +7621,7 @@ func (x *GetBindingRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetBindingRequest.ProtoReflect.Descriptor instead. func (*GetBindingRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{137} + return file_state_v1_state_proto_rawDescGZIP(), []int{139} } func (x *GetBindingRequest) GetId() string { @@ -7520,7 +7641,7 @@ type GetBindingResponse struct { func (x *GetBindingResponse) Reset() { *x = GetBindingResponse{} - mi := &file_state_v1_state_proto_msgTypes[138] + mi := &file_state_v1_state_proto_msgTypes[140] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7532,7 +7653,7 @@ func (x *GetBindingResponse) String() string { func (*GetBindingResponse) ProtoMessage() {} func (x *GetBindingResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[138] + mi := &file_state_v1_state_proto_msgTypes[140] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7545,7 +7666,7 @@ func (x *GetBindingResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetBindingResponse.ProtoReflect.Descriptor instead. func (*GetBindingResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{138} + return file_state_v1_state_proto_rawDescGZIP(), []int{140} } func (x *GetBindingResponse) GetBinding() *Binding { @@ -7570,7 +7691,7 @@ type ListBindingsRequest struct { func (x *ListBindingsRequest) Reset() { *x = ListBindingsRequest{} - mi := &file_state_v1_state_proto_msgTypes[139] + mi := &file_state_v1_state_proto_msgTypes[141] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7582,7 +7703,7 @@ func (x *ListBindingsRequest) String() string { func (*ListBindingsRequest) ProtoMessage() {} func (x *ListBindingsRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[139] + mi := &file_state_v1_state_proto_msgTypes[141] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7595,7 +7716,7 @@ func (x *ListBindingsRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ListBindingsRequest.ProtoReflect.Descriptor instead. func (*ListBindingsRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{139} + return file_state_v1_state_proto_rawDescGZIP(), []int{141} } type ListBindingsResponse struct { @@ -7607,7 +7728,7 @@ type ListBindingsResponse struct { func (x *ListBindingsResponse) Reset() { *x = ListBindingsResponse{} - mi := &file_state_v1_state_proto_msgTypes[140] + mi := &file_state_v1_state_proto_msgTypes[142] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7619,7 +7740,7 @@ func (x *ListBindingsResponse) String() string { func (*ListBindingsResponse) ProtoMessage() {} func (x *ListBindingsResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[140] + mi := &file_state_v1_state_proto_msgTypes[142] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7632,7 +7753,7 @@ func (x *ListBindingsResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ListBindingsResponse.ProtoReflect.Descriptor instead. func (*ListBindingsResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{140} + return file_state_v1_state_proto_rawDescGZIP(), []int{142} } func (x *ListBindingsResponse) GetBindings() []*Binding { @@ -7651,7 +7772,7 @@ type UpdateBindingRequest struct { func (x *UpdateBindingRequest) Reset() { *x = UpdateBindingRequest{} - mi := &file_state_v1_state_proto_msgTypes[141] + mi := &file_state_v1_state_proto_msgTypes[143] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7663,7 +7784,7 @@ func (x *UpdateBindingRequest) String() string { func (*UpdateBindingRequest) ProtoMessage() {} func (x *UpdateBindingRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[141] + mi := &file_state_v1_state_proto_msgTypes[143] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7676,7 +7797,7 @@ func (x *UpdateBindingRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use UpdateBindingRequest.ProtoReflect.Descriptor instead. func (*UpdateBindingRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{141} + return file_state_v1_state_proto_rawDescGZIP(), []int{143} } func (x *UpdateBindingRequest) GetBinding() *Binding { @@ -7694,7 +7815,7 @@ type UpdateBindingResponse struct { func (x *UpdateBindingResponse) Reset() { *x = UpdateBindingResponse{} - mi := &file_state_v1_state_proto_msgTypes[142] + mi := &file_state_v1_state_proto_msgTypes[144] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7706,7 +7827,7 @@ func (x *UpdateBindingResponse) String() string { func (*UpdateBindingResponse) ProtoMessage() {} func (x *UpdateBindingResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[142] + mi := &file_state_v1_state_proto_msgTypes[144] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7719,7 +7840,7 @@ func (x *UpdateBindingResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use UpdateBindingResponse.ProtoReflect.Descriptor instead. func (*UpdateBindingResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{142} + return file_state_v1_state_proto_rawDescGZIP(), []int{144} } type DeleteBindingRequest struct { @@ -7731,7 +7852,7 @@ type DeleteBindingRequest struct { func (x *DeleteBindingRequest) Reset() { *x = DeleteBindingRequest{} - mi := &file_state_v1_state_proto_msgTypes[143] + mi := &file_state_v1_state_proto_msgTypes[145] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7743,7 +7864,7 @@ func (x *DeleteBindingRequest) String() string { func (*DeleteBindingRequest) ProtoMessage() {} func (x *DeleteBindingRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[143] + mi := &file_state_v1_state_proto_msgTypes[145] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7756,7 +7877,7 @@ func (x *DeleteBindingRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use DeleteBindingRequest.ProtoReflect.Descriptor instead. func (*DeleteBindingRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{143} + return file_state_v1_state_proto_rawDescGZIP(), []int{145} } func (x *DeleteBindingRequest) GetId() string { @@ -7774,7 +7895,7 @@ type DeleteBindingResponse struct { func (x *DeleteBindingResponse) Reset() { *x = DeleteBindingResponse{} - mi := &file_state_v1_state_proto_msgTypes[144] + mi := &file_state_v1_state_proto_msgTypes[146] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7786,7 +7907,7 @@ func (x *DeleteBindingResponse) String() string { func (*DeleteBindingResponse) ProtoMessage() {} func (x *DeleteBindingResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[144] + mi := &file_state_v1_state_proto_msgTypes[146] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7799,7 +7920,7 @@ func (x *DeleteBindingResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use DeleteBindingResponse.ProtoReflect.Descriptor instead. func (*DeleteBindingResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{144} + return file_state_v1_state_proto_rawDescGZIP(), []int{146} } type ApproveBindingRequest struct { @@ -7811,7 +7932,7 @@ type ApproveBindingRequest struct { func (x *ApproveBindingRequest) Reset() { *x = ApproveBindingRequest{} - mi := &file_state_v1_state_proto_msgTypes[145] + mi := &file_state_v1_state_proto_msgTypes[147] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7823,7 +7944,7 @@ func (x *ApproveBindingRequest) String() string { func (*ApproveBindingRequest) ProtoMessage() {} func (x *ApproveBindingRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[145] + mi := &file_state_v1_state_proto_msgTypes[147] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7836,7 +7957,7 @@ func (x *ApproveBindingRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ApproveBindingRequest.ProtoReflect.Descriptor instead. func (*ApproveBindingRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{145} + return file_state_v1_state_proto_rawDescGZIP(), []int{147} } func (x *ApproveBindingRequest) GetId() string { @@ -7854,7 +7975,7 @@ type ApproveBindingResponse struct { func (x *ApproveBindingResponse) Reset() { *x = ApproveBindingResponse{} - mi := &file_state_v1_state_proto_msgTypes[146] + mi := &file_state_v1_state_proto_msgTypes[148] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7866,7 +7987,7 @@ func (x *ApproveBindingResponse) String() string { func (*ApproveBindingResponse) ProtoMessage() {} func (x *ApproveBindingResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[146] + mi := &file_state_v1_state_proto_msgTypes[148] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7879,7 +8000,7 @@ func (x *ApproveBindingResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ApproveBindingResponse.ProtoReflect.Descriptor instead. func (*ApproveBindingResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{146} + return file_state_v1_state_proto_rawDescGZIP(), []int{148} } type ArmedBindingsForSourceRequest struct { @@ -7891,7 +8012,7 @@ type ArmedBindingsForSourceRequest struct { func (x *ArmedBindingsForSourceRequest) Reset() { *x = ArmedBindingsForSourceRequest{} - mi := &file_state_v1_state_proto_msgTypes[147] + mi := &file_state_v1_state_proto_msgTypes[149] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7903,7 +8024,7 @@ func (x *ArmedBindingsForSourceRequest) String() string { func (*ArmedBindingsForSourceRequest) ProtoMessage() {} func (x *ArmedBindingsForSourceRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[147] + mi := &file_state_v1_state_proto_msgTypes[149] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7916,7 +8037,7 @@ func (x *ArmedBindingsForSourceRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ArmedBindingsForSourceRequest.ProtoReflect.Descriptor instead. func (*ArmedBindingsForSourceRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{147} + return file_state_v1_state_proto_rawDescGZIP(), []int{149} } func (x *ArmedBindingsForSourceRequest) GetSource() string { @@ -7935,7 +8056,7 @@ type ArmedBindingsForSourceResponse struct { func (x *ArmedBindingsForSourceResponse) Reset() { *x = ArmedBindingsForSourceResponse{} - mi := &file_state_v1_state_proto_msgTypes[148] + mi := &file_state_v1_state_proto_msgTypes[150] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7947,7 +8068,7 @@ func (x *ArmedBindingsForSourceResponse) String() string { func (*ArmedBindingsForSourceResponse) ProtoMessage() {} func (x *ArmedBindingsForSourceResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[148] + mi := &file_state_v1_state_proto_msgTypes[150] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -7960,7 +8081,7 @@ func (x *ArmedBindingsForSourceResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ArmedBindingsForSourceResponse.ProtoReflect.Descriptor instead. func (*ArmedBindingsForSourceResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{148} + return file_state_v1_state_proto_rawDescGZIP(), []int{150} } func (x *ArmedBindingsForSourceResponse) GetBindings() []*Binding { @@ -7983,7 +8104,7 @@ type RecordDispatchRequest struct { func (x *RecordDispatchRequest) Reset() { *x = RecordDispatchRequest{} - mi := &file_state_v1_state_proto_msgTypes[149] + mi := &file_state_v1_state_proto_msgTypes[151] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -7995,7 +8116,7 @@ func (x *RecordDispatchRequest) String() string { func (*RecordDispatchRequest) ProtoMessage() {} func (x *RecordDispatchRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[149] + mi := &file_state_v1_state_proto_msgTypes[151] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -8008,7 +8129,7 @@ func (x *RecordDispatchRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use RecordDispatchRequest.ProtoReflect.Descriptor instead. func (*RecordDispatchRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{149} + return file_state_v1_state_proto_rawDescGZIP(), []int{151} } func (x *RecordDispatchRequest) GetBindingId() string { @@ -8047,7 +8168,7 @@ type RecordDispatchResponse struct { func (x *RecordDispatchResponse) Reset() { *x = RecordDispatchResponse{} - mi := &file_state_v1_state_proto_msgTypes[150] + mi := &file_state_v1_state_proto_msgTypes[152] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -8059,7 +8180,7 @@ func (x *RecordDispatchResponse) String() string { func (*RecordDispatchResponse) ProtoMessage() {} func (x *RecordDispatchResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[150] + mi := &file_state_v1_state_proto_msgTypes[152] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -8072,7 +8193,7 @@ func (x *RecordDispatchResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use RecordDispatchResponse.ProtoReflect.Descriptor instead. func (*RecordDispatchResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{150} + return file_state_v1_state_proto_rawDescGZIP(), []int{152} } type RecordPlaybookDispatchRequest struct { @@ -8087,7 +8208,7 @@ type RecordPlaybookDispatchRequest struct { func (x *RecordPlaybookDispatchRequest) Reset() { *x = RecordPlaybookDispatchRequest{} - mi := &file_state_v1_state_proto_msgTypes[151] + mi := &file_state_v1_state_proto_msgTypes[153] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -8099,7 +8220,7 @@ func (x *RecordPlaybookDispatchRequest) String() string { func (*RecordPlaybookDispatchRequest) ProtoMessage() {} func (x *RecordPlaybookDispatchRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[151] + mi := &file_state_v1_state_proto_msgTypes[153] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -8112,7 +8233,7 @@ func (x *RecordPlaybookDispatchRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use RecordPlaybookDispatchRequest.ProtoReflect.Descriptor instead. func (*RecordPlaybookDispatchRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{151} + return file_state_v1_state_proto_rawDescGZIP(), []int{153} } func (x *RecordPlaybookDispatchRequest) GetPlaybookId() string { @@ -8151,7 +8272,7 @@ type RecordPlaybookDispatchResponse struct { func (x *RecordPlaybookDispatchResponse) Reset() { *x = RecordPlaybookDispatchResponse{} - mi := &file_state_v1_state_proto_msgTypes[152] + mi := &file_state_v1_state_proto_msgTypes[154] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -8163,7 +8284,7 @@ func (x *RecordPlaybookDispatchResponse) String() string { func (*RecordPlaybookDispatchResponse) ProtoMessage() {} func (x *RecordPlaybookDispatchResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[152] + mi := &file_state_v1_state_proto_msgTypes[154] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -8176,7 +8297,7 @@ func (x *RecordPlaybookDispatchResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use RecordPlaybookDispatchResponse.ProtoReflect.Descriptor instead. func (*RecordPlaybookDispatchResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{152} + return file_state_v1_state_proto_rawDescGZIP(), []int{154} } type DeletePlaybookDispatchesRequest struct { @@ -8188,7 +8309,7 @@ type DeletePlaybookDispatchesRequest struct { func (x *DeletePlaybookDispatchesRequest) Reset() { *x = DeletePlaybookDispatchesRequest{} - mi := &file_state_v1_state_proto_msgTypes[153] + mi := &file_state_v1_state_proto_msgTypes[155] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -8200,7 +8321,7 @@ func (x *DeletePlaybookDispatchesRequest) String() string { func (*DeletePlaybookDispatchesRequest) ProtoMessage() {} func (x *DeletePlaybookDispatchesRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[153] + mi := &file_state_v1_state_proto_msgTypes[155] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -8213,7 +8334,7 @@ func (x *DeletePlaybookDispatchesRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use DeletePlaybookDispatchesRequest.ProtoReflect.Descriptor instead. func (*DeletePlaybookDispatchesRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{153} + return file_state_v1_state_proto_rawDescGZIP(), []int{155} } func (x *DeletePlaybookDispatchesRequest) GetPlaybookId() string { @@ -8231,7 +8352,7 @@ type DeletePlaybookDispatchesResponse struct { func (x *DeletePlaybookDispatchesResponse) Reset() { *x = DeletePlaybookDispatchesResponse{} - mi := &file_state_v1_state_proto_msgTypes[154] + mi := &file_state_v1_state_proto_msgTypes[156] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -8243,7 +8364,7 @@ func (x *DeletePlaybookDispatchesResponse) String() string { func (*DeletePlaybookDispatchesResponse) ProtoMessage() {} func (x *DeletePlaybookDispatchesResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[154] + mi := &file_state_v1_state_proto_msgTypes[156] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -8256,7 +8377,7 @@ func (x *DeletePlaybookDispatchesResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use DeletePlaybookDispatchesResponse.ProtoReflect.Descriptor instead. func (*DeletePlaybookDispatchesResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{154} + return file_state_v1_state_proto_rawDescGZIP(), []int{156} } type ListUndispatchedCapturesRequest struct { @@ -8269,7 +8390,7 @@ type ListUndispatchedCapturesRequest struct { func (x *ListUndispatchedCapturesRequest) Reset() { *x = ListUndispatchedCapturesRequest{} - mi := &file_state_v1_state_proto_msgTypes[155] + mi := &file_state_v1_state_proto_msgTypes[157] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -8281,7 +8402,7 @@ func (x *ListUndispatchedCapturesRequest) String() string { func (*ListUndispatchedCapturesRequest) ProtoMessage() {} func (x *ListUndispatchedCapturesRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[155] + mi := &file_state_v1_state_proto_msgTypes[157] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -8294,7 +8415,7 @@ func (x *ListUndispatchedCapturesRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ListUndispatchedCapturesRequest.ProtoReflect.Descriptor instead. func (*ListUndispatchedCapturesRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{155} + return file_state_v1_state_proto_rawDescGZIP(), []int{157} } func (x *ListUndispatchedCapturesRequest) GetSources() []string { @@ -8320,7 +8441,7 @@ type ListUndispatchedCapturesResponse struct { func (x *ListUndispatchedCapturesResponse) Reset() { *x = ListUndispatchedCapturesResponse{} - mi := &file_state_v1_state_proto_msgTypes[156] + mi := &file_state_v1_state_proto_msgTypes[158] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -8332,7 +8453,7 @@ func (x *ListUndispatchedCapturesResponse) String() string { func (*ListUndispatchedCapturesResponse) ProtoMessage() {} func (x *ListUndispatchedCapturesResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[156] + mi := &file_state_v1_state_proto_msgTypes[158] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -8345,7 +8466,7 @@ func (x *ListUndispatchedCapturesResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ListUndispatchedCapturesResponse.ProtoReflect.Descriptor instead. func (*ListUndispatchedCapturesResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{156} + return file_state_v1_state_proto_rawDescGZIP(), []int{158} } func (x *ListUndispatchedCapturesResponse) GetCaptures() []*CapturedEvent { @@ -8365,7 +8486,7 @@ type StreamUndispatchedCapturesRequest struct { func (x *StreamUndispatchedCapturesRequest) Reset() { *x = StreamUndispatchedCapturesRequest{} - mi := &file_state_v1_state_proto_msgTypes[157] + mi := &file_state_v1_state_proto_msgTypes[159] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -8377,7 +8498,7 @@ func (x *StreamUndispatchedCapturesRequest) String() string { func (*StreamUndispatchedCapturesRequest) ProtoMessage() {} func (x *StreamUndispatchedCapturesRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[157] + mi := &file_state_v1_state_proto_msgTypes[159] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -8390,7 +8511,7 @@ func (x *StreamUndispatchedCapturesRequest) ProtoReflect() protoreflect.Message // Deprecated: Use StreamUndispatchedCapturesRequest.ProtoReflect.Descriptor instead. func (*StreamUndispatchedCapturesRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{157} + return file_state_v1_state_proto_rawDescGZIP(), []int{159} } func (x *StreamUndispatchedCapturesRequest) GetSources() []string { @@ -8417,7 +8538,7 @@ type StreamUndispatchedCapturesResponse struct { func (x *StreamUndispatchedCapturesResponse) Reset() { *x = StreamUndispatchedCapturesResponse{} - mi := &file_state_v1_state_proto_msgTypes[158] + mi := &file_state_v1_state_proto_msgTypes[160] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -8429,7 +8550,7 @@ func (x *StreamUndispatchedCapturesResponse) String() string { func (*StreamUndispatchedCapturesResponse) ProtoMessage() {} func (x *StreamUndispatchedCapturesResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[158] + mi := &file_state_v1_state_proto_msgTypes[160] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -8442,7 +8563,7 @@ func (x *StreamUndispatchedCapturesResponse) ProtoReflect() protoreflect.Message // Deprecated: Use StreamUndispatchedCapturesResponse.ProtoReflect.Descriptor instead. func (*StreamUndispatchedCapturesResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{158} + return file_state_v1_state_proto_rawDescGZIP(), []int{160} } func (x *StreamUndispatchedCapturesResponse) GetCapture() *CapturedEvent { @@ -8468,7 +8589,7 @@ type EnqueueBindingTaskRequest struct { func (x *EnqueueBindingTaskRequest) Reset() { *x = EnqueueBindingTaskRequest{} - mi := &file_state_v1_state_proto_msgTypes[159] + mi := &file_state_v1_state_proto_msgTypes[161] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -8480,7 +8601,7 @@ func (x *EnqueueBindingTaskRequest) String() string { func (*EnqueueBindingTaskRequest) ProtoMessage() {} func (x *EnqueueBindingTaskRequest) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[159] + mi := &file_state_v1_state_proto_msgTypes[161] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -8493,7 +8614,7 @@ func (x *EnqueueBindingTaskRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use EnqueueBindingTaskRequest.ProtoReflect.Descriptor instead. func (*EnqueueBindingTaskRequest) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{159} + return file_state_v1_state_proto_rawDescGZIP(), []int{161} } func (x *EnqueueBindingTaskRequest) GetOwner() string { @@ -8561,7 +8682,7 @@ type EnqueueBindingTaskResponse struct { func (x *EnqueueBindingTaskResponse) Reset() { *x = EnqueueBindingTaskResponse{} - mi := &file_state_v1_state_proto_msgTypes[160] + mi := &file_state_v1_state_proto_msgTypes[162] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -8573,7 +8694,7 @@ func (x *EnqueueBindingTaskResponse) String() string { func (*EnqueueBindingTaskResponse) ProtoMessage() {} func (x *EnqueueBindingTaskResponse) ProtoReflect() protoreflect.Message { - mi := &file_state_v1_state_proto_msgTypes[160] + mi := &file_state_v1_state_proto_msgTypes[162] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -8586,7 +8707,7 @@ func (x *EnqueueBindingTaskResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use EnqueueBindingTaskResponse.ProtoReflect.Descriptor instead. func (*EnqueueBindingTaskResponse) Descriptor() ([]byte, []int) { - return file_state_v1_state_proto_rawDescGZIP(), []int{160} + return file_state_v1_state_proto_rawDescGZIP(), []int{162} } func (x *EnqueueBindingTaskResponse) GetTask() *Task { @@ -8776,7 +8897,7 @@ const file_state_v1_state_proto_rawDesc = "" + "\x04name\x18\x01 \x01(\tR\x04name\x12\x12\n" + "\x04path\x18\x02 \x01(\tR\x04path\x12\x12\n" + "\x04type\x18\x03 \x01(\tR\x04type\x12\x1a\n" + - "\brequired\x18\x04 \x01(\bR\brequired\"\xf4\x01\n" + + "\brequired\x18\x04 \x01(\bR\brequired\"\xfd\x02\n" + "\aMapping\x12\x0e\n" + "\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" + "\x04name\x18\x02 \x01(\tR\x04name\x12\x1f\n" + @@ -8786,9 +8907,13 @@ const file_state_v1_state_proto_rawDesc = "" + "\n" + "created_at\x18\x05 \x01(\v2\x1a.google.protobuf.TimestampR\tcreatedAt\x129\n" + "\n" + - "updated_at\x18\x06 \x01(\v2\x1a.google.protobuf.TimestampR\tupdatedAt\"(\n" + + "updated_at\x18\x06 \x01(\v2\x1a.google.protobuf.TimestampR\tupdatedAt\x12\"\n" + + "\revent_type_id\x18\a \x01(\tR\veventTypeId\x12\x1f\n" + + "\vmatch_count\x18\b \x01(\x03R\n" + + "matchCount\x12B\n" + + "\x0flast_matched_at\x18\t \x01(\v2\x1a.google.protobuf.TimestampR\rlastMatchedAt\"(\n" + "\x0eBindingMatcher\x12\x16\n" + - "\x06source\x18\x01 \x01(\tR\x06source\"\x86\x03\n" + + "\x06source\x18\x01 \x01(\tR\x06source\"\x9e\x03\n" + "\aBinding\x12\x0e\n" + "\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" + "\x04name\x18\x02 \x01(\tR\x04name\x122\n" + @@ -8805,7 +8930,8 @@ const file_state_v1_state_proto_rawDesc = "" + "\n" + "created_at\x18\v \x01(\v2\x1a.google.protobuf.TimestampR\tcreatedAt\x129\n" + "\n" + - "updated_at\x18\f \x01(\v2\x1a.google.protobuf.TimestampR\tupdatedAt\"\xe6\x01\n" + + "updated_at\x18\f \x01(\v2\x1a.google.protobuf.TimestampR\tupdatedAt\x12\x16\n" + + "\x06filter\x18\r \x01(\tR\x06filter\"\xe6\x01\n" + "\fWorkflowStat\x12\x1a\n" + "\bworkflow\x18\x01 \x01(\tR\bworkflow\x12\x12\n" + "\x04runs\x18\x02 \x01(\x03R\x04runs\x12\x16\n" + @@ -9069,7 +9195,13 @@ const file_state_v1_state_proto_rawDesc = "" + "\x15UpdateMappingResponse\"&\n" + "\x14DeleteMappingRequest\x12\x0e\n" + "\x02id\x18\x01 \x01(\tR\x02id\"\x17\n" + - "\x15DeleteMappingResponse\"L\n" + + "\x15DeleteMappingResponse\"Y\n" + + "\x19RecordMappingMatchRequest\x12\x1d\n" + + "\n" + + "mapping_id\x18\x01 \x01(\tR\tmappingId\x12\x1d\n" + + "\n" + + "capture_id\x18\x02 \x01(\tR\tcaptureId\"\x1c\n" + + "\x1aRecordMappingMatchResponse\"L\n" + "\x16InsertEventTypeRequest\x122\n" + "\n" + "event_type\x18\x01 \x01(\v2\x13.state.v1.EventTypeR\teventType\")\n" + @@ -9151,7 +9283,7 @@ const file_state_v1_state_proto_rawDesc = "" + "binding_id\x18\a \x01(\tR\tbindingId\x12'\n" + "\x0fbinding_version\x18\b \x01(\x03R\x0ebindingVersion\"@\n" + "\x1aEnqueueBindingTaskResponse\x12\"\n" + - "\x04task\x18\x01 \x01(\v2\x0e.state.v1.TaskR\x04task2\x9b/\n" + + "\x04task\x18\x01 \x01(\v2\x0e.state.v1.TaskR\x04task2\xfc/\n" + "\x11StateStoreService\x12\\\n" + "\x11RegisterTaskGrant\x12\".state.v1.RegisterTaskGrantRequest\x1a#.state.v1.RegisterTaskGrantResponse\x12V\n" + "\x0fRevokeTaskGrant\x12 .state.v1.RevokeTaskGrantRequest\x1a!.state.v1.RevokeTaskGrantResponse\x12S\n" + @@ -9210,7 +9342,8 @@ const file_state_v1_state_proto_rawDesc = "" + "GetMapping\x12\x1b.state.v1.GetMappingRequest\x1a\x1c.state.v1.GetMappingResponse\x12M\n" + "\fListMappings\x12\x1d.state.v1.ListMappingsRequest\x1a\x1e.state.v1.ListMappingsResponse\x12P\n" + "\rUpdateMapping\x12\x1e.state.v1.UpdateMappingRequest\x1a\x1f.state.v1.UpdateMappingResponse\x12P\n" + - "\rDeleteMapping\x12\x1e.state.v1.DeleteMappingRequest\x1a\x1f.state.v1.DeleteMappingResponse\x12V\n" + + "\rDeleteMapping\x12\x1e.state.v1.DeleteMappingRequest\x1a\x1f.state.v1.DeleteMappingResponse\x12_\n" + + "\x12RecordMappingMatch\x12#.state.v1.RecordMappingMatchRequest\x1a$.state.v1.RecordMappingMatchResponse\x12V\n" + "\x0fInsertEventType\x12 .state.v1.InsertEventTypeRequest\x1a!.state.v1.InsertEventTypeResponse\x12V\n" + "\x0fUpdateEventType\x12 .state.v1.UpdateEventTypeRequest\x1a!.state.v1.UpdateEventTypeResponse\x12V\n" + "\x0fDeleteEventType\x12 .state.v1.DeleteEventTypeRequest\x1a!.state.v1.DeleteEventTypeResponse\x12S\n" + @@ -9244,7 +9377,7 @@ func file_state_v1_state_proto_rawDescGZIP() []byte { return file_state_v1_state_proto_rawDescData } -var file_state_v1_state_proto_msgTypes = make([]protoimpl.MessageInfo, 163) +var file_state_v1_state_proto_msgTypes = make([]protoimpl.MessageInfo, 165) var file_state_v1_state_proto_goTypes = []any{ (*RegisterTaskGrantRequest)(nil), // 0: state.v1.RegisterTaskGrantRequest (*RegisterTaskGrantResponse)(nil), // 1: state.v1.RegisterTaskGrantResponse @@ -9373,47 +9506,49 @@ var file_state_v1_state_proto_goTypes = []any{ (*UpdateMappingResponse)(nil), // 124: state.v1.UpdateMappingResponse (*DeleteMappingRequest)(nil), // 125: state.v1.DeleteMappingRequest (*DeleteMappingResponse)(nil), // 126: state.v1.DeleteMappingResponse - (*InsertEventTypeRequest)(nil), // 127: state.v1.InsertEventTypeRequest - (*InsertEventTypeResponse)(nil), // 128: state.v1.InsertEventTypeResponse - (*UpdateEventTypeRequest)(nil), // 129: state.v1.UpdateEventTypeRequest - (*UpdateEventTypeResponse)(nil), // 130: state.v1.UpdateEventTypeResponse - (*DeleteEventTypeRequest)(nil), // 131: state.v1.DeleteEventTypeRequest - (*DeleteEventTypeResponse)(nil), // 132: state.v1.DeleteEventTypeResponse - (*ListEventTypesRequest)(nil), // 133: state.v1.ListEventTypesRequest - (*ListEventTypesResponse)(nil), // 134: state.v1.ListEventTypesResponse - (*InsertBindingRequest)(nil), // 135: state.v1.InsertBindingRequest - (*InsertBindingResponse)(nil), // 136: state.v1.InsertBindingResponse - (*GetBindingRequest)(nil), // 137: state.v1.GetBindingRequest - (*GetBindingResponse)(nil), // 138: state.v1.GetBindingResponse - (*ListBindingsRequest)(nil), // 139: state.v1.ListBindingsRequest - (*ListBindingsResponse)(nil), // 140: state.v1.ListBindingsResponse - (*UpdateBindingRequest)(nil), // 141: state.v1.UpdateBindingRequest - (*UpdateBindingResponse)(nil), // 142: state.v1.UpdateBindingResponse - (*DeleteBindingRequest)(nil), // 143: state.v1.DeleteBindingRequest - (*DeleteBindingResponse)(nil), // 144: state.v1.DeleteBindingResponse - (*ApproveBindingRequest)(nil), // 145: state.v1.ApproveBindingRequest - (*ApproveBindingResponse)(nil), // 146: state.v1.ApproveBindingResponse - (*ArmedBindingsForSourceRequest)(nil), // 147: state.v1.ArmedBindingsForSourceRequest - (*ArmedBindingsForSourceResponse)(nil), // 148: state.v1.ArmedBindingsForSourceResponse - (*RecordDispatchRequest)(nil), // 149: state.v1.RecordDispatchRequest - (*RecordDispatchResponse)(nil), // 150: state.v1.RecordDispatchResponse - (*RecordPlaybookDispatchRequest)(nil), // 151: state.v1.RecordPlaybookDispatchRequest - (*RecordPlaybookDispatchResponse)(nil), // 152: state.v1.RecordPlaybookDispatchResponse - (*DeletePlaybookDispatchesRequest)(nil), // 153: state.v1.DeletePlaybookDispatchesRequest - (*DeletePlaybookDispatchesResponse)(nil), // 154: state.v1.DeletePlaybookDispatchesResponse - (*ListUndispatchedCapturesRequest)(nil), // 155: state.v1.ListUndispatchedCapturesRequest - (*ListUndispatchedCapturesResponse)(nil), // 156: state.v1.ListUndispatchedCapturesResponse - (*StreamUndispatchedCapturesRequest)(nil), // 157: state.v1.StreamUndispatchedCapturesRequest - (*StreamUndispatchedCapturesResponse)(nil), // 158: state.v1.StreamUndispatchedCapturesResponse - (*EnqueueBindingTaskRequest)(nil), // 159: state.v1.EnqueueBindingTaskRequest - (*EnqueueBindingTaskResponse)(nil), // 160: state.v1.EnqueueBindingTaskResponse - nil, // 161: state.v1.EventType.SchemaEntry - nil, // 162: state.v1.StatusCountsResponse.CountsEntry - (*timestamppb.Timestamp)(nil), // 163: google.protobuf.Timestamp + (*RecordMappingMatchRequest)(nil), // 127: state.v1.RecordMappingMatchRequest + (*RecordMappingMatchResponse)(nil), // 128: state.v1.RecordMappingMatchResponse + (*InsertEventTypeRequest)(nil), // 129: state.v1.InsertEventTypeRequest + (*InsertEventTypeResponse)(nil), // 130: state.v1.InsertEventTypeResponse + (*UpdateEventTypeRequest)(nil), // 131: state.v1.UpdateEventTypeRequest + (*UpdateEventTypeResponse)(nil), // 132: state.v1.UpdateEventTypeResponse + (*DeleteEventTypeRequest)(nil), // 133: state.v1.DeleteEventTypeRequest + (*DeleteEventTypeResponse)(nil), // 134: state.v1.DeleteEventTypeResponse + (*ListEventTypesRequest)(nil), // 135: state.v1.ListEventTypesRequest + (*ListEventTypesResponse)(nil), // 136: state.v1.ListEventTypesResponse + (*InsertBindingRequest)(nil), // 137: state.v1.InsertBindingRequest + (*InsertBindingResponse)(nil), // 138: state.v1.InsertBindingResponse + (*GetBindingRequest)(nil), // 139: state.v1.GetBindingRequest + (*GetBindingResponse)(nil), // 140: state.v1.GetBindingResponse + (*ListBindingsRequest)(nil), // 141: state.v1.ListBindingsRequest + (*ListBindingsResponse)(nil), // 142: state.v1.ListBindingsResponse + (*UpdateBindingRequest)(nil), // 143: state.v1.UpdateBindingRequest + (*UpdateBindingResponse)(nil), // 144: state.v1.UpdateBindingResponse + (*DeleteBindingRequest)(nil), // 145: state.v1.DeleteBindingRequest + (*DeleteBindingResponse)(nil), // 146: state.v1.DeleteBindingResponse + (*ApproveBindingRequest)(nil), // 147: state.v1.ApproveBindingRequest + (*ApproveBindingResponse)(nil), // 148: state.v1.ApproveBindingResponse + (*ArmedBindingsForSourceRequest)(nil), // 149: state.v1.ArmedBindingsForSourceRequest + (*ArmedBindingsForSourceResponse)(nil), // 150: state.v1.ArmedBindingsForSourceResponse + (*RecordDispatchRequest)(nil), // 151: state.v1.RecordDispatchRequest + (*RecordDispatchResponse)(nil), // 152: state.v1.RecordDispatchResponse + (*RecordPlaybookDispatchRequest)(nil), // 153: state.v1.RecordPlaybookDispatchRequest + (*RecordPlaybookDispatchResponse)(nil), // 154: state.v1.RecordPlaybookDispatchResponse + (*DeletePlaybookDispatchesRequest)(nil), // 155: state.v1.DeletePlaybookDispatchesRequest + (*DeletePlaybookDispatchesResponse)(nil), // 156: state.v1.DeletePlaybookDispatchesResponse + (*ListUndispatchedCapturesRequest)(nil), // 157: state.v1.ListUndispatchedCapturesRequest + (*ListUndispatchedCapturesResponse)(nil), // 158: state.v1.ListUndispatchedCapturesResponse + (*StreamUndispatchedCapturesRequest)(nil), // 159: state.v1.StreamUndispatchedCapturesRequest + (*StreamUndispatchedCapturesResponse)(nil), // 160: state.v1.StreamUndispatchedCapturesResponse + (*EnqueueBindingTaskRequest)(nil), // 161: state.v1.EnqueueBindingTaskRequest + (*EnqueueBindingTaskResponse)(nil), // 162: state.v1.EnqueueBindingTaskResponse + nil, // 163: state.v1.EventType.SchemaEntry + nil, // 164: state.v1.StatusCountsResponse.CountsEntry + (*timestamppb.Timestamp)(nil), // 165: google.protobuf.Timestamp } var file_state_v1_state_proto_depIdxs = []int32{ - 163, // 0: state.v1.Identity.created_at:type_name -> google.protobuf.Timestamp - 163, // 1: state.v1.Identity.updated_at:type_name -> google.protobuf.Timestamp + 165, // 0: state.v1.Identity.created_at:type_name -> google.protobuf.Timestamp + 165, // 1: state.v1.Identity.updated_at:type_name -> google.protobuf.Timestamp 4, // 2: state.v1.ListIdentitiesResponse.identities:type_name -> state.v1.Identity 4, // 3: state.v1.GetIdentityResponse.identity:type_name -> state.v1.Identity 5, // 4: state.v1.CreateIdentityRequest.audit:type_name -> state.v1.IdentityAudit @@ -9429,216 +9564,219 @@ var file_state_v1_state_proto_depIdxs = []int32{ 4, // 14: state.v1.ResolveIdentitySubjectResponse.identity:type_name -> state.v1.Identity 5, // 15: state.v1.BindIdentitySubjectRequest.audit:type_name -> state.v1.IdentityAudit 4, // 16: state.v1.BindIdentitySubjectResponse.identity:type_name -> state.v1.Identity - 163, // 17: state.v1.Task.created_at:type_name -> google.protobuf.Timestamp - 163, // 18: state.v1.Task.updated_at:type_name -> google.protobuf.Timestamp - 163, // 19: state.v1.Event.at:type_name -> google.protobuf.Timestamp - 163, // 20: state.v1.CapturedEvent.received_at:type_name -> google.protobuf.Timestamp + 165, // 17: state.v1.Task.created_at:type_name -> google.protobuf.Timestamp + 165, // 18: state.v1.Task.updated_at:type_name -> google.protobuf.Timestamp + 165, // 19: state.v1.Event.at:type_name -> google.protobuf.Timestamp + 165, // 20: state.v1.CapturedEvent.received_at:type_name -> google.protobuf.Timestamp 27, // 21: state.v1.EventType.header_conditions:type_name -> state.v1.EventTypeHeaderCondition 28, // 22: state.v1.EventType.payload_conditions:type_name -> state.v1.EventTypePayloadCondition - 161, // 23: state.v1.EventType.schema:type_name -> state.v1.EventType.SchemaEntry - 163, // 24: state.v1.EventType.created_at:type_name -> google.protobuf.Timestamp - 163, // 25: state.v1.EventType.updated_at:type_name -> google.protobuf.Timestamp + 163, // 23: state.v1.EventType.schema:type_name -> state.v1.EventType.SchemaEntry + 165, // 24: state.v1.EventType.created_at:type_name -> google.protobuf.Timestamp + 165, // 25: state.v1.EventType.updated_at:type_name -> google.protobuf.Timestamp 30, // 26: state.v1.Mapping.fields:type_name -> state.v1.MappingField - 163, // 27: state.v1.Mapping.created_at:type_name -> google.protobuf.Timestamp - 163, // 28: state.v1.Mapping.updated_at:type_name -> google.protobuf.Timestamp - 32, // 29: state.v1.Binding.matcher:type_name -> state.v1.BindingMatcher - 163, // 30: state.v1.Binding.created_at:type_name -> google.protobuf.Timestamp - 163, // 31: state.v1.Binding.updated_at:type_name -> google.protobuf.Timestamp - 24, // 32: state.v1.EnqueueChatTaskResponse.task:type_name -> state.v1.Task - 24, // 33: state.v1.ClaimNextResponse.task:type_name -> state.v1.Task - 24, // 34: state.v1.ClaimByIssueResponse.task:type_name -> state.v1.Task - 24, // 35: state.v1.UpdateRequest.task:type_name -> state.v1.Task - 25, // 36: state.v1.ArchiveTaskRequest.audit:type_name -> state.v1.Event - 24, // 37: state.v1.TaskByIssueResponse.task:type_name -> state.v1.Task - 24, // 38: state.v1.OpenTaskByPRResponse.task:type_name -> state.v1.Task - 24, // 39: state.v1.TaskByIDResponse.task:type_name -> state.v1.Task - 24, // 40: state.v1.OpenPRsResponse.tasks:type_name -> state.v1.Task - 24, // 41: state.v1.TasksResponse.tasks:type_name -> state.v1.Task - 162, // 42: state.v1.StatusCountsResponse.counts:type_name -> state.v1.StatusCountsResponse.CountsEntry - 25, // 43: state.v1.InsertEventRequest.event:type_name -> state.v1.Event - 25, // 44: state.v1.EventsSinceResponse.events:type_name -> state.v1.Event - 25, // 45: state.v1.TaskEventsResponse.events:type_name -> state.v1.Event - 34, // 46: state.v1.WorkflowStatsResponse.stats:type_name -> state.v1.WorkflowStat - 35, // 47: state.v1.StageStatsResponse.stats:type_name -> state.v1.StageStat - 36, // 48: state.v1.TokensByDayResponse.tokens:type_name -> state.v1.DayTokens - 163, // 49: state.v1.ConfigSnapshot.published_at:type_name -> google.protobuf.Timestamp - 91, // 50: state.v1.PutConfigSnapshotRequest.snapshot:type_name -> state.v1.ConfigSnapshot - 91, // 51: state.v1.GetConfigSnapshotResponse.snapshot:type_name -> state.v1.ConfigSnapshot - 163, // 52: state.v1.ChannelStatus.observed_at:type_name -> google.protobuf.Timestamp - 96, // 53: state.v1.PutChannelStatusRequest.channels:type_name -> state.v1.ChannelStatus - 96, // 54: state.v1.ListChannelStatusResponse.channels:type_name -> state.v1.ChannelStatus - 163, // 55: state.v1.ApplyStatus.reported_at:type_name -> google.protobuf.Timestamp - 101, // 56: state.v1.PutApplyStatusRequest.status:type_name -> state.v1.ApplyStatus - 101, // 57: state.v1.ListApplyStatusResponse.statuses:type_name -> state.v1.ApplyStatus - 163, // 58: state.v1.TaskLogEntry.time:type_name -> google.protobuf.Timestamp - 163, // 59: state.v1.ReadTaskLogRequest.since:type_name -> google.protobuf.Timestamp - 163, // 60: state.v1.ReadTaskLogRequest.until:type_name -> google.protobuf.Timestamp - 106, // 61: state.v1.ReadTaskLogResponse.entries:type_name -> state.v1.TaskLogEntry - 26, // 62: state.v1.InsertCaptureRequest.capture:type_name -> state.v1.CapturedEvent - 26, // 63: state.v1.ListCapturesResponse.captures:type_name -> state.v1.CapturedEvent - 26, // 64: state.v1.StreamCapturesResponse.capture:type_name -> state.v1.CapturedEvent - 31, // 65: state.v1.InsertMappingRequest.mapping:type_name -> state.v1.Mapping - 31, // 66: state.v1.GetMappingResponse.mapping:type_name -> state.v1.Mapping - 31, // 67: state.v1.ListMappingsResponse.mappings:type_name -> state.v1.Mapping - 31, // 68: state.v1.UpdateMappingRequest.mapping:type_name -> state.v1.Mapping - 29, // 69: state.v1.InsertEventTypeRequest.event_type:type_name -> state.v1.EventType - 29, // 70: state.v1.UpdateEventTypeRequest.event_type:type_name -> state.v1.EventType - 29, // 71: state.v1.ListEventTypesResponse.event_types:type_name -> state.v1.EventType - 33, // 72: state.v1.InsertBindingRequest.binding:type_name -> state.v1.Binding - 33, // 73: state.v1.GetBindingResponse.binding:type_name -> state.v1.Binding - 33, // 74: state.v1.ListBindingsResponse.bindings:type_name -> state.v1.Binding - 33, // 75: state.v1.UpdateBindingRequest.binding:type_name -> state.v1.Binding - 33, // 76: state.v1.ArmedBindingsForSourceResponse.bindings:type_name -> state.v1.Binding - 26, // 77: state.v1.ListUndispatchedCapturesResponse.captures:type_name -> state.v1.CapturedEvent - 26, // 78: state.v1.StreamUndispatchedCapturesResponse.capture:type_name -> state.v1.CapturedEvent - 24, // 79: state.v1.EnqueueBindingTaskResponse.task:type_name -> state.v1.Task - 0, // 80: state.v1.StateStoreService.RegisterTaskGrant:input_type -> state.v1.RegisterTaskGrantRequest - 2, // 81: state.v1.StateStoreService.RevokeTaskGrant:input_type -> state.v1.RevokeTaskGrantRequest - 6, // 82: state.v1.StateStoreService.ListIdentities:input_type -> state.v1.ListIdentitiesRequest - 8, // 83: state.v1.StateStoreService.GetIdentity:input_type -> state.v1.GetIdentityRequest - 10, // 84: state.v1.StateStoreService.CreateIdentity:input_type -> state.v1.CreateIdentityRequest - 11, // 85: state.v1.StateStoreService.RenameIdentity:input_type -> state.v1.RenameIdentityRequest - 12, // 86: state.v1.StateStoreService.SuspendIdentity:input_type -> state.v1.SuspendIdentityRequest - 13, // 87: state.v1.StateStoreService.ReactivateIdentity:input_type -> state.v1.ReactivateIdentityRequest - 14, // 88: state.v1.StateStoreService.RetireIdentity:input_type -> state.v1.RetireIdentityRequest - 20, // 89: state.v1.StateStoreService.ResolveIdentitySubject:input_type -> state.v1.ResolveIdentitySubjectRequest - 22, // 90: state.v1.StateStoreService.BindIdentitySubject:input_type -> state.v1.BindIdentitySubjectRequest - 37, // 91: state.v1.StateStoreService.EnqueueIssue:input_type -> state.v1.EnqueueIssueRequest - 39, // 92: state.v1.StateStoreService.EnqueueChatTask:input_type -> state.v1.EnqueueChatTaskRequest - 41, // 93: state.v1.StateStoreService.ClaimNext:input_type -> state.v1.ClaimNextRequest - 43, // 94: state.v1.StateStoreService.ClaimByIssue:input_type -> state.v1.ClaimByIssueRequest - 45, // 95: state.v1.StateStoreService.Transition:input_type -> state.v1.TransitionRequest - 47, // 96: state.v1.StateStoreService.Update:input_type -> state.v1.UpdateRequest - 49, // 97: state.v1.StateStoreService.Requeue:input_type -> state.v1.RequeueRequest - 51, // 98: state.v1.StateStoreService.ParkTask:input_type -> state.v1.ParkTaskRequest - 53, // 99: state.v1.StateStoreService.RecoverStale:input_type -> state.v1.RecoverStaleRequest - 55, // 100: state.v1.StateStoreService.ArchiveTask:input_type -> state.v1.ArchiveTaskRequest - 57, // 101: state.v1.StateStoreService.RetryTask:input_type -> state.v1.RetryTaskRequest - 59, // 102: state.v1.StateStoreService.BeginRemediation:input_type -> state.v1.BeginRemediationRequest - 61, // 103: state.v1.StateStoreService.UpdateReviewPayload:input_type -> state.v1.UpdateReviewPayloadRequest - 63, // 104: state.v1.StateStoreService.SetReviewCursors:input_type -> state.v1.SetReviewCursorsRequest - 65, // 105: state.v1.StateStoreService.TaskByIssue:input_type -> state.v1.TaskByIssueRequest - 67, // 106: state.v1.StateStoreService.OpenTaskByPR:input_type -> state.v1.OpenTaskByPRRequest - 69, // 107: state.v1.StateStoreService.TaskByID:input_type -> state.v1.TaskByIDRequest - 71, // 108: state.v1.StateStoreService.OpenPRs:input_type -> state.v1.OpenPRsRequest - 73, // 109: state.v1.StateStoreService.ClearTerminalTasks:input_type -> state.v1.ClearTerminalTasksRequest - 75, // 110: state.v1.StateStoreService.Tasks:input_type -> state.v1.TasksRequest - 77, // 111: state.v1.StateStoreService.StatusCounts:input_type -> state.v1.StatusCountsRequest - 79, // 112: state.v1.StateStoreService.InsertEvent:input_type -> state.v1.InsertEventRequest - 81, // 113: state.v1.StateStoreService.EventsSince:input_type -> state.v1.EventsSinceRequest - 83, // 114: state.v1.StateStoreService.TaskEvents:input_type -> state.v1.TaskEventsRequest - 85, // 115: state.v1.StateStoreService.WorkflowStats:input_type -> state.v1.WorkflowStatsRequest - 87, // 116: state.v1.StateStoreService.StageStats:input_type -> state.v1.StageStatsRequest - 89, // 117: state.v1.StateStoreService.TokensByDay:input_type -> state.v1.TokensByDayRequest - 92, // 118: state.v1.StateStoreService.PutConfigSnapshot:input_type -> state.v1.PutConfigSnapshotRequest - 94, // 119: state.v1.StateStoreService.GetConfigSnapshot:input_type -> state.v1.GetConfigSnapshotRequest - 97, // 120: state.v1.StateStoreService.PutChannelStatus:input_type -> state.v1.PutChannelStatusRequest - 99, // 121: state.v1.StateStoreService.ListChannelStatus:input_type -> state.v1.ListChannelStatusRequest - 102, // 122: state.v1.StateStoreService.PutApplyStatus:input_type -> state.v1.PutApplyStatusRequest - 104, // 123: state.v1.StateStoreService.ListApplyStatus:input_type -> state.v1.ListApplyStatusRequest - 107, // 124: state.v1.StateStoreService.ReadTaskLog:input_type -> state.v1.ReadTaskLogRequest - 109, // 125: state.v1.StateStoreService.StreamTaskLogContent:input_type -> state.v1.StreamTaskLogContentRequest - 111, // 126: state.v1.StateStoreService.InsertCapture:input_type -> state.v1.InsertCaptureRequest - 113, // 127: state.v1.StateStoreService.ListCaptures:input_type -> state.v1.ListCapturesRequest - 115, // 128: state.v1.StateStoreService.StreamCaptures:input_type -> state.v1.StreamCapturesRequest - 117, // 129: state.v1.StateStoreService.InsertMapping:input_type -> state.v1.InsertMappingRequest - 119, // 130: state.v1.StateStoreService.GetMapping:input_type -> state.v1.GetMappingRequest - 121, // 131: state.v1.StateStoreService.ListMappings:input_type -> state.v1.ListMappingsRequest - 123, // 132: state.v1.StateStoreService.UpdateMapping:input_type -> state.v1.UpdateMappingRequest - 125, // 133: state.v1.StateStoreService.DeleteMapping:input_type -> state.v1.DeleteMappingRequest - 127, // 134: state.v1.StateStoreService.InsertEventType:input_type -> state.v1.InsertEventTypeRequest - 129, // 135: state.v1.StateStoreService.UpdateEventType:input_type -> state.v1.UpdateEventTypeRequest - 131, // 136: state.v1.StateStoreService.DeleteEventType:input_type -> state.v1.DeleteEventTypeRequest - 133, // 137: state.v1.StateStoreService.ListEventTypes:input_type -> state.v1.ListEventTypesRequest - 135, // 138: state.v1.StateStoreService.InsertBinding:input_type -> state.v1.InsertBindingRequest - 137, // 139: state.v1.StateStoreService.GetBinding:input_type -> state.v1.GetBindingRequest - 139, // 140: state.v1.StateStoreService.ListBindings:input_type -> state.v1.ListBindingsRequest - 141, // 141: state.v1.StateStoreService.UpdateBinding:input_type -> state.v1.UpdateBindingRequest - 143, // 142: state.v1.StateStoreService.DeleteBinding:input_type -> state.v1.DeleteBindingRequest - 145, // 143: state.v1.StateStoreService.ApproveBinding:input_type -> state.v1.ApproveBindingRequest - 147, // 144: state.v1.StateStoreService.ArmedBindingsForSource:input_type -> state.v1.ArmedBindingsForSourceRequest - 149, // 145: state.v1.StateStoreService.RecordDispatch:input_type -> state.v1.RecordDispatchRequest - 151, // 146: state.v1.StateStoreService.RecordPlaybookDispatch:input_type -> state.v1.RecordPlaybookDispatchRequest - 153, // 147: state.v1.StateStoreService.DeletePlaybookDispatches:input_type -> state.v1.DeletePlaybookDispatchesRequest - 155, // 148: state.v1.StateStoreService.ListUndispatchedCaptures:input_type -> state.v1.ListUndispatchedCapturesRequest - 157, // 149: state.v1.StateStoreService.StreamUndispatchedCaptures:input_type -> state.v1.StreamUndispatchedCapturesRequest - 159, // 150: state.v1.StateStoreService.EnqueueBindingTask:input_type -> state.v1.EnqueueBindingTaskRequest - 1, // 151: state.v1.StateStoreService.RegisterTaskGrant:output_type -> state.v1.RegisterTaskGrantResponse - 3, // 152: state.v1.StateStoreService.RevokeTaskGrant:output_type -> state.v1.RevokeTaskGrantResponse - 7, // 153: state.v1.StateStoreService.ListIdentities:output_type -> state.v1.ListIdentitiesResponse - 9, // 154: state.v1.StateStoreService.GetIdentity:output_type -> state.v1.GetIdentityResponse - 15, // 155: state.v1.StateStoreService.CreateIdentity:output_type -> state.v1.CreateIdentityResponse - 16, // 156: state.v1.StateStoreService.RenameIdentity:output_type -> state.v1.RenameIdentityResponse - 17, // 157: state.v1.StateStoreService.SuspendIdentity:output_type -> state.v1.SuspendIdentityResponse - 18, // 158: state.v1.StateStoreService.ReactivateIdentity:output_type -> state.v1.ReactivateIdentityResponse - 19, // 159: state.v1.StateStoreService.RetireIdentity:output_type -> state.v1.RetireIdentityResponse - 21, // 160: state.v1.StateStoreService.ResolveIdentitySubject:output_type -> state.v1.ResolveIdentitySubjectResponse - 23, // 161: state.v1.StateStoreService.BindIdentitySubject:output_type -> state.v1.BindIdentitySubjectResponse - 38, // 162: state.v1.StateStoreService.EnqueueIssue:output_type -> state.v1.EnqueueIssueResponse - 40, // 163: state.v1.StateStoreService.EnqueueChatTask:output_type -> state.v1.EnqueueChatTaskResponse - 42, // 164: state.v1.StateStoreService.ClaimNext:output_type -> state.v1.ClaimNextResponse - 44, // 165: state.v1.StateStoreService.ClaimByIssue:output_type -> state.v1.ClaimByIssueResponse - 46, // 166: state.v1.StateStoreService.Transition:output_type -> state.v1.TransitionResponse - 48, // 167: state.v1.StateStoreService.Update:output_type -> state.v1.UpdateResponse - 50, // 168: state.v1.StateStoreService.Requeue:output_type -> state.v1.RequeueResponse - 52, // 169: state.v1.StateStoreService.ParkTask:output_type -> state.v1.ParkTaskResponse - 54, // 170: state.v1.StateStoreService.RecoverStale:output_type -> state.v1.RecoverStaleResponse - 56, // 171: state.v1.StateStoreService.ArchiveTask:output_type -> state.v1.ArchiveTaskResponse - 58, // 172: state.v1.StateStoreService.RetryTask:output_type -> state.v1.RetryTaskResponse - 60, // 173: state.v1.StateStoreService.BeginRemediation:output_type -> state.v1.BeginRemediationResponse - 62, // 174: state.v1.StateStoreService.UpdateReviewPayload:output_type -> state.v1.UpdateReviewPayloadResponse - 64, // 175: state.v1.StateStoreService.SetReviewCursors:output_type -> state.v1.SetReviewCursorsResponse - 66, // 176: state.v1.StateStoreService.TaskByIssue:output_type -> state.v1.TaskByIssueResponse - 68, // 177: state.v1.StateStoreService.OpenTaskByPR:output_type -> state.v1.OpenTaskByPRResponse - 70, // 178: state.v1.StateStoreService.TaskByID:output_type -> state.v1.TaskByIDResponse - 72, // 179: state.v1.StateStoreService.OpenPRs:output_type -> state.v1.OpenPRsResponse - 74, // 180: state.v1.StateStoreService.ClearTerminalTasks:output_type -> state.v1.ClearTerminalTasksResponse - 76, // 181: state.v1.StateStoreService.Tasks:output_type -> state.v1.TasksResponse - 78, // 182: state.v1.StateStoreService.StatusCounts:output_type -> state.v1.StatusCountsResponse - 80, // 183: state.v1.StateStoreService.InsertEvent:output_type -> state.v1.InsertEventResponse - 82, // 184: state.v1.StateStoreService.EventsSince:output_type -> state.v1.EventsSinceResponse - 84, // 185: state.v1.StateStoreService.TaskEvents:output_type -> state.v1.TaskEventsResponse - 86, // 186: state.v1.StateStoreService.WorkflowStats:output_type -> state.v1.WorkflowStatsResponse - 88, // 187: state.v1.StateStoreService.StageStats:output_type -> state.v1.StageStatsResponse - 90, // 188: state.v1.StateStoreService.TokensByDay:output_type -> state.v1.TokensByDayResponse - 93, // 189: state.v1.StateStoreService.PutConfigSnapshot:output_type -> state.v1.PutConfigSnapshotResponse - 95, // 190: state.v1.StateStoreService.GetConfigSnapshot:output_type -> state.v1.GetConfigSnapshotResponse - 98, // 191: state.v1.StateStoreService.PutChannelStatus:output_type -> state.v1.PutChannelStatusResponse - 100, // 192: state.v1.StateStoreService.ListChannelStatus:output_type -> state.v1.ListChannelStatusResponse - 103, // 193: state.v1.StateStoreService.PutApplyStatus:output_type -> state.v1.PutApplyStatusResponse - 105, // 194: state.v1.StateStoreService.ListApplyStatus:output_type -> state.v1.ListApplyStatusResponse - 108, // 195: state.v1.StateStoreService.ReadTaskLog:output_type -> state.v1.ReadTaskLogResponse - 110, // 196: state.v1.StateStoreService.StreamTaskLogContent:output_type -> state.v1.StreamTaskLogContentResponse - 112, // 197: state.v1.StateStoreService.InsertCapture:output_type -> state.v1.InsertCaptureResponse - 114, // 198: state.v1.StateStoreService.ListCaptures:output_type -> state.v1.ListCapturesResponse - 116, // 199: state.v1.StateStoreService.StreamCaptures:output_type -> state.v1.StreamCapturesResponse - 118, // 200: state.v1.StateStoreService.InsertMapping:output_type -> state.v1.InsertMappingResponse - 120, // 201: state.v1.StateStoreService.GetMapping:output_type -> state.v1.GetMappingResponse - 122, // 202: state.v1.StateStoreService.ListMappings:output_type -> state.v1.ListMappingsResponse - 124, // 203: state.v1.StateStoreService.UpdateMapping:output_type -> state.v1.UpdateMappingResponse - 126, // 204: state.v1.StateStoreService.DeleteMapping:output_type -> state.v1.DeleteMappingResponse - 128, // 205: state.v1.StateStoreService.InsertEventType:output_type -> state.v1.InsertEventTypeResponse - 130, // 206: state.v1.StateStoreService.UpdateEventType:output_type -> state.v1.UpdateEventTypeResponse - 132, // 207: state.v1.StateStoreService.DeleteEventType:output_type -> state.v1.DeleteEventTypeResponse - 134, // 208: state.v1.StateStoreService.ListEventTypes:output_type -> state.v1.ListEventTypesResponse - 136, // 209: state.v1.StateStoreService.InsertBinding:output_type -> state.v1.InsertBindingResponse - 138, // 210: state.v1.StateStoreService.GetBinding:output_type -> state.v1.GetBindingResponse - 140, // 211: state.v1.StateStoreService.ListBindings:output_type -> state.v1.ListBindingsResponse - 142, // 212: state.v1.StateStoreService.UpdateBinding:output_type -> state.v1.UpdateBindingResponse - 144, // 213: state.v1.StateStoreService.DeleteBinding:output_type -> state.v1.DeleteBindingResponse - 146, // 214: state.v1.StateStoreService.ApproveBinding:output_type -> state.v1.ApproveBindingResponse - 148, // 215: state.v1.StateStoreService.ArmedBindingsForSource:output_type -> state.v1.ArmedBindingsForSourceResponse - 150, // 216: state.v1.StateStoreService.RecordDispatch:output_type -> state.v1.RecordDispatchResponse - 152, // 217: state.v1.StateStoreService.RecordPlaybookDispatch:output_type -> state.v1.RecordPlaybookDispatchResponse - 154, // 218: state.v1.StateStoreService.DeletePlaybookDispatches:output_type -> state.v1.DeletePlaybookDispatchesResponse - 156, // 219: state.v1.StateStoreService.ListUndispatchedCaptures:output_type -> state.v1.ListUndispatchedCapturesResponse - 158, // 220: state.v1.StateStoreService.StreamUndispatchedCaptures:output_type -> state.v1.StreamUndispatchedCapturesResponse - 160, // 221: state.v1.StateStoreService.EnqueueBindingTask:output_type -> state.v1.EnqueueBindingTaskResponse - 151, // [151:222] is the sub-list for method output_type - 80, // [80:151] is the sub-list for method input_type - 80, // [80:80] is the sub-list for extension type_name - 80, // [80:80] is the sub-list for extension extendee - 0, // [0:80] is the sub-list for field type_name + 165, // 27: state.v1.Mapping.created_at:type_name -> google.protobuf.Timestamp + 165, // 28: state.v1.Mapping.updated_at:type_name -> google.protobuf.Timestamp + 165, // 29: state.v1.Mapping.last_matched_at:type_name -> google.protobuf.Timestamp + 32, // 30: state.v1.Binding.matcher:type_name -> state.v1.BindingMatcher + 165, // 31: state.v1.Binding.created_at:type_name -> google.protobuf.Timestamp + 165, // 32: state.v1.Binding.updated_at:type_name -> google.protobuf.Timestamp + 24, // 33: state.v1.EnqueueChatTaskResponse.task:type_name -> state.v1.Task + 24, // 34: state.v1.ClaimNextResponse.task:type_name -> state.v1.Task + 24, // 35: state.v1.ClaimByIssueResponse.task:type_name -> state.v1.Task + 24, // 36: state.v1.UpdateRequest.task:type_name -> state.v1.Task + 25, // 37: state.v1.ArchiveTaskRequest.audit:type_name -> state.v1.Event + 24, // 38: state.v1.TaskByIssueResponse.task:type_name -> state.v1.Task + 24, // 39: state.v1.OpenTaskByPRResponse.task:type_name -> state.v1.Task + 24, // 40: state.v1.TaskByIDResponse.task:type_name -> state.v1.Task + 24, // 41: state.v1.OpenPRsResponse.tasks:type_name -> state.v1.Task + 24, // 42: state.v1.TasksResponse.tasks:type_name -> state.v1.Task + 164, // 43: state.v1.StatusCountsResponse.counts:type_name -> state.v1.StatusCountsResponse.CountsEntry + 25, // 44: state.v1.InsertEventRequest.event:type_name -> state.v1.Event + 25, // 45: state.v1.EventsSinceResponse.events:type_name -> state.v1.Event + 25, // 46: state.v1.TaskEventsResponse.events:type_name -> state.v1.Event + 34, // 47: state.v1.WorkflowStatsResponse.stats:type_name -> state.v1.WorkflowStat + 35, // 48: state.v1.StageStatsResponse.stats:type_name -> state.v1.StageStat + 36, // 49: state.v1.TokensByDayResponse.tokens:type_name -> state.v1.DayTokens + 165, // 50: state.v1.ConfigSnapshot.published_at:type_name -> google.protobuf.Timestamp + 91, // 51: state.v1.PutConfigSnapshotRequest.snapshot:type_name -> state.v1.ConfigSnapshot + 91, // 52: state.v1.GetConfigSnapshotResponse.snapshot:type_name -> state.v1.ConfigSnapshot + 165, // 53: state.v1.ChannelStatus.observed_at:type_name -> google.protobuf.Timestamp + 96, // 54: state.v1.PutChannelStatusRequest.channels:type_name -> state.v1.ChannelStatus + 96, // 55: state.v1.ListChannelStatusResponse.channels:type_name -> state.v1.ChannelStatus + 165, // 56: state.v1.ApplyStatus.reported_at:type_name -> google.protobuf.Timestamp + 101, // 57: state.v1.PutApplyStatusRequest.status:type_name -> state.v1.ApplyStatus + 101, // 58: state.v1.ListApplyStatusResponse.statuses:type_name -> state.v1.ApplyStatus + 165, // 59: state.v1.TaskLogEntry.time:type_name -> google.protobuf.Timestamp + 165, // 60: state.v1.ReadTaskLogRequest.since:type_name -> google.protobuf.Timestamp + 165, // 61: state.v1.ReadTaskLogRequest.until:type_name -> google.protobuf.Timestamp + 106, // 62: state.v1.ReadTaskLogResponse.entries:type_name -> state.v1.TaskLogEntry + 26, // 63: state.v1.InsertCaptureRequest.capture:type_name -> state.v1.CapturedEvent + 26, // 64: state.v1.ListCapturesResponse.captures:type_name -> state.v1.CapturedEvent + 26, // 65: state.v1.StreamCapturesResponse.capture:type_name -> state.v1.CapturedEvent + 31, // 66: state.v1.InsertMappingRequest.mapping:type_name -> state.v1.Mapping + 31, // 67: state.v1.GetMappingResponse.mapping:type_name -> state.v1.Mapping + 31, // 68: state.v1.ListMappingsResponse.mappings:type_name -> state.v1.Mapping + 31, // 69: state.v1.UpdateMappingRequest.mapping:type_name -> state.v1.Mapping + 29, // 70: state.v1.InsertEventTypeRequest.event_type:type_name -> state.v1.EventType + 29, // 71: state.v1.UpdateEventTypeRequest.event_type:type_name -> state.v1.EventType + 29, // 72: state.v1.ListEventTypesResponse.event_types:type_name -> state.v1.EventType + 33, // 73: state.v1.InsertBindingRequest.binding:type_name -> state.v1.Binding + 33, // 74: state.v1.GetBindingResponse.binding:type_name -> state.v1.Binding + 33, // 75: state.v1.ListBindingsResponse.bindings:type_name -> state.v1.Binding + 33, // 76: state.v1.UpdateBindingRequest.binding:type_name -> state.v1.Binding + 33, // 77: state.v1.ArmedBindingsForSourceResponse.bindings:type_name -> state.v1.Binding + 26, // 78: state.v1.ListUndispatchedCapturesResponse.captures:type_name -> state.v1.CapturedEvent + 26, // 79: state.v1.StreamUndispatchedCapturesResponse.capture:type_name -> state.v1.CapturedEvent + 24, // 80: state.v1.EnqueueBindingTaskResponse.task:type_name -> state.v1.Task + 0, // 81: state.v1.StateStoreService.RegisterTaskGrant:input_type -> state.v1.RegisterTaskGrantRequest + 2, // 82: state.v1.StateStoreService.RevokeTaskGrant:input_type -> state.v1.RevokeTaskGrantRequest + 6, // 83: state.v1.StateStoreService.ListIdentities:input_type -> state.v1.ListIdentitiesRequest + 8, // 84: state.v1.StateStoreService.GetIdentity:input_type -> state.v1.GetIdentityRequest + 10, // 85: state.v1.StateStoreService.CreateIdentity:input_type -> state.v1.CreateIdentityRequest + 11, // 86: state.v1.StateStoreService.RenameIdentity:input_type -> state.v1.RenameIdentityRequest + 12, // 87: state.v1.StateStoreService.SuspendIdentity:input_type -> state.v1.SuspendIdentityRequest + 13, // 88: state.v1.StateStoreService.ReactivateIdentity:input_type -> state.v1.ReactivateIdentityRequest + 14, // 89: state.v1.StateStoreService.RetireIdentity:input_type -> state.v1.RetireIdentityRequest + 20, // 90: state.v1.StateStoreService.ResolveIdentitySubject:input_type -> state.v1.ResolveIdentitySubjectRequest + 22, // 91: state.v1.StateStoreService.BindIdentitySubject:input_type -> state.v1.BindIdentitySubjectRequest + 37, // 92: state.v1.StateStoreService.EnqueueIssue:input_type -> state.v1.EnqueueIssueRequest + 39, // 93: state.v1.StateStoreService.EnqueueChatTask:input_type -> state.v1.EnqueueChatTaskRequest + 41, // 94: state.v1.StateStoreService.ClaimNext:input_type -> state.v1.ClaimNextRequest + 43, // 95: state.v1.StateStoreService.ClaimByIssue:input_type -> state.v1.ClaimByIssueRequest + 45, // 96: state.v1.StateStoreService.Transition:input_type -> state.v1.TransitionRequest + 47, // 97: state.v1.StateStoreService.Update:input_type -> state.v1.UpdateRequest + 49, // 98: state.v1.StateStoreService.Requeue:input_type -> state.v1.RequeueRequest + 51, // 99: state.v1.StateStoreService.ParkTask:input_type -> state.v1.ParkTaskRequest + 53, // 100: state.v1.StateStoreService.RecoverStale:input_type -> state.v1.RecoverStaleRequest + 55, // 101: state.v1.StateStoreService.ArchiveTask:input_type -> state.v1.ArchiveTaskRequest + 57, // 102: state.v1.StateStoreService.RetryTask:input_type -> state.v1.RetryTaskRequest + 59, // 103: state.v1.StateStoreService.BeginRemediation:input_type -> state.v1.BeginRemediationRequest + 61, // 104: state.v1.StateStoreService.UpdateReviewPayload:input_type -> state.v1.UpdateReviewPayloadRequest + 63, // 105: state.v1.StateStoreService.SetReviewCursors:input_type -> state.v1.SetReviewCursorsRequest + 65, // 106: state.v1.StateStoreService.TaskByIssue:input_type -> state.v1.TaskByIssueRequest + 67, // 107: state.v1.StateStoreService.OpenTaskByPR:input_type -> state.v1.OpenTaskByPRRequest + 69, // 108: state.v1.StateStoreService.TaskByID:input_type -> state.v1.TaskByIDRequest + 71, // 109: state.v1.StateStoreService.OpenPRs:input_type -> state.v1.OpenPRsRequest + 73, // 110: state.v1.StateStoreService.ClearTerminalTasks:input_type -> state.v1.ClearTerminalTasksRequest + 75, // 111: state.v1.StateStoreService.Tasks:input_type -> state.v1.TasksRequest + 77, // 112: state.v1.StateStoreService.StatusCounts:input_type -> state.v1.StatusCountsRequest + 79, // 113: state.v1.StateStoreService.InsertEvent:input_type -> state.v1.InsertEventRequest + 81, // 114: state.v1.StateStoreService.EventsSince:input_type -> state.v1.EventsSinceRequest + 83, // 115: state.v1.StateStoreService.TaskEvents:input_type -> state.v1.TaskEventsRequest + 85, // 116: state.v1.StateStoreService.WorkflowStats:input_type -> state.v1.WorkflowStatsRequest + 87, // 117: state.v1.StateStoreService.StageStats:input_type -> state.v1.StageStatsRequest + 89, // 118: state.v1.StateStoreService.TokensByDay:input_type -> state.v1.TokensByDayRequest + 92, // 119: state.v1.StateStoreService.PutConfigSnapshot:input_type -> state.v1.PutConfigSnapshotRequest + 94, // 120: state.v1.StateStoreService.GetConfigSnapshot:input_type -> state.v1.GetConfigSnapshotRequest + 97, // 121: state.v1.StateStoreService.PutChannelStatus:input_type -> state.v1.PutChannelStatusRequest + 99, // 122: state.v1.StateStoreService.ListChannelStatus:input_type -> state.v1.ListChannelStatusRequest + 102, // 123: state.v1.StateStoreService.PutApplyStatus:input_type -> state.v1.PutApplyStatusRequest + 104, // 124: state.v1.StateStoreService.ListApplyStatus:input_type -> state.v1.ListApplyStatusRequest + 107, // 125: state.v1.StateStoreService.ReadTaskLog:input_type -> state.v1.ReadTaskLogRequest + 109, // 126: state.v1.StateStoreService.StreamTaskLogContent:input_type -> state.v1.StreamTaskLogContentRequest + 111, // 127: state.v1.StateStoreService.InsertCapture:input_type -> state.v1.InsertCaptureRequest + 113, // 128: state.v1.StateStoreService.ListCaptures:input_type -> state.v1.ListCapturesRequest + 115, // 129: state.v1.StateStoreService.StreamCaptures:input_type -> state.v1.StreamCapturesRequest + 117, // 130: state.v1.StateStoreService.InsertMapping:input_type -> state.v1.InsertMappingRequest + 119, // 131: state.v1.StateStoreService.GetMapping:input_type -> state.v1.GetMappingRequest + 121, // 132: state.v1.StateStoreService.ListMappings:input_type -> state.v1.ListMappingsRequest + 123, // 133: state.v1.StateStoreService.UpdateMapping:input_type -> state.v1.UpdateMappingRequest + 125, // 134: state.v1.StateStoreService.DeleteMapping:input_type -> state.v1.DeleteMappingRequest + 127, // 135: state.v1.StateStoreService.RecordMappingMatch:input_type -> state.v1.RecordMappingMatchRequest + 129, // 136: state.v1.StateStoreService.InsertEventType:input_type -> state.v1.InsertEventTypeRequest + 131, // 137: state.v1.StateStoreService.UpdateEventType:input_type -> state.v1.UpdateEventTypeRequest + 133, // 138: state.v1.StateStoreService.DeleteEventType:input_type -> state.v1.DeleteEventTypeRequest + 135, // 139: state.v1.StateStoreService.ListEventTypes:input_type -> state.v1.ListEventTypesRequest + 137, // 140: state.v1.StateStoreService.InsertBinding:input_type -> state.v1.InsertBindingRequest + 139, // 141: state.v1.StateStoreService.GetBinding:input_type -> state.v1.GetBindingRequest + 141, // 142: state.v1.StateStoreService.ListBindings:input_type -> state.v1.ListBindingsRequest + 143, // 143: state.v1.StateStoreService.UpdateBinding:input_type -> state.v1.UpdateBindingRequest + 145, // 144: state.v1.StateStoreService.DeleteBinding:input_type -> state.v1.DeleteBindingRequest + 147, // 145: state.v1.StateStoreService.ApproveBinding:input_type -> state.v1.ApproveBindingRequest + 149, // 146: state.v1.StateStoreService.ArmedBindingsForSource:input_type -> state.v1.ArmedBindingsForSourceRequest + 151, // 147: state.v1.StateStoreService.RecordDispatch:input_type -> state.v1.RecordDispatchRequest + 153, // 148: state.v1.StateStoreService.RecordPlaybookDispatch:input_type -> state.v1.RecordPlaybookDispatchRequest + 155, // 149: state.v1.StateStoreService.DeletePlaybookDispatches:input_type -> state.v1.DeletePlaybookDispatchesRequest + 157, // 150: state.v1.StateStoreService.ListUndispatchedCaptures:input_type -> state.v1.ListUndispatchedCapturesRequest + 159, // 151: state.v1.StateStoreService.StreamUndispatchedCaptures:input_type -> state.v1.StreamUndispatchedCapturesRequest + 161, // 152: state.v1.StateStoreService.EnqueueBindingTask:input_type -> state.v1.EnqueueBindingTaskRequest + 1, // 153: state.v1.StateStoreService.RegisterTaskGrant:output_type -> state.v1.RegisterTaskGrantResponse + 3, // 154: state.v1.StateStoreService.RevokeTaskGrant:output_type -> state.v1.RevokeTaskGrantResponse + 7, // 155: state.v1.StateStoreService.ListIdentities:output_type -> state.v1.ListIdentitiesResponse + 9, // 156: state.v1.StateStoreService.GetIdentity:output_type -> state.v1.GetIdentityResponse + 15, // 157: state.v1.StateStoreService.CreateIdentity:output_type -> state.v1.CreateIdentityResponse + 16, // 158: state.v1.StateStoreService.RenameIdentity:output_type -> state.v1.RenameIdentityResponse + 17, // 159: state.v1.StateStoreService.SuspendIdentity:output_type -> state.v1.SuspendIdentityResponse + 18, // 160: state.v1.StateStoreService.ReactivateIdentity:output_type -> state.v1.ReactivateIdentityResponse + 19, // 161: state.v1.StateStoreService.RetireIdentity:output_type -> state.v1.RetireIdentityResponse + 21, // 162: state.v1.StateStoreService.ResolveIdentitySubject:output_type -> state.v1.ResolveIdentitySubjectResponse + 23, // 163: state.v1.StateStoreService.BindIdentitySubject:output_type -> state.v1.BindIdentitySubjectResponse + 38, // 164: state.v1.StateStoreService.EnqueueIssue:output_type -> state.v1.EnqueueIssueResponse + 40, // 165: state.v1.StateStoreService.EnqueueChatTask:output_type -> state.v1.EnqueueChatTaskResponse + 42, // 166: state.v1.StateStoreService.ClaimNext:output_type -> state.v1.ClaimNextResponse + 44, // 167: state.v1.StateStoreService.ClaimByIssue:output_type -> state.v1.ClaimByIssueResponse + 46, // 168: state.v1.StateStoreService.Transition:output_type -> state.v1.TransitionResponse + 48, // 169: state.v1.StateStoreService.Update:output_type -> state.v1.UpdateResponse + 50, // 170: state.v1.StateStoreService.Requeue:output_type -> state.v1.RequeueResponse + 52, // 171: state.v1.StateStoreService.ParkTask:output_type -> state.v1.ParkTaskResponse + 54, // 172: state.v1.StateStoreService.RecoverStale:output_type -> state.v1.RecoverStaleResponse + 56, // 173: state.v1.StateStoreService.ArchiveTask:output_type -> state.v1.ArchiveTaskResponse + 58, // 174: state.v1.StateStoreService.RetryTask:output_type -> state.v1.RetryTaskResponse + 60, // 175: state.v1.StateStoreService.BeginRemediation:output_type -> state.v1.BeginRemediationResponse + 62, // 176: state.v1.StateStoreService.UpdateReviewPayload:output_type -> state.v1.UpdateReviewPayloadResponse + 64, // 177: state.v1.StateStoreService.SetReviewCursors:output_type -> state.v1.SetReviewCursorsResponse + 66, // 178: state.v1.StateStoreService.TaskByIssue:output_type -> state.v1.TaskByIssueResponse + 68, // 179: state.v1.StateStoreService.OpenTaskByPR:output_type -> state.v1.OpenTaskByPRResponse + 70, // 180: state.v1.StateStoreService.TaskByID:output_type -> state.v1.TaskByIDResponse + 72, // 181: state.v1.StateStoreService.OpenPRs:output_type -> state.v1.OpenPRsResponse + 74, // 182: state.v1.StateStoreService.ClearTerminalTasks:output_type -> state.v1.ClearTerminalTasksResponse + 76, // 183: state.v1.StateStoreService.Tasks:output_type -> state.v1.TasksResponse + 78, // 184: state.v1.StateStoreService.StatusCounts:output_type -> state.v1.StatusCountsResponse + 80, // 185: state.v1.StateStoreService.InsertEvent:output_type -> state.v1.InsertEventResponse + 82, // 186: state.v1.StateStoreService.EventsSince:output_type -> state.v1.EventsSinceResponse + 84, // 187: state.v1.StateStoreService.TaskEvents:output_type -> state.v1.TaskEventsResponse + 86, // 188: state.v1.StateStoreService.WorkflowStats:output_type -> state.v1.WorkflowStatsResponse + 88, // 189: state.v1.StateStoreService.StageStats:output_type -> state.v1.StageStatsResponse + 90, // 190: state.v1.StateStoreService.TokensByDay:output_type -> state.v1.TokensByDayResponse + 93, // 191: state.v1.StateStoreService.PutConfigSnapshot:output_type -> state.v1.PutConfigSnapshotResponse + 95, // 192: state.v1.StateStoreService.GetConfigSnapshot:output_type -> state.v1.GetConfigSnapshotResponse + 98, // 193: state.v1.StateStoreService.PutChannelStatus:output_type -> state.v1.PutChannelStatusResponse + 100, // 194: state.v1.StateStoreService.ListChannelStatus:output_type -> state.v1.ListChannelStatusResponse + 103, // 195: state.v1.StateStoreService.PutApplyStatus:output_type -> state.v1.PutApplyStatusResponse + 105, // 196: state.v1.StateStoreService.ListApplyStatus:output_type -> state.v1.ListApplyStatusResponse + 108, // 197: state.v1.StateStoreService.ReadTaskLog:output_type -> state.v1.ReadTaskLogResponse + 110, // 198: state.v1.StateStoreService.StreamTaskLogContent:output_type -> state.v1.StreamTaskLogContentResponse + 112, // 199: state.v1.StateStoreService.InsertCapture:output_type -> state.v1.InsertCaptureResponse + 114, // 200: state.v1.StateStoreService.ListCaptures:output_type -> state.v1.ListCapturesResponse + 116, // 201: state.v1.StateStoreService.StreamCaptures:output_type -> state.v1.StreamCapturesResponse + 118, // 202: state.v1.StateStoreService.InsertMapping:output_type -> state.v1.InsertMappingResponse + 120, // 203: state.v1.StateStoreService.GetMapping:output_type -> state.v1.GetMappingResponse + 122, // 204: state.v1.StateStoreService.ListMappings:output_type -> state.v1.ListMappingsResponse + 124, // 205: state.v1.StateStoreService.UpdateMapping:output_type -> state.v1.UpdateMappingResponse + 126, // 206: state.v1.StateStoreService.DeleteMapping:output_type -> state.v1.DeleteMappingResponse + 128, // 207: state.v1.StateStoreService.RecordMappingMatch:output_type -> state.v1.RecordMappingMatchResponse + 130, // 208: state.v1.StateStoreService.InsertEventType:output_type -> state.v1.InsertEventTypeResponse + 132, // 209: state.v1.StateStoreService.UpdateEventType:output_type -> state.v1.UpdateEventTypeResponse + 134, // 210: state.v1.StateStoreService.DeleteEventType:output_type -> state.v1.DeleteEventTypeResponse + 136, // 211: state.v1.StateStoreService.ListEventTypes:output_type -> state.v1.ListEventTypesResponse + 138, // 212: state.v1.StateStoreService.InsertBinding:output_type -> state.v1.InsertBindingResponse + 140, // 213: state.v1.StateStoreService.GetBinding:output_type -> state.v1.GetBindingResponse + 142, // 214: state.v1.StateStoreService.ListBindings:output_type -> state.v1.ListBindingsResponse + 144, // 215: state.v1.StateStoreService.UpdateBinding:output_type -> state.v1.UpdateBindingResponse + 146, // 216: state.v1.StateStoreService.DeleteBinding:output_type -> state.v1.DeleteBindingResponse + 148, // 217: state.v1.StateStoreService.ApproveBinding:output_type -> state.v1.ApproveBindingResponse + 150, // 218: state.v1.StateStoreService.ArmedBindingsForSource:output_type -> state.v1.ArmedBindingsForSourceResponse + 152, // 219: state.v1.StateStoreService.RecordDispatch:output_type -> state.v1.RecordDispatchResponse + 154, // 220: state.v1.StateStoreService.RecordPlaybookDispatch:output_type -> state.v1.RecordPlaybookDispatchResponse + 156, // 221: state.v1.StateStoreService.DeletePlaybookDispatches:output_type -> state.v1.DeletePlaybookDispatchesResponse + 158, // 222: state.v1.StateStoreService.ListUndispatchedCaptures:output_type -> state.v1.ListUndispatchedCapturesResponse + 160, // 223: state.v1.StateStoreService.StreamUndispatchedCaptures:output_type -> state.v1.StreamUndispatchedCapturesResponse + 162, // 224: state.v1.StateStoreService.EnqueueBindingTask:output_type -> state.v1.EnqueueBindingTaskResponse + 153, // [153:225] is the sub-list for method output_type + 81, // [81:153] is the sub-list for method input_type + 81, // [81:81] is the sub-list for extension type_name + 81, // [81:81] is the sub-list for extension extendee + 0, // [0:81] is the sub-list for field type_name } func init() { file_state_v1_state_proto_init() } @@ -9652,7 +9790,7 @@ func file_state_v1_state_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_state_v1_state_proto_rawDesc), len(file_state_v1_state_proto_rawDesc)), NumEnums: 0, - NumMessages: 163, + NumMessages: 165, NumExtensions: 0, NumServices: 1, }, diff --git a/internal/contracts/state/v1/state_grpc.pb.go b/internal/contracts/state/v1/state_grpc.pb.go index 094bcae61..7c7714d9c 100644 --- a/internal/contracts/state/v1/state_grpc.pb.go +++ b/internal/contracts/state/v1/state_grpc.pb.go @@ -73,6 +73,7 @@ const ( StateStoreService_ListMappings_FullMethodName = "/state.v1.StateStoreService/ListMappings" StateStoreService_UpdateMapping_FullMethodName = "/state.v1.StateStoreService/UpdateMapping" StateStoreService_DeleteMapping_FullMethodName = "/state.v1.StateStoreService/DeleteMapping" + StateStoreService_RecordMappingMatch_FullMethodName = "/state.v1.StateStoreService/RecordMappingMatch" StateStoreService_InsertEventType_FullMethodName = "/state.v1.StateStoreService/InsertEventType" StateStoreService_UpdateEventType_FullMethodName = "/state.v1.StateStoreService/UpdateEventType" StateStoreService_DeleteEventType_FullMethodName = "/state.v1.StateStoreService/DeleteEventType" @@ -201,6 +202,9 @@ type StateStoreServiceClient interface { ListMappings(ctx context.Context, in *ListMappingsRequest, opts ...grpc.CallOption) (*ListMappingsResponse, error) UpdateMapping(ctx context.Context, in *UpdateMappingRequest, opts ...grpc.CallOption) (*UpdateMappingResponse, error) DeleteMapping(ctx context.Context, in *DeleteMappingRequest, opts ...grpc.CallOption) (*DeleteMappingResponse, error) + // RecordMappingMatch counts one event a mapping resolved; the same + // (mapping, capture) twice counts once. + RecordMappingMatch(ctx context.Context, in *RecordMappingMatchRequest, opts ...grpc.CallOption) (*RecordMappingMatchResponse, error) // EventType (docs/prds/event-automation.md, "Event types"). Insert and // Update refuse an overlapping or malformed type. InsertEventType(ctx context.Context, in *InsertEventTypeRequest, opts ...grpc.CallOption) (*InsertEventTypeResponse, error) @@ -799,6 +803,16 @@ func (c *stateStoreServiceClient) DeleteMapping(ctx context.Context, in *DeleteM return out, nil } +func (c *stateStoreServiceClient) RecordMappingMatch(ctx context.Context, in *RecordMappingMatchRequest, opts ...grpc.CallOption) (*RecordMappingMatchResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(RecordMappingMatchResponse) + err := c.cc.Invoke(ctx, StateStoreService_RecordMappingMatch_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *stateStoreServiceClient) InsertEventType(ctx context.Context, in *InsertEventTypeRequest, opts ...grpc.CallOption) (*InsertEventTypeResponse, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(InsertEventTypeResponse) @@ -1088,6 +1102,9 @@ type StateStoreServiceServer interface { ListMappings(context.Context, *ListMappingsRequest) (*ListMappingsResponse, error) UpdateMapping(context.Context, *UpdateMappingRequest) (*UpdateMappingResponse, error) DeleteMapping(context.Context, *DeleteMappingRequest) (*DeleteMappingResponse, error) + // RecordMappingMatch counts one event a mapping resolved; the same + // (mapping, capture) twice counts once. + RecordMappingMatch(context.Context, *RecordMappingMatchRequest) (*RecordMappingMatchResponse, error) // EventType (docs/prds/event-automation.md, "Event types"). Insert and // Update refuse an overlapping or malformed type. InsertEventType(context.Context, *InsertEventTypeRequest) (*InsertEventTypeResponse, error) @@ -1289,6 +1306,9 @@ func (UnimplementedStateStoreServiceServer) UpdateMapping(context.Context, *Upda func (UnimplementedStateStoreServiceServer) DeleteMapping(context.Context, *DeleteMappingRequest) (*DeleteMappingResponse, error) { return nil, status.Error(codes.Unimplemented, "method DeleteMapping not implemented") } +func (UnimplementedStateStoreServiceServer) RecordMappingMatch(context.Context, *RecordMappingMatchRequest) (*RecordMappingMatchResponse, error) { + return nil, status.Error(codes.Unimplemented, "method RecordMappingMatch not implemented") +} func (UnimplementedStateStoreServiceServer) InsertEventType(context.Context, *InsertEventTypeRequest) (*InsertEventTypeResponse, error) { return nil, status.Error(codes.Unimplemented, "method InsertEventType not implemented") } @@ -2319,6 +2339,24 @@ func _StateStoreService_DeleteMapping_Handler(srv interface{}, ctx context.Conte return interceptor(ctx, in, info, handler) } +func _StateStoreService_RecordMappingMatch_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RecordMappingMatchRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StateStoreServiceServer).RecordMappingMatch(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: StateStoreService_RecordMappingMatch_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StateStoreServiceServer).RecordMappingMatch(ctx, req.(*RecordMappingMatchRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _StateStoreService_InsertEventType_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(InsertEventTypeRequest) if err := dec(in); err != nil { @@ -2833,6 +2871,10 @@ var StateStoreService_ServiceDesc = grpc.ServiceDesc{ MethodName: "DeleteMapping", Handler: _StateStoreService_DeleteMapping_Handler, }, + { + MethodName: "RecordMappingMatch", + Handler: _StateStoreService_RecordMappingMatch_Handler, + }, { MethodName: "InsertEventType", Handler: _StateStoreService_InsertEventType_Handler, diff --git a/internal/daemon/daemon.go b/internal/daemon/daemon.go index 7823f027b..169944792 100644 --- a/internal/daemon/daemon.go +++ b/internal/daemon/daemon.go @@ -9,6 +9,7 @@ import ( "errors" "fmt" "log/slog" + "maps" "os" "strings" "sync" @@ -120,6 +121,9 @@ type Daemon struct { // BindingStore to keep the CRUD interface under the interfacebloat // limit. Optional: nil disables the dispatch loop. BindingDispatcher storecontract.BindingDispatcher + // MappingMatches counts each event a mapping resolved at dispatch. + // Optional: nil leaves match counts unrecorded. + MappingMatches storecontract.MappingMatchRecorder // BindingTaskCreator enqueues a task triggered by a binding. Split // off TaskLifecycle so the lifecycle surface stays narrow and the // dispatch loop does not acquire the full task-creation contract. @@ -611,30 +615,18 @@ func (d *Daemon) cleanupExpiredStorage(ctx context.Context) { // single cycle's worst-case latency on a backlog. const bindingDispatchBatchLimit = 100 -// dispatchBindings walks authenticated captures whose source has at -// least one armed binding, evaluates each binding's matcher against -// the capture, resolves fields through the binding's mapping, and -// enqueues a task per matched (binding, capture) pair. +// dispatchBindings walks identified captures on sources with an armed +// binding and offers each capture to every armed binding on its source. +// Each binding dispatches it at most once (dispatchOneBinding). // -// The binding_dispatches ledger is the at-most-once guarantee across -// cycles and daemon restarts: RecordDispatch returns -// storecontract.ErrAlreadyDispatched on a duplicate (binding_id, capture_id) -// pair, and dispatchOneBinding treats that as a normal "another cycle -// raced us" outcome rather than an error. -// -// Nil Bindings, BindingDispatcher or BindingTaskCreator disables the -// loop (legacy behaviour: daemons built before t2db.4 Phase E had no -// playbook bindings, and each field's own doc comment promises this -// degrade-not-panic contract independently). +// Nil Bindings, BindingDispatcher or BindingTaskCreator disables the loop. func (d *Daemon) dispatchBindings(ctx context.Context) { if d.Bindings == nil || d.BindingDispatcher == nil || d.BindingTaskCreator == nil { return } // Gather armed sources first so the captures query filters down to - // only relevant rows -- the table-level view over captured_events - // is otherwise unbounded, and a backlog of unrelated sources - // should never be scanned on a cycle. + // only relevant rows. bindings, err := d.Bindings.ListBindings(ctx) if err != nil { d.Log.Warn("list bindings failed", "error", err) @@ -670,19 +662,15 @@ func (d *Daemon) dispatchBindings(ctx context.Context) { } } -// dispatchOneBinding handles a single (binding, capture) match: resolve -// fields through the binding's mapping, enqueue a task, and record the -// dispatch in the dedup ledger. Each step degrades independently -- -// a mapping lookup failure logs and returns, a required-field -// resolution failure records a binding_dispatch_failure event and -// returns without enqueueing, an enqueue failure logs and returns, and -// a RecordDispatch returning ErrAlreadyDispatched is treated as a -// benign race winner (another cycle already created the task). -// -// Owner/repo resolution currently falls back to the single configured -// repo (when exactly one is configured); binding.Owner/Repo is a -// follow-up so multi-repo deployments don't have to live with the -// ambiguity. +// dispatchOneBinding offers one capture to one binding. The binding applies +// when its mapping belongs to the capture's event type. The mapping resolves +// the payload (a required-field failure records binding_dispatch_failure and +// stops), counts the match, and the binding's filter must admit the resolved +// parameters. The dispatch is then claimed in the binding_dispatches ledger +// before the task is enqueued: a capture stays listed until every binding for +// its event type has dispatched it, so the claim is what stops a binding that +// already fired from firing again on a later cycle. A failed enqueue after the +// claim loses that dispatch, which is the at-most-once side of the trade. func (d *Daemon) dispatchOneBinding(ctx context.Context, b binding.Binding, c storecontract.CapturedEvent) { if d.Mappings == nil { d.Log.Warn("binding dispatch: mapping store unavailable", "binding", b.ID) @@ -697,18 +685,25 @@ func (d *Daemon) dispatchOneBinding(ctx context.Context, b binding.Binding, c st d.Log.Warn("binding dispatch: mapping missing", "binding", b.ID, "mapping", b.MappingID) return } + if m.EventTypeID != c.EventType { + return + } values, failures := mapping.Resolve(m.Fields, []byte(c.Body)) if hasBlockingFailure(m.Fields, failures) { - _, _ = d.Store.InsertEvent(ctx, events.Event{ - Kind: "binding_dispatch_failure", - Detail: fmt.Sprintf("binding %q (capture %q): required field failed", b.ID, c.ID), - Data: map[string]any{ - "binding_id": b.ID, - "binding_version": b.Version, - "capture_id": c.ID, - "failures": failures, - }, - }) + d.recordDispatchFailure(ctx, b, c, "required field failed", map[string]any{"failures": failures}) + return + } + if d.MappingMatches != nil { + if err := d.MappingMatches.RecordMappingMatch(ctx, m.ID, c.ID); err != nil { + d.Log.Warn("binding dispatch: record mapping match", "mapping", m.ID, "capture", c.ID, "error", err) + } + } + filter, err := binding.CompileFilter(b.Filter, m.Fields) + if err != nil { + d.recordDispatchFailure(ctx, b, c, "filter does not compile", map[string]any{"error": err.Error()}) + return + } + if admitted, _ := filter.Admits(values); !admitted { return } @@ -716,27 +711,32 @@ func (d *Daemon) dispatchOneBinding(ctx context.Context, b binding.Binding, c st if !ok { return // resolveBindingRepo already logged a warning } + if err := d.BindingDispatcher.RecordDispatch(ctx, b.ID, int64(b.Version), c.ID, 0); err != nil { + if !errors.Is(err, storecontract.ErrAlreadyDispatched) { + d.Log.Warn("binding dispatch: record", "binding", b.ID, "capture", c.ID, "error", err) + } + return + } title := fmt.Sprintf("binding %s/%d from %s", b.Name, b.Version, c.Source) body := renderBindingBody(values, c) - - task, err := d.BindingTaskCreator.EnqueueBindingTask(ctx, owner, repo, title, body, b.Workflow, "", b.ID, b.Version) - if err != nil { + if _, err := d.BindingTaskCreator.EnqueueBindingTask(ctx, owner, repo, title, body, b.Workflow, "", b.ID, b.Version); err != nil { d.Log.Warn("binding dispatch: enqueue", "binding", b.ID, "capture", c.ID, "error", err) - return } +} - if err := d.BindingDispatcher.RecordDispatch(ctx, b.ID, int64(b.Version), c.ID, task.ID); err != nil { - if errors.Is(err, storecontract.ErrAlreadyDispatched) { - // Another cycle or daemon instance raced us and already - // recorded the dispatch. The duplicate task remains - // queued (delete-on-races is its own can of worms), - // but the ledger prevents the same (binding, capture) - // pair from ever being dispatched again. - return - } - d.Log.Warn("binding dispatch: record", "binding", b.ID, "capture", c.ID, "error", err) - return +// recordDispatchFailure records why a binding did not dispatch a capture. +func (d *Daemon) recordDispatchFailure(ctx context.Context, b binding.Binding, c storecontract.CapturedEvent, reason string, extra map[string]any) { + data := map[string]any{ + "binding_id": b.ID, + "binding_version": b.Version, + "capture_id": c.ID, } + maps.Copy(data, extra) + _, _ = d.Store.InsertEvent(ctx, events.Event{ + Kind: "binding_dispatch_failure", + Detail: fmt.Sprintf("binding %q (capture %q): %s", b.ID, c.ID, reason), + Data: data, + }) } // hasBlockingFailure reports whether any of the failures belongs to a diff --git a/internal/daemon/dispatch_bindings_test.go b/internal/daemon/dispatch_bindings_test.go index 362e920fc..5072212c3 100644 --- a/internal/daemon/dispatch_bindings_test.go +++ b/internal/daemon/dispatch_bindings_test.go @@ -48,7 +48,7 @@ func TestDispatchBindingsCreatesTaskFromArmedCapture(t *testing.T) { t.Errorf("task.Status = %q, want %q", got.Status, workflow.StatusQueued) } - assertDispatchRecorded(t, s, bindingID, got.ID) + assertDispatchRecorded(t, s, bindingID) } // TestDispatchBindingsUsesBindingRepoPinWithMultipleConfiguredRepos is the @@ -78,7 +78,7 @@ func TestDispatchBindingsUsesBindingRepoPinWithMultipleConfiguredRepos(t *testin if tasks[0].Owner != "acme" || tasks[0].Repo != "widget" { t.Fatalf("task owner/repo = %s/%s, want acme/widget (the binding's own pin, not a guess)", tasks[0].Owner, tasks[0].Repo) } - assertDispatchRecorded(t, s, bindingID, tasks[0].ID) + assertDispatchRecorded(t, s, bindingID) } // TestDispatchBindingsRefusesUnpinnedBindingWithMultipleConfiguredRepos @@ -367,23 +367,16 @@ func newDispatchDaemonWithRepos(t *testing.T, s *dispatchStores, repos []config. } } -// assertDispatchRecorded reads the dedup ledger directly: the -// (binding, capture) unique index is what guarantees no double -// dispatch. Going through the SQL table rather than the public -// BindingStore surface keeps the assertion focused on the contract -// Phase E actually writes to, not on a ListDispatches helper that -// may not exist. -func assertDispatchRecorded(t *testing.T, s *dispatchStores, bindingID string, taskID int64) { +// assertDispatchRecorded reads the dedup ledger directly: the (binding, +// capture) unique index is what guarantees no double dispatch. The dispatch +// is claimed before its task exists, so the row carries no task id. +func assertDispatchRecorded(t *testing.T, s *dispatchStores, bindingID string) { t.Helper() var gotBindingID string - var gotTaskID int64 if err := s.EdaStore.App().DB().NewQuery( - "SELECT binding, task_id FROM binding_dispatches WHERE binding = {:binding}"). + "SELECT binding FROM binding_dispatches WHERE binding = {:binding}"). Bind(map[string]any{"binding": bindingID}). - Row(&gotBindingID, &gotTaskID); err != nil { + Row(&gotBindingID); err != nil { t.Fatalf("binding_dispatches row missing: %v", err) } - if gotBindingID != bindingID || gotTaskID != taskID { - t.Fatalf("binding_dispatches row = (%q, %d), want (%q, %d)", gotBindingID, gotTaskID, bindingID, taskID) - } } diff --git a/internal/daemon/dispatch_event_types_test.go b/internal/daemon/dispatch_event_types_test.go new file mode 100644 index 000000000..65a4b7697 --- /dev/null +++ b/internal/daemon/dispatch_event_types_test.go @@ -0,0 +1,176 @@ +package daemon + +import ( + "context" + "log/slog" + "path/filepath" + "testing" + + "github.com/samcharles93/archie-core/internal/config" + "github.com/samcharles93/archie-core/internal/domain/binding" + "github.com/samcharles93/archie-core/internal/domain/mapping" + "github.com/samcharles93/archie-core/internal/domain/storecontract" + "github.com/samcharles93/archie-core/internal/store" +) + +// fakeEDA serves bindings, mappings and one capture from memory, and records +// dispatches and mapping matches the way the store's unique keys do. +type fakeEDA struct { + bindings []binding.Binding + mappings map[string]mapping.Mapping + captures []storecontract.CapturedEvent + dispatched map[[2]string]bool + matches map[[2]string]bool +} + +func (f *fakeEDA) InsertMapping(context.Context, mapping.Mapping) (string, error) { return "", nil } +func (f *fakeEDA) GetMapping(_ context.Context, id string) (*mapping.Mapping, error) { + m, ok := f.mappings[id] + if !ok { + return nil, nil + } + return &m, nil +} +func (f *fakeEDA) ListMappings(context.Context) ([]mapping.Mapping, error) { return nil, nil } +func (f *fakeEDA) UpdateMapping(context.Context, mapping.Mapping) error { return nil } +func (f *fakeEDA) DeleteMapping(context.Context, string) error { return nil } + +func (f *fakeEDA) InsertBinding(context.Context, binding.Binding) (string, error) { return "", nil } +func (f *fakeEDA) GetBinding(context.Context, string) (*binding.Binding, error) { return nil, nil } + +func (f *fakeEDA) ListBindings(context.Context) ([]binding.Binding, error) { return f.bindings, nil } +func (f *fakeEDA) UpdateBinding(context.Context, binding.Binding) error { return nil } +func (f *fakeEDA) DeleteBinding(context.Context, string) error { return nil } +func (f *fakeEDA) ApproveBinding(context.Context, string) error { return nil } + +func (f *fakeEDA) ArmedBindingsForSource(_ context.Context, source string) ([]binding.Binding, error) { + var out []binding.Binding + for _, b := range f.bindings { + if b.Status == binding.StatusArmed && b.Matcher.Source == source { + out = append(out, b) + } + } + return out, nil +} + +func (f *fakeEDA) RecordDispatch(_ context.Context, bindingID string, _ int64, captureID string, _ int64) error { + key := [2]string{bindingID, captureID} + if f.dispatched[key] { + return storecontract.ErrAlreadyDispatched + } + f.dispatched[key] = true + return nil +} + +func (f *fakeEDA) ListUndispatchedCaptures(context.Context, []string, int) ([]storecontract.CapturedEvent, error) { + return f.captures, nil +} + +func (f *fakeEDA) RecordMappingMatch(_ context.Context, mappingID, captureID string) error { + f.matches[[2]string{mappingID, captureID}] = true + return nil +} + +func armed(id, mappingID, filter string) binding.Binding { + return binding.Binding{ + ID: id, Name: id, Matcher: binding.Matcher{Source: "fw"}, MappingID: mappingID, + Filter: filter, Workflow: "implement", Status: binding.StatusArmed, Version: 1, + } +} + +func severityMapping(id, eventType string) mapping.Mapping { + return mapping.Mapping{ + ID: id, Name: id, EventTypeID: eventType, + Fields: []mapping.Field{{Name: "severity", Path: "severity", Type: mapping.TypeString, Required: true}}, + } +} + +func TestDispatchPerBindingByEventTypeAndFilter(t *testing.T) { + capture := storecontract.CapturedEvent{ + ID: "c1", Source: "fw", EventType: "blocked", Authenticated: true, Body: `{"severity":"high"}`, + } + tests := []struct { + name string + bindings []binding.Binding + mappings []mapping.Mapping + wantTasks []string + wantMatches [][2]string + }{ + { + name: "several bindings on one source each dispatch once", + bindings: []binding.Binding{armed("a", "m", ""), armed("b", "m", "")}, + mappings: []mapping.Mapping{severityMapping("m", "blocked")}, + wantTasks: []string{"a", "b"}, + wantMatches: [][2]string{{"m", "c1"}}, + }, + { + name: "a binding for another event type does not dispatch", + bindings: []binding.Binding{armed("a", "m", "")}, + mappings: []mapping.Mapping{severityMapping("m", "allowed")}, + }, + { + name: "a filter that excludes the event does not dispatch it", + bindings: []binding.Binding{armed("a", "m", `severity == "low"`), armed("b", "m", `severity in ["high", "critical"]`)}, + mappings: []mapping.Mapping{severityMapping("m", "blocked")}, + wantTasks: []string{"b"}, + wantMatches: [][2]string{{"m", "c1"}}, + }, + { + name: "a filter that does not compile does not dispatch", + bindings: []binding.Binding{armed("a", "m", `nope ==`)}, + mappings: []mapping.Mapping{severityMapping("m", "blocked")}, + // The mapping still resolved the event. + wantMatches: [][2]string{{"m", "c1"}}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "dispatch.db")) + if err != nil { + t.Fatalf("store.Open: %v", err) + } + t.Cleanup(func() { _ = st.Close() }) + eda := &fakeEDA{ + bindings: tt.bindings, mappings: map[string]mapping.Mapping{}, + captures: []storecontract.CapturedEvent{capture}, + dispatched: map[[2]string]bool{}, matches: map[[2]string]bool{}, + } + for _, m := range tt.mappings { + eda.mappings[m.ID] = m + } + d := &Daemon{ + Cfg: config.NewHolder(config.Config{Repos: []config.Repo{{Owner: "acme", Name: "widget"}}}), + Store: st, Mappings: eda, Bindings: eda, BindingDispatcher: eda, MappingMatches: eda, + BindingTaskCreator: st, + Log: slog.New(slog.DiscardHandler), + } + d.dispatchBindings(t.Context()) + d.dispatchBindings(t.Context()) + + tasks, err := st.Tasks(t.Context(), 10) + if err != nil { + t.Fatalf("Tasks: %v", err) + } + got := map[string]int{} + for _, task := range tasks { + got[task.BindingID]++ + } + if len(tasks) != len(tt.wantTasks) { + t.Fatalf("tasks by binding = %v, want one each for %v", got, tt.wantTasks) + } + for _, id := range tt.wantTasks { + if got[id] != 1 { + t.Fatalf("tasks by binding = %v, want one each for %v", got, tt.wantTasks) + } + } + if len(eda.matches) != len(tt.wantMatches) { + t.Fatalf("mapping matches = %v, want %v", eda.matches, tt.wantMatches) + } + for _, key := range tt.wantMatches { + if !eda.matches[key] { + t.Fatalf("mapping matches = %v, want %v", eda.matches, tt.wantMatches) + } + } + }) + } +} diff --git a/internal/domain/binding/binding.go b/internal/domain/binding/binding.go index 590b45bf3..37ce8ee15 100644 --- a/internal/domain/binding/binding.go +++ b/internal/domain/binding/binding.go @@ -34,7 +34,8 @@ type Matcher struct { // Binding is the runtime-editable entity that ties a matcher, a payload // mapping, and a workflow together. Bindings live in the store, not in // config.toml, so operators can author them from the dashboard while the -// daemon runs. +// daemon runs. Any number of bindings may share a source: each one applies to +// the event type its mapping belongs to. // // Version is bumped on every UpdateBinding so a later edit cannot // silently rewrite the historical provenance of a task that already @@ -46,7 +47,10 @@ type Binding struct { Name string `json:"name"` Matcher Matcher `json:"matcher"` MappingID string `json:"mapping_id"` - Workflow string `json:"workflow"` + // Filter is an optional CEL expression over the mapping's parameters + // (CompileFilter). An event it excludes is not dispatched. + Filter string `json:"filter,omitempty"` + Workflow string `json:"workflow"` // Owner and Repo pin a binding to a specific configured repo, so a // multi-repo deployment can dispatch correctly. Both empty means "no // pin" -- resolveBindingRepo falls back to the single-configured-repo diff --git a/internal/domain/binding/filter.go b/internal/domain/binding/filter.go new file mode 100644 index 000000000..eaf792702 --- /dev/null +++ b/internal/domain/binding/filter.go @@ -0,0 +1,78 @@ +package binding + +import ( + "fmt" + "strings" + + "cel.dev/cel-go/cel" + + "github.com/samcharles93/archie-core/internal/domain/eda/expr" + "github.com/samcharles93/archie-core/internal/domain/mapping" +) + +// Filter is a compiled binding filter: a CEL expression over the mapping's +// named parameters, each declared as a variable of its field type +// (`severity in ["high", "critical"]`). A nil Filter admits every event. +type Filter struct { + prg cel.Program +} + +// CompileFilter checks src against the mapping's fields and compiles it. An +// empty src is no filter. A reference to a parameter the mapping lacks, a type +// error, or a non-boolean result is refused. +func CompileFilter(src string, fields []mapping.Field) (*Filter, error) { + if strings.TrimSpace(src) == "" { + return nil, nil + } + opts := make([]cel.EnvOption, 0, len(fields)) + for _, f := range fields { + opts = append(opts, cel.Variable(f.Name, celType(f.Type))) + } + env, err := cel.NewEnv(opts...) + if err != nil { + return nil, fmt.Errorf("binding: filter: %w", err) + } + ast, issues := env.Compile(src) + if issues != nil && issues.Err() != nil { + return nil, fmt.Errorf("binding: filter: %w", issues.Err()) + } + if !ast.OutputType().IsExactType(cel.BoolType) { + return nil, fmt.Errorf("binding: filter must be a boolean, not %s", ast.OutputType()) + } + prg, err := env.Program(ast, cel.CostLimit(expr.DefaultCostLimit)) + if err != nil { + return nil, fmt.Errorf("binding: filter: %w", err) + } + return &Filter{prg: prg}, nil +} + +// Admits evaluates the filter over resolved parameter values. An evaluation +// error, such as a parameter that did not resolve, excludes the event. +func (f *Filter) Admits(values map[string]any) (bool, error) { + if f == nil { + return true, nil + } + v, _, err := f.prg.Eval(values) + if err != nil { + return false, fmt.Errorf("binding: filter: %w", err) + } + admitted, _ := v.Value().(bool) + return admitted, nil +} + +func celType(t mapping.FieldType) *cel.Type { + switch t { + case mapping.TypeString: + return cel.StringType + case mapping.TypeNumber: + return cel.DoubleType + case mapping.TypeBool: + return cel.BoolType + case mapping.TypeObject: + return cel.MapType(cel.StringType, cel.DynType) + case mapping.TypeArray: + return cel.ListType(cel.DynType) + default: + return cel.DynType + } +} diff --git a/internal/domain/binding/filter_test.go b/internal/domain/binding/filter_test.go new file mode 100644 index 000000000..4d23b3e08 --- /dev/null +++ b/internal/domain/binding/filter_test.go @@ -0,0 +1,59 @@ +package binding + +import ( + "testing" + + "github.com/samcharles93/archie-core/internal/domain/mapping" +) + +var filterFields = []mapping.Field{ + {Name: "severity", Path: "severity", Type: mapping.TypeString}, + {Name: "count", Path: "count", Type: mapping.TypeNumber}, + {Name: "urgent", Path: "urgent", Type: mapping.TypeBool}, + {Name: "extra", Path: "extra", Type: mapping.TypeAny}, +} + +func TestCompileFilterRefuses(t *testing.T) { + tests := []struct{ name, src string }{ + {"unknown parameter", `sender == "x"`}, + {"not boolean", `severity`}, + {"type mismatch", `count == "3"`}, + {"syntax", `severity in [`}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if _, err := CompileFilter(tt.src, filterFields); err == nil { + t.Fatalf("CompileFilter(%q) = nil error, want refusal", tt.src) + } + }) + } +} + +func TestFilterAdmits(t *testing.T) { + values := map[string]any{"severity": "high", "count": float64(3), "urgent": true, "extra": "x"} + tests := []struct { + name string + src string + values map[string]any + want bool + }{ + {"empty filter admits everything", "", values, true}, + {"list membership admits", `severity in ["high", "critical"]`, values, true}, + {"list membership excludes", `severity in ["critical"]`, values, false}, + {"number comparison", `count > 2.0 && urgent`, values, true}, + {"dyn parameter", `extra == "x"`, values, true}, + {"unresolved parameter excludes", `severity == "high"`, map[string]any{"count": float64(1)}, false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := CompileFilter(tt.src, filterFields) + if err != nil { + t.Fatalf("CompileFilter: %v", err) + } + got, _ := f.Admits(tt.values) + if got != tt.want { + t.Fatalf("Admits = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/domain/mapping/mapping.go b/internal/domain/mapping/mapping.go index c225210b0..f99c2e590 100644 --- a/internal/domain/mapping/mapping.go +++ b/internal/domain/mapping/mapping.go @@ -8,10 +8,13 @@ package mapping import ( "bytes" "encoding/json" + "errors" "fmt" "strconv" "strings" "time" + + "github.com/samcharles93/archie-core/internal/domain/eventtype" ) // FieldType is the expected JSON shape of a mapped field, checked at @@ -46,16 +49,20 @@ type Field struct { Required bool `json:"required"` } -// Mapping is a named, reusable set of field bindings, authored by clicking -// through one example captured event but not pinned to that event or its -// source -- t2db.4's matcher decides which events a binding applies to. +// Mapping is a named set of field bindings belonging to one event type and +// checked against its schema (CheckSchema). Any number of bindings may reuse +// it. MatchCount and LastMatchedAt are read-only: the store counts each +// capture the mapping resolved at dispatch. type Mapping struct { - ID string `json:"id"` - Name string `json:"name"` - SourceHint string `json:"source_hint"` - Fields []Field `json:"fields"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` + ID string `json:"id"` + Name string `json:"name"` + SourceHint string `json:"source_hint"` + EventTypeID string `json:"event_type_id"` + Fields []Field `json:"fields"` + MatchCount int64 `json:"match_count"` + LastMatchedAt time.Time `json:"last_matched_at"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } // validTypes is the set of FieldType values Validate accepts. @@ -231,6 +238,46 @@ func walk(node any, path []pathSegment) (value any, found bool) { return cur, true } +// ErrSchema marks a mapping whose field paths or types disagree with its +// event type's inferred schema. +var ErrSchema = errors.New("mapping: field does not fit the event type's schema") + +// CheckSchema refuses fields whose path the event type's schema lacks, or +// whose declared type differs from the schema's. Array indices match the +// schema's "[]" segment, and a path the example held as null accepts any type. +func CheckSchema(fields []Field, schema map[string]eventtype.ValueType) error { + for _, f := range fields { + got, ok := schema[schemaPath(f.Path)] + if !ok { + return fmt.Errorf("%w: %s: path %q is not in the event type", ErrSchema, f.Name, f.Path) + } + if f.Type != TypeAny && got != eventtype.TypeNull && string(got) != string(f.Type) { + return fmt.Errorf("%w: %s: path %q is %s, not %s", ErrSchema, f.Name, f.Path, got, f.Type) + } + } + return nil +} + +// schemaPath rewrites a resolve path ("items[0].id") into the schema's form +// ("items[].id"). A malformed path has no schema form. +func schemaPath(path string) string { + var b strings.Builder + for _, seg := range parsePath(path) { + switch { + case seg.Invalid: + return "" + case seg.Index >= 0: + b.WriteString("[]") + default: + if b.Len() > 0 { + b.WriteByte('.') + } + b.WriteString(seg.Key) + } + } + return b.String() +} + func typeMatches(v any, want FieldType) bool { if want == TypeAny { return true diff --git a/internal/domain/mapping/schema_test.go b/internal/domain/mapping/schema_test.go new file mode 100644 index 000000000..0b1a1b654 --- /dev/null +++ b/internal/domain/mapping/schema_test.go @@ -0,0 +1,51 @@ +package mapping_test + +import ( + "errors" + "testing" + + "github.com/samcharles93/archie-core/internal/domain/eventtype" + "github.com/samcharles93/archie-core/internal/domain/mapping" +) + +func TestCheckSchema(t *testing.T) { + schema := map[string]eventtype.ValueType{ + "action": eventtype.TypeString, + "issue": eventtype.TypeObject, + "issue.number": eventtype.TypeNumber, + "labels": eventtype.TypeArray, + "labels[]": eventtype.TypeObject, + "labels[].name": eventtype.TypeString, + "closed_at": eventtype.TypeNull, + "repository.url": eventtype.TypeString, + } + tests := []struct { + name string + fields []mapping.Field + ok bool + }{ + {"top level path with matching type", []mapping.Field{{Name: "a", Path: "action", Type: mapping.TypeString}}, true}, + {"nested number", []mapping.Field{{Name: "n", Path: "issue.number", Type: mapping.TypeNumber}}, true}, + {"indexed array element maps to the [] path", []mapping.Field{{Name: "l", Path: "labels[0].name", Type: mapping.TypeString}}, true}, + {"any accepts every schema type", []mapping.Field{{Name: "i", Path: "issue", Type: mapping.TypeAny}}, true}, + {"a null example value accepts any declared type", []mapping.Field{{Name: "c", Path: "closed_at", Type: mapping.TypeString}}, true}, + {"path the type does not have", []mapping.Field{{Name: "x", Path: "sender.login", Type: mapping.TypeString}}, false}, + {"type differs from the schema", []mapping.Field{{Name: "n", Path: "issue.number", Type: mapping.TypeString}}, false}, + {"malformed index", []mapping.Field{{Name: "l", Path: "labels[x].name", Type: mapping.TypeString}}, false}, + {"one bad field refuses the mapping", []mapping.Field{ + {Name: "a", Path: "action", Type: mapping.TypeString}, + {Name: "b", Path: "nope", Type: mapping.TypeString}, + }, false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := mapping.CheckSchema(tt.fields, schema) + if tt.ok && err != nil { + t.Fatalf("CheckSchema() = %v, want nil", err) + } + if !tt.ok && !errors.Is(err, mapping.ErrSchema) { + t.Fatalf("CheckSchema() = %v, want ErrSchema", err) + } + }) + } +} diff --git a/internal/domain/storecontract/storecontract.go b/internal/domain/storecontract/storecontract.go index 483e89618..fe7906359 100644 --- a/internal/domain/storecontract/storecontract.go +++ b/internal/domain/storecontract/storecontract.go @@ -178,6 +178,13 @@ type MappingStore interface { DeleteMapping(ctx context.Context, id string) error } +// MappingMatchRecorder counts the events each mapping resolved, which the +// store reports as Mapping.MatchCount and LastMatchedAt. Recording the same +// (mapping, capture) twice counts once. +type MappingMatchRecorder interface { + RecordMappingMatch(ctx context.Context, mappingID, captureID string) error +} + // EventTypeStore persists event types (docs/prds/event-automation.md, "Event // types"). Insert and Update refuse a type whose rule overlaps another on the // same source with eventtype.ErrOverlap, and a malformed one with @@ -219,7 +226,8 @@ type BindingDispatcher interface { bindingVersion int64, captureID string, // taskID addresses the SQLite-owned task tables, which are not - // migrating: it stays an integer on purpose. + // migrating: it stays an integer on purpose. The binding dispatch + // loop claims before it enqueues, so it records 0. taskID int64, ) error ListUndispatchedCaptures(ctx context.Context, sources []string, limit int) ([]CapturedEvent, error) diff --git a/internal/infrastructure/captureintake/receiver.go b/internal/infrastructure/captureintake/receiver.go index cae93b7b5..a3b33ee6c 100644 --- a/internal/infrastructure/captureintake/receiver.go +++ b/internal/infrastructure/captureintake/receiver.go @@ -15,7 +15,6 @@ package captureintake import ( "context" "encoding/json" - "fmt" "io" "log/slog" "net" @@ -92,10 +91,7 @@ func (rc *Receiver) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - armed, ok := rc.armedBindings(w, r, source) - if !ok { - return - } + armed := rc.armedBindings(r, source) r.Body = http.MaxBytesReader(w, r.Body, maxBodyBytesOrFallback(rc.MaxBodyBytes)) body, err := io.ReadAll(r.Body) @@ -106,19 +102,22 @@ func (rc *Receiver) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - // HMAC verification -- only when exactly one binding is armed for this - // source. Mirrors channels/webhook/webhook.go's header precedence: + // HMAC verification against each binding armed for this source: a + // signature valid for any of their secrets authenticates the event. Mirrors channels/webhook/webhook.go's header precedence: // GitHub-style X-Hub-Signature-256 first, X-Signature-256 fallback. // Empty header + non-empty secret is never valid (VerifyHMAC's own // guard), so an absent signature with an armed binding lands here as // authenticated=false rather than authenticated=true. + sig := r.Header.Get("X-Hub-Signature-256") + if sig == "" { + sig = r.Header.Get("X-Signature-256") + } authenticated := false - if len(armed) == 1 { - sig := r.Header.Get("X-Hub-Signature-256") - if sig == "" { - sig = r.Header.Get("X-Signature-256") + for _, b := range armed { + if webhookguard.VerifyHMAC(body, sig, b.Secret) { + authenticated = true + break } - authenticated = webhookguard.VerifyHMAC(body, sig, armed[0].Secret) } headers, _ := json.Marshal(r.Header) @@ -173,30 +172,17 @@ func (rc *Receiver) ServeHTTP(w http.ResponseWriter, r *http.Request) { // read. A lookup error is logged and treated as "no armed binding" -- the // dispatch loop's auth check is the actual gate, so failing closed here would // amplify a transient store hiccup into a capture outage for every -// sender-not-yet-bound flow. If a future phase wants fail-closed semantics, -// that is a separate decision and should not silently land here. -// -// Two armed bindings for one source would race over every inbound webhook for -// that source: the write-time overlap check should make this state -// impossible, but the dispatch loop needs a single binding per capture, so -// the overlap surfaces as 409 at capture time (belt-and-braces TOCTOU guard -// -- see the store's ApproveBinding). -func (rc *Receiver) armedBindings(w http.ResponseWriter, r *http.Request, source string) ([]binding.Binding, bool) { +// sender-not-yet-bound flow. +func (rc *Receiver) armedBindings(r *http.Request, source string) []binding.Binding { if rc.Bindings == nil { - return nil, true + return nil } armed, err := rc.Bindings.ArmedBindingsForSource(r.Context(), source) if err != nil { rc.logger().Warn("armed bindings lookup", "source", source, "err", err) - return nil, true + return nil } - if len(armed) > 1 { - http.Error(w, - fmt.Sprintf("multiple armed bindings for source %q -- overlap rejected", source), - http.StatusConflict) - return nil, false - } - return armed, true + return armed } func (rc *Receiver) logger() *slog.Logger { diff --git a/internal/infrastructure/captureintake/receiver_test.go b/internal/infrastructure/captureintake/receiver_test.go index 7889ff515..6f2385042 100644 --- a/internal/infrastructure/captureintake/receiver_test.go +++ b/internal/infrastructure/captureintake/receiver_test.go @@ -75,13 +75,8 @@ func captureTestServer(t *testing.T) testReceiver { } // stubBindingStore injects a configurable armed-binding lookup result so -// handleCapture tests can exercise the single-binding HMAC path and the -// belt-and-braces 409-on-multiple path without seeding the real store -// (which would either run into the overlap-rejection guard or require -// bypassing the draft -> pending_approval -> armed lifecycle). The 409 -// path exists exactly for the case where the write-time check was -// bypassed somehow, so simulating that case directly is the most honest -// way to cover it. +// handleCapture tests can exercise the HMAC path without seeding the real +// store through the draft -> pending_approval -> armed lifecycle. type stubBindingStore struct { armedBySource map[string][]binding.Binding lookupErr error @@ -529,37 +524,47 @@ func TestHandleCaptureWithNoSignatureMarksUnauthenticated(t *testing.T) { } } -// TestHandleCaptureWithMultipleArmedBindingsReturns409 covers the -// belt-and-braces TOCTOU guard: two armed bindings for the same source -// would race over every inbound webhook for that source, so the -// capture-time handler returns 409 Conflict instead of silently picking -// a winner. The store's overlap check should make this impossible in -// practice; the 409 is the safety net. The stub injects the state -// directly to exercise that safety net. -func TestHandleCaptureWithMultipleArmedBindingsReturns409(t *testing.T) { - srv := captureTestServer(t) - srv.Bindings = &stubBindingStore{ - armedBySource: map[string][]binding.Binding{ - "github": { - {ID: "rbind0000000001", Matcher: binding.Matcher{Source: "github"}, Status: binding.StatusArmed, Secret: "abcdefghijklmnop"}, - {ID: "rbind0000000002", Matcher: binding.Matcher{Source: "github"}, Status: binding.StatusArmed, Secret: "qrstuvwxyz123456"}, - }, - }, +// TestHandleCaptureWithSeveralArmedBindings: several bindings may share a +// source, and an event signed with any one of their secrets is authenticated. +func TestHandleCaptureWithSeveralArmedBindings(t *testing.T) { + tests := []struct { + name string + secret string + want bool + }{ + {"first binding's secret", "abcdefghijklmnop", true}, + {"second binding's secret", "qrstuvwxyz123456", true}, + {"no binding's secret", "not-the-real-secret-aaaaaaaaa", false}, } - req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/webhooks/capture/github", strings.NewReader(`{}`)) - w := httptest.NewRecorder() + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + srv := captureTestServer(t) + srv.Bindings = &stubBindingStore{ + armedBySource: map[string][]binding.Binding{ + "github": { + {ID: "rbind0000000001", Matcher: binding.Matcher{Source: "github"}, Status: binding.StatusArmed, Secret: "abcdefghijklmnop"}, + {ID: "rbind0000000002", Matcher: binding.Matcher{Source: "github"}, Status: binding.StatusArmed, Secret: "qrstuvwxyz123456"}, + }, + }, + } + body := `{}` + req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/webhooks/capture/github", strings.NewReader(body)) + req.Header.Set("X-Hub-Signature-256", hmacSHA256(tt.secret, body)) + w := httptest.NewRecorder() - srv.Handler().ServeHTTP(w, req) + srv.Handler().ServeHTTP(w, req) - if w.Code != http.StatusConflict { - t.Fatalf("status = %d, want %d (multiple armed bindings must surface as 409 at capture time)", w.Code, http.StatusConflict) - } - got, err := srv.store.ListCaptures(t.Context(), 10) - if err != nil { - t.Fatalf("ListCaptures: %v", err) - } - if len(got) != 0 { - t.Fatalf("captured rows = %d, want 0 (a 409 must never persist a row)", len(got)) + if w.Code != http.StatusAccepted { + t.Fatalf("status = %d, want %d", w.Code, http.StatusAccepted) + } + got, err := srv.store.ListCaptures(t.Context(), 10) + if err != nil { + t.Fatalf("ListCaptures: %v", err) + } + if len(got) != 1 || got[0].Authenticated != tt.want { + t.Fatalf("captured = %+v, want 1 row with Authenticated=%v", got, tt.want) + } + }) } } diff --git a/internal/infrastructure/legacyimport/load.go b/internal/infrastructure/legacyimport/load.go index 127e367ac..92c6664b5 100644 --- a/internal/infrastructure/legacyimport/load.go +++ b/internal/infrastructure/legacyimport/load.go @@ -25,9 +25,13 @@ var droppedColumns = map[string]bool{ // newColumns are target columns added after the legacy stores, with no // legacy value to carry. Imported rows take the column default: an imported -// capture has no event type, so it stays unidentified and never dispatches. +// capture has no event type, so it stays unidentified and never dispatches; +// an imported mapping has no event type, so no binding using it dispatches +// until it is given one; an imported binding has no filter. var newColumns = map[string]bool{ "captures.event_type": true, + "mappings.event_type": true, + "bindings.filter": true, } // targetKeys override a table's legacy key where the target has no column diff --git a/internal/infrastructure/postgres/edastore.go b/internal/infrastructure/postgres/edastore.go index 75aac0422..95847b0dd 100644 --- a/internal/infrastructure/postgres/edastore.go +++ b/internal/infrastructure/postgres/edastore.go @@ -29,11 +29,12 @@ import ( // satisfies the same surface as *edastore.Store, so the cutover wave can swap // one for the other behind storecontract without touching the consumers. var ( - _ storecontract.CaptureStore = (*EDA)(nil) - _ storecontract.MappingStore = (*EDA)(nil) - _ storecontract.BindingStore = (*EDA)(nil) - _ storecontract.BindingDispatcher = (*EDA)(nil) - _ storecontract.PlaybookDispatcher = (*EDA)(nil) + _ storecontract.CaptureStore = (*EDA)(nil) + _ storecontract.MappingStore = (*EDA)(nil) + _ storecontract.BindingStore = (*EDA)(nil) + _ storecontract.BindingDispatcher = (*EDA)(nil) + _ storecontract.MappingMatchRecorder = (*EDA)(nil) + _ storecontract.PlaybookDispatcher = (*EDA)(nil) ) // EDA is the PostgreSQL-backed EDA persistence. @@ -151,8 +152,8 @@ func (s *EDA) ListCaptures(ctx context.Context, limit int) ([]storecontract.Capt } // ListUndispatchedCaptures returns recent identified captures for the given -// sources that no binding has dispatched yet. An unidentified capture is -// never returned, so it never dispatches. +// sources that some armed binding for their event type has not dispatched yet. +// An unidentified capture is never returned, so it never dispatches. func (s *EDA) ListUndispatchedCaptures(ctx context.Context, sources []string, limit int) ([]storecontract.CapturedEvent, error) { if len(sources) == 0 || limit <= 0 { return nil, nil @@ -181,20 +182,27 @@ func marshalMappingFields(fields []mapping.Field) (string, error) { return string(encoded), nil } -func mappingValue(r postgresdb.Mapping) (mapping.Mapping, error) { +func mappingValue(r postgresdb.Mapping, matches int64, lastMatched time.Time) (mapping.Mapping, error) { var fields []mapping.Field if raw := r.Fields; raw != "" { if err := json.Unmarshal([]byte(raw), &fields); err != nil { return mapping.Mapping{}, fmt.Errorf("edastore: decode mapping fields: %w", err) } } + // The query reports the epoch for a mapping that never matched. + if matches == 0 { + lastMatched = time.Time{} + } return mapping.Mapping{ - ID: r.ID, - Name: r.Name, - SourceHint: r.SourceHint, - Fields: fields, - CreatedAt: r.CreatedAt, - UpdatedAt: r.UpdatedAt, + ID: r.ID, + Name: r.Name, + SourceHint: r.SourceHint, + EventTypeID: r.EventType, + Fields: fields, + MatchCount: matches, + LastMatchedAt: lastMatched, + CreatedAt: r.CreatedAt, + UpdatedAt: r.UpdatedAt, }, nil } @@ -208,6 +216,7 @@ func (s *EDA) InsertMapping(ctx context.Context, m mapping.Mapping) (string, err ID: id, Name: m.Name, SourceHint: m.SourceHint, + EventType: m.EventTypeID, Fields: encoded, }); err != nil { return "", fmt.Errorf("edastore: insert mapping: %w", err) @@ -226,7 +235,7 @@ func (s *EDA) GetMapping(ctx context.Context, id string) (*mapping.Mapping, erro if err != nil { return nil, err } - m, err := mappingValue(r) + m, err := mappingValue(r.Mapping, r.MatchCount, r.LastMatchedAt) if err != nil { return nil, err } @@ -240,7 +249,7 @@ func (s *EDA) ListMappings(ctx context.Context) ([]mapping.Mapping, error) { } out := make([]mapping.Mapping, 0, len(rows)) for _, r := range rows { - m, err := mappingValue(r) + m, err := mappingValue(r.Mapping, r.MatchCount, r.LastMatchedAt) if err != nil { return nil, err } @@ -258,6 +267,7 @@ func (s *EDA) UpdateMapping(ctx context.Context, m mapping.Mapping) error { ID: m.ID, Name: m.Name, SourceHint: m.SourceHint, + EventType: m.EventTypeID, Fields: encoded, }) if err != nil { @@ -282,6 +292,16 @@ func (s *EDA) DeleteMapping(ctx context.Context, id string) error { return nil } +// RecordMappingMatch counts one event a mapping resolved. Recording the same +// (mapping, capture) again is a no-op, so the count rises once per event no +// matter how many bindings share the mapping. +func (s *EDA) RecordMappingMatch(ctx context.Context, mappingID, captureID string) error { + if err := s.q.InsertMappingMatch(ctx, postgresdb.InsertMappingMatchParams{Mapping: mappingID, Capture: captureID}); err != nil { + return fmt.Errorf("edastore: record mapping match: %w", err) + } + return nil +} + // --- bindings --- func (s *EDA) encryptSecret(secret string) (string, error) { @@ -301,6 +321,7 @@ func (s *EDA) bindingValue(r postgresdb.Binding) (binding.Binding, error) { Name: r.Name, Matcher: binding.Matcher{Source: r.Source}, MappingID: r.Mapping, + Filter: r.Filter, Workflow: r.Workflow, Owner: r.Owner, Repo: r.Repo, @@ -320,10 +341,8 @@ func (s *EDA) bindingValue(r postgresdb.Binding) (binding.Binding, error) { return b, nil } -// InsertBinding stores a new binding as pending_approval. "One binding per -// source" is a schema constraint (idx_bindings_source), so a concurrent -// second insert for the same source is refused by the database and surfaced -// here as ErrBindingOverlap. +// InsertBinding stores a new binding as pending_approval. Any number of +// bindings may share a source. func (s *EDA) InsertBinding(ctx context.Context, b binding.Binding) (string, error) { secret := b.Secret if secret != "" { @@ -339,15 +358,13 @@ func (s *EDA) InsertBinding(ctx context.Context, b binding.Binding) (string, err Name: b.Name, Source: b.Matcher.Source, Mapping: b.MappingID, + Filter: b.Filter, Workflow: b.Workflow, Owner: b.Owner, Repo: b.Repo, Status: string(binding.StatusPendingApproval), Secret: secret, }) - if isUniqueViolation(err) { - return "", storecontract.ErrBindingOverlap - } if err != nil { return "", fmt.Errorf("edastore: insert binding: %w", err) } @@ -423,15 +440,13 @@ func (s *EDA) UpdateBinding(ctx context.Context, b binding.Binding) error { Name: b.Name, Source: b.Matcher.Source, Mapping: b.MappingID, + Filter: b.Filter, Workflow: b.Workflow, Owner: b.Owner, Repo: b.Repo, Status: string(binding.StatusPendingApproval), Secret: secret, }) - if isUniqueViolation(err) { - return storecontract.ErrBindingOverlap - } if err != nil { return err } @@ -454,10 +469,7 @@ func (s *EDA) DeleteBinding(ctx context.Context, id string) error { return nil } -// ApproveBinding is the only transition that arms a binding. "One armed -// binding per source" is a partial unique constraint (idx_bindings_armed_source), -// so a concurrent approval of a sibling binding on the same source is refused -// by the database and surfaced here as ErrBindingOverlap. +// ApproveBinding is the only transition that arms a binding. func (s *EDA) ApproveBinding(ctx context.Context, id string) error { r, err := s.q.GetBinding(ctx, id) if errors.Is(err, pgx.ErrNoRows) { @@ -470,9 +482,6 @@ func (s *EDA) ApproveBinding(ctx context.Context, id string) error { return storecontract.ErrBindingTransition } n, err := s.q.SetBindingArmed(ctx, id) - if isUniqueViolation(err) { - return storecontract.ErrBindingOverlap - } if err != nil { return err } diff --git a/internal/infrastructure/postgres/edastore_binding_test.go b/internal/infrastructure/postgres/edastore_binding_test.go new file mode 100644 index 000000000..6b668fc6b --- /dev/null +++ b/internal/infrastructure/postgres/edastore_binding_test.go @@ -0,0 +1,166 @@ +package postgres + +import ( + "testing" + "time" + + "github.com/samcharles93/archie-core/internal/domain/binding" + "github.com/samcharles93/archie-core/internal/domain/eventtype" + "github.com/samcharles93/archie-core/internal/domain/mapping" + "github.com/samcharles93/archie-core/internal/domain/storecontract" +) + +// eventTypeFixture saves a type on source matching events whose "kind" equals kind. +func eventTypeFixture(t *testing.T, s *EDA, source, kind string) string { + t.Helper() + id, err := s.InsertEventType(t.Context(), eventtype.EventType{ + Source: source, Name: kind, + Rule: eventtype.Rule{Payload: []eventtype.PayloadCondition{{Path: "kind", Op: eventtype.OpEquals, Value: kind}}}, + }) + if err != nil { + t.Fatalf("InsertEventType() error = %v", err) + } + return id +} + +func armedBinding(t *testing.T, s *EDA, source, mappingID string) string { + t.Helper() + id, err := s.InsertBinding(t.Context(), binding.Binding{ + Name: "n", Matcher: binding.Matcher{Source: source}, MappingID: mappingID, Workflow: "implement", + }) + if err != nil { + t.Fatalf("InsertBinding() error = %v", err) + } + if err := s.ApproveBinding(t.Context(), id); err != nil { + t.Fatalf("ApproveBinding() error = %v", err) + } + return id +} + +func captureOf(t *testing.T, s *EDA, source, body string) string { + t.Helper() + id, err := s.InsertCapture(t.Context(), storecontract.CapturedEvent{Source: source, Body: body}, 0, 0) + if err != nil { + t.Fatalf("InsertCapture() error = %v", err) + } + return id +} + +func undispatchedIDs(t *testing.T, s *EDA, source string) map[string]bool { + t.Helper() + list, err := s.ListUndispatchedCaptures(t.Context(), []string{source}, 10) + if err != nil { + t.Fatalf("ListUndispatchedCaptures() error = %v", err) + } + out := map[string]bool{} + for _, c := range list { + out[c.ID] = true + } + return out +} + +func TestSeveralArmedBindingsShareASource(t *testing.T) { + s := edaFor(t) + a := armedBinding(t, s, "github", "") + b := armedBinding(t, s, "github", "") + armed, err := s.ArmedBindingsForSource(t.Context(), "github") + if err != nil { + t.Fatalf("ArmedBindingsForSource() error = %v", err) + } + got := map[string]bool{} + for _, x := range armed { + got[x.ID] = true + } + if !got[a] || !got[b] || len(armed) != 2 { + t.Fatalf("armed = %v, want both %s and %s", got, a, b) + } +} + +func TestMappingAndBindingRoundTripEventTypeAndFilter(t *testing.T) { + s := edaFor(t) + typeID := eventTypeFixture(t, s, "github", "push") + mid, err := s.InsertMapping(t.Context(), mapping.Mapping{Name: "m", EventTypeID: typeID}) + if err != nil { + t.Fatalf("InsertMapping() error = %v", err) + } + m, err := s.GetMapping(t.Context(), mid) + if err != nil || m.EventTypeID != typeID { + t.Fatalf("GetMapping() event type = %q (err %v), want %q", m.EventTypeID, err, typeID) + } + bid, err := s.InsertBinding(t.Context(), binding.Binding{ + Name: "n", Matcher: binding.Matcher{Source: "github"}, MappingID: mid, Workflow: "implement", + Filter: `kind == "push"`, + }) + if err != nil { + t.Fatalf("InsertBinding() error = %v", err) + } + b, err := s.GetBinding(t.Context(), bid) + if err != nil || b.Filter != `kind == "push"` { + t.Fatalf("GetBinding() filter = %q (err %v)", b.Filter, err) + } + b.Filter = "" + if err := s.UpdateBinding(t.Context(), *b); err != nil { + t.Fatalf("UpdateBinding() error = %v", err) + } + if b, _ = s.GetBinding(t.Context(), bid); b.Filter != "" { + t.Fatalf("filter after clearing = %q, want empty", b.Filter) + } +} + +func TestMappingMatchCountRisesOncePerEvent(t *testing.T) { + s := edaFor(t) + mid, err := s.InsertMapping(t.Context(), mapping.Mapping{Name: "m"}) + if err != nil { + t.Fatalf("InsertMapping() error = %v", err) + } + before := time.Now().Add(-time.Minute) + for _, capture := range []string{"c1", "c2", "c1"} { + if err := s.RecordMappingMatch(t.Context(), mid, capture); err != nil { + t.Fatalf("RecordMappingMatch(%s) error = %v", capture, err) + } + } + list, err := s.ListMappings(t.Context()) + if err != nil || len(list) != 1 { + t.Fatalf("ListMappings() = %d (err %v)", len(list), err) + } + if list[0].MatchCount != 2 { + t.Errorf("MatchCount = %d, want 2 (one per distinct event)", list[0].MatchCount) + } + if !list[0].LastMatchedAt.After(before) { + t.Errorf("LastMatchedAt = %v, want a recent time", list[0].LastMatchedAt) + } + got, _ := s.GetMapping(t.Context(), mid) + if got.MatchCount != 2 { + t.Errorf("GetMapping MatchCount = %d, want 2", got.MatchCount) + } +} + +// A capture stays undispatched until every armed binding for its event type +// has dispatched it; a binding for another event type does not hold it. +func TestUndispatchedIsPerBinding(t *testing.T) { + s := edaFor(t) + push := eventTypeFixture(t, s, "github", "push") + issue := eventTypeFixture(t, s, "github", "issue") + pushMap, _ := s.InsertMapping(t.Context(), mapping.Mapping{Name: "p", EventTypeID: push}) + issueMap, _ := s.InsertMapping(t.Context(), mapping.Mapping{Name: "i", EventTypeID: issue}) + a := armedBinding(t, s, "github", pushMap) + b := armedBinding(t, s, "github", pushMap) + c := armedBinding(t, s, "github", issueMap) + + capture := captureOf(t, s, "github", `{"kind":"push"}`) + if !undispatchedIDs(t, s, "github")[capture] { + t.Fatal("new push capture not listed") + } + if err := s.RecordDispatch(t.Context(), a, 1, capture, 1); err != nil { + t.Fatalf("RecordDispatch(a) error = %v", err) + } + if !undispatchedIDs(t, s, "github")[capture] { + t.Fatal("capture dropped after one of two push bindings dispatched it") + } + if err := s.RecordDispatch(t.Context(), b, 1, capture, 2); err != nil { + t.Fatalf("RecordDispatch(b) error = %v", err) + } + if undispatchedIDs(t, s, "github")[capture] { + t.Fatalf("capture still listed after both push bindings dispatched it (issue binding %s must not hold it)", c) + } +} diff --git a/internal/infrastructure/postgres/edastore_eventtype_test.go b/internal/infrastructure/postgres/edastore_eventtype_test.go index 2546ee821..80b85d7a2 100644 --- a/internal/infrastructure/postgres/edastore_eventtype_test.go +++ b/internal/infrastructure/postgres/edastore_eventtype_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/samcharles93/archie-core/internal/domain/eventtype" + "github.com/samcharles93/archie-core/internal/domain/mapping" "github.com/samcharles93/archie-core/internal/domain/storecontract" ) @@ -142,6 +143,11 @@ func TestPastedTypeIdentifiesLaterCaptures(t *testing.T) { t.Errorf("unmatched capture event type = %q, want unidentified", byBody[`{"ref":"main"}`]) } + mid, err := s.InsertMapping(t.Context(), mapping.Mapping{Name: "m", EventTypeID: id}) + if err != nil { + t.Fatalf("InsertMapping() error = %v", err) + } + armedBinding(t, s, "gh", mid) undispatched, err := s.ListUndispatchedCaptures(t.Context(), []string{"gh"}, 10) if err != nil { t.Fatalf("ListUndispatchedCaptures() error = %v", err) diff --git a/internal/infrastructure/postgres/edastore_test.go b/internal/infrastructure/postgres/edastore_test.go index c8baf1c76..21722cc6a 100644 --- a/internal/infrastructure/postgres/edastore_test.go +++ b/internal/infrastructure/postgres/edastore_test.go @@ -9,7 +9,6 @@ import ( "github.com/jackc/pgx/v5/pgxpool" "github.com/samcharles93/archie-core/internal/domain/binding" - "github.com/samcharles93/archie-core/internal/domain/eventtype" "github.com/samcharles93/archie-core/internal/domain/mapping" "github.com/samcharles93/archie-core/internal/domain/storecontract" "github.com/samcharles93/archie-core/internal/events" @@ -92,42 +91,6 @@ func TestPlaybookDispatchIsIdempotent(t *testing.T) { } } -// Hazard 3: "one binding per source" is a schema constraint, so concurrent -// inserts for one source produce exactly one success and one ErrBindingOverlap -// rather than two bindings that a single SQLite writer would have serialised. -func TestConcurrentInsertBindingSameSource(t *testing.T) { - s := edaFor(t) - type result struct{ err error } - start := make(chan struct{}) - results := make(chan result, 2) - for range 2 { - go func() { - <-start - _, err := s.InsertBinding(t.Context(), binding.Binding{ - Name: "n", Matcher: binding.Matcher{Source: "sentry"}, Workflow: "implement", - }) - results <- result{err: err} - }() - } - close(start) - - var succeeded, overlapped int - for range 2 { - outcome := <-results - switch { - case outcome.err == nil: - succeeded++ - case errors.Is(outcome.err, storecontract.ErrBindingOverlap): - overlapped++ - default: - t.Fatalf("concurrent InsertBinding error = %v", outcome.err) - } - } - if succeeded != 1 || overlapped != 1 { - t.Fatalf("concurrent inserts = %d succeeded, %d overlapped; want 1 each", succeeded, overlapped) - } -} - // Hazard 1: UpdateBinding with an empty secret must leave the stored envelope // untouched, so an edit form that does not echo the secret cannot blank an // armed binding's HMAC key. @@ -219,13 +182,9 @@ func TestBindingLifecycle(t *testing.T) { } } -// A capture round-trips its payload verbatim, and a dispatched capture drops -// out of the undispatched listing. -func TestCaptureRoundTripAndUndispatched(t *testing.T) { +// A capture round-trips its payload verbatim. +func TestCaptureRoundTrip(t *testing.T) { s := edaFor(t) - if _, err := s.InsertEventType(t.Context(), eventtype.EventType{Source: "sentry", Name: "any"}); err != nil { - t.Fatalf("InsertEventType() error = %v", err) - } body := `{"action":"created"}` if _, err := s.InsertCapture(t.Context(), storecontract.CapturedEvent{ Source: "sentry", Body: body, Headers: `{"X-Hook":"1"}`, ContentType: "application/json", @@ -239,19 +198,6 @@ func TestCaptureRoundTripAndUndispatched(t *testing.T) { if list[0].Body != body { t.Errorf("Body round-trip = %q, want %q", list[0].Body, body) } - - undispatched, err := s.ListUndispatchedCaptures(t.Context(), []string{"sentry"}, 10) - if err != nil || len(undispatched) != 1 { - t.Fatalf("ListUndispatchedCaptures() = %d (err %v), want 1", len(undispatched), err) - } - // Dispatch it; the capture must no longer be undispatched. - if err := s.RecordDispatch(t.Context(), "b1", 1, list[0].ID, 42); err != nil { - t.Fatalf("RecordDispatch() error = %v", err) - } - undispatched, err = s.ListUndispatchedCaptures(t.Context(), []string{"sentry"}, 10) - if err != nil || len(undispatched) != 0 { - t.Fatalf("ListUndispatchedCaptures() after dispatch = %d (err %v), want 0", len(undispatched), err) - } } func TestMappingCRUD(t *testing.T) { diff --git a/internal/infrastructure/postgres/migrations/0008_mappings_per_event_type.sql b/internal/infrastructure/postgres/migrations/0008_mappings_per_event_type.sql new file mode 100644 index 000000000..94c5f27db --- /dev/null +++ b/internal/infrastructure/postgres/migrations/0008_mappings_per_event_type.sql @@ -0,0 +1,34 @@ +-- Mappings per event type, match counts and several bindings per source +-- (docs/prds/event-automation.md, "Mappings" and "Bindings"). +-- +-- mappings.event_type is the event type a mapping belongs to; like +-- captures.event_type it is plain text, not a foreign key. A binding applies +-- to its mapping's event type, so any number of bindings may share a source +-- and the two per-source unique indexes are dropped. +-- +-- mapping_matches holds one row per (mapping, capture) the mapping resolved; +-- a mapping's matched-event count and last match are read from it. +-- bindings.filter is an optional CEL expression over the mapping's parameters. + +-- +goose Up + +ALTER TABLE mappings ADD COLUMN event_type text NOT NULL DEFAULT ''; +ALTER TABLE bindings ADD COLUMN filter text NOT NULL DEFAULT ''; + +DROP INDEX idx_bindings_source; +DROP INDEX idx_bindings_armed_source; + +CREATE TABLE mapping_matches ( + mapping text NOT NULL, + capture text NOT NULL, + matched_at timestamptz NOT NULL DEFAULT now(), + PRIMARY KEY (mapping, capture) +); + +-- +goose Down + +DROP TABLE mapping_matches; +CREATE UNIQUE INDEX idx_bindings_armed_source ON bindings (source) WHERE status = 'armed'; +CREATE UNIQUE INDEX idx_bindings_source ON bindings (source); +ALTER TABLE bindings DROP COLUMN filter; +ALTER TABLE mappings DROP COLUMN event_type; diff --git a/internal/infrastructure/postgres/postgresdb/edastore.sql.go b/internal/infrastructure/postgres/postgresdb/edastore.sql.go index ab6fb99f7..d50c94019 100644 --- a/internal/infrastructure/postgres/postgresdb/edastore.sql.go +++ b/internal/infrastructure/postgres/postgresdb/edastore.sql.go @@ -11,7 +11,7 @@ import ( ) const armedBindingsForSource = `-- name: ArmedBindingsForSource :many -SELECT id, name, source, mapping, workflow, owner, repo, version, status, secret, created_at, updated_at +SELECT id, name, source, mapping, workflow, owner, repo, version, status, secret, created_at, updated_at, filter FROM bindings WHERE source = $1 AND status = 'armed' ORDER BY created_at DESC ` @@ -37,6 +37,7 @@ func (q *Queries) ArmedBindingsForSource(ctx context.Context, source string) ([] &i.Secret, &i.CreatedAt, &i.UpdatedAt, + &i.Filter, ); err != nil { return nil, err } @@ -147,7 +148,7 @@ func (q *Queries) EventTypesForSource(ctx context.Context, source string) ([]Eve } const getBinding = `-- name: GetBinding :one -SELECT id, name, source, mapping, workflow, owner, repo, version, status, secret, created_at, updated_at +SELECT id, name, source, mapping, workflow, owner, repo, version, status, secret, created_at, updated_at, filter FROM bindings WHERE id = $1 ` @@ -167,6 +168,7 @@ func (q *Queries) GetBinding(ctx context.Context, id string) (Binding, error) { &i.Secret, &i.CreatedAt, &i.UpdatedAt, + &i.Filter, ) return i, err } @@ -192,27 +194,38 @@ func (q *Queries) GetEventType(ctx context.Context, id string) (EventType, error } const getMapping = `-- name: GetMapping :one -SELECT id, name, source_hint, fields, created_at, updated_at +SELECT mappings.id, mappings.name, mappings.source_hint, mappings.fields, mappings.created_at, mappings.updated_at, mappings.event_type, + (SELECT count(*) FROM mapping_matches mm WHERE mm.mapping = mappings.id)::bigint AS match_count, + COALESCE((SELECT max(mm.matched_at) FROM mapping_matches mm WHERE mm.mapping = mappings.id), 'epoch')::timestamptz AS last_matched_at FROM mappings WHERE id = $1 ` -func (q *Queries) GetMapping(ctx context.Context, id string) (Mapping, error) { +type GetMappingRow struct { + Mapping Mapping + MatchCount int64 + LastMatchedAt time.Time +} + +func (q *Queries) GetMapping(ctx context.Context, id string) (GetMappingRow, error) { row := q.db.QueryRow(ctx, getMapping, id) - var i Mapping + var i GetMappingRow err := row.Scan( - &i.ID, - &i.Name, - &i.SourceHint, - &i.Fields, - &i.CreatedAt, - &i.UpdatedAt, + &i.Mapping.ID, + &i.Mapping.Name, + &i.Mapping.SourceHint, + &i.Mapping.Fields, + &i.Mapping.CreatedAt, + &i.Mapping.UpdatedAt, + &i.Mapping.EventType, + &i.MatchCount, + &i.LastMatchedAt, ) return i, err } const insertBinding = `-- name: InsertBinding :exec -INSERT INTO bindings (id, name, source, mapping, workflow, owner, repo, version, status, secret) -VALUES ($1, $2, $3, $4, $5, $6, $7, 1, $8, $9) +INSERT INTO bindings (id, name, source, mapping, filter, workflow, owner, repo, version, status, secret) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, 1, $9, $10) ` type InsertBindingParams struct { @@ -220,6 +233,7 @@ type InsertBindingParams struct { Name string Source string Mapping string + Filter string Workflow string Owner string Repo string @@ -233,6 +247,7 @@ func (q *Queries) InsertBinding(ctx context.Context, arg InsertBindingParams) er arg.Name, arg.Source, arg.Mapping, + arg.Filter, arg.Workflow, arg.Owner, arg.Repo, @@ -323,14 +338,15 @@ func (q *Queries) InsertEventType(ctx context.Context, arg InsertEventTypeParams } const insertMapping = `-- name: InsertMapping :exec -INSERT INTO mappings (id, name, source_hint, fields) -VALUES ($1, $2, $3, $4) +INSERT INTO mappings (id, name, source_hint, event_type, fields) +VALUES ($1, $2, $3, $4, $5) ` type InsertMappingParams struct { ID string Name string SourceHint string + EventType string Fields string } @@ -339,11 +355,27 @@ func (q *Queries) InsertMapping(ctx context.Context, arg InsertMappingParams) er arg.ID, arg.Name, arg.SourceHint, + arg.EventType, arg.Fields, ) return err } +const insertMappingMatch = `-- name: InsertMappingMatch :exec +INSERT INTO mapping_matches (mapping, capture) VALUES ($1, $2) +ON CONFLICT DO NOTHING +` + +type InsertMappingMatchParams struct { + Mapping string + Capture string +} + +func (q *Queries) InsertMappingMatch(ctx context.Context, arg InsertMappingMatchParams) error { + _, err := q.db.Exec(ctx, insertMappingMatch, arg.Mapping, arg.Capture) + return err +} + const insertPlaybookDispatch = `-- name: InsertPlaybookDispatch :exec INSERT INTO playbook_dispatches (playbook_id, playbook_version, event_id, action_id) VALUES ($1, $2, $3, $4) @@ -395,7 +427,7 @@ func (q *Queries) InsertToolCall(ctx context.Context, arg InsertToolCallParams) } const listBindings = `-- name: ListBindings :many -SELECT id, name, source, mapping, workflow, owner, repo, version, status, secret, created_at, updated_at +SELECT id, name, source, mapping, workflow, owner, repo, version, status, secret, created_at, updated_at, filter FROM bindings ORDER BY created_at DESC ` @@ -421,6 +453,7 @@ func (q *Queries) ListBindings(ctx context.Context) ([]Binding, error) { &i.Secret, &i.CreatedAt, &i.UpdatedAt, + &i.Filter, ); err != nil { return nil, err } @@ -503,26 +536,37 @@ func (q *Queries) ListEventTypes(ctx context.Context) ([]EventType, error) { } const listMappings = `-- name: ListMappings :many -SELECT id, name, source_hint, fields, created_at, updated_at +SELECT mappings.id, mappings.name, mappings.source_hint, mappings.fields, mappings.created_at, mappings.updated_at, mappings.event_type, + (SELECT count(*) FROM mapping_matches mm WHERE mm.mapping = mappings.id)::bigint AS match_count, + COALESCE((SELECT max(mm.matched_at) FROM mapping_matches mm WHERE mm.mapping = mappings.id), 'epoch')::timestamptz AS last_matched_at FROM mappings ORDER BY created_at DESC ` -func (q *Queries) ListMappings(ctx context.Context) ([]Mapping, error) { +type ListMappingsRow struct { + Mapping Mapping + MatchCount int64 + LastMatchedAt time.Time +} + +func (q *Queries) ListMappings(ctx context.Context) ([]ListMappingsRow, error) { rows, err := q.db.Query(ctx, listMappings) if err != nil { return nil, err } defer rows.Close() - var items []Mapping + var items []ListMappingsRow for rows.Next() { - var i Mapping + var i ListMappingsRow if err := rows.Scan( - &i.ID, - &i.Name, - &i.SourceHint, - &i.Fields, - &i.CreatedAt, - &i.UpdatedAt, + &i.Mapping.ID, + &i.Mapping.Name, + &i.Mapping.SourceHint, + &i.Mapping.Fields, + &i.Mapping.CreatedAt, + &i.Mapping.UpdatedAt, + &i.Mapping.EventType, + &i.MatchCount, + &i.LastMatchedAt, ); err != nil { return nil, err } @@ -535,13 +579,16 @@ func (q *Queries) ListMappings(ctx context.Context) ([]Mapping, error) { } const listUndispatchedCaptures = `-- name: ListUndispatchedCaptures :many -SELECT id, source, remote_addr, content_type, headers, body, authenticated, received_at, event_type -FROM captures -WHERE source = ANY($1::text[]) - -- An unidentified capture is never dispatched. - AND event_type <> '' - AND id NOT IN (SELECT capture FROM binding_dispatches) -ORDER BY received_at DESC +SELECT c.id, c.source, c.remote_addr, c.content_type, c.headers, c.body, c.authenticated, c.received_at, c.event_type +FROM captures c +WHERE c.source = ANY($1::text[]) + AND c.event_type <> '' + AND EXISTS ( + SELECT 1 FROM bindings b JOIN mappings m ON m.id = b.mapping + WHERE b.source = c.source AND b.status = 'armed' AND m.event_type = c.event_type + AND NOT EXISTS (SELECT 1 FROM binding_dispatches d WHERE d.binding = b.id AND d.capture = c.id) + ) +ORDER BY c.received_at DESC LIMIT $2 ` @@ -550,6 +597,9 @@ type ListUndispatchedCapturesParams struct { EntryLimit int32 } +// A capture is undispatched while some armed binding on its source, whose +// mapping belongs to the capture's event type, has not dispatched it. An +// unidentified capture has no event type, so it is never listed. func (q *Queries) ListUndispatchedCaptures(ctx context.Context, arg ListUndispatchedCapturesParams) ([]Capture, error) { rows, err := q.db.Query(ctx, listUndispatchedCaptures, arg.Sources, arg.EntryLimit) if err != nil { @@ -648,9 +698,9 @@ func (q *Queries) TaskToolCalls(ctx context.Context, taskID int64) ([]TaskToolCa const updateBinding = `-- name: UpdateBinding :execrows UPDATE bindings -SET name = $2, source = $3, mapping = $4, workflow = $5, owner = $6, repo = $7, - version = version + 1, status = $8, - secret = CASE WHEN $9::text = '' THEN secret ELSE $9 END, +SET name = $2, source = $3, mapping = $4, filter = $5, workflow = $6, owner = $7, repo = $8, + version = version + 1, status = $9, + secret = CASE WHEN $10::text = '' THEN secret ELSE $10 END, updated_at = now() WHERE id = $1 ` @@ -660,6 +710,7 @@ type UpdateBindingParams struct { Name string Source string Mapping string + Filter string Workflow string Owner string Repo string @@ -676,6 +727,7 @@ func (q *Queries) UpdateBinding(ctx context.Context, arg UpdateBindingParams) (i arg.Name, arg.Source, arg.Mapping, + arg.Filter, arg.Workflow, arg.Owner, arg.Repo, @@ -708,7 +760,7 @@ func (q *Queries) UpdateEventType(ctx context.Context, arg UpdateEventTypeParams const updateMapping = `-- name: UpdateMapping :execrows UPDATE mappings -SET name = $2, source_hint = $3, fields = $4, updated_at = now() +SET name = $2, source_hint = $3, event_type = $4, fields = $5, updated_at = now() WHERE id = $1 ` @@ -716,6 +768,7 @@ type UpdateMappingParams struct { ID string Name string SourceHint string + EventType string Fields string } @@ -724,6 +777,7 @@ func (q *Queries) UpdateMapping(ctx context.Context, arg UpdateMappingParams) (i arg.ID, arg.Name, arg.SourceHint, + arg.EventType, arg.Fields, ) if err != nil { diff --git a/internal/infrastructure/postgres/postgresdb/models.go b/internal/infrastructure/postgres/postgresdb/models.go index b454bb2ae..f7796d3b0 100644 --- a/internal/infrastructure/postgres/postgresdb/models.go +++ b/internal/infrastructure/postgres/postgresdb/models.go @@ -29,6 +29,7 @@ type Binding struct { Secret string CreatedAt time.Time UpdatedAt time.Time + Filter string } type BindingDispatch struct { @@ -144,6 +145,13 @@ type Mapping struct { Fields string CreatedAt time.Time UpdatedAt time.Time + EventType string +} + +type MappingMatch struct { + Mapping string + Capture string + MatchedAt time.Time } type Message struct { diff --git a/internal/infrastructure/postgres/queries/edastore.sql b/internal/infrastructure/postgres/queries/edastore.sql index 1aacfbad5..051f0f5c8 100644 --- a/internal/infrastructure/postgres/queries/edastore.sql +++ b/internal/infrastructure/postgres/queries/edastore.sql @@ -11,13 +11,19 @@ ORDER BY received_at DESC LIMIT $1; -- name: ListUndispatchedCaptures :many -SELECT id, source, remote_addr, content_type, headers, body, authenticated, received_at, event_type -FROM captures -WHERE source = ANY(@sources::text[]) - -- An unidentified capture is never dispatched. - AND event_type <> '' - AND id NOT IN (SELECT capture FROM binding_dispatches) -ORDER BY received_at DESC +-- A capture is undispatched while some armed binding on its source, whose +-- mapping belongs to the capture's event type, has not dispatched it. An +-- unidentified capture has no event type, so it is never listed. +SELECT c.id, c.source, c.remote_addr, c.content_type, c.headers, c.body, c.authenticated, c.received_at, c.event_type +FROM captures c +WHERE c.source = ANY(@sources::text[]) + AND c.event_type <> '' + AND EXISTS ( + SELECT 1 FROM bindings b JOIN mappings m ON m.id = b.mapping + WHERE b.source = c.source AND b.status = 'armed' AND m.event_type = c.event_type + AND NOT EXISTS (SELECT 1 FROM binding_dispatches d WHERE d.binding = b.id AND d.capture = c.id) + ) +ORDER BY c.received_at DESC LIMIT @entry_limit; -- name: DeleteCapturesOlderThan :exec @@ -29,39 +35,47 @@ DELETE FROM captures WHERE id NOT IN ( ); -- name: InsertMapping :exec -INSERT INTO mappings (id, name, source_hint, fields) -VALUES ($1, $2, $3, $4); +INSERT INTO mappings (id, name, source_hint, event_type, fields) +VALUES ($1, $2, $3, $4, $5); -- name: GetMapping :one -SELECT id, name, source_hint, fields, created_at, updated_at +SELECT sqlc.embed(mappings), + (SELECT count(*) FROM mapping_matches mm WHERE mm.mapping = mappings.id)::bigint AS match_count, + COALESCE((SELECT max(mm.matched_at) FROM mapping_matches mm WHERE mm.mapping = mappings.id), 'epoch')::timestamptz AS last_matched_at FROM mappings WHERE id = $1; -- name: ListMappings :many -SELECT id, name, source_hint, fields, created_at, updated_at +SELECT sqlc.embed(mappings), + (SELECT count(*) FROM mapping_matches mm WHERE mm.mapping = mappings.id)::bigint AS match_count, + COALESCE((SELECT max(mm.matched_at) FROM mapping_matches mm WHERE mm.mapping = mappings.id), 'epoch')::timestamptz AS last_matched_at FROM mappings ORDER BY created_at DESC; -- name: UpdateMapping :execrows UPDATE mappings -SET name = $2, source_hint = $3, fields = $4, updated_at = now() +SET name = $2, source_hint = $3, event_type = $4, fields = $5, updated_at = now() WHERE id = $1; +-- name: InsertMappingMatch :exec +INSERT INTO mapping_matches (mapping, capture) VALUES ($1, $2) +ON CONFLICT DO NOTHING; + -- name: DeleteMapping :execrows DELETE FROM mappings WHERE id = $1; -- name: InsertBinding :exec -INSERT INTO bindings (id, name, source, mapping, workflow, owner, repo, version, status, secret) -VALUES ($1, $2, $3, $4, $5, $6, $7, 1, $8, $9); +INSERT INTO bindings (id, name, source, mapping, filter, workflow, owner, repo, version, status, secret) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, 1, $9, $10); -- name: GetBinding :one -SELECT id, name, source, mapping, workflow, owner, repo, version, status, secret, created_at, updated_at +SELECT id, name, source, mapping, workflow, owner, repo, version, status, secret, created_at, updated_at, filter FROM bindings WHERE id = $1; -- name: ListBindings :many -SELECT id, name, source, mapping, workflow, owner, repo, version, status, secret, created_at, updated_at +SELECT id, name, source, mapping, workflow, owner, repo, version, status, secret, created_at, updated_at, filter FROM bindings ORDER BY created_at DESC; -- name: ArmedBindingsForSource :many -SELECT id, name, source, mapping, workflow, owner, repo, version, status, secret, created_at, updated_at +SELECT id, name, source, mapping, workflow, owner, repo, version, status, secret, created_at, updated_at, filter FROM bindings WHERE source = $1 AND status = 'armed' ORDER BY created_at DESC; -- name: UpdateBinding :execrows @@ -69,8 +83,8 @@ FROM bindings WHERE source = $1 AND status = 'armed' ORDER BY created_at DESC; -- untouched so an edit form that does not echo the secret cannot blank an -- armed binding's HMAC key. UPDATE bindings -SET name = $2, source = $3, mapping = $4, workflow = $5, owner = $6, repo = $7, - version = version + 1, status = $8, +SET name = $2, source = $3, mapping = $4, filter = $5, workflow = $6, owner = $7, repo = $8, + version = version + 1, status = $9, secret = CASE WHEN sqlc.arg(secret)::text = '' THEN secret ELSE sqlc.arg(secret) END, updated_at = now() WHERE id = $1; diff --git a/internal/infrastructure/staterpc/client.go b/internal/infrastructure/staterpc/client.go index 7689190ad..5998cf6c3 100644 --- a/internal/infrastructure/staterpc/client.go +++ b/internal/infrastructure/staterpc/client.go @@ -41,19 +41,20 @@ func (c *Client) ControlPlane() controlpb.ControlPlaneServiceClient { return c.c func (c *Client) Close() error { return nil } var ( - _ task.Store = (*Client)(nil) - _ storecontract.TaskStore = (*Client)(nil) - _ storecontract.TaskLogStore = (*Client)(nil) - _ storecontract.CaptureStore = (*Client)(nil) - _ storecontract.MappingStore = (*Client)(nil) - _ storecontract.BindingStore = (*Client)(nil) - _ storecontract.BindingDispatcher = (*Client)(nil) - _ storecontract.BindingTaskCreator = (*Client)(nil) - _ storecontract.PlaybookDispatcher = (*Client)(nil) - _ storecontract.ConfigSnapshotStore = (*Client)(nil) - _ storecontract.ChannelStatusStore = (*Client)(nil) - _ storecontract.ApplyStatusStore = (*Client)(nil) - _ identity.Repository = (*Client)(nil) + _ task.Store = (*Client)(nil) + _ storecontract.TaskStore = (*Client)(nil) + _ storecontract.TaskLogStore = (*Client)(nil) + _ storecontract.CaptureStore = (*Client)(nil) + _ storecontract.MappingStore = (*Client)(nil) + _ storecontract.BindingStore = (*Client)(nil) + _ storecontract.BindingDispatcher = (*Client)(nil) + _ storecontract.MappingMatchRecorder = (*Client)(nil) + _ storecontract.BindingTaskCreator = (*Client)(nil) + _ storecontract.PlaybookDispatcher = (*Client)(nil) + _ storecontract.ConfigSnapshotStore = (*Client)(nil) + _ storecontract.ChannelStatusStore = (*Client)(nil) + _ storecontract.ApplyStatusStore = (*Client)(nil) + _ identity.Repository = (*Client)(nil) ) // Lifecycle @@ -415,6 +416,11 @@ func (c *Client) DeleteMapping(ctx context.Context, id string) error { return unmapError(err) } +func (c *Client) RecordMappingMatch(ctx context.Context, mappingID, captureID string) error { + _, err := c.client.RecordMappingMatch(ctx, &pb.RecordMappingMatchRequest{MappingId: mappingID, CaptureId: captureID}) + return unmapError(err) +} + // Binding func (c *Client) InsertBinding(ctx context.Context, b binding.Binding) (string, error) { diff --git a/internal/infrastructure/staterpc/mapping_match_test.go b/internal/infrastructure/staterpc/mapping_match_test.go new file mode 100644 index 000000000..cd3d0cf63 --- /dev/null +++ b/internal/infrastructure/staterpc/mapping_match_test.go @@ -0,0 +1,58 @@ +package staterpc + +import ( + "context" + "net" + "reflect" + "testing" + "time" + + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/test/bufconn" + + "github.com/samcharles93/archie-core/internal/domain/binding" + "github.com/samcharles93/archie-core/internal/domain/mapping" +) + +type fakeMappingMatches struct{ mappingID, captureID string } + +func (f *fakeMappingMatches) RecordMappingMatch(_ context.Context, mappingID, captureID string) error { + f.mappingID, f.captureID = mappingID, captureID + return nil +} + +func TestRecordMappingMatchCrossesTheWire(t *testing.T) { + fake := &fakeMappingMatches{} + listener := bufconn.Listen(1 << 20) + server := grpc.NewServer() + RegisterServer(server, Deps{MappingMatches: fake}) + go func() { _ = server.Serve(listener) }() + t.Cleanup(func() { server.Stop(); _ = listener.Close() }) + conn, err := grpc.NewClient("passthrough:///state", + grpc.WithTransportCredentials(insecure.NewCredentials()), + grpc.WithContextDialer(func(ctx context.Context, _ string) (net.Conn, error) { return listener.DialContext(ctx) })) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = conn.Close() }) + + if err := NewClient(conn).RecordMappingMatch(t.Context(), "m1", "c1"); err != nil { + t.Fatalf("RecordMappingMatch() error = %v", err) + } + if fake.mappingID != "m1" || fake.captureID != "c1" { + t.Fatalf("server received (%q, %q), want (m1, c1)", fake.mappingID, fake.captureID) + } +} + +func TestMappingAndBindingCarryEventTypeCountsAndFilter(t *testing.T) { + stamp := time.Date(2026, 9, 24, 9, 0, 0, 0, time.UTC) + m := mapping.Mapping{ID: "m", Name: "n", Fields: []mapping.Field{{Name: "a", Path: "a", Type: mapping.TypeString}}, EventTypeID: "et-1", MatchCount: 7, LastMatchedAt: stamp, CreatedAt: stamp, UpdatedAt: stamp} + if got := mappingValue(mappingProto(m)); !reflect.DeepEqual(got, m) { + t.Fatalf("mapping after round trip = %+v, want %+v", got, m) + } + b := binding.Binding{ID: "b", Filter: `severity == "high"`, CreatedAt: stamp, UpdatedAt: stamp} + if got := bindingValue(bindingProto(b)); got.Filter != b.Filter { + t.Fatalf("binding filter after round trip = %q, want %q", got.Filter, b.Filter) + } +} diff --git a/internal/infrastructure/staterpc/server.go b/internal/infrastructure/staterpc/server.go index 27b8f62eb..c4317b696 100644 --- a/internal/infrastructure/staterpc/server.go +++ b/internal/infrastructure/staterpc/server.go @@ -73,10 +73,13 @@ type Deps struct { // ChannelStatus is the channel runtime state the process hosting the channels // reports. Optional: nil disables the pair with codes.Unavailable, which is // the honest answer for a store service no messaging process is writing to. - ChannelStatus storecontract.ChannelStatusStore - ApplyStatus storecontract.ApplyStatusStore - Mappings storecontract.MappingStore - EventTypes storecontract.EventTypeStore + ChannelStatus storecontract.ChannelStatusStore + ApplyStatus storecontract.ApplyStatusStore + Mappings storecontract.MappingStore + EventTypes storecontract.EventTypeStore + // MappingMatches counts the events each mapping resolved. Optional: nil + // answers RecordMappingMatch with codes.Unavailable. + MappingMatches storecontract.MappingMatchRecorder Bindings storecontract.BindingStore BindingDispatcher storecontract.BindingDispatcher BindingTaskCreator storecontract.BindingTaskCreator @@ -569,6 +572,16 @@ func (s *server) DeleteMapping(ctx context.Context, r *pb.DeleteMappingRequest) return &pb.DeleteMappingResponse{}, nil } +func (s *server) RecordMappingMatch(ctx context.Context, r *pb.RecordMappingMatchRequest) (*pb.RecordMappingMatchResponse, error) { + if s.deps.MappingMatches == nil { + return nil, status.Error(codes.Unavailable, "mapping match recorder unavailable") + } + if err := s.deps.MappingMatches.RecordMappingMatch(ctx, r.MappingId, r.CaptureId); err != nil { + return nil, s.logErr("RecordMappingMatch", err) + } + return &pb.RecordMappingMatchResponse{}, nil +} + // Binding func (s *server) binding() (storecontract.BindingStore, error) { diff --git a/internal/infrastructure/staterpc/values.go b/internal/infrastructure/staterpc/values.go index dea78e9f6..a2ff7f748 100644 --- a/internal/infrastructure/staterpc/values.go +++ b/internal/infrastructure/staterpc/values.go @@ -178,8 +178,9 @@ func mappingFieldValue(f *pb.MappingField) mapping.Field { func mappingProto(m mapping.Mapping) *pb.Mapping { return &pb.Mapping{ - Id: m.ID, Name: m.Name, SourceHint: m.SourceHint, - Fields: mapValues(m.Fields, mappingFieldProto), + Id: m.ID, Name: m.Name, SourceHint: m.SourceHint, EventTypeId: m.EventTypeID, + Fields: mapValues(m.Fields, mappingFieldProto), + MatchCount: m.MatchCount, LastMatchedAt: timestamp(m.LastMatchedAt), CreatedAt: timestamp(m.CreatedAt), UpdatedAt: timestamp(m.UpdatedAt), } } @@ -189,8 +190,9 @@ func mappingValue(m *pb.Mapping) mapping.Mapping { return mapping.Mapping{} } return mapping.Mapping{ - ID: m.Id, Name: m.Name, SourceHint: m.SourceHint, - Fields: mapValues(m.Fields, mappingFieldValue), + ID: m.Id, Name: m.Name, SourceHint: m.SourceHint, EventTypeID: m.EventTypeId, + Fields: mapValues(m.Fields, mappingFieldValue), + MatchCount: m.MatchCount, LastMatchedAt: timeValue(m.LastMatchedAt), CreatedAt: timeValue(m.CreatedAt), UpdatedAt: timeValue(m.UpdatedAt), } } @@ -198,7 +200,7 @@ func mappingValue(m *pb.Mapping) mapping.Mapping { func bindingProto(b binding.Binding) *pb.Binding { return &pb.Binding{ Id: b.ID, Name: b.Name, Matcher: &pb.BindingMatcher{Source: b.Matcher.Source}, - MappingId: b.MappingID, Workflow: b.Workflow, Owner: b.Owner, Repo: b.Repo, + MappingId: b.MappingID, Filter: b.Filter, Workflow: b.Workflow, Owner: b.Owner, Repo: b.Repo, Version: int64(b.Version), Status: string(b.Status), Secret: b.Secret, CreatedAt: timestamp(b.CreatedAt), UpdatedAt: timestamp(b.UpdatedAt), } @@ -214,7 +216,7 @@ func bindingValue(b *pb.Binding) binding.Binding { } return binding.Binding{ ID: b.Id, Name: b.Name, Matcher: binding.Matcher{Source: source}, - MappingID: b.MappingId, Workflow: b.Workflow, Owner: b.Owner, Repo: b.Repo, + MappingID: b.MappingId, Filter: b.Filter, Workflow: b.Workflow, Owner: b.Owner, Repo: b.Repo, Version: int(b.Version), Status: binding.Status(b.Status), Secret: b.Secret, CreatedAt: timeValue(b.CreatedAt), UpdatedAt: timeValue(b.UpdatedAt), } diff --git a/internal/store/store.go b/internal/store/store.go index 60da7f5f6..26a7faa9e 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -398,11 +398,9 @@ func (s *Store) EnqueueChatTask(ctx context.Context, owner, repo, title, body, w // binding_version on the new row in a second statement. // // A crash between the two writes leaves the task without provenance -// (binding_id == 0); the binding_dispatches ledger row written by the -// dispatch loop still records the (binding, capture, task) triple, so -// a future repair pass could backfill. This is the same -// best-effort-provenance pattern the rest of the task lifecycle uses -// for fields added after the row's primary insert. +// (binding_id == 0). This is the same best-effort-provenance pattern the +// rest of the task lifecycle uses for fields added after the row's primary +// insert. func (s *Store) EnqueueBindingTask(ctx context.Context, owner, repo, title, body, wf, identity, bindingID string, bindingVersion int) (*workflow.Task, error) { t, err := s.EnqueueChatTask(ctx, owner, repo, title, body, wf, identity) if err != nil { diff --git a/internal/webui/api_binding.go b/internal/webui/api_binding.go index 385377aa9..ef3a21705 100644 --- a/internal/webui/api_binding.go +++ b/internal/webui/api_binding.go @@ -16,6 +16,7 @@ type bindingRequest struct { Name string `json:"name"` Matcher binding.Matcher `json:"matcher"` MappingID string `json:"mapping_id"` + Filter string `json:"filter"` Workflow string `json:"workflow"` // Owner and Repo optionally pin the binding to one configured repo, // for multi-repo deployments. Both empty is valid (falls back to the @@ -67,6 +68,7 @@ func (s *Server) handleBindingCreate(w http.ResponseWriter, r *http.Request) { Name: req.Name, Matcher: req.Matcher, MappingID: req.MappingID, + Filter: req.Filter, Workflow: req.Workflow, Owner: req.Owner, Repo: req.Repo, @@ -77,12 +79,11 @@ func (s *Server) handleBindingCreate(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusBadRequest) return } + if !s.checkBindingFilter(w, r, b) { + return + } id, err := s.Bindings.InsertBinding(r.Context(), b) if err != nil { - if errors.Is(err, storecontract.ErrBindingOverlap) { - http.Error(w, "binding source overlaps an existing binding", http.StatusConflict) - return - } s.Log.Error("insert binding", "err", err) http.Error(w, "create binding failed", http.StatusInternalServerError) return @@ -154,6 +155,7 @@ func (s *Server) handleBindingUpdate(w http.ResponseWriter, r *http.Request) { Name: req.Name, Matcher: req.Matcher, MappingID: req.MappingID, + Filter: req.Filter, Workflow: req.Workflow, Owner: req.Owner, Repo: req.Repo, @@ -163,12 +165,13 @@ func (s *Server) handleBindingUpdate(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusBadRequest) return } + if !s.checkBindingFilter(w, r, b) { + return + } if err := s.Bindings.UpdateBinding(r.Context(), b); err != nil { switch { case errors.Is(err, storecontract.ErrBindingNotFound): http.Error(w, "binding not found", http.StatusNotFound) - case errors.Is(err, storecontract.ErrBindingOverlap): - http.Error(w, "binding source overlaps an existing binding", http.StatusConflict) default: s.Log.Error("update binding", "err", err, "id", id) http.Error(w, "update binding failed", http.StatusInternalServerError) @@ -229,8 +232,6 @@ func (s *Server) handleBindingApprove(w http.ResponseWriter, r *http.Request) { http.Error(w, "binding not found", http.StatusNotFound) case errors.Is(err, storecontract.ErrBindingTransition): http.Error(w, "binding cannot be approved from its current state", http.StatusConflict) - case errors.Is(err, storecontract.ErrBindingOverlap): - http.Error(w, "binding source overlaps an existing binding", http.StatusConflict) default: s.Log.Error("approve binding", "err", err, "id", id) http.Error(w, "approve binding failed", http.StatusInternalServerError) @@ -247,6 +248,30 @@ func (s *Server) handleBindingApprove(w http.ResponseWriter, r *http.Request) { writeJSON(w, updated) } +// checkBindingFilter refuses a binding whose mapping does not exist or whose +// filter does not compile against the mapping's parameters. +func (s *Server) checkBindingFilter(w http.ResponseWriter, r *http.Request, b binding.Binding) bool { + if s.Mappings == nil { + http.Error(w, "mappings not configured", http.StatusServiceUnavailable) + return false + } + m, err := s.Mappings.GetMapping(r.Context(), b.MappingID) + if err != nil { + s.Log.Error("get mapping for binding", "err", err, "mapping", b.MappingID) + http.Error(w, "get mapping failed", http.StatusInternalServerError) + return false + } + if m == nil { + http.Error(w, "binding: mapping not found: "+b.MappingID, http.StatusBadRequest) + return false + } + if _, err := binding.CompileFilter(b.Filter, m.Fields); err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return false + } + return true +} + // stripBindingSecrets zeroes the Secret field on every binding in the slice // so the list handler never leaks a shared HMAC secret through /api/bindings. // Single-binding reads do the same inline; this covers the list path. diff --git a/internal/webui/api_binding_filter_test.go b/internal/webui/api_binding_filter_test.go new file mode 100644 index 000000000..71385816e --- /dev/null +++ b/internal/webui/api_binding_filter_test.go @@ -0,0 +1,137 @@ +package webui + +import ( + "context" + "encoding/json" + "fmt" + "log/slog" + "net/http" + "testing" + + "github.com/samcharles93/archie-core/internal/domain/binding" + "github.com/samcharles93/archie-core/internal/domain/mapping" + "github.com/samcharles93/archie-core/internal/domain/storecontract" + "github.com/samcharles93/archie-core/internal/domain/workflow" +) + +// memBindings keeps mappings and bindings in memory with no per-source limit, +// as the Postgres store does. +type memBindings struct { + mappings map[string]mapping.Mapping + bindings map[string]binding.Binding +} + +func newMemBindings() *memBindings { + return &memBindings{mappings: map[string]mapping.Mapping{}, bindings: map[string]binding.Binding{}} +} + +func (m *memBindings) InsertMapping(_ context.Context, v mapping.Mapping) (string, error) { + v.ID = fmt.Sprintf("m%d", len(m.mappings)+1) + m.mappings[v.ID] = v + return v.ID, nil +} + +func (m *memBindings) GetMapping(_ context.Context, id string) (*mapping.Mapping, error) { + v, ok := m.mappings[id] + if !ok { + return nil, nil + } + return &v, nil +} +func (m *memBindings) ListMappings(context.Context) ([]mapping.Mapping, error) { return nil, nil } +func (m *memBindings) UpdateMapping(context.Context, mapping.Mapping) error { return nil } +func (m *memBindings) DeleteMapping(context.Context, string) error { return nil } + +func (m *memBindings) InsertBinding(_ context.Context, b binding.Binding) (string, error) { + b.ID = fmt.Sprintf("b%d", len(m.bindings)+1) + m.bindings[b.ID] = b + return b.ID, nil +} + +func (m *memBindings) GetBinding(_ context.Context, id string) (*binding.Binding, error) { + v, ok := m.bindings[id] + if !ok { + return nil, nil + } + return &v, nil +} +func (m *memBindings) ListBindings(context.Context) ([]binding.Binding, error) { return nil, nil } +func (m *memBindings) UpdateBinding(_ context.Context, b binding.Binding) error { + if _, ok := m.bindings[b.ID]; !ok { + return storecontract.ErrBindingNotFound + } + m.bindings[b.ID] = b + return nil +} +func (m *memBindings) DeleteBinding(context.Context, string) error { return nil } +func (m *memBindings) ApproveBinding(context.Context, string) error { return nil } + +func memBindingServer(t *testing.T) (*Server, string) { + t.Helper() + store := newMemBindings() + mappingID, _ := store.InsertMapping(t.Context(), mapping.Mapping{ + Name: "m", EventTypeID: "et-1", + Fields: []mapping.Field{{Name: "title", Path: "issue.title", Type: mapping.TypeString}}, + }) + return &Server{ + Log: slog.New(slog.DiscardHandler), + Mappings: store, + Bindings: store, + ControlPlane: workflowControlPlane(t, workflow.WorkflowDefinitionCollection{Definitions: []workflow.WorkflowDefinitionEntry{{ID: "implement", YAML: "id: implement\nsteps:\n - type: implement.prepare\n"}}}), + }, mappingID +} + +// Several bindings may share a source. +func TestHandleBindingCreateAllowsSeveralPerSource(t *testing.T) { + srv, mappingID := memBindingServer(t) + for _, suffix := range []string{"first", "second"} { + w := doJSON(t, srv, http.MethodPost, "/api/bindings", validBindingRequest(suffix, "sentry", mappingID)) + if w.Code != http.StatusCreated { + t.Fatalf("%s create status = %d, want %d; body = %s", suffix, w.Code, http.StatusCreated, w.Body.String()) + } + } +} + +// A binding's filter is checked against its mapping's parameters on save. +func TestHandleBindingFilterIsCheckedAgainstMapping(t *testing.T) { + tests := []struct { + name string + filter string + want int + }{ + {"no filter", "", http.StatusCreated}, + {"filter on a mapped parameter", `title.startsWith("P1")`, http.StatusCreated}, + {"unknown parameter", `severity == "high"`, http.StatusBadRequest}, + {"not boolean", `title`, http.StatusBadRequest}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + srv, mappingID := memBindingServer(t) + req := validBindingRequest("f", "sentry", mappingID) + req["filter"] = tt.filter + w := doJSON(t, srv, http.MethodPost, "/api/bindings", req) + if w.Code != tt.want { + t.Fatalf("create status = %d, want %d; body = %s", w.Code, tt.want, w.Body.String()) + } + if w.Code == http.StatusCreated { + var created binding.Binding + _ = json.Unmarshal(w.Body.Bytes(), &created) + if created.Filter != tt.filter { + t.Fatalf("created.Filter = %q, want %q", created.Filter, tt.filter) + } + w = doJSON(t, srv, http.MethodPatch, "/api/bindings/"+created.ID, req) + if w.Code != http.StatusOK { + t.Fatalf("update status = %d; body = %s", w.Code, w.Body.String()) + } + } + }) + } +} + +func TestHandleBindingRejectsUnknownMapping(t *testing.T) { + srv, _ := memBindingServer(t) + w := doJSON(t, srv, http.MethodPost, "/api/bindings", validBindingRequest("x", "sentry", "absent")) + if w.Code != http.StatusBadRequest { + t.Fatalf("create status = %d, want %d; body = %s", w.Code, http.StatusBadRequest, w.Body.String()) + } +} diff --git a/internal/webui/api_binding_test.go b/internal/webui/api_binding_test.go index 0efa8db44..13b1955f3 100644 --- a/internal/webui/api_binding_test.go +++ b/internal/webui/api_binding_test.go @@ -187,23 +187,6 @@ func TestHandleBindingsListStripsSecrets(t *testing.T) { } } -func TestHandleBindingCreateRejectsOverlap(t *testing.T) { - srv := bindingTestServer(t) - mappingID := seedMapping(t, srv, "m") - - w := doJSON(t, srv, http.MethodPost, "/api/bindings", validBindingRequest("first", "sentry", mappingID)) - if w.Code != http.StatusCreated { - t.Fatalf("first create status = %d, want %d; body = %s", w.Code, http.StatusCreated, w.Body.String()) - } - - // Overlap because Per bead t2db.4, two bindings may not own the same - // source; the second insert must surface ErrBindingOverlap -> 409. - w = doJSON(t, srv, http.MethodPost, "/api/bindings", validBindingRequest("second", "sentry", mappingID)) - if w.Code != http.StatusConflict { - t.Fatalf("second create status = %d, want %d; body = %s", w.Code, http.StatusConflict, w.Body.String()) - } -} - func TestHandleBindingCreateRejectsMissingWorkflow(t *testing.T) { srv := bindingTestServer(t) mappingID := seedMapping(t, srv, "m") diff --git a/internal/webui/api_mapping.go b/internal/webui/api_mapping.go index 1a0cd343a..fa96a57bf 100644 --- a/internal/webui/api_mapping.go +++ b/internal/webui/api_mapping.go @@ -14,9 +14,40 @@ import ( // PATCH /api/mappings/{id} both accept. ID/CreatedAt/UpdatedAt are // server-assigned, never taken from the request body. type mappingRequest struct { - Name string `json:"name"` - SourceHint string `json:"source_hint"` - Fields []mapping.Field `json:"fields"` + Name string `json:"name"` + SourceHint string `json:"source_hint"` + EventTypeID string `json:"event_type_id"` + Fields []mapping.Field `json:"fields"` +} + +// validateMapping checks m is well-formed and fits its event type's schema. +// It writes the refusal and returns false when it does not. +func (s *Server) validateMapping(w http.ResponseWriter, r *http.Request, m mapping.Mapping) bool { + if err := m.Validate(); err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return false + } + if s.EventTypes == nil { + http.Error(w, "event types not configured", http.StatusServiceUnavailable) + return false + } + types, err := s.EventTypes.ListEventTypes(r.Context()) + if err != nil { + s.Log.Error("list event types", "err", err) + http.Error(w, "list event types failed", http.StatusInternalServerError) + return false + } + for _, t := range types { + if t.ID == m.EventTypeID { + if err := mapping.CheckSchema(m.Fields, t.Schema); err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return false + } + return true + } + } + http.Error(w, "mapping: event type not found: "+m.EventTypeID, http.StatusBadRequest) + return false } func (s *Server) handleMappingsList(w http.ResponseWriter, r *http.Request) { @@ -46,9 +77,8 @@ func (s *Server) handleMappingCreate(w http.ResponseWriter, r *http.Request) { http.Error(w, "invalid request body: "+err.Error(), http.StatusBadRequest) return } - m := mapping.Mapping{Name: req.Name, SourceHint: req.SourceHint, Fields: req.Fields} - if err := m.Validate(); err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) + m := mapping.Mapping{Name: req.Name, SourceHint: req.SourceHint, EventTypeID: req.EventTypeID, Fields: req.Fields} + if !s.validateMapping(w, r, m) { return } id, err := s.Mappings.InsertMapping(r.Context(), m) @@ -108,9 +138,8 @@ func (s *Server) handleMappingUpdate(w http.ResponseWriter, r *http.Request) { http.Error(w, "invalid request body: "+err.Error(), http.StatusBadRequest) return } - m := mapping.Mapping{ID: id, Name: req.Name, SourceHint: req.SourceHint, Fields: req.Fields} - if err := m.Validate(); err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) + m := mapping.Mapping{ID: id, Name: req.Name, SourceHint: req.SourceHint, EventTypeID: req.EventTypeID, Fields: req.Fields} + if !s.validateMapping(w, r, m) { return } if err := s.Mappings.UpdateMapping(r.Context(), m); err != nil { diff --git a/internal/webui/api_mapping_test.go b/internal/webui/api_mapping_test.go index d5306b9a0..b14ea4be5 100644 --- a/internal/webui/api_mapping_test.go +++ b/internal/webui/api_mapping_test.go @@ -9,6 +9,7 @@ import ( "path/filepath" "testing" + "github.com/samcharles93/archie-core/internal/domain/eventtype" "github.com/samcharles93/archie-core/internal/domain/mapping" "github.com/samcharles93/archie-core/internal/infrastructure/edastore" "github.com/samcharles93/archie-core/internal/store" @@ -26,10 +27,66 @@ func mappingTestServer(t *testing.T) *Server { t.Cleanup(func() { _ = s.Close() }) eda := edastore.OpenTest(t) return &Server{ - Store: s, - Log: slog.New(slog.DiscardHandler), - Mappings: eda, - Captures: eda, + Store: s, + Log: slog.New(slog.DiscardHandler), + Mappings: eda, + Captures: eda, + EventTypes: testEventTypes(), + } +} + +// testEventTypes holds one event type, et-1, whose schema has every path the +// mapping tests write. +func testEventTypes() *memEventTypes { + return &memEventTypes{types: []eventtype.EventType{{ + ID: "et-1", Source: "sentry", Name: "issue", + Schema: map[string]eventtype.ValueType{ + "a": eventtype.TypeString, "b": eventtype.TypeBool, + "issue": eventtype.TypeObject, "issue.title": eventtype.TypeString, + }, + }}} +} + +// A mapping belongs to an event type and is checked against its schema. +func TestHandleMappingSaveChecksEventTypeSchema(t *testing.T) { + tests := []struct { + name string + eventType string + path string + fieldType mapping.FieldType + want int + }{ + {"fits the schema", "et-1", "issue.title", mapping.TypeString, http.StatusCreated}, + {"no event type", "", "issue.title", mapping.TypeString, http.StatusBadRequest}, + {"unknown event type", "et-9", "issue.title", mapping.TypeString, http.StatusBadRequest}, + {"path the type does not have", "et-1", "sender.login", mapping.TypeString, http.StatusBadRequest}, + {"type differs from the schema", "et-1", "issue.title", mapping.TypeNumber, http.StatusBadRequest}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + srv := mappingTestServer(t) + req := map[string]any{ + "name": "m", + "event_type_id": tt.eventType, + "fields": []mapping.Field{{Name: "f", Path: tt.path, Type: tt.fieldType}}, + } + if w := doJSON(t, srv, http.MethodPost, "/api/mappings", req); w.Code != tt.want { + t.Fatalf("create status = %d, want %d; body = %s", w.Code, tt.want, w.Body.String()) + } + ok := doJSON(t, srv, http.MethodPost, "/api/mappings", map[string]any{ + "name": "base", "event_type_id": "et-1", + "fields": []mapping.Field{{Name: "a", Path: "a", Type: mapping.TypeString}}, + }) + var created mapping.Mapping + _ = json.Unmarshal(ok.Body.Bytes(), &created) + want := tt.want + if want == http.StatusCreated { + want = http.StatusOK + } + if w := doJSON(t, srv, http.MethodPatch, "/api/mappings/"+created.ID, req); w.Code != want { + t.Fatalf("update status = %d, want %d; body = %s", w.Code, want, w.Body.String()) + } + }) } } @@ -74,8 +131,9 @@ func doJSONWithHeaders(t *testing.T, srv *Server, method, path string, body any, func TestHandleMappingCreateAndGet(t *testing.T) { srv := mappingTestServer(t) w := doJSON(t, srv, http.MethodPost, "/api/mappings", map[string]any{ - "name": "sentry issue opened", - "source_hint": "sentry", + "name": "sentry issue opened", + "source_hint": "sentry", + "event_type_id": "et-1", "fields": []mapping.Field{ {Name: "title", Path: "issue.title", Type: mapping.TypeString, Required: true}, }, @@ -124,8 +182,9 @@ func TestHandleMappingsList(t *testing.T) { srv := mappingTestServer(t) for range 3 { doJSON(t, srv, http.MethodPost, "/api/mappings", map[string]any{ - "name": "m", - "fields": []mapping.Field{{Name: "a", Path: "a", Type: mapping.TypeString}}, + "name": "m", + "event_type_id": "et-1", + "fields": []mapping.Field{{Name: "a", Path: "a", Type: mapping.TypeString}}, }) } w := doJSON(t, srv, http.MethodGet, "/api/mappings", nil) @@ -146,15 +205,17 @@ func TestHandleMappingsList(t *testing.T) { func TestHandleMappingUpdate(t *testing.T) { srv := mappingTestServer(t) w := doJSON(t, srv, http.MethodPost, "/api/mappings", map[string]any{ - "name": "orig", - "fields": []mapping.Field{{Name: "a", Path: "a", Type: mapping.TypeString}}, + "name": "orig", + "event_type_id": "et-1", + "fields": []mapping.Field{{Name: "a", Path: "a", Type: mapping.TypeString}}, }) var created mapping.Mapping _ = json.Unmarshal(w.Body.Bytes(), &created) w = doJSON(t, srv, http.MethodPatch, "/api/mappings/"+created.ID, map[string]any{ - "name": "renamed", - "fields": []mapping.Field{{Name: "b", Path: "b", Type: mapping.TypeBool}}, + "name": "renamed", + "event_type_id": "et-1", + "fields": []mapping.Field{{Name: "b", Path: "b", Type: mapping.TypeBool}}, }) if w.Code != http.StatusOK { t.Fatalf("update status = %d, want %d; body = %s", w.Code, http.StatusOK, w.Body.String()) @@ -171,8 +232,9 @@ func TestHandleMappingUpdate(t *testing.T) { func TestHandleMappingUpdateMissingReturns404(t *testing.T) { srv := mappingTestServer(t) w := doJSON(t, srv, http.MethodPatch, "/api/mappings/999", map[string]any{ - "name": "x", - "fields": []mapping.Field{{Name: "a", Path: "a", Type: mapping.TypeString}}, + "name": "x", + "event_type_id": "et-1", + "fields": []mapping.Field{{Name: "a", Path: "a", Type: mapping.TypeString}}, }) if w.Code != http.StatusNotFound { t.Fatalf("status = %d, want %d; body = %s", w.Code, http.StatusNotFound, w.Body.String()) @@ -182,8 +244,9 @@ func TestHandleMappingUpdateMissingReturns404(t *testing.T) { func TestHandleMappingDelete(t *testing.T) { srv := mappingTestServer(t) w := doJSON(t, srv, http.MethodPost, "/api/mappings", map[string]any{ - "name": "m", - "fields": []mapping.Field{{Name: "a", Path: "a", Type: mapping.TypeString}}, + "name": "m", + "event_type_id": "et-1", + "fields": []mapping.Field{{Name: "a", Path: "a", Type: mapping.TypeString}}, }) var created mapping.Mapping _ = json.Unmarshal(w.Body.Bytes(), &created) @@ -274,8 +337,9 @@ func TestHandleMappingsUnavailableWhenNotConfigured(t *testing.T) { func TestHandleMappingMutationsRequireCSRFHeader(t *testing.T) { srv := mappingTestServer(t) newMapping := map[string]any{ - "name": "sentry issue opened", - "source_hint": "sentry", + "name": "sentry issue opened", + "source_hint": "sentry", + "event_type_id": "et-1", "fields": []mapping.Field{ {Name: "title", Path: "issue.title", Type: mapping.TypeString, Required: true}, }, diff --git a/proto/state/v1/state.proto b/proto/state/v1/state.proto index 546e10fb1..4c688eb34 100644 --- a/proto/state/v1/state.proto +++ b/proto/state/v1/state.proto @@ -119,6 +119,9 @@ service StateStoreService { rpc ListMappings(ListMappingsRequest) returns (ListMappingsResponse); rpc UpdateMapping(UpdateMappingRequest) returns (UpdateMappingResponse); rpc DeleteMapping(DeleteMappingRequest) returns (DeleteMappingResponse); + // RecordMappingMatch counts one event a mapping resolved; the same + // (mapping, capture) twice counts once. + rpc RecordMappingMatch(RecordMappingMatchRequest) returns (RecordMappingMatchResponse); // EventType (docs/prds/event-automation.md, "Event types"). Insert and // Update refuse an overlapping or malformed type. @@ -362,6 +365,10 @@ message Mapping { repeated MappingField fields = 4; google.protobuf.Timestamp created_at = 5; google.protobuf.Timestamp updated_at = 6; + string event_type_id = 7; + // match_count and last_matched_at are read-only: the store counts them. + int64 match_count = 8; + google.protobuf.Timestamp last_matched_at = 9; } // BindingMatcher mirrors internal/domain/binding.Matcher. @@ -383,6 +390,7 @@ message Binding { string secret = 10; google.protobuf.Timestamp created_at = 11; google.protobuf.Timestamp updated_at = 12; + string filter = 13; } // WorkflowStat mirrors internal/store.WorkflowStat. @@ -724,6 +732,12 @@ message UpdateMappingResponse {} message DeleteMappingRequest { string id = 1; } message DeleteMappingResponse {} +message RecordMappingMatchRequest { + string mapping_id = 1; + string capture_id = 2; +} +message RecordMappingMatchResponse {} + message InsertEventTypeRequest { EventType event_type = 1; } message InsertEventTypeResponse { string id = 1; }