reduct_base/msg/
token_api.rs

1// Copyright 2023 ReductSoftware UG
2// This Source Code Form is subject to the terms of the Mozilla Public
3//    License, v. 2.0. If a copy of the MPL was not distributed with this
4//    file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
6use chrono::{DateTime, Utc};
7use serde::{Deserialize, Serialize};
8
9/// Permissions for a token
10#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
11pub struct Permissions {
12    /// Full access to all buckets and tokens
13    #[serde(default)]
14    pub full_access: bool,
15    /// Read access to certain buckets
16    #[serde(default)]
17    pub read: Vec<String>,
18    /// Write access to certain buckets
19    #[serde(default)]
20    pub write: Vec<String>,
21}
22
23/// Token
24#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
25pub struct Token {
26    /// Unique token name
27    pub name: String,
28    /// Unique token value
29    pub value: String,
30    /// Creation time
31    pub created_at: DateTime<Utc>,
32    /// Permissions
33    pub permissions: Option<Permissions>,
34    /// Provisioned
35    pub is_provisioned: bool,
36}
37
38/// Response for created token
39#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
40pub struct TokenCreateResponse {
41    pub value: String,
42    pub created_at: DateTime<Utc>,
43}
44
45/// Token repository
46#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
47pub struct TokenList {
48    pub tokens: Vec<Token>,
49}