Skip to main content

mesa_dev/models/
admin.rs

1//! Admin / API key models.
2
3use serde::{Deserialize, Serialize};
4
5/// A permission scope for an API key.
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
7pub enum ApiKeyScope {
8    /// Read git data.
9    #[serde(rename = "git:read")]
10    GitRead,
11    /// Write git data.
12    #[serde(rename = "git:write")]
13    GitWrite,
14    /// Read repository metadata.
15    #[serde(rename = "repo:read")]
16    RepoRead,
17    /// Create repositories.
18    #[serde(rename = "repo:create")]
19    RepoCreate,
20    /// Delete repositories.
21    #[serde(rename = "repo:delete")]
22    RepoDelete,
23    /// Full admin access.
24    #[serde(rename = "admin")]
25    Admin,
26}
27
28/// Request body for creating an API key.
29#[derive(Debug, Clone, Serialize)]
30pub struct CreateApiKeyRequest {
31    /// Human-readable name for the key.
32    pub name: String,
33    /// Permission scopes.
34    pub scopes: Vec<ApiKeyScope>,
35}
36
37/// Response returned when an API key is created (includes the secret).
38#[derive(Debug, Clone, Deserialize)]
39pub struct ApiKeyCreated {
40    /// Key identifier.
41    pub id: String,
42    /// The secret key value (only returned at creation time).
43    pub key: String,
44    /// Human-readable name.
45    pub name: Option<String>,
46    /// Permission scopes.
47    pub scopes: Vec<ApiKeyScope>,
48    /// Creation timestamp.
49    pub created_at: String,
50}
51
52/// An existing API key (without the secret).
53#[derive(Debug, Clone, Deserialize)]
54pub struct ApiKey {
55    /// Key identifier.
56    pub id: String,
57    /// Human-readable name.
58    pub name: Option<String>,
59    /// Permission scopes.
60    pub scopes: Vec<ApiKeyScope>,
61    /// Last usage timestamp.
62    pub last_used_at: Option<String>,
63    /// Expiration timestamp.
64    pub expires_at: Option<String>,
65    /// Revocation timestamp.
66    pub revoked_at: Option<String>,
67    /// Creation timestamp.
68    pub created_at: String,
69}
70
71/// Response listing API keys.
72#[derive(Debug, Clone, Deserialize)]
73pub struct ListApiKeysResponse {
74    /// The API keys.
75    pub api_keys: Vec<ApiKey>,
76}