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(api): Fix panic that occurred when sentry-cli login called with --auth-token #1893

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
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
168 changes: 162 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ prettytable-rs = "0.10.0"
proguard = { version = "5.0.0", features = ["uuid"] }
r2d2 = "0.8.10"
rayon = "1.6.1"
regex = "1.7.1"
regex = "1.7.3"
runas = "1.0.0"
rust-ini = "0.18.0"
semver = "1.0.16"
Expand Down Expand Up @@ -83,7 +83,9 @@ chrono-tz = "0.8.4"
insta = { version = "1.26.0", features = ["redactions", "yaml"] }
mockito = "0.31.1"
predicates = "2.1.5"
rstest = "0.18.2"
tempfile = "3.8.1"
testing_logger = "0.1.1"
trycmd = "0.14.11"

[features]
Expand Down
15 changes: 8 additions & 7 deletions src/commands/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use url::Url;

use crate::api::Api;
use crate::config::{Auth, Config};
use crate::utils::auth_token::AuthToken;
use crate::utils::ui::{prompt, prompt_to_continue};

pub fn make_command(command: Command) -> Command {
Expand All @@ -18,9 +19,9 @@ pub fn make_command(command: Command) -> Command {
)
}

fn update_config(config: &Config, token: &str) -> Result<()> {
fn update_config(config: &Config, token: AuthToken) -> Result<()> {
let mut new_cfg = config.clone();
new_cfg.set_auth(Auth::Token(token.to_string()))?;
new_cfg.set_auth(Auth::Token(token))?;
new_cfg.save()?;
Ok(())
}
Expand All @@ -31,7 +32,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
"{}/orgredirect/organizations/:orgslug/settings/auth-tokens/",
config.get_base_url()?
);
let predefined_token = matches.get_one::<String>("auth_token");
let predefined_token = matches.get_one::<AuthToken>("auth_token");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the change that fixes the error – the other changes to this file in this commit are to handle the new type

let has_predefined_token = predefined_token.is_some();

println!("This helps you signing in your sentry-cli with an authentication token.");
Expand Down Expand Up @@ -62,13 +63,13 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
let mut token;
loop {
token = if let Some(token) = predefined_token {
token.to_string()
token.to_owned()
} else {
prompt("Enter your token")?
prompt("Enter your token")?.into()
};

let test_cfg = config.make_copy(|cfg| {
cfg.set_auth(Auth::Token(token.to_string()))?;
cfg.set_auth(Auth::Token(token.clone()))?;
Ok(())
})?;

Expand Down Expand Up @@ -103,7 +104,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
Config::from_cli_config()?
};

update_config(&config_to_update, &token)?;
update_config(&config_to_update, token)?;
println!();
println!(
"Stored token in {}",
Expand Down
4 changes: 3 additions & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use log::{debug, info, set_logger, set_max_level, LevelFilter};
use crate::api::Api;
use crate::config::{Auth, Config};
use crate::constants::{ARCH, PLATFORM, VERSION};
use crate::utils::auth_token::AuthToken;
use crate::utils::logging::set_quiet_mode;
use crate::utils::logging::Logger;
use crate::utils::system::{init_backtrace, load_dotenv, print_error, QuietExit};
Expand Down Expand Up @@ -107,7 +108,7 @@ fn configure_args(config: &mut Config, matches: &ArgMatches) -> Result<()> {
config.set_auth(Auth::Key(api_key.to_owned()))?;
}

if let Some(auth_token) = matches.get_one::<String>("auth_token") {
if let Some(auth_token) = matches.get_one::<AuthToken>("auth_token") {
config.set_auth(Auth::Token(auth_token.to_owned()))?;
}

Expand Down Expand Up @@ -161,6 +162,7 @@ fn app() -> Command {
.value_name("AUTH_TOKEN")
.long("auth-token")
.global(true)
.value_parser(value_parser!(AuthToken))
.help("Use the given Sentry auth token."),
)
.arg(
Expand Down
Loading
Loading