1
1
use crate :: DruidCluster ;
2
2
3
+
3
4
use serde:: { Deserialize , Serialize } ;
4
5
use snafu:: { ResultExt , Snafu } ;
5
6
use stackable_operator:: {
@@ -11,6 +12,7 @@ use stackable_operator::{
11
12
kube:: runtime:: reflector:: ObjectRef ,
12
13
schemars:: { self , JsonSchema } ,
13
14
} ;
15
+
14
16
use strum:: { EnumDiscriminants , IntoStaticStr } ;
15
17
16
18
#[ derive( Snafu , Debug , EnumDiscriminants ) ]
@@ -87,6 +89,38 @@ impl DruidAuthentication {
87
89
}
88
90
}
89
91
92
+ if let Some ( DruidAuthentication {
93
+ tls : _,
94
+ ldap : Some ( druid_ldap) ,
95
+ } ) = & druid. spec . cluster_config . authentication
96
+ {
97
+ let authentication_class =
98
+ AuthenticationClass :: resolve ( client, & druid_ldap. authentication_class )
99
+ . await
100
+ . context ( AuthenticationClassRetrievalSnafu {
101
+ authentication_class : ObjectRef :: < AuthenticationClass > :: new (
102
+ & druid_ldap. authentication_class ,
103
+ ) ,
104
+ } ) ?;
105
+
106
+ match authentication_class. spec . provider {
107
+ AuthenticationClassProvider :: Ldap ( tls_provider) => {
108
+ druid_authentication_config. push ( DruidAuthenticationConfig :: Ldap ( tls_provider) ) ;
109
+ }
110
+ _ => {
111
+ return Err ( Error :: AuthenticationClassProviderNotSupported {
112
+ authentication_class_provider : authentication_class
113
+ . spec
114
+ . provider
115
+ . to_string ( ) ,
116
+ authentication_class : ObjectRef :: < AuthenticationClass > :: new (
117
+ & druid_ldap. authentication_class ,
118
+ ) ,
119
+ } )
120
+ }
121
+ }
122
+ }
123
+
90
124
Ok ( druid_authentication_config)
91
125
}
92
126
}
@@ -101,4 +135,35 @@ impl DruidAuthenticationConfig {
101
135
pub fn is_tls_auth ( & self ) -> bool {
102
136
matches ! ( self , DruidAuthenticationConfig :: Tls ( _) )
103
137
}
104
- }
138
+ }
139
+
140
+ /*
141
+ #[cfg(test)]
142
+ mod tests {
143
+ use super::*;
144
+
145
+ #[test]
146
+ fn test_process_ldap_authentication() {
147
+ let result = DruidAuthentication::resolve()
148
+ // TODO: replace client with mockable interface
149
+ // TODO: pass LDAPy config
150
+ // TODO: expect no error (the current code provides this)
151
+
152
+ let cluster: DruidCluster = serde_yaml::from_reader(&cluster_cr).unwrap();
153
+
154
+
155
+
156
+ assert_eq!(cluster.metadata.name, Some("testcluster".to_string()));
157
+
158
+ assert_eq!(
159
+ cluster.role_service_name(&DruidRole::Router),
160
+ Some("testcluster-router".to_string())
161
+ );
162
+
163
+ assert_eq!(
164
+ cluster.role_service_fqdn(&DruidRole::Router),
165
+ Some("testcluster-router.default.svc.cluster.local".to_string())
166
+ )
167
+ }
168
+ }
169
+ */
0 commit comments