Skip to main content

openstack_keystone_core/token/
backend.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//! Token provider backends.
15
16use crate::config::Config;
17use crate::token::{TokenProviderError, types::*};
18
19use crate::keystone::ServiceState;
20
21pub mod fernet;
22pub use fernet::*;
23
24/// Token Provider backend interface.
25#[cfg_attr(test, mockall::automock)]
26pub trait TokenBackend: Send + Sync {
27    /// Set config.
28    fn set_config(&mut self, g: Config);
29
30    /// Extract the token from string.
31    fn decode(&self, credential: &str) -> Result<Token, TokenProviderError>;
32
33    /// Extract the token from string.
34    fn encode(&self, token: &Token) -> Result<String, TokenProviderError>;
35}
36
37/// Token restrictions backend interface.
38#[cfg_attr(test, mockall::automock)]
39#[async_trait::async_trait]
40pub trait TokenRestrictionBackend: Send + Sync {
41    /// Get the token restriction by the ID.
42    async fn get_token_restriction<'a>(
43        &self,
44        state: &ServiceState,
45        id: &'a str,
46        expand_roles: bool,
47    ) -> Result<Option<TokenRestriction>, TokenProviderError>;
48
49    /// Create new token restriction.
50    async fn create_token_restriction<'a>(
51        &self,
52        state: &ServiceState,
53        restriction: TokenRestrictionCreate,
54    ) -> Result<TokenRestriction, TokenProviderError>;
55
56    /// List token restrictions.
57    async fn list_token_restrictions<'a>(
58        &self,
59        state: &ServiceState,
60        params: &TokenRestrictionListParameters,
61    ) -> Result<Vec<TokenRestriction>, TokenProviderError>;
62
63    /// Update token restriction by the ID.
64    async fn update_token_restriction<'a>(
65        &self,
66        state: &ServiceState,
67        id: &'a str,
68        restriction: TokenRestrictionUpdate,
69    ) -> Result<TokenRestriction, TokenProviderError>;
70
71    /// Delete token restriction by the ID.
72    async fn delete_token_restriction<'a>(
73        &self,
74        state: &ServiceState,
75        id: &'a str,
76    ) -> Result<(), TokenProviderError>;
77}