Skip to main content

gatekeep_keepsake/
target.rs

1use gatekeep::{FactId, SubjectSlot};
2use keepsake::{CommandContext, RelationId, RevokeBySubject, SubjectRef};
3use time::OffsetDateTime;
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(
24        &self,
25        at: OffsetDateTime,
26        context: CommandContext,
27    ) -> RevokeBySubject {
28        RevokeBySubject::new(
29            self.tenant_id.clone(),
30            self.subject.clone(),
31            self.relation_id,
32            at,
33            context,
34        )
35    }
36}