From b19cabfe4dfe7f062613e1555e5996ddd85376bc Mon Sep 17 00:00:00 2001 From: Nicole Hubbard Date: Tue, 18 Jul 2023 14:11:56 +0000 Subject: [PATCH] Add AuthRelationshipMessage type Signed-off-by: GitHub --- events/message.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/events/message.go b/events/message.go index db74abf..79137da 100644 --- a/events/message.go +++ b/events/message.go @@ -92,6 +92,26 @@ type EventMessage struct { Data map[string]interface{} `json:"data"` } +// AuthRelationshipMessage contains the data structure expected to be used to write or delete +// an auth relationship from PermissionsAPI +type AuthRelationshipMessage struct { + // ObjectID is the PrefixedID of the object the permissions will be granted on + ObjectID gidx.PrefixedID `json:"objectID"` + // RelationshipName is the relationship being created on the object for the subject + RelationshipName string `json:"relationshipName"` + // SubjectID is the PrefixedID of the object the permissions apply to + SubjectID gidx.PrefixedID `json:"subjectID"` + // ConditionName represents the name of a conditional check that will be applied to this relationship. (Optional) + // In SpiceDB this would be a caveat name + ConditionName string `json:"conditionName"` + // ConditionValues are the condition values to be used on the condition check. (Optional) + ConditionValues map[string]interface{} `json:"conditionValue"` + // TraceID is the ID of the trace for this event + TraceID string `json:"traceID"` + // SpanID is the ID of the span that additional traces should based off of + SpanID string `json:"spanID"` +} + // UnmarshalChangeMessage returns a ChangeMessage from a json []byte. func UnmarshalChangeMessage(b []byte) (ChangeMessage, error) { var c ChangeMessage @@ -107,3 +127,11 @@ func UnmarshalEventMessage(b []byte) (EventMessage, error) { return m, err } + +// UnmarshalAuthRelationshipMessage returns an AuthRelationshipMessage from a json []byte. +func UnmarshalAuthRelationshipMessage(b []byte) (AuthRelationshipMessage, error) { + var m AuthRelationshipMessage + err := json.Unmarshal(b, &m) + + return m, err +}