Skip to main content

openstack_keystone_core/resource/
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
15use async_trait::async_trait;
16
17use crate::keystone::ServiceState;
18use crate::resource::ResourceProviderError;
19use crate::resource::types::*;
20
21/// Resource driver interface.
22#[cfg_attr(test, mockall::automock)]
23#[async_trait]
24pub trait ResourceBackend: Send + Sync {
25    /// Get `enabled` field of the domain.
26    async fn get_domain_enabled<'a>(
27        &self,
28        state: &ServiceState,
29        domain_id: &'a str,
30    ) -> Result<bool, ResourceProviderError>;
31
32    /// Create new domain.
33    async fn create_domain(
34        &self,
35        state: &ServiceState,
36        domain: DomainCreate,
37    ) -> Result<Domain, ResourceProviderError>;
38
39    /// Create new project.
40    async fn create_project(
41        &self,
42        state: &ServiceState,
43        project: ProjectCreate,
44    ) -> Result<Project, ResourceProviderError>;
45
46    /// Delete domain by the ID
47    async fn delete_domain<'a>(
48        &self,
49        state: &ServiceState,
50        id: &'a str,
51    ) -> Result<(), ResourceProviderError>;
52
53    /// Delete project by the ID
54    async fn delete_project<'a>(
55        &self,
56        state: &ServiceState,
57        id: &'a str,
58    ) -> Result<(), ResourceProviderError>;
59
60    /// Get single domain by ID
61    async fn get_domain<'a>(
62        &self,
63        state: &ServiceState,
64        domain_id: &'a str,
65    ) -> Result<Option<Domain>, ResourceProviderError>;
66
67    /// Get single domain by Name
68    async fn get_domain_by_name<'a>(
69        &self,
70        state: &ServiceState,
71        domain_name: &'a str,
72    ) -> Result<Option<Domain>, ResourceProviderError>;
73
74    /// Get single project by ID
75    async fn get_project<'a>(
76        &self,
77        state: &ServiceState,
78        project_id: &'a str,
79    ) -> Result<Option<Project>, ResourceProviderError>;
80
81    /// Get single project by Name and Domain ID
82    async fn get_project_by_name<'a>(
83        &self,
84        state: &ServiceState,
85        name: &'a str,
86        domain_id: &'a str,
87    ) -> Result<Option<Project>, ResourceProviderError>;
88
89    /// Get project parents
90    async fn get_project_parents<'a>(
91        &self,
92        state: &ServiceState,
93        project_id: &'a str,
94    ) -> Result<Option<Vec<Project>>, ResourceProviderError>;
95
96    /// List domains.
97    async fn list_domains(
98        &self,
99        state: &ServiceState,
100        params: &DomainListParameters,
101    ) -> Result<Vec<Domain>, ResourceProviderError>;
102
103    /// List projects.
104    async fn list_projects(
105        &self,
106        state: &ServiceState,
107        params: &ProjectListParameters,
108    ) -> Result<Vec<Project>, ResourceProviderError>;
109}