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

WIP: feat: Send all requests to region URL when using org auth token #2005

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
36 changes: 16 additions & 20 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,15 @@ impl Config {
};

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

let url = match (default_url.as_str(), token_url) {
(_, "") => default_url,
_ if default_url == token_url => default_url,
(DEFAULT_URL | "", _) => String::from(token_url),
_ => bail!(
"Two different url values supplied: `{token_url}` (from token), `{default_url}`."
),
let token_region_url = token_embedded_data.as_ref().map(|td| &td.region_url);

let url = match token_region_url {
Some(region_url) => {
log::info!("Using region URL from token: {}", region_url);

region_url.clone()
}
None => default_url,
};

Ok(Config {
Expand Down Expand Up @@ -204,14 +201,13 @@ impl Config {

/// Sets the URL
pub fn set_base_url(&mut self, url: &str) -> Result<()> {
let token_url = self
.cached_token_data
.as_ref()
.map(|td| td.url.as_str())
.unwrap_or_default();

if !token_url.is_empty() && url != token_url {
bail!("Two different url values supplied: `{token_url}` (from token), `{url}`.");
if self.cached_token_data.is_some() {
log::warn!(
"Ignoring the --url argument because org auth token authentication is used. \
We are using the following URL from the token, instead: {}",
self.cached_base_url
);
return Ok(());
}

self.cached_base_url = url.to_owned();
Expand Down
Loading