use std::time::Duration;
use ulid::Ulid;
use super::{Act, EntityType};
#[derive(Debug, Clone)]
pub struct IssueRequest {
pub sub: String,
pub client_id: String,
pub ttl: Duration,
pub jti: Option<Ulid>,
pub entity_type: Option<EntityType>,
pub admin: bool,
pub caps: Vec<String>,
pub act: Option<Act>,
pub cid: Option<String>,
pub sv: Option<u64>,
pub active_ppnum: Option<String>,
pub scopes: Vec<String>,
pub sid: Option<String>,
}
impl IssueRequest {
pub fn new(sub: impl Into<String>, client_id: impl Into<String>, ttl: Duration) -> Self {
Self {
sub: sub.into(),
client_id: client_id.into(),
ttl,
jti: None,
entity_type: None,
admin: false,
caps: Vec::new(),
act: None,
cid: None,
sv: None,
active_ppnum: None,
scopes: Vec::new(),
sid: None,
}
}
#[must_use]
pub fn with_jti(mut self, jti: Ulid) -> Self {
self.jti = Some(jti);
self
}
#[must_use]
pub fn with_entity_type(mut self, entity_type: EntityType) -> Self {
self.entity_type = Some(entity_type);
self
}
#[must_use]
pub fn with_admin(mut self, admin: bool) -> Self {
self.admin = admin;
self
}
#[must_use]
pub fn with_caps(mut self, caps: Vec<String>) -> Self {
self.caps = caps;
self
}
#[must_use]
pub fn with_act(mut self, act: Act) -> Self {
self.act = Some(act);
self
}
#[must_use]
pub fn with_credential_id(mut self, credential_id: impl Into<String>) -> Self {
self.cid = Some(credential_id.into());
self
}
#[must_use]
pub fn with_session_version(mut self, sv: u64) -> Self {
self.sv = Some(sv);
self
}
#[must_use]
pub fn with_active_ppnum(mut self, active_ppnum: impl Into<String>) -> Self {
self.active_ppnum = Some(active_ppnum.into());
self
}
#[must_use]
pub fn with_scopes(mut self, scopes: Vec<String>) -> Self {
self.scopes = scopes;
self
}
#[must_use]
pub fn with_sid(mut self, sid: impl Into<String>) -> Self {
self.sid = Some(sid.into());
self
}
}