Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error on partial config #6

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 47 additions & 47 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
all(target_os = "linux", target_arch = "x86_64"),
all(target_os = "macos", target_arch = "aarch64")
)))]
use std::string::String as KafkaSslProtocol;

Check warning on line 40 in src/cli.rs

View workflow job for this annotation

GitHub Actions / Build for aarch64-unknown-linux-gnu

unused import: `std::string::String as KafkaSslProtocol`

/// Default username and password for Parseable server, used by default for local mode.
/// NOTE: obviously not recommended for production
Expand All @@ -52,7 +52,7 @@
long_about = r#"
Cloud Native, log analytics platform for modern applications.

Usage:
Usage:
parseable [command] [options..]


Expand Down Expand Up @@ -126,7 +126,7 @@
// Server configuration
#[arg(
long,
env = "P_ADDR",
env = "P_ADDR",
default_value = "0.0.0.0:8000",
value_parser = validation::socket_addr,
help = "Address and port for Parseable HTTP(s) server"
Expand Down Expand Up @@ -294,29 +294,8 @@
)]
pub ingestor_endpoint: String,

// OIDC Configuration
#[arg(
long,
long = "oidc-client",
env = "P_OIDC_CLIENT_ID",
help = "Client id for OIDC provider"
)]
oidc_client_id: Option<String>,

#[arg(
long,
env = "P_OIDC_CLIENT_SECRET",
help = "Client secret for OIDC provider"
)]
oidc_client_secret: Option<String>,

#[arg(
long,
env = "P_OIDC_ISSUER",
value_parser = validation::url,
help = "OIDC provider's host address"
)]
oidc_issuer: Option<Url>,
#[command(flatten)]
oidc: Option<OidcConfig>,

// Kafka configuration (conditionally compiled)
#[cfg(any(
Expand Down Expand Up @@ -385,6 +364,31 @@
pub ms_clarity_tag: Option<String>,
}

#[derive(Parser, Debug)]
pub struct OidcConfig {
#[arg(
long = "oidc-client-id",
env = "P_OIDC_CLIENT_ID",
help = "Client id for OIDC provider"
)]
pub client_id: String,

#[arg(
long = "oidc-client-secret",
env = "P_OIDC_CLIENT_SECRET",
help = "Client secret for OIDC provider"
)]
pub secret: String,

#[arg(
long = "oidc-issuer",
env = "P_OIDC_ISSUER",
value_parser = validation::url,
help = "OIDC provider's host address"
)]
pub issuer: Url,
}

impl Options {
pub fn local_stream_data_path(&self, stream_name: &str) -> PathBuf {
self.local_staging_path.join(stream_name)
Expand All @@ -399,28 +403,24 @@
}

pub fn openid(&self) -> Option<OpenidConfig> {
match (
&self.oidc_client_id,
&self.oidc_client_secret,
&self.oidc_issuer,
) {
(Some(id), Some(secret), Some(issuer)) => {
let origin = if let Some(url) = self.domain_address.clone() {
oidc::Origin::Production(url)
} else {
oidc::Origin::Local {
socket_addr: self.address.clone(),
https: self.tls_cert_path.is_some() && self.tls_key_path.is_some(),
}
};
Some(OpenidConfig {
id: id.clone(),
secret: secret.clone(),
issuer: issuer.clone(),
origin,
})
let OidcConfig {
secret,
client_id,
issuer,
} = self.oidc.as_ref()?;
let origin = if let Some(url) = self.domain_address.clone() {
oidc::Origin::Production(url)
} else {
oidc::Origin::Local {
socket_addr: self.address.clone(),
https: self.tls_cert_path.is_some() && self.tls_key_path.is_some(),
}
_ => None,
}
};
Some(OpenidConfig {
id: client_id.clone(),
secret: secret.clone(),
issuer: issuer.clone(),
origin,
})
}
}
Loading