-
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(token): Separate validation warning from parsing
Separate logic for issuing the invalid auth token format validation warning from the parsing logic. This will allow us in the future to test whether a certain string might be an auth token without logging a warning.
- Loading branch information
1 parent
8343763
commit bd83744
Showing
7 changed files
with
26 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
use crate::utils::auth_token::AuthToken; | ||
use anyhow::{anyhow, Result}; | ||
use std::convert::Infallible; | ||
|
||
/// Parse key:value pair from string, used as a value_parser for Clap arguments | ||
pub fn kv_parser(s: &str) -> Result<(String, String)> { | ||
s.split_once(':') | ||
.map(|(k, v)| (k.into(), v.into())) | ||
.ok_or_else(|| anyhow!("`{s}` is missing a `:`")) | ||
} | ||
|
||
/// Parse an AuthToken, and warn if the format is unrecognized | ||
pub fn auth_token_parser(s: &str) -> Result<AuthToken, Infallible> { | ||
let token = AuthToken::from(s); | ||
if !token.format_recognized() { | ||
log::warn!("Unrecognized auth token format. Ensure you copied your token correctly."); | ||
} | ||
|
||
Ok(token) | ||
} |
5 changes: 2 additions & 3 deletions
5
tests/integration/_cases/token_validation/warn-invalid-auth-token.trycmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
``` | ||
$ sentry-cli --auth-token not_a_valid_auth_token --version | ||
? success | ||
[..]WARN[..]Unrecognized auth token format! | ||
Hint: Did you copy your token correctly? | ||
sentry-cli [..] | ||
[..]WARN[..] Unrecognized auth token format. Ensure you copied your token correctly. | ||
... | ||
|
||
``` |