use std::time::Duration;
use ulid::Ulid;
#[derive(Debug, Clone)]
pub struct IssueRequest {
pub sub: String,
pub client_id: String,
pub ttl: Duration,
pub jti: Option<Ulid>,
pub account_type: Option<String>,
pub admin: bool,
pub caps: Vec<String>,
pub delegator: Option<String>,
pub dlg_depth: u8,
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,
account_type: None,
admin: false,
caps: Vec::new(),
delegator: None,
dlg_depth: 0,
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_account_type(mut self, account_type: impl Into<String>) -> Self {
self.account_type = Some(account_type.into());
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_delegator(mut self, delegator: impl Into<String>) -> Self {
self.delegator = Some(delegator.into());
self
}
#[must_use]
pub fn with_dlg_depth(mut self, dlg_depth: u8) -> Self {
self.dlg_depth = dlg_depth;
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
}
}