Skip to content

Commit

Permalink
wip: throwaway code
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Supalov committed Nov 16, 2022
1 parent cac2028 commit 8a4b340
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
8 changes: 8 additions & 0 deletions deploy/crd/druidcluster.crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ spec:
description: Authentication class settings for Druid like TLS authentication or LDAP
nullable: true
properties:
ldap:
nullable: true
properties:
authenticationClass:
type: string
required:
- authenticationClass
type: object
tls:
description: TLS based client authentication (mutual TLS)
nullable: true
Expand Down
67 changes: 66 additions & 1 deletion rust/crd/src/authentication.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::DruidCluster;


use serde::{Deserialize, Serialize};
use snafu::{ResultExt, Snafu};
use stackable_operator::{
Expand All @@ -11,6 +12,7 @@ use stackable_operator::{
kube::runtime::reflector::ObjectRef,
schemars::{self, JsonSchema},
};

use strum::{EnumDiscriminants, IntoStaticStr};

#[derive(Snafu, Debug, EnumDiscriminants)]
Expand Down Expand Up @@ -87,6 +89,38 @@ impl DruidAuthentication {
}
}

if let Some(DruidAuthentication {
tls: _,
ldap: Some(druid_ldap),
}) = &druid.spec.cluster_config.authentication
{
let authentication_class =
AuthenticationClass::resolve(client, &druid_ldap.authentication_class)
.await
.context(AuthenticationClassRetrievalSnafu {
authentication_class: ObjectRef::<AuthenticationClass>::new(
&druid_ldap.authentication_class,
),
})?;

match authentication_class.spec.provider {
AuthenticationClassProvider::Ldap(tls_provider) => {
druid_authentication_config.push(DruidAuthenticationConfig::Ldap(tls_provider));
}
_ => {
return Err(Error::AuthenticationClassProviderNotSupported {
authentication_class_provider: authentication_class
.spec
.provider
.to_string(),
authentication_class: ObjectRef::<AuthenticationClass>::new(
&druid_ldap.authentication_class,
),
})
}
}
}

Ok(druid_authentication_config)
}
}
Expand All @@ -101,4 +135,35 @@ impl DruidAuthenticationConfig {
pub fn is_tls_auth(&self) -> bool {
matches!(self, DruidAuthenticationConfig::Tls(_))
}
}
}

/*
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_process_ldap_authentication() {
let result = DruidAuthentication::resolve()
// TODO: replace client with mockable interface
// TODO: pass LDAPy config
// TODO: expect no error (the current code provides this)
let cluster: DruidCluster = serde_yaml::from_reader(&cluster_cr).unwrap();
assert_eq!(cluster.metadata.name, Some("testcluster".to_string()));
assert_eq!(
cluster.role_service_name(&DruidRole::Router),
Some("testcluster-router".to_string())
);
assert_eq!(
cluster.role_service_fqdn(&DruidRole::Router),
Some("testcluster-router.default.svc.cluster.local".to_string())
)
}
}
*/

0 comments on commit 8a4b340

Please sign in to comment.