Skip to main content

openstack_keystone_api_types/
scope.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5//     http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12//
13// SPDX-License-Identifier: Apache-2.0
14//! # Keystone Scope API types
15use derive_builder::Builder;
16use serde::{Deserialize, Serialize};
17use utoipa::ToSchema;
18use validator::{Validate, ValidationErrors};
19
20use crate::error::BuilderError;
21
22/// The authorization scope, including the system, a project, or a domain.
23///
24/// If multiple scopes are specified in the same request (e.g. project and
25/// domain or domain and system) an HTTP 400 Bad Request will be returned, as a
26/// token cannot be simultaneously scoped to multiple authorization targets. An
27/// ID is sufficient to uniquely identify a project but if a project is
28/// specified by name, then the domain of the project must also be specified in
29/// order to uniquely identify the project by name. A domain scope may be
30/// specified by either the domain's ID or name with equivalent results.
31#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, ToSchema)]
32#[serde(rename_all = "lowercase")]
33pub enum Scope {
34    /// Project scope.
35    Project(ScopeProject),
36    /// Domain scope.
37    Domain(Domain),
38    /// System scope.
39    System(System),
40}
41
42impl Validate for Scope {
43    fn validate(&self) -> Result<(), ValidationErrors> {
44        match self {
45            Self::Project(project) => project.validate(),
46            Self::Domain(domain) => domain.validate(),
47            Self::System(system) => system.validate(),
48        }
49    }
50}
51
52/// Project scope information.
53#[derive(Builder, Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema, Validate)]
54#[builder(build_fn(error = "BuilderError"))]
55#[builder(setter(into, strip_option))]
56pub struct ScopeProject {
57    /// Project ID.
58    #[builder(default)]
59    #[validate(length(max = 64))]
60    pub id: Option<String>,
61    /// Project Name.
62    #[builder(default)]
63    #[validate(length(max = 64))]
64    pub name: Option<String>,
65    /// Project domain.
66    #[builder(default)]
67    pub domain: Option<Domain>,
68}
69
70/// Domain information.
71#[derive(Builder, Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema, Validate)]
72#[builder(build_fn(error = "BuilderError"))]
73#[builder(setter(into, strip_option))]
74pub struct Domain {
75    /// Domain ID.
76    #[builder(default)]
77    #[validate(length(max = 64))]
78    pub id: Option<String>,
79    /// Domain Name.
80    #[builder(default)]
81    #[validate(length(max = 64))]
82    pub name: Option<String>,
83}
84
85/// Project information.
86#[derive(Builder, Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema, Validate)]
87#[builder(build_fn(error = "BuilderError"))]
88pub struct Project {
89    /// Project ID.
90    #[validate(length(max = 64))]
91    pub id: String,
92    /// Project Name.
93    #[builder(default)]
94    #[validate(length(max = 64))]
95    pub name: String,
96    /// project domain.
97    pub domain: Domain,
98}
99
100/// System scope.
101#[derive(Builder, Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema, Validate)]
102#[builder(build_fn(error = "BuilderError"))]
103#[builder(setter(into, strip_option))]
104pub struct System {
105    /// All systems access.
106    #[builder(default)]
107    pub all: Option<bool>,
108}