openstack_keystone_core/keystone.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 state
15use sea_orm::DatabaseConnection;
16use std::sync::Arc;
17use tracing::info;
18
19use crate::config::Config;
20use crate::error::KeystoneError;
21//#[double]
22use crate::policy::PolicyEnforcer;
23use crate::provider::Provider;
24
25// Placing ServiceState behind Arc is necessary to address DatabaseConnection
26// not implementing Clone.
27//#[derive(Clone)]
28pub struct Service {
29 /// Config file.
30 pub config: Config,
31
32 /// Database connection.
33 pub db: DatabaseConnection,
34
35 /// Policy enforcer.
36 pub policy_enforcer: Arc<dyn PolicyEnforcer>,
37
38 /// Service/resource Provider.
39 pub provider: Provider,
40
41 /// Shutdown flag.
42 pub shutdown: bool,
43}
44
45pub type ServiceState = Arc<Service>;
46
47impl Service {
48 pub fn new(
49 cfg: Config,
50 db: DatabaseConnection,
51 provider: Provider,
52 policy_enforcer: Arc<dyn PolicyEnforcer>,
53 ) -> Result<Self, KeystoneError> {
54 Ok(Self {
55 config: cfg.clone(),
56 provider,
57 db,
58 policy_enforcer,
59 shutdown: false,
60 })
61 }
62
63 pub async fn terminate(&self) -> Result<(), KeystoneError> {
64 info!("Terminating Keystone");
65 Ok(())
66 }
67}