openstack_keystone_core/identity_mapping/
mod.rs1use async_trait::async_trait;
21
22pub mod backend;
23pub mod error;
24#[cfg(any(test, feature = "mock"))]
25pub mod mock;
26pub mod service;
27pub mod types;
28
29use crate::config::Config;
30use crate::identity_mapping::service::IdentityMappingService;
31use crate::keystone::ServiceState;
32use crate::plugin_manager::PluginManagerApi;
33use types::*;
34
35pub use error::IdentityMappingProviderError;
36#[cfg(any(test, feature = "mock"))]
37pub use mock::MockIdentityMappingProvider;
38pub use types::IdentityMappingApi;
39
40pub enum IdentityMappingProvider {
41 Service(IdentityMappingService),
42 #[cfg(any(test, feature = "mock"))]
43 Mock(MockIdentityMappingProvider),
44}
45
46impl IdentityMappingProvider {
47 pub fn new<P: PluginManagerApi>(
48 config: &Config,
49 plugin_manager: &P,
50 ) -> Result<Self, IdentityMappingProviderError> {
51 Ok(Self::Service(IdentityMappingService::new(
52 config,
53 plugin_manager,
54 )?))
55 }
56}
57
58#[async_trait]
59impl IdentityMappingApi for IdentityMappingProvider {
60 async fn get_by_local_id<'a>(
62 &self,
63 state: &ServiceState,
64 local_id: &'a str,
65 domain_id: &'a str,
66 entity_type: IdMappingEntityType,
67 ) -> Result<Option<IdMapping>, IdentityMappingProviderError> {
68 match self {
69 Self::Service(provider) => {
70 provider
71 .get_by_local_id(state, local_id, domain_id, entity_type)
72 .await
73 }
74 #[cfg(any(test, feature = "mock"))]
75 Self::Mock(provider) => {
76 provider
77 .get_by_local_id(state, local_id, domain_id, entity_type)
78 .await
79 }
80 }
81 }
82
83 #[tracing::instrument(level = "info", skip(self, state))]
85 async fn get_by_public_id<'a>(
86 &self,
87 state: &ServiceState,
88 public_id: &'a str,
89 ) -> Result<Option<IdMapping>, IdentityMappingProviderError> {
90 match self {
91 Self::Service(provider) => provider.get_by_public_id(state, public_id).await,
92 #[cfg(any(test, feature = "mock"))]
93 Self::Mock(provider) => provider.get_by_public_id(state, public_id).await,
94 }
95 }
96}