Skip to main content

fastly_api/models/
automation_token_create_request.rs

1/*
2 * Fastly API
3 *
4 * Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) 
5 *
6 */
7
8
9
10
11#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
12pub struct AutomationTokenCreateRequest {
13    /// The name of the token.
14    #[serde(rename = "name")]
15    pub name: String,
16    /// The role for the token. The `roles` field is the preferred way to assign roles. This field is supported for backwards compatibility with single-role tokens.
17    #[serde(rename = "role", skip_serializing_if = "Option::is_none")]
18    pub role: Option<Role>,
19    /// Array of role IDs to assign to the token. Use this field for tokens with multiple roles. When provided, this takes precedence over the `role` field. To get available role IDs, use [GET /roles](https://www.fastly.com/documentation/reference/api/account/roles/).
20    #[serde(rename = "roles", skip_serializing_if = "Option::is_none")]
21    pub roles: Option<Vec<String>>,
22    /// List of service IDs the token can access. Only used when `limit_services` is `true`.
23    #[serde(rename = "services", skip_serializing_if = "Option::is_none")]
24    pub services: Option<Vec<String>>,
25    /// When `true`, restricts the token to only the services specified in the `services` array. When `false` (default), the token has access to all services.
26    #[serde(rename = "limit_services", skip_serializing_if = "Option::is_none")]
27    pub limit_services: Option<bool>,
28    /// When `true` (default), restricts the token to only the workspaces specified in the `workspaces` array. When `false`, the token has access to all workspaces. Only applies to roles that support workspace access (such as Next-Gen WAF roles). For roles without workspace support, this field has no effect.
29    #[serde(rename = "limit_workspaces", skip_serializing_if = "Option::is_none")]
30    pub limit_workspaces: Option<bool>,
31    /// List of workspace IDs the token can access. Only used when `limit_workspaces` is `true` and the token has roles that support workspace access.
32    #[serde(rename = "workspaces", skip_serializing_if = "Option::is_none")]
33    pub workspaces: Option<Vec<String>>,
34    #[serde(rename = "scope", skip_serializing_if = "Option::is_none")]
35    pub scope: Option<Scope>,
36    /// A UTC timestamp of when the token will expire.
37    #[serde(rename = "expires_at")]
38    pub expires_at: Option<String>,
39    /// Indicates whether TLS access is enabled for the token. Only applicable when using the single-role `role` field. For tokens with multiple roles, assign TLS roles (`tls_admin` or `tls_viewer`) via the `roles` field instead.
40    #[serde(rename = "tls_access", skip_serializing_if = "Option::is_none")]
41    pub tls_access: Option<bool>,
42}
43
44impl AutomationTokenCreateRequest {
45    pub fn new(name: String, expires_at: Option<String>) -> AutomationTokenCreateRequest {
46        AutomationTokenCreateRequest {
47            name,
48            role: None,
49            roles: None,
50            services: None,
51            limit_services: None,
52            limit_workspaces: None,
53            workspaces: None,
54            scope: None,
55            expires_at,
56            tls_access: None,
57        }
58    }
59}
60
61/// The role for the token. The `roles` field is the preferred way to assign roles. This field is supported for backwards compatibility with single-role tokens.
62#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
63pub enum Role {
64    #[serde(rename = "engineer")]
65    Engineer,
66    #[serde(rename = "billing")]
67    Billing,
68    #[serde(rename = "user")]
69    User,
70}
71
72impl Default for Role {
73    fn default() -> Role {
74        Self::Engineer
75    }
76}
77/// 
78#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
79pub enum Scope {
80    #[serde(rename = "global")]
81    Global,
82    #[serde(rename = "global:read")]
83    Globalread,
84    #[serde(rename = "purge_all")]
85    PurgeAll,
86    #[serde(rename = "purge_select")]
87    PurgeSelect,
88}
89
90impl Default for Scope {
91    fn default() -> Scope {
92        Self::Global
93    }
94}
95