1use rdkafka::ClientConfig;
2use uuid::Uuid;
3
4pub trait GcnClientConfig {
5 fn set_gcn_auth(
6 &mut self,
7 client_id: &str,
8 client_secret: &str,
9 domain: Option<&str>,
10 ) -> &mut Self;
11}
12
13impl GcnClientConfig for ClientConfig {
14 fn set_gcn_auth(
15 &mut self,
16 client_id: &str,
17 client_secret: &str,
18 domain: Option<&str>,
19 ) -> &mut Self {
20 let domain = domain.unwrap_or("gcn.nasa.gov");
21 match self.get("group.id") {
22 Some(_) => self,
23 _ => self.set("group.id", Uuid::new_v4()),
24 }
25 .set("bootstrap.servers", format!("kafka.{domain}"))
26 .set("sasl.mechanisms", "OAUTHBEARER")
27 .set("sasl.oauthbearer.client.id", client_id)
28 .set("sasl.oauthbearer.client.secret", client_secret)
29 .set("sasl.oauthbearer.method", "oidc")
30 .set(
31 "sasl.oauthbearer.token.endpoint.url",
32 format!("https://auth.{domain}/oauth2/token"),
33 )
34 .set("security.protocol", "sasl_ssl")
35 }
36}