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: Only warn about mismatched URLs when they are different #2143

Merged
merged 1 commit into from
Sep 5, 2024
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
fix: Only about mismatched URLs when they are different
Previously, we warned about a mismatch between the auth token URL and the manually configured URL even when they were the same. We also sometimes issued the warning when no URL was manually configured (i.e. when the default https://sentry.io/ was used).

Now, we only warn when the two are actually different and we also only warn if a URL was actually manually configured.

Fixes #2137
  • Loading branch information
szokeasaurusrex committed Sep 5, 2024
commit 06d6b968f3acbae464557a599b058793d3ed7fe2
38 changes: 22 additions & 16 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,16 @@ impl Config {
_ => None, // get_default_auth never returns Auth::Token variant
};

let default_url = get_default_url(&ini);
let manually_configured_url = configured_url(&ini);
let token_url = token_embedded_data
.as_ref()
.map(|td| td.url.as_str())
.unwrap_or_default();

let url = if token_url.is_empty() {
default_url
manually_configured_url.unwrap_or_else(|| DEFAULT_URL.to_string())
} else {
if !default_url.is_empty() {
log::warn!(
"Using {token_url} (embedded in token) rather than manually-configured URL {default_url}. \
To use {default_url}, please provide an auth token for this URL."
);
}
warn_about_conflicting_urls(token_url, manually_configured_url.as_deref());
token_url.into()
};

Expand Down Expand Up @@ -535,6 +530,18 @@ impl Config {
}
}

fn warn_about_conflicting_urls(token_url: &str, manually_configured_url: Option<&str>) {
if let Some(manually_configured_url) = manually_configured_url {
if manually_configured_url != token_url {
warn!(
"Using {token_url} (embedded in token) rather than manually-configured URL \
{manually_configured_url}. To use {manually_configured_url}, please provide an \
auth token for {manually_configured_url}."
);
}
}
}

fn find_global_config_file() -> Result<PathBuf> {
let home_dir_file = dirs::home_dir().map(|p| p.join(CONFIG_RC_FILE_NAME));
let config_dir_file = dirs::config_dir().map(|p| p.join(CONFIG_INI_FILE_PATH));
Expand Down Expand Up @@ -694,14 +701,13 @@ fn get_default_auth(ini: &Ini) -> Option<Auth> {
}
}

fn get_default_url(ini: &Ini) -> String {
if let Ok(val) = env::var("SENTRY_URL") {
val
} else if let Some(val) = ini.get_from(Some("defaults"), "url") {
val.to_owned()
} else {
DEFAULT_URL.to_owned()
}
/// Returns the URL configured in the SENTRY_URL environment variable or provided ini (in that
/// order of precedence), or returns None if neither is set.
fn configured_url(ini: &Ini) -> Option<String> {
env::var("SENTRY_URL").ok().or_else(|| {
ini.get_from(Some("defaults"), "url")
.map(|url| url.to_owned())
})
}

fn get_default_headers(ini: &Ini) -> Option<Vec<String>> {
Expand Down
Loading