Skip to content

Commit

Permalink
Add AuthRelationshipMessage type
Browse files Browse the repository at this point in the history
Signed-off-by: GitHub <noreply@github.com>
  • Loading branch information
nicolerenee committed Jul 18, 2023
1 parent de3c900 commit b19cabf
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions events/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

0 comments on commit b19cabf

Please sign in to comment.