Skip to content

Commit 4adf285

Browse files
fix: oidc connection (#1117)
--------- Co-authored-by: Devdutt Shenoi <devdutt@outlook.in>
1 parent 4e79561 commit 4adf285

File tree

1 file changed

+50
-53
lines changed

1 file changed

+50
-53
lines changed

src/cli.rs

+50-53
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub const DEFAULT_PASSWORD: &str = "admin";
5252
long_about = r#"
5353
Cloud Native, log analytics platform for modern applications.
5454
55-
Usage:
55+
Usage:
5656
parseable [command] [options..]
5757
5858
@@ -126,7 +126,7 @@ pub struct Options {
126126
// Server configuration
127127
#[arg(
128128
long,
129-
env = "P_ADDR",
129+
env = "P_ADDR",
130130
default_value = "0.0.0.0:8000",
131131
value_parser = validation::socket_addr,
132132
help = "Address and port for Parseable HTTP(s) server"
@@ -294,35 +294,8 @@ pub struct Options {
294294
)]
295295
pub ingestor_endpoint: String,
296296

297-
// OIDC Configuration
298-
#[arg(
299-
long,
300-
long = "oidc-client",
301-
env = "P_OIDC_CLIENT_ID",
302-
requires = "oidc",
303-
group = "oidc",
304-
help = "Client id for OIDC provider"
305-
)]
306-
oidc_client_id: Option<String>,
307-
308-
#[arg(
309-
long,
310-
env = "P_OIDC_CLIENT_SECRET",
311-
requires = "oidc",
312-
group = "oidc",
313-
help = "Client secret for OIDC provider"
314-
)]
315-
oidc_client_secret: Option<String>,
316-
317-
#[arg(
318-
long,
319-
env = "P_OIDC_ISSUER",
320-
value_parser = validation::url,
321-
requires = "oidc",
322-
group = "oidc",
323-
help = "OIDC provider's host address"
324-
)]
325-
oidc_issuer: Option<Url>,
297+
#[command(flatten)]
298+
oidc: Option<OidcConfig>,
326299

327300
// Kafka configuration (conditionally compiled)
328301
#[cfg(any(
@@ -391,6 +364,34 @@ pub struct Options {
391364
pub ms_clarity_tag: Option<String>,
392365
}
393366

367+
#[derive(Parser, Debug)]
368+
pub struct OidcConfig {
369+
#[arg(
370+
long = "oidc-client-id",
371+
env = "P_OIDC_CLIENT_ID",
372+
required = false,
373+
help = "Client id for OIDC provider"
374+
)]
375+
pub client_id: String,
376+
377+
#[arg(
378+
long = "oidc-client-secret",
379+
env = "P_OIDC_CLIENT_SECRET",
380+
required = false,
381+
help = "Client secret for OIDC provider"
382+
)]
383+
pub secret: String,
384+
385+
#[arg(
386+
long = "oidc-issuer",
387+
env = "P_OIDC_ISSUER",
388+
required = false,
389+
value_parser = validation::url,
390+
help = "OIDC provider's host address"
391+
)]
392+
pub issuer: Url,
393+
}
394+
394395
impl Options {
395396
pub fn local_stream_data_path(&self, stream_name: &str) -> PathBuf {
396397
self.local_staging_path.join(stream_name)
@@ -405,28 +406,24 @@ impl Options {
405406
}
406407

407408
pub fn openid(&self) -> Option<OpenidConfig> {
408-
match (
409-
&self.oidc_client_id,
410-
&self.oidc_client_secret,
411-
&self.oidc_issuer,
412-
) {
413-
(Some(id), Some(secret), Some(issuer)) => {
414-
let origin = if let Some(url) = self.domain_address.clone() {
415-
oidc::Origin::Production(url)
416-
} else {
417-
oidc::Origin::Local {
418-
socket_addr: self.address.clone(),
419-
https: self.tls_cert_path.is_some() && self.tls_key_path.is_some(),
420-
}
421-
};
422-
Some(OpenidConfig {
423-
id: id.clone(),
424-
secret: secret.clone(),
425-
issuer: issuer.clone(),
426-
origin,
427-
})
409+
let OidcConfig {
410+
secret,
411+
client_id,
412+
issuer,
413+
} = self.oidc.as_ref()?;
414+
let origin = if let Some(url) = self.domain_address.clone() {
415+
oidc::Origin::Production(url)
416+
} else {
417+
oidc::Origin::Local {
418+
socket_addr: self.address.clone(),
419+
https: self.tls_cert_path.is_some() && self.tls_key_path.is_some(),
428420
}
429-
_ => None,
430-
}
421+
};
422+
Some(OpenidConfig {
423+
id: client_id.clone(),
424+
secret: secret.clone(),
425+
issuer: issuer.clone(),
426+
origin,
427+
})
431428
}
432429
}

0 commit comments

Comments
 (0)