feat(judgement): a target's owner is looked up from the connectors at decision time, and an unknown owner is a finding that sends the request to the default owner (#1991)

This commit is contained in:
sam committed 2026-11-16 09:49:33 +11:00
1 parent 4bc0d54341
commit a4a4e97f07
15 files changed
+498 -84

No files matched your search

+1 -1
View File
@@ -134,7 +134,7 @@ func newPolicies(db *sqlx.DB, log *slog.Logger, mux *http.ServeMux, guard func(h
// and change-request rules. A failed action tightens its class. // and change-request rules. A failed action tightens its class.
func newJudgement(db *sqlx.DB, log *slog.Logger, conns *connectors.Module, classes *judgement.Classes, policies *judgement.Policies, settings *governance.Module, heard judgement.Events) *judgement.Module { func newJudgement(db *sqlx.DB, log *slog.Logger, conns *connectors.Module, classes *judgement.Classes, policies *judgement.Policies, settings *governance.Module, heard judgement.Events) *judgement.Module {
guards := []judgement.Guard{ guards := []judgement.Guard{
judgement.Impact{Lookup: judgement.NoTargetFacts{}}, judgement.Impact{Lookup: judgement.RecordedFacts{Source: conns, People: settings}, Defaults: settings},
judgement.Reversibility{}, judgement.Reversibility{},
judgement.Precedent{Classes: classes}, judgement.Precedent{Classes: classes},
judgement.Provenance{Events: heard}, judgement.Provenance{Events: heard},
+187 -46
View File
@@ -210,7 +210,9 @@ type DescribeResponse struct {
Lookups []*LookupType `protobuf:"bytes,4,rep,name=lookups,proto3" json:"lookups,omitempty"` Lookups []*LookupType `protobuf:"bytes,4,rep,name=lookups,proto3" json:"lookups,omitempty"`
Deliveries []*DeliveryType `protobuf:"bytes,5,rep,name=deliveries,proto3" json:"deliveries,omitempty"` Deliveries []*DeliveryType `protobuf:"bytes,5,rep,name=deliveries,proto3" json:"deliveries,omitempty"`
// listens says the connector serves Listen. // listens says the connector serves Listen.
Listens bool `protobuf:"varint,6,opt,name=listens,proto3" json:"listens,omitempty"` Listens bool `protobuf:"varint,6,opt,name=listens,proto3" json:"listens,omitempty"`
// target_facts says the connector serves TargetFacts.
TargetFacts bool `protobuf:"varint,7,opt,name=target_facts,json=targetFacts,proto3" json:"target_facts,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
} }
@@ -287,6 +289,13 @@ func (x *DescribeResponse) GetListens() bool {
return false return false
} }
func (x *DescribeResponse) GetTargetFacts() bool {
if x != nil {
return x.TargetFacts
}
return false
}
type EventType struct { type EventType struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
@@ -1302,6 +1311,123 @@ func (x *DeliverResponse) GetExternalId() string {
return "" return ""
} }
type TargetFactsRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Target *Target `protobuf:"bytes,1,opt,name=target,proto3" json:"target,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *TargetFactsRequest) Reset() {
*x = TargetFactsRequest{}
mi := &file_connector_v1_connector_proto_msgTypes[21]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *TargetFactsRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*TargetFactsRequest) ProtoMessage() {}
func (x *TargetFactsRequest) ProtoReflect() protoreflect.Message {
mi := &file_connector_v1_connector_proto_msgTypes[21]
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 TargetFactsRequest.ProtoReflect.Descriptor instead.
func (*TargetFactsRequest) Descriptor() ([]byte, []int) {
return file_connector_v1_connector_proto_rawDescGZIP(), []int{21}
}
func (x *TargetFactsRequest) GetTarget() *Target {
if x != nil {
return x.Target
}
return nil
}
type TargetFactsResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
// found is false when the connector has no record of the target.
Found bool `protobuf:"varint,1,opt,name=found,proto3" json:"found,omitempty"`
// owner_identity is who answers for the target, as an identity on a channel
// or system, such as "servicenow:jdoe" or "email:jo@example.com".
OwnerIdentity string `protobuf:"bytes,2,opt,name=owner_identity,json=ownerIdentity,proto3" json:"owner_identity,omitempty"`
// data_class names what the target holds, such as "customer" or "temp".
DataClass string `protobuf:"bytes,3,opt,name=data_class,json=dataClass,proto3" json:"data_class,omitempty"`
// count is how many things the target stands for, zero when unknown.
Count int32 `protobuf:"varint,4,opt,name=count,proto3" json:"count,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *TargetFactsResponse) Reset() {
*x = TargetFactsResponse{}
mi := &file_connector_v1_connector_proto_msgTypes[22]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *TargetFactsResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*TargetFactsResponse) ProtoMessage() {}
func (x *TargetFactsResponse) ProtoReflect() protoreflect.Message {
mi := &file_connector_v1_connector_proto_msgTypes[22]
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 TargetFactsResponse.ProtoReflect.Descriptor instead.
func (*TargetFactsResponse) Descriptor() ([]byte, []int) {
return file_connector_v1_connector_proto_rawDescGZIP(), []int{22}
}
func (x *TargetFactsResponse) GetFound() bool {
if x != nil {
return x.Found
}
return false
}
func (x *TargetFactsResponse) GetOwnerIdentity() string {
if x != nil {
return x.OwnerIdentity
}
return ""
}
func (x *TargetFactsResponse) GetDataClass() string {
if x != nil {
return x.DataClass
}
return ""
}
func (x *TargetFactsResponse) GetCount() int32 {
if x != nil {
return x.Count
}
return 0
}
type ListenRequest struct { type ListenRequest struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
// cursor is the last cursor the host stored, empty from the start. // cursor is the last cursor the host stored, empty from the start.
@@ -1312,7 +1438,7 @@ type ListenRequest struct {
func (x *ListenRequest) Reset() { func (x *ListenRequest) Reset() {
*x = ListenRequest{} *x = ListenRequest{}
mi := &file_connector_v1_connector_proto_msgTypes[21] mi := &file_connector_v1_connector_proto_msgTypes[23]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@@ -1324,7 +1450,7 @@ func (x *ListenRequest) String() string {
func (*ListenRequest) ProtoMessage() {} func (*ListenRequest) ProtoMessage() {}
func (x *ListenRequest) ProtoReflect() protoreflect.Message { func (x *ListenRequest) ProtoReflect() protoreflect.Message {
mi := &file_connector_v1_connector_proto_msgTypes[21] mi := &file_connector_v1_connector_proto_msgTypes[23]
if x != nil { if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@@ -1337,7 +1463,7 @@ func (x *ListenRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use ListenRequest.ProtoReflect.Descriptor instead. // Deprecated: Use ListenRequest.ProtoReflect.Descriptor instead.
func (*ListenRequest) Descriptor() ([]byte, []int) { func (*ListenRequest) Descriptor() ([]byte, []int) {
return file_connector_v1_connector_proto_rawDescGZIP(), []int{21} return file_connector_v1_connector_proto_rawDescGZIP(), []int{23}
} }
func (x *ListenRequest) GetCursor() string { func (x *ListenRequest) GetCursor() string {
@@ -1357,7 +1483,7 @@ type ListenResponse struct {
func (x *ListenResponse) Reset() { func (x *ListenResponse) Reset() {
*x = ListenResponse{} *x = ListenResponse{}
mi := &file_connector_v1_connector_proto_msgTypes[22] mi := &file_connector_v1_connector_proto_msgTypes[24]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@@ -1369,7 +1495,7 @@ func (x *ListenResponse) String() string {
func (*ListenResponse) ProtoMessage() {} func (*ListenResponse) ProtoMessage() {}
func (x *ListenResponse) ProtoReflect() protoreflect.Message { func (x *ListenResponse) ProtoReflect() protoreflect.Message {
mi := &file_connector_v1_connector_proto_msgTypes[22] mi := &file_connector_v1_connector_proto_msgTypes[24]
if x != nil { if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@@ -1382,7 +1508,7 @@ func (x *ListenResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use ListenResponse.ProtoReflect.Descriptor instead. // Deprecated: Use ListenResponse.ProtoReflect.Descriptor instead.
func (*ListenResponse) Descriptor() ([]byte, []int) { func (*ListenResponse) Descriptor() ([]byte, []int) {
return file_connector_v1_connector_proto_rawDescGZIP(), []int{22} return file_connector_v1_connector_proto_rawDescGZIP(), []int{24}
} }
func (x *ListenResponse) GetEvents() []*Event { func (x *ListenResponse) GetEvents() []*Event {
@@ -1414,7 +1540,7 @@ const file_connector_v1_connector_proto_rawDesc = "" +
"\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" +
"\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\"\x13\n" + "\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\"\x13\n" +
"\x11ConfigureResponse\"\x11\n" + "\x11ConfigureResponse\"\x11\n" +
"\x0fDescribeRequest\"\x9d\x02\n" + "\x0fDescribeRequest\"\xc0\x02\n" +
"\x10DescribeResponse\x12\x1a\n" + "\x10DescribeResponse\x12\x1a\n" +
"\bcontract\x18\x01 \x01(\tR\bcontract\x12/\n" + "\bcontract\x18\x01 \x01(\tR\bcontract\x12/\n" +
"\x06events\x18\x02 \x03(\v2\x17.connector.v1.EventTypeR\x06events\x122\n" + "\x06events\x18\x02 \x03(\v2\x17.connector.v1.EventTypeR\x06events\x122\n" +
@@ -1423,7 +1549,8 @@ const file_connector_v1_connector_proto_rawDesc = "" +
"\n" + "\n" +
"deliveries\x18\x05 \x03(\v2\x1a.connector.v1.DeliveryTypeR\n" + "deliveries\x18\x05 \x03(\v2\x1a.connector.v1.DeliveryTypeR\n" +
"deliveries\x12\x18\n" + "deliveries\x12\x18\n" +
"\alistens\x18\x06 \x01(\bR\alistens\"Y\n" + "\alistens\x18\x06 \x01(\bR\alistens\x12!\n" +
"\ftarget_facts\x18\a \x01(\bR\vtargetFacts\"Y\n" +
"\tEventType\x12\x12\n" + "\tEventType\x12\x12\n" +
"\x04name\x18\x01 \x01(\tR\x04name\x12 \n" + "\x04name\x18\x01 \x01(\tR\x04name\x12 \n" +
"\vdescription\x18\x02 \x01(\tR\vdescription\x12\x16\n" + "\vdescription\x18\x02 \x01(\tR\vdescription\x12\x16\n" +
@@ -1499,7 +1626,15 @@ const file_connector_v1_connector_proto_rawDesc = "" +
"\x0fidempotency_key\x18\x03 \x01(\tR\x0eidempotencyKey\"2\n" + "\x0fidempotency_key\x18\x03 \x01(\tR\x0eidempotencyKey\"2\n" +
"\x0fDeliverResponse\x12\x1f\n" + "\x0fDeliverResponse\x12\x1f\n" +
"\vexternal_id\x18\x01 \x01(\tR\n" + "\vexternal_id\x18\x01 \x01(\tR\n" +
"externalId\"'\n" + "externalId\"B\n" +
"\x12TargetFactsRequest\x12,\n" +
"\x06target\x18\x01 \x01(\v2\x14.connector.v1.TargetR\x06target\"\x87\x01\n" +
"\x13TargetFactsResponse\x12\x14\n" +
"\x05found\x18\x01 \x01(\bR\x05found\x12%\n" +
"\x0eowner_identity\x18\x02 \x01(\tR\rownerIdentity\x12\x1d\n" +
"\n" +
"data_class\x18\x03 \x01(\tR\tdataClass\x12\x14\n" +
"\x05count\x18\x04 \x01(\x05R\x05count\"'\n" +
"\rListenRequest\x12\x16\n" + "\rListenRequest\x12\x16\n" +
"\x06cursor\x18\x01 \x01(\tR\x06cursor\"U\n" + "\x06cursor\x18\x01 \x01(\tR\x06cursor\"U\n" +
"\x0eListenResponse\x12+\n" + "\x0eListenResponse\x12+\n" +
@@ -1509,7 +1644,7 @@ const file_connector_v1_connector_proto_rawDesc = "" +
"\x19REVERSIBILITY_UNSPECIFIED\x10\x00\x12&\n" + "\x19REVERSIBILITY_UNSPECIFIED\x10\x00\x12&\n" +
"\"REVERSIBILITY_UNDONE_AUTOMATICALLY\x10\x01\x12\x1d\n" + "\"REVERSIBILITY_UNDONE_AUTOMATICALLY\x10\x01\x12\x1d\n" +
"\x19REVERSIBILITY_RECOVERABLE\x10\x02\x12\x1e\n" + "\x19REVERSIBILITY_RECOVERABLE\x10\x02\x12\x1e\n" +
"\x1aREVERSIBILITY_IRREVERSIBLE\x10\x032\xce\x04\n" + "\x1aREVERSIBILITY_IRREVERSIBLE\x10\x032\xa2\x05\n" +
"\x10ConnectorService\x12L\n" + "\x10ConnectorService\x12L\n" +
"\tConfigure\x12\x1e.connector.v1.ConfigureRequest\x1a\x1f.connector.v1.ConfigureResponse\x12I\n" + "\tConfigure\x12\x1e.connector.v1.ConfigureRequest\x1a\x1f.connector.v1.ConfigureResponse\x12I\n" +
"\bDescribe\x12\x1d.connector.v1.DescribeRequest\x1a\x1e.connector.v1.DescribeResponse\x12@\n" + "\bDescribe\x12\x1d.connector.v1.DescribeRequest\x1a\x1e.connector.v1.DescribeResponse\x12@\n" +
@@ -1518,7 +1653,8 @@ const file_connector_v1_connector_proto_rawDesc = "" +
"\x06Invoke\x12\x1b.connector.v1.InvokeRequest\x1a\x1c.connector.v1.InvokeResponse\x12C\n" + "\x06Invoke\x12\x1b.connector.v1.InvokeRequest\x1a\x1c.connector.v1.InvokeResponse\x12C\n" +
"\x06Lookup\x12\x1b.connector.v1.LookupRequest\x1a\x1c.connector.v1.LookupResponse\x12F\n" + "\x06Lookup\x12\x1b.connector.v1.LookupRequest\x1a\x1c.connector.v1.LookupResponse\x12F\n" +
"\aDeliver\x12\x1c.connector.v1.DeliverRequest\x1a\x1d.connector.v1.DeliverResponse\x12E\n" + "\aDeliver\x12\x1c.connector.v1.DeliverRequest\x1a\x1d.connector.v1.DeliverResponse\x12E\n" +
"\x06Listen\x12\x1b.connector.v1.ListenRequest\x1a\x1c.connector.v1.ListenResponse0\x01B\xc4\x01\n" + "\x06Listen\x12\x1b.connector.v1.ListenRequest\x1a\x1c.connector.v1.ListenResponse0\x01\x12R\n" +
"\vTargetFacts\x12 .connector.v1.TargetFactsRequest\x1a!.connector.v1.TargetFactsResponseB\xc4\x01\n" +
"\x10com.connector.v1B\x0eConnectorProtoP\x01ZOgithub.com/samcharles93/archie-core/internal/contracts/connector/v1;connectorv1\xa2\x02\x03CXX\xaa\x02\fConnector.V1\xca\x02\fConnector\\V1\xe2\x02\x18Connector\\V1\\GPBMetadata\xea\x02\rConnector::V1b\x06proto3" "\x10com.connector.v1B\x0eConnectorProtoP\x01ZOgithub.com/samcharles93/archie-core/internal/contracts/connector/v1;connectorv1\xa2\x02\x03CXX\xaa\x02\fConnector.V1\xca\x02\fConnector\\V1\xe2\x02\x18Connector\\V1\\GPBMetadata\xea\x02\rConnector::V1b\x06proto3"
var ( var (
@@ -1534,7 +1670,7 @@ func file_connector_v1_connector_proto_rawDescGZIP() []byte {
} }
var file_connector_v1_connector_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_connector_v1_connector_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_connector_v1_connector_proto_msgTypes = make([]protoimpl.MessageInfo, 26) var file_connector_v1_connector_proto_msgTypes = make([]protoimpl.MessageInfo, 28)
var file_connector_v1_connector_proto_goTypes = []any{ var file_connector_v1_connector_proto_goTypes = []any{
(Reversibility)(0), // 0: connector.v1.Reversibility (Reversibility)(0), // 0: connector.v1.Reversibility
(*ConfigureRequest)(nil), // 1: connector.v1.ConfigureRequest (*ConfigureRequest)(nil), // 1: connector.v1.ConfigureRequest
@@ -1558,49 +1694,54 @@ var file_connector_v1_connector_proto_goTypes = []any{
(*LookupResponse)(nil), // 19: connector.v1.LookupResponse (*LookupResponse)(nil), // 19: connector.v1.LookupResponse
(*DeliverRequest)(nil), // 20: connector.v1.DeliverRequest (*DeliverRequest)(nil), // 20: connector.v1.DeliverRequest
(*DeliverResponse)(nil), // 21: connector.v1.DeliverResponse (*DeliverResponse)(nil), // 21: connector.v1.DeliverResponse
(*ListenRequest)(nil), // 22: connector.v1.ListenRequest (*TargetFactsRequest)(nil), // 22: connector.v1.TargetFactsRequest
(*ListenResponse)(nil), // 23: connector.v1.ListenResponse (*TargetFactsResponse)(nil), // 23: connector.v1.TargetFactsResponse
nil, // 24: connector.v1.ConfigureRequest.SettingsEntry (*ListenRequest)(nil), // 24: connector.v1.ListenRequest
nil, // 25: connector.v1.ConfigureRequest.SecretsEntry (*ListenResponse)(nil), // 25: connector.v1.ListenResponse
nil, // 26: connector.v1.ParseRequest.HeadersEntry nil, // 26: connector.v1.ConfigureRequest.SettingsEntry
(*timestamppb.Timestamp)(nil), // 27: google.protobuf.Timestamp nil, // 27: connector.v1.ConfigureRequest.SecretsEntry
nil, // 28: connector.v1.ParseRequest.HeadersEntry
(*timestamppb.Timestamp)(nil), // 29: google.protobuf.Timestamp
} }
var file_connector_v1_connector_proto_depIdxs = []int32{ var file_connector_v1_connector_proto_depIdxs = []int32{
24, // 0: connector.v1.ConfigureRequest.settings:type_name -> connector.v1.ConfigureRequest.SettingsEntry 26, // 0: connector.v1.ConfigureRequest.settings:type_name -> connector.v1.ConfigureRequest.SettingsEntry
25, // 1: connector.v1.ConfigureRequest.secrets:type_name -> connector.v1.ConfigureRequest.SecretsEntry 27, // 1: connector.v1.ConfigureRequest.secrets:type_name -> connector.v1.ConfigureRequest.SecretsEntry
5, // 2: connector.v1.DescribeResponse.events:type_name -> connector.v1.EventType 5, // 2: connector.v1.DescribeResponse.events:type_name -> connector.v1.EventType
6, // 3: connector.v1.DescribeResponse.actions:type_name -> connector.v1.ActionType 6, // 3: connector.v1.DescribeResponse.actions:type_name -> connector.v1.ActionType
8, // 4: connector.v1.DescribeResponse.lookups:type_name -> connector.v1.LookupType 8, // 4: connector.v1.DescribeResponse.lookups:type_name -> connector.v1.LookupType
7, // 5: connector.v1.DescribeResponse.deliveries:type_name -> connector.v1.DeliveryType 7, // 5: connector.v1.DescribeResponse.deliveries:type_name -> connector.v1.DeliveryType
9, // 6: connector.v1.ActionType.effect:type_name -> connector.v1.Effect 9, // 6: connector.v1.ActionType.effect:type_name -> connector.v1.Effect
0, // 7: connector.v1.Effect.reversibility:type_name -> connector.v1.Reversibility 0, // 7: connector.v1.Effect.reversibility:type_name -> connector.v1.Reversibility
26, // 8: connector.v1.ParseRequest.headers:type_name -> connector.v1.ParseRequest.HeadersEntry 28, // 8: connector.v1.ParseRequest.headers:type_name -> connector.v1.ParseRequest.HeadersEntry
13, // 9: connector.v1.ParseResponse.events:type_name -> connector.v1.Event 13, // 9: connector.v1.ParseResponse.events:type_name -> connector.v1.Event
27, // 10: connector.v1.Event.occurred_at:type_name -> google.protobuf.Timestamp 29, // 10: connector.v1.Event.occurred_at:type_name -> google.protobuf.Timestamp
10, // 11: connector.v1.ResolveResponse.target:type_name -> connector.v1.Target 10, // 11: connector.v1.ResolveResponse.target:type_name -> connector.v1.Target
9, // 12: connector.v1.ResolveResponse.effect:type_name -> connector.v1.Effect 9, // 12: connector.v1.ResolveResponse.effect:type_name -> connector.v1.Effect
13, // 13: connector.v1.ListenResponse.events:type_name -> connector.v1.Event 10, // 13: connector.v1.TargetFactsRequest.target:type_name -> connector.v1.Target
1, // 14: connector.v1.ConnectorService.Configure:input_type -> connector.v1.ConfigureRequest 13, // 14: connector.v1.ListenResponse.events:type_name -> connector.v1.Event
3, // 15: connector.v1.ConnectorService.Describe:input_type -> connector.v1.DescribeRequest 1, // 15: connector.v1.ConnectorService.Configure:input_type -> connector.v1.ConfigureRequest
11, // 16: connector.v1.ConnectorService.Parse:input_type -> connector.v1.ParseRequest 3, // 16: connector.v1.ConnectorService.Describe:input_type -> connector.v1.DescribeRequest
14, // 17: connector.v1.ConnectorService.Resolve:input_type -> connector.v1.ResolveRequest 11, // 17: connector.v1.ConnectorService.Parse:input_type -> connector.v1.ParseRequest
16, // 18: connector.v1.ConnectorService.Invoke:input_type -> connector.v1.InvokeRequest 14, // 18: connector.v1.ConnectorService.Resolve:input_type -> connector.v1.ResolveRequest
18, // 19: connector.v1.ConnectorService.Lookup:input_type -> connector.v1.LookupRequest 16, // 19: connector.v1.ConnectorService.Invoke:input_type -> connector.v1.InvokeRequest
20, // 20: connector.v1.ConnectorService.Deliver:input_type -> connector.v1.DeliverRequest 18, // 20: connector.v1.ConnectorService.Lookup:input_type -> connector.v1.LookupRequest
22, // 21: connector.v1.ConnectorService.Listen:input_type -> connector.v1.ListenRequest 20, // 21: connector.v1.ConnectorService.Deliver:input_type -> connector.v1.DeliverRequest
2, // 22: connector.v1.ConnectorService.Configure:output_type -> connector.v1.ConfigureResponse 24, // 22: connector.v1.ConnectorService.Listen:input_type -> connector.v1.ListenRequest
4, // 23: connector.v1.ConnectorService.Describe:output_type -> connector.v1.DescribeResponse 22, // 23: connector.v1.ConnectorService.TargetFacts:input_type -> connector.v1.TargetFactsRequest
12, // 24: connector.v1.ConnectorService.Parse:output_type -> connector.v1.ParseResponse 2, // 24: connector.v1.ConnectorService.Configure:output_type -> connector.v1.ConfigureResponse
15, // 25: connector.v1.ConnectorService.Resolve:output_type -> connector.v1.ResolveResponse 4, // 25: connector.v1.ConnectorService.Describe:output_type -> connector.v1.DescribeResponse
17, // 26: connector.v1.ConnectorService.Invoke:output_type -> connector.v1.InvokeResponse 12, // 26: connector.v1.ConnectorService.Parse:output_type -> connector.v1.ParseResponse
19, // 27: connector.v1.ConnectorService.Lookup:output_type -> connector.v1.LookupResponse 15, // 27: connector.v1.ConnectorService.Resolve:output_type -> connector.v1.ResolveResponse
21, // 28: connector.v1.ConnectorService.Deliver:output_type -> connector.v1.DeliverResponse 17, // 28: connector.v1.ConnectorService.Invoke:output_type -> connector.v1.InvokeResponse
23, // 29: connector.v1.ConnectorService.Listen:output_type -> connector.v1.ListenResponse 19, // 29: connector.v1.ConnectorService.Lookup:output_type -> connector.v1.LookupResponse
22, // [22:30] is the sub-list for method output_type 21, // 30: connector.v1.ConnectorService.Deliver:output_type -> connector.v1.DeliverResponse
14, // [14:22] is the sub-list for method input_type 25, // 31: connector.v1.ConnectorService.Listen:output_type -> connector.v1.ListenResponse
14, // [14:14] is the sub-list for extension type_name 23, // 32: connector.v1.ConnectorService.TargetFacts:output_type -> connector.v1.TargetFactsResponse
14, // [14:14] is the sub-list for extension extendee 24, // [24:33] is the sub-list for method output_type
0, // [0:14] is the sub-list for field type_name 15, // [15:24] is the sub-list for method input_type
15, // [15:15] is the sub-list for extension type_name
15, // [15:15] is the sub-list for extension extendee
0, // [0:15] is the sub-list for field type_name
} }
func init() { file_connector_v1_connector_proto_init() } func init() { file_connector_v1_connector_proto_init() }
@@ -1614,7 +1755,7 @@ func file_connector_v1_connector_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_connector_v1_connector_proto_rawDesc), len(file_connector_v1_connector_proto_rawDesc)), RawDescriptor: unsafe.Slice(unsafe.StringData(file_connector_v1_connector_proto_rawDesc), len(file_connector_v1_connector_proto_rawDesc)),
NumEnums: 1, NumEnums: 1,
NumMessages: 26, NumMessages: 28,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },
@@ -19,14 +19,15 @@ import (
const _ = grpc.SupportPackageIsVersion9 const _ = grpc.SupportPackageIsVersion9
const ( const (
ConnectorService_Configure_FullMethodName = "/connector.v1.ConnectorService/Configure" ConnectorService_Configure_FullMethodName = "/connector.v1.ConnectorService/Configure"
ConnectorService_Describe_FullMethodName = "/connector.v1.ConnectorService/Describe" ConnectorService_Describe_FullMethodName = "/connector.v1.ConnectorService/Describe"
ConnectorService_Parse_FullMethodName = "/connector.v1.ConnectorService/Parse" ConnectorService_Parse_FullMethodName = "/connector.v1.ConnectorService/Parse"
ConnectorService_Resolve_FullMethodName = "/connector.v1.ConnectorService/Resolve" ConnectorService_Resolve_FullMethodName = "/connector.v1.ConnectorService/Resolve"
ConnectorService_Invoke_FullMethodName = "/connector.v1.ConnectorService/Invoke" ConnectorService_Invoke_FullMethodName = "/connector.v1.ConnectorService/Invoke"
ConnectorService_Lookup_FullMethodName = "/connector.v1.ConnectorService/Lookup" ConnectorService_Lookup_FullMethodName = "/connector.v1.ConnectorService/Lookup"
ConnectorService_Deliver_FullMethodName = "/connector.v1.ConnectorService/Deliver" ConnectorService_Deliver_FullMethodName = "/connector.v1.ConnectorService/Deliver"
ConnectorService_Listen_FullMethodName = "/connector.v1.ConnectorService/Listen" ConnectorService_Listen_FullMethodName = "/connector.v1.ConnectorService/Listen"
ConnectorService_TargetFacts_FullMethodName = "/connector.v1.ConnectorService/TargetFacts"
) )
// ConnectorServiceClient is the client API for ConnectorService service. // ConnectorServiceClient is the client API for ConnectorService service.
@@ -65,6 +66,11 @@ type ConnectorServiceClient interface {
// carries the cursor to resume after its events, which the host keeps only // carries the cursor to resume after its events, which the host keeps only
// once those events are stored. // once those events are stored.
Listen(ctx context.Context, in *ListenRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[ListenResponse], error) Listen(ctx context.Context, in *ListenRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[ListenResponse], error)
// TargetFacts answers what the connector's system of record knows about a
// target, such as who owns it, at the moment an action on it is judged. The
// host asks only connectors that declare target_facts, and never stores the
// answer.
TargetFacts(ctx context.Context, in *TargetFactsRequest, opts ...grpc.CallOption) (*TargetFactsResponse, error)
} }
type connectorServiceClient struct { type connectorServiceClient struct {
@@ -164,6 +170,16 @@ func (c *connectorServiceClient) Listen(ctx context.Context, in *ListenRequest,
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. // This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type ConnectorService_ListenClient = grpc.ServerStreamingClient[ListenResponse] type ConnectorService_ListenClient = grpc.ServerStreamingClient[ListenResponse]
func (c *connectorServiceClient) TargetFacts(ctx context.Context, in *TargetFactsRequest, opts ...grpc.CallOption) (*TargetFactsResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(TargetFactsResponse)
err := c.cc.Invoke(ctx, ConnectorService_TargetFacts_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// ConnectorServiceServer is the server API for ConnectorService service. // ConnectorServiceServer is the server API for ConnectorService service.
// All implementations must embed UnimplementedConnectorServiceServer // All implementations must embed UnimplementedConnectorServiceServer
// for forward compatibility. // for forward compatibility.
@@ -200,6 +216,11 @@ type ConnectorServiceServer interface {
// carries the cursor to resume after its events, which the host keeps only // carries the cursor to resume after its events, which the host keeps only
// once those events are stored. // once those events are stored.
Listen(*ListenRequest, grpc.ServerStreamingServer[ListenResponse]) error Listen(*ListenRequest, grpc.ServerStreamingServer[ListenResponse]) error
// TargetFacts answers what the connector's system of record knows about a
// target, such as who owns it, at the moment an action on it is judged. The
// host asks only connectors that declare target_facts, and never stores the
// answer.
TargetFacts(context.Context, *TargetFactsRequest) (*TargetFactsResponse, error)
mustEmbedUnimplementedConnectorServiceServer() mustEmbedUnimplementedConnectorServiceServer()
} }
@@ -234,6 +255,9 @@ func (UnimplementedConnectorServiceServer) Deliver(context.Context, *DeliverRequ
func (UnimplementedConnectorServiceServer) Listen(*ListenRequest, grpc.ServerStreamingServer[ListenResponse]) error { func (UnimplementedConnectorServiceServer) Listen(*ListenRequest, grpc.ServerStreamingServer[ListenResponse]) error {
return status.Error(codes.Unimplemented, "method Listen not implemented") return status.Error(codes.Unimplemented, "method Listen not implemented")
} }
func (UnimplementedConnectorServiceServer) TargetFacts(context.Context, *TargetFactsRequest) (*TargetFactsResponse, error) {
return nil, status.Error(codes.Unimplemented, "method TargetFacts not implemented")
}
func (UnimplementedConnectorServiceServer) mustEmbedUnimplementedConnectorServiceServer() {} func (UnimplementedConnectorServiceServer) mustEmbedUnimplementedConnectorServiceServer() {}
func (UnimplementedConnectorServiceServer) testEmbeddedByValue() {} func (UnimplementedConnectorServiceServer) testEmbeddedByValue() {}
@@ -392,6 +416,24 @@ func _ConnectorService_Listen_Handler(srv interface{}, stream grpc.ServerStream)
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. // This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type ConnectorService_ListenServer = grpc.ServerStreamingServer[ListenResponse] type ConnectorService_ListenServer = grpc.ServerStreamingServer[ListenResponse]
func _ConnectorService_TargetFacts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(TargetFactsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ConnectorServiceServer).TargetFacts(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: ConnectorService_TargetFacts_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ConnectorServiceServer).TargetFacts(ctx, req.(*TargetFactsRequest))
}
return interceptor(ctx, in, info, handler)
}
// ConnectorService_ServiceDesc is the grpc.ServiceDesc for ConnectorService service. // ConnectorService_ServiceDesc is the grpc.ServiceDesc for ConnectorService service.
// It's only intended for direct use with grpc.RegisterService, // It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy) // and not to be introspected or modified (even as a copy)
@@ -427,6 +469,10 @@ var ConnectorService_ServiceDesc = grpc.ServiceDesc{
MethodName: "Deliver", MethodName: "Deliver",
Handler: _ConnectorService_Deliver_Handler, Handler: _ConnectorService_Deliver_Handler,
}, },
{
MethodName: "TargetFacts",
Handler: _ConnectorService_TargetFacts_Handler,
},
}, },
Streams: []grpc.StreamDesc{ Streams: []grpc.StreamDesc{
{ {
+1 -1
View File
@@ -435,7 +435,7 @@ func mayAnswer(who governance.Verified, row store.Request) error {
return ErrNoAuthority return ErrNoAuthority
case row.Kind == KindRaise: case row.Kind == KindRaise:
return nil return nil
case !who.Approver: case !who.Approver && !slices.Contains(askedOf(row), who.ID):
return ErrNotApprover return ErrNotApprover
case row.Level == judgement.Escalate.String() && !who.Authority: case row.Level == judgement.Escalate.String() && !who.Authority:
return ErrNeedsAuthority return ErrNeedsAuthority
+1
View File
@@ -45,6 +45,7 @@ func TestVerifyAcceptsAnAnswerOnlyFromAPersonWhoMayGiveIt(t *testing.T) {
{name: "an unmapped identity is refused", identity: "telegram:9999", row: action(propose, "owner"), wantErr: ErrUnverified}, {name: "an unmapped identity is refused", identity: "telegram:9999", row: action(propose, "owner"), wantErr: ErrUnverified},
{name: "an unmapped identity can't answer a raise", identity: "telegram:9999", row: store.Request{Kind: KindRaise}, wantErr: ErrUnverified}, {name: "an unmapped identity can't answer a raise", identity: "telegram:9999", row: store.Request{Kind: KindRaise}, wantErr: ErrUnverified},
{name: "a person who isn't an approver is refused an action", identity: "telegram:1003", row: action(propose, "owner"), wantErr: ErrNotApprover}, {name: "a person who isn't an approver is refused an action", identity: "telegram:1003", row: action(propose, "owner"), wantErr: ErrNotApprover},
{name: "the target's owner answers when the request was put to them", identity: "telegram:1003", row: action(propose, "bystander")},
{name: "an approver without authority is refused a raise", identity: "telegram:1001", row: store.Request{Kind: KindRaise}, wantErr: ErrNoAuthority}, {name: "an approver without authority is refused a raise", identity: "telegram:1001", row: store.Request{Kind: KindRaise}, wantErr: ErrNoAuthority},
{name: "authority answers a raise", identity: "telegram:1002", row: store.Request{Kind: KindRaise}}, {name: "authority answers a raise", identity: "telegram:1002", row: store.Request{Kind: KindRaise}},
{name: "a person on the path is refused until the request reaches them", identity: "telegram:1004", row: action(propose, "owner"), wantErr: ErrNotAsked}, {name: "a person on the path is refused until the request reaches them", identity: "telegram:1004", row: action(propose, "owner"), wantErr: ErrNotAsked},
+32
View File
@@ -136,6 +136,8 @@ type Connector struct {
// agent. // agent.
deliveries map[string]*jsonschema.Resolved deliveries map[string]*jsonschema.Resolved
listens bool listens bool
// facts says it answers TargetFacts.
facts bool
} }
// open configures a connector and reads its declaration. // open configures a connector and reads its declaration.
@@ -157,6 +159,7 @@ func open(ctx context.Context, name string, client pb.ConnectorServiceClient, se
lookups: map[string]lookup{}, lookups: map[string]lookup{},
deliveries: map[string]*jsonschema.Resolved{}, deliveries: map[string]*jsonschema.Resolved{},
listens: desc.GetListens(), listens: desc.GetListens(),
facts: desc.GetTargetFacts(),
} }
return c, c.load(desc) return c, c.load(desc)
} }
@@ -246,6 +249,35 @@ func (c *Connector) Listen(ctx context.Context, cursor string, store func(events
} }
} }
// TargetFacts is what a connector's system of record knows about a target.
// A zero field is a fact it doesn't hold.
type TargetFacts struct {
// OwnerIdentity is who answers for the target, such as "servicenow:jdoe".
OwnerIdentity string
DataClass string
Count int
}
// TargetFacts asks the connector what it knows about t. A connector that
// doesn't serve target facts, or has no record of t, supplies none.
func (c *Connector) TargetFacts(ctx context.Context, t Target) (TargetFacts, error) {
if !c.facts {
return TargetFacts{}, nil
}
resp, err := c.client.TargetFacts(ctx, &pb.TargetFactsRequest{Target: &pb.Target{
Kind: t.Kind, Id: t.ID, Environment: t.Environment, Disposable: t.Disposable,
}})
if err != nil {
return TargetFacts{}, fmt.Errorf("connector %q: target facts: %w", c.name, err)
}
if !resp.GetFound() {
return TargetFacts{}, nil
}
return TargetFacts{
OwnerIdentity: resp.GetOwnerIdentity(), DataClass: resp.GetDataClass(), Count: int(resp.GetCount()),
}, nil
}
// Declarations lists the connector's lookups and actions in name order. // Declarations lists the connector's lookups and actions in name order.
func (c *Connector) Declarations() []Declaration { func (c *Connector) Declarations() []Declaration {
out := make([]Declaration, 0, len(c.lookups)+len(c.actions)) out := make([]Declaration, 0, len(c.lookups)+len(c.actions))
+25
View File
@@ -132,6 +132,31 @@ func (m *Module) Tool(name string) (Tool, bool) {
return s, ok return s, ok
} }
// TargetFacts asks every running connector that serves target facts what it
// knows about t, now, and keeps nothing. Connectors are asked in name order and
// the first to supply a fact wins it.
func (m *Module) TargetFacts(ctx context.Context, t Target) (TargetFacts, error) {
m.mu.RLock()
asked := make([]*Connector, 0, len(m.running))
for _, name := range slices.Sorted(maps.Keys(m.running)) {
if c := m.running[name]; c.facts {
asked = append(asked, c)
}
}
m.mu.RUnlock()
var out TargetFacts
for _, c := range asked {
got, err := c.TargetFacts(ctx, t)
if err != nil {
return TargetFacts{}, err
}
out.OwnerIdentity = cmp.Or(out.OwnerIdentity, got.OwnerIdentity)
out.DataClass = cmp.Or(out.DataClass, got.DataClass)
out.Count = cmp.Or(out.Count, got.Count)
}
return out, nil
}
// Guards lists the running guard extensions in name order. // Guards lists the running guard extensions in name order.
func (m *Module) Guards() []*Guard { func (m *Module) Guards() []*Guard {
m.mu.RLock() m.mu.RLock()
+34 -13
View File
@@ -9,8 +9,9 @@ import (
) )
// PathStep is one stop on the route an unanswered approval request takes: who // PathStep is one stop on the route an unanswered approval request takes: who
// it is passed to, and how long it waits there. The first step is the default // it is passed to, and how long it waits there. The first step is the target's
// owner, who may be nobody, and anyone with authority. // owner when there is one, otherwise the default owner, who may be nobody, and
// then anyone with authority.
type PathStep struct { type PathStep struct {
// Person is the id of the person asked at this step, or empty. // Person is the id of the person asked at this step, or empty.
Person string `json:"person"` Person string `json:"person"`
@@ -21,11 +22,23 @@ type PathStep struct {
// Deadline is how long the request waits at this step. // Deadline is how long the request waits at this step.
func (p PathStep) Deadline() time.Duration { return time.Duration(p.DeadlineMS) * time.Millisecond } func (p PathStep) Deadline() time.Duration { return time.Duration(p.DeadlineMS) * time.Millisecond }
// EscalationPath returns the route an approval request takes, with its first // HasDefaultOwner reports whether the organisation has a default owner.
// step the default owner and every later step a person on the escalation path. func (m *Module) HasDefaultOwner(ctx context.Context) (bool, error) {
// When the action needs authority, a step held by someone without it is left set, err := m.Settings(ctx)
// out, so the request never moves to a person who could not answer it. if err != nil {
func (m *Module) EscalationPath(ctx context.Context, needAuthority bool) ([]PathStep, error) { return false, err
}
return set.DefaultOwner != "", nil
}
// EscalationPath returns the route an approval request takes. owner is the
// person who answers for the action's target, or empty when none is known. A
// known owner is asked first and the default owner is the next step; an unknown
// owner leaves the default owner first. Every later step is a person on the
// escalation path. When the action needs authority, a step held by someone
// without it is left out, so the request never moves to a person who could not
// answer it.
func (m *Module) EscalationPath(ctx context.Context, owner string, needAuthority bool) ([]PathStep, error) {
set, err := m.Settings(ctx) set, err := m.Settings(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -34,10 +47,10 @@ func (m *Module) EscalationPath(ctx context.Context, needAuthority bool) ([]Path
if err != nil { if err != nil {
return nil, err return nil, err
} }
return set.path(people, needAuthority), nil return set.path(people, owner, needAuthority), nil
} }
func (s Settings) path(people []store.Person, needAuthority bool) []PathStep { func (s Settings) path(people []store.Person, owner string, needAuthority bool) []PathStep {
find := func(id string) (store.Person, bool) { find := func(id string) (store.Person, bool) {
i := slices.IndexFunc(people, func(p store.Person) bool { return p.ID.String() == id }) i := slices.IndexFunc(people, func(p store.Person) bool { return p.ID.String() == id })
if i < 0 { if i < 0 {
@@ -45,14 +58,22 @@ func (s Settings) path(people []store.Person, needAuthority bool) []PathStep {
} }
return people[i], true return people[i], true
} }
first := PathStep{Person: s.DefaultOwner, DeadlineMS: s.ApprovalDeadline.Milliseconds()} defaultOwner := PathStep{Person: s.DefaultOwner, DeadlineMS: s.ApprovalDeadline.Milliseconds()}
if p, ok := find(s.DefaultOwner); ok { if p, ok := find(s.DefaultOwner); ok {
first.Name = p.Name defaultOwner.Name = p.Name
}
var out []PathStep
if p, ok := find(owner); ok && owner != "" && (p.Authority || !needAuthority) {
out = append(out, PathStep{Person: owner, Name: p.Name, DeadlineMS: s.ApprovalDeadline.Milliseconds()})
}
// With no owner to ask, the default owner leads even when nobody is set,
// so the request still goes to anyone who may answer it.
if len(out) == 0 || (s.DefaultOwner != "" && s.DefaultOwner != owner) {
out = append(out, defaultOwner)
} }
out := []PathStep{first}
for _, st := range s.Escalation { for _, st := range s.Escalation {
p, ok := find(st.Person) p, ok := find(st.Person)
if !ok || (needAuthority && !p.Authority) { if !ok || (needAuthority && !p.Authority) || slices.ContainsFunc(out, func(o PathStep) bool { return o.Person == st.Person }) {
continue continue
} }
out = append(out, PathStep{Person: st.Person, Name: p.Name, DeadlineMS: st.Deadline.Milliseconds()}) out = append(out, PathStep{Person: st.Person, Name: p.Name, DeadlineMS: st.Deadline.Milliseconds()})
+17 -2
View File
@@ -12,7 +12,8 @@ import (
// TestPathNeverDropsBelowTheAuthorityTheActionNeeds guards the escalation // TestPathNeverDropsBelowTheAuthorityTheActionNeeds guards the escalation
// path: an action that needs authority is never passed to a person without // path: an action that needs authority is never passed to a person without
// it, however the path is set, and every step keeps its own deadline. // it, however the path is set, every step keeps its own deadline, and a target's
// known owner is asked before the default owner, which an unknown owner leaves first.
func TestPathNeverDropsBelowTheAuthorityTheActionNeeds(t *testing.T) { func TestPathNeverDropsBelowTheAuthorityTheActionNeeds(t *testing.T) {
owner := store.Person{ID: uuid.New(), Name: "Owner"} owner := store.Person{ID: uuid.New(), Name: "Owner"}
peer := store.Person{ID: uuid.New(), Name: "Peer"} peer := store.Person{ID: uuid.New(), Name: "Peer"}
@@ -28,6 +29,8 @@ func TestPathNeverDropsBelowTheAuthorityTheActionNeeds(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
needAuthority bool needAuthority bool
// target is the person who answers for the action's target.
target string
want []string want []string
wantDeadlines []time.Duration wantDeadlines []time.Duration
}{ }{
@@ -39,12 +42,24 @@ func TestPathNeverDropsBelowTheAuthorityTheActionNeeds(t *testing.T) {
name: "an action that needs authority skips a step without it", needAuthority: true, name: "an action that needs authority skips a step without it", needAuthority: true,
want: []string{"Owner", "Lead"}, wantDeadlines: []time.Duration{time.Hour, 3 * time.Hour}, want: []string{"Owner", "Lead"}, wantDeadlines: []time.Duration{time.Hour, 3 * time.Hour},
}, },
{
name: "the target's owner is asked first, then the default owner and the path", target: peer.ID.String(),
want: []string{"Peer", "Owner", "Lead"}, wantDeadlines: []time.Duration{time.Hour, time.Hour, 3 * time.Hour},
},
{
name: "a target owner without the authority an action needs is not asked", target: peer.ID.String(), needAuthority: true,
want: []string{"Owner", "Lead"}, wantDeadlines: []time.Duration{time.Hour, 3 * time.Hour},
},
{
name: "a target owner nobody knows leaves the default owner first", target: uuid.NewString(),
want: []string{"Owner", "Peer", "Lead"}, wantDeadlines: []time.Duration{time.Hour, 2 * time.Hour, 3 * time.Hour},
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
var names []string var names []string
var deadlines []time.Duration var deadlines []time.Duration
for _, st := range set.path(people, tt.needAuthority) { for _, st := range set.path(people, tt.target, tt.needAuthority) {
names = append(names, st.Name) names = append(names, st.Name)
deadlines = append(deadlines, st.Deadline()) deadlines = append(deadlines, st.Deadline())
} }
+12 -1
View File
@@ -24,7 +24,8 @@ type Verified struct {
Authority bool Authority bool
// Approver is whether the person may answer an approval for an action: // Approver is whether the person may answer an approval for an action:
// they hold authority, are the default owner, or are on the escalation // they hold authority, are the default owner, or are on the escalation
// path. // path. A person a request was put to as the target's owner may answer
// it without.
Approver bool Approver bool
} }
@@ -45,6 +46,16 @@ func (m *Module) Verify(ctx context.Context, identity string) (Verified, bool, e
return Verified{ID: id, Name: p.Name, Authority: p.Authority, Approver: approver}, true, nil return Verified{ID: id, Name: p.Name, Authority: p.Authority, Approver: approver}, true, nil
} }
// PersonID returns the id of the person who holds identity; ok is false when
// nobody does.
func (m *Module) PersonID(ctx context.Context, identity string) (string, bool, error) {
p, ok, err := m.store.PersonByIdentity(ctx, m.orgID, identity)
if err != nil || !ok {
return "", false, err
}
return p.ID.String(), true, nil
}
// personRequest is a person as the API shows and sets them. An empty id is a // personRequest is a person as the API shows and sets them. An empty id is a
// new person. // new person.
type personRequest struct { type personRequest struct {
+47
View File
@@ -0,0 +1,47 @@
package judgement
import (
"context"
"fmt"
"github.com/samcharles93/archie-core/modules/connectors"
)
// FactsSource answers what the connectors' systems of record know about a
// target, at the moment it is asked.
type FactsSource interface {
TargetFacts(ctx context.Context, t connectors.Target) (connectors.TargetFacts, error)
}
// Identities says which person holds an identity, such as "servicenow:jdoe".
type Identities interface {
PersonID(ctx context.Context, identity string) (id string, ok bool, err error)
}
// RecordedFacts looks a target's facts up in the connectors each time and
// keeps none. The owner a connector names counts only when the identity is a
// person Archie knows, so the request can be put to them.
type RecordedFacts struct {
Source FactsSource
People Identities
}
// Facts asks the connectors about t and maps the owner they name to a person.
func (r RecordedFacts) Facts(ctx context.Context, t connectors.Target) (TargetFacts, error) {
got, err := r.Source.TargetFacts(ctx, t)
if err != nil {
return TargetFacts{}, fmt.Errorf("ask connectors: %w", err)
}
facts := TargetFacts{Count: got.Count, DataClass: got.DataClass, OwnerIdentity: got.OwnerIdentity}
if got.OwnerIdentity == "" {
return facts, nil
}
id, ok, err := r.People.PersonID(ctx, got.OwnerIdentity)
if err != nil {
return TargetFacts{}, fmt.Errorf("match owner %s: %w", got.OwnerIdentity, err)
}
if ok {
facts.Owner = id
}
return facts, nil
}
+48 -10
View File
@@ -15,8 +15,18 @@ type TargetFacts struct {
Count int Count int
// DataClass names what the target holds, such as "temp" or "customer". // DataClass names what the target holds, such as "temp" or "customer".
DataClass string DataClass string
// Owner is who answers for the target. // Owner is the id of the person who answers for the target, empty when the
// target has no recorded owner or the owner isn't a person Archie knows.
Owner string Owner string
// OwnerIdentity is the owner as the source recorded them, kept so a finding
// can say who couldn't be matched to a person.
OwnerIdentity string
}
// DefaultOwners says whether the organisation has a default owner, who is
// asked when a target's owner is unknown.
type DefaultOwners interface {
HasDefaultOwner(ctx context.Context) (bool, error)
} }
// TargetLookup supplies the facts the target's own declaration lacks. // TargetLookup supplies the facts the target's own declaration lacks.
@@ -24,15 +34,6 @@ type TargetLookup interface {
Facts(ctx context.Context, t connectors.Target) (TargetFacts, error) Facts(ctx context.Context, t connectors.Target) (TargetFacts, error)
} }
// NoTargetFacts knows nothing about any target, so Impact holds every changing
// action until a connector lookup supplies the data.
type NoTargetFacts struct{}
// Facts returns no facts.
func (NoTargetFacts) Facts(context.Context, connectors.Target) (TargetFacts, error) {
return TargetFacts{}, nil
}
const ( const (
environmentProduction = "production" environmentProduction = "production"
dataTemp = "temp" dataTemp = "temp"
@@ -49,6 +50,9 @@ var lowRiskData = []string{dataTemp, dataCache, dataNone}
// them. A datum nobody supplied holds the action at propose and wait. // them. A datum nobody supplied holds the action at propose and wait.
type Impact struct { type Impact struct {
Lookup TargetLookup Lookup TargetLookup
// Defaults, when set, lets an unknown owner's finding say that no default
// owner is set to take the request.
Defaults DefaultOwners
} }
// Name is the guard's name in verdicts. // Name is the guard's name in verdicts.
@@ -66,9 +70,24 @@ func (i Impact) Judge(ctx context.Context, a Action) (Verdict, error) {
if err != nil { if err != nil {
return Verdict{}, fmt.Errorf("look up target facts: %w", err) return Verdict{}, fmt.Errorf("look up target facts: %w", err)
} }
v, err := i.verdict(ctx, a, facts)
v.Owner = facts.Owner
return v, err
}
// verdict folds the facts into a ceiling.
func (i Impact) verdict(ctx context.Context, a Action, facts TargetFacts) (Verdict, error) {
if missing := missingImpactData(a.Target, facts); len(missing) > 0 { if missing := missingImpactData(a.Target, facts); len(missing) > 0 {
v := Verdict{Ceiling: ProposeAndWait, BlindSpots: missing} v := Verdict{Ceiling: ProposeAndWait, BlindSpots: missing}
for _, m := range missing { for _, m := range missing {
if m == "owner" {
text, err := i.unknownOwner(ctx, facts)
if err != nil {
return Verdict{}, err
}
v.Findings = append(v.Findings, Finding{Text: text})
continue
}
v.Findings = append(v.Findings, Finding{Text: "no " + m + " is known for the target"}) v.Findings = append(v.Findings, Finding{Text: "no " + m + " is known for the target"})
} }
return v, nil return v, nil
@@ -84,6 +103,25 @@ func (i Impact) Judge(ctx context.Context, a Action) (Verdict, error) {
return Verdict{Ceiling: ActQuietly}, nil return Verdict{Ceiling: ActQuietly}, nil
} }
// unknownOwner words the finding for a target nobody is known to own, and says
// where the request goes instead.
func (i Impact) unknownOwner(ctx context.Context, f TargetFacts) (string, error) {
text := "unknown owner: no owner is recorded for the target"
if f.OwnerIdentity != "" {
text = fmt.Sprintf("unknown owner: %s isn't a person Archie knows", f.OwnerIdentity)
}
if i.Defaults != nil {
set, err := i.Defaults.HasDefaultOwner(ctx)
if err != nil {
return "", fmt.Errorf("read default owner: %w", err)
}
if !set {
return text + ", and no default owner is set", nil
}
}
return text + ", so the request goes to the default owner", nil
}
// missingImpactData names what Impact needs and doesn't have. // missingImpactData names what Impact needs and doesn't have.
func missingImpactData(t connectors.Target, f TargetFacts) []string { func missingImpactData(t connectors.Target, f TargetFacts) []string {
var missing []string var missing []string
+15
View File
@@ -84,6 +84,9 @@ type Verdict struct {
// Failed says why the guard couldn't answer; its ceiling is then // Failed says why the guard couldn't answer; its ceiling is then
// propose and wait. // propose and wait.
Failed string `json:"failed,omitzero"` Failed string `json:"failed,omitzero"`
// Owner is the id of the person the impact guard found answering for the
// target, empty when it found none.
Owner string `json:"owner,omitzero"`
} }
// Guard judges one concrete action. // Guard judges one concrete action.
@@ -120,6 +123,18 @@ type Decision struct {
At time.Time `json:"at"` At time.Time `json:"at"`
} }
// Owner is the id of the person who answers for the decision's target, or empty
// when the impact guard found none. Only the built-in guard's word counts, so
// an extension can't name who is asked.
func (d Decision) Owner() string {
for _, v := range d.Verdicts {
if v.Guard == (Impact{}).Name() && v.Owner != "" {
return v.Owner
}
}
return ""
}
// Request asks for one action to be judged. Key identifies the attempt to run // Request asks for one action to be judged. Key identifies the attempt to run
// it: the same key is the same decision, so a replayed step never judges // it: the same key is the same decision, so a replayed step never judges
// twice. // twice.
+2 -2
View File
@@ -29,7 +29,7 @@ import (
// model it runs, and the escalation path an approval request takes. // model it runs, and the escalation path an approval request takes.
type Settings interface { type Settings interface {
AgentModel(ctx context.Context) (governance.Model, error) AgentModel(ctx context.Context) (governance.Model, error)
EscalationPath(ctx context.Context, needAuthority bool) ([]governance.PathStep, error) EscalationPath(ctx context.Context, owner string, needAuthority bool) ([]governance.PathStep, error)
RecurrenceThreshold(ctx context.Context) (int, error) RecurrenceThreshold(ctx context.Context) (int, error)
AttemptsPerRun(ctx context.Context) (int, error) AttemptsPerRun(ctx context.Context) (int, error)
} }
@@ -362,7 +362,7 @@ func settleOne(rc *Context, judge Judge, ask Approver, settings Settings, d judg
// the request as it stood when it settled, and the answer if there was one. // the request as it stood when it settled, and the answer if there was one.
func askThroughPath(rc *Context, ask Approver, settings Settings, d judgement.Decision) (approvals.Request, approvals.Answer, error) { func askThroughPath(rc *Context, ask Approver, settings Settings, d judgement.Decision) (approvals.Request, approvals.Answer, error) {
path, err := rc.Step("path:"+d.Key, func(ctx context.Context, _ string) ([]governance.PathStep, error) { path, err := rc.Step("path:"+d.Key, func(ctx context.Context, _ string) ([]governance.PathStep, error) {
return settings.EscalationPath(ctx, d.Level == judgement.Escalate) return settings.EscalationPath(ctx, d.Owner(), d.Level == judgement.Escalate)
}) })
if err != nil { if err != nil {
return approvals.Request{}, approvals.Answer{}, err return approvals.Request{}, approvals.Answer{}, err
+22
View File
@@ -36,6 +36,11 @@ service ConnectorService {
// carries the cursor to resume after its events, which the host keeps only // carries the cursor to resume after its events, which the host keeps only
// once those events are stored. // once those events are stored.
rpc Listen(ListenRequest) returns (stream ListenResponse); rpc Listen(ListenRequest) returns (stream ListenResponse);
// TargetFacts answers what the connector's system of record knows about a
// target, such as who owns it, at the moment an action on it is judged. The
// host asks only connectors that declare target_facts, and never stores the
// answer.
rpc TargetFacts(TargetFactsRequest) returns (TargetFactsResponse);
} }
message ConfigureRequest { message ConfigureRequest {
@@ -54,6 +59,8 @@ message DescribeResponse {
repeated DeliveryType deliveries = 5; repeated DeliveryType deliveries = 5;
// listens says the connector serves Listen. // listens says the connector serves Listen.
bool listens = 6; bool listens = 6;
// target_facts says the connector serves TargetFacts.
bool target_facts = 7;
} }
message EventType { message EventType {
@@ -179,6 +186,21 @@ message DeliverResponse {
string external_id = 1; string external_id = 1;
} }
message TargetFactsRequest {
Target target = 1;
}
message TargetFactsResponse {
// found is false when the connector has no record of the target.
bool found = 1;
// owner_identity is who answers for the target, as an identity on a channel
// or system, such as "servicenow:jdoe" or "email:jo@example.com".
string owner_identity = 2;
// data_class names what the target holds, such as "customer" or "temp".
string data_class = 3;
// count is how many things the target stands for, zero when unknown.
int32 count = 4;
}
message ListenRequest { message ListenRequest {
// cursor is the last cursor the host stored, empty from the start. // cursor is the last cursor the host stored, empty from the start.
string cursor = 1; string cursor = 1;