zlayer-types 0.14.0

Shared wire types for the ZLayer platform — API DTOs, OCI image references, and related serde types.
Documentation
//! Scoped access-token management DTOs.
//!
//! Request/response shapes for the token-management API, which mints
//! scoped, time-boxed bearer tokens (e.g. for CI runners / least-privilege
//! automation). The raw JWT is returned exactly once, in
//! [`CreateTokenResponse::token`].

use serde::{Deserialize, Serialize};

use crate::storage::TokenScope;

/// Request body for minting a scoped access token.
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct CreateTokenRequest {
    /// Human-friendly label for the token (e.g. `"ci-runner"`).
    pub name: String,

    /// Scopes to bake into the token. The caller may only request scopes that
    /// fall within their own authority.
    #[serde(default)]
    pub scopes: Vec<TokenScope>,

    /// Role claims to carry on the token. Only admins may request privileged
    /// roles (`admin`/`operator`); for least-privilege tokens this is empty.
    #[serde(default)]
    pub roles: Vec<String>,

    /// Time-to-live in seconds. Defaults to 1h and is hard-capped at 365d.
    #[serde(default)]
    pub ttl_secs: Option<u64>,
}

/// Response returned once at token creation.
///
/// The `token` field is the raw JWT and is never persisted nor returned again.
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct CreateTokenResponse {
    /// UUID identifier — also the JWT `jti` claim (the revocation handle).
    pub id: String,

    /// The raw JWT bearer token. Shown only once; store it securely.
    pub token: String,

    /// The human-friendly label echoed back from the request.
    pub name: String,

    /// The scopes baked into the token.
    pub scopes: Vec<TokenScope>,

    /// When the token expires.
    #[schema(value_type = String, example = "2026-04-15T12:00:00Z")]
    pub expires_at: chrono::DateTime<chrono::Utc>,
}