Skip to content

Commit 335f9bc

Browse files
feat: Prefer org auth token URL over manually provided URL (#2122)
1 parent 519d4e3 commit 335f9bc

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

src/commands/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn configure_args(config: &mut Config, matches: &ArgMatches) -> Result<()> {
120120
}
121121

122122
if let Some(url) = matches.get_one::<String>("url") {
123-
config.set_base_url(url)?;
123+
config.set_base_url(url);
124124
}
125125

126126
if let Some(headers) = matches.get_many::<String>("headers") {

src/config.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,16 @@ impl Config {
7171
.map(|td| td.url.as_str())
7272
.unwrap_or_default();
7373

74-
let url = match (default_url.as_str(), token_url) {
75-
(_, "") => default_url,
76-
_ if default_url == token_url => default_url,
77-
(DEFAULT_URL | "", _) => String::from(token_url),
78-
_ => bail!(
79-
"Two different url values supplied: `{token_url}` (from token), `{default_url}`."
80-
),
74+
let url = if token_url.is_empty() {
75+
default_url
76+
} else {
77+
if !default_url.is_empty() {
78+
log::warn!(
79+
"Using {token_url} (embedded in token) rather than manually-configured URL {default_url}. \
80+
To use {default_url}, please provide an auth token for this URL."
81+
);
82+
}
83+
token_url.into()
8184
};
8285

8386
Ok(Config {
@@ -211,21 +214,23 @@ impl Config {
211214
}
212215

213216
/// Sets the URL
214-
pub fn set_base_url(&mut self, url: &str) -> Result<()> {
217+
pub fn set_base_url(&mut self, url: &str) {
215218
let token_url = self
216219
.cached_token_data
217220
.as_ref()
218221
.map(|td| td.url.as_str())
219222
.unwrap_or_default();
220223

221224
if !token_url.is_empty() && url != token_url {
222-
bail!("Two different url values supplied: `{token_url}` (from token), `{url}`.");
225+
log::warn!(
226+
"Using {token_url} (embedded in token) rather than manually-configured URL {url}. \
227+
To use {url}, please provide an auth token for this URL."
228+
);
229+
} else {
230+
url.clone_into(&mut self.cached_base_url);
231+
self.ini
232+
.set_to(Some("defaults"), "url".into(), self.cached_base_url.clone());
223233
}
224-
225-
url.clone_into(&mut self.cached_base_url);
226-
self.ini
227-
.set_to(Some("defaults"), "url".into(), self.cached_base_url.clone());
228-
Ok(())
229234
}
230235

231236
/// Sets headers that should be attached to all requests
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
```
22
$ sentry-cli --auth-token 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 --url http://example.com sourcemaps upload test_path
33
? failed
4-
error: Two different url values supplied: `http://localhost:8000` (from token), `http://example.com`.
5-
6-
Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output.
7-
Please attach the full debug log to all bug reports.
4+
[..]WARN[..] Using http://localhost:8000 (embedded in token) rather than manually-configured URL http://example.com. To use http://example.com, please provide an auth token for this URL.
5+
...
86

97
```

0 commit comments

Comments
 (0)