Skip to main content

gatekeep_keepsake/
target.rs

1use chrono::{DateTime, Utc};
2use gatekeep::{FactId, SubjectSlot};
3use keepsake::{CommandContext, RelationId, RevokeBySubject, SubjectRef};
4
5/// Resolved keepsake target for a gatekeep fact binding.
6#[derive(Clone, Debug, PartialEq, Eq)]
7pub struct KeepsakeRelationTarget {
8    /// Tenant containing the subject and relation.
9    pub tenant_id: keepsake::TenantId,
10    /// Gatekeep fact that maps to this keepsake relation target.
11    pub fact: FactId,
12    /// Keepsake subject used for relation lookups and lifecycle writes.
13    pub subject: SubjectRef,
14    /// Keepsake relation definition id.
15    pub relation_id: RelationId,
16    /// Request-scoped subject slot used by this target, when any.
17    pub subject_slot: Option<SubjectSlot>,
18}
19
20impl KeepsakeRelationTarget {
21    /// Builds a keepsake revoke-by-subject command for this target.
22    #[must_use]
23    pub fn revoke_by_subject(&self, at: DateTime<Utc>, context: CommandContext) -> RevokeBySubject {
24        RevokeBySubject::new(
25            self.tenant_id.clone(),
26            self.subject.clone(),
27            self.relation_id,
28            at,
29            context,
30        )
31    }
32}