Skip to content
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
110 changes: 88 additions & 22 deletions rust/Cargo.lock

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

2 changes: 1 addition & 1 deletion rust/agama-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ zbus = { version = "3", default-features = false, features = ["tokio"] }
tokio = { version = "1.33.0", features = ["macros", "rt-multi-thread"] }
async-trait = "0.1.77"
reqwest = { version = "0.11", features = ["json"] }
rpassword = "7.3.1"
url = "2.5.0"
inquire = { version = "0.7.5", default-features = false, features = ["crossterm", "one-liners"] }

[[bin]]
name = "agama"
Expand Down
15 changes: 13 additions & 2 deletions rust/agama-cli/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use agama_lib::auth::AuthToken;
use clap::Subcommand;

use crate::error::CliError;
use inquire::Password;
use reqwest::header::{HeaderMap, HeaderValue, CONTENT_TYPE};
use std::io::{self, IsTerminal};

Expand Down Expand Up @@ -37,15 +38,25 @@ pub async fn run(subcommand: AuthCommands) -> anyhow::Result<()> {
fn read_password() -> Result<String, CliError> {
let stdin = io::stdin();
let password = if stdin.is_terminal() {
rpassword::prompt_password("Please, introduce the root password: ")?
ask_password()?
} else {
let mut buffer = String::new();
stdin.read_line(&mut buffer)?;
stdin
.read_line(&mut buffer)
.map_err(CliError::StdinPassword)?;
buffer
};
Ok(password)
}

/// Asks interactively for the password. (For authentication, not for changing it)
fn ask_password() -> Result<String, CliError> {
Password::new("Please enter the root password:")
.without_confirmation()
.prompt()
.map_err(CliError::InteractivePassword)
}

/// Necessary http request header for authenticate
fn authenticate_headers() -> HeaderMap {
let mut headers = HeaderMap::new();
Expand Down
11 changes: 7 additions & 4 deletions rust/agama-cli/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use inquire::InquireError;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum CliError {
#[error("Cannot perform the installation as the settings are not valid")]
ValidationError,
Validation,
#[error("Could not start the installation")]
InstallationError,
#[error("Could not read the password: {0}")]
MissingPassword(#[from] std::io::Error),
Installation,
#[error("Could not read the password")]
InteractivePassword(#[source] InquireError),
#[error("Could not read the password from the standard input")]
StdinPassword(#[source] std::io::Error),
}
4 changes: 2 additions & 2 deletions rust/agama-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async fn install(manager: &ManagerClient<'_>, max_attempts: u8) -> anyhow::Resul
manager.wait().await?;

if !manager.can_install().await? {
return Err(CliError::ValidationError)?;
return Err(CliError::Validation)?;
}

let progress = tokio::spawn(async { show_progress().await });
Expand All @@ -81,7 +81,7 @@ async fn install(manager: &ManagerClient<'_>, max_attempts: u8) -> anyhow::Resul
}
if attempts == max_attempts {
eprintln!("Giving up.");
return Err(CliError::InstallationError)?;
return Err(CliError::Installation)?;
}
attempts += 1;
sleep(Duration::from_secs(1));
Expand Down
6 changes: 6 additions & 0 deletions rust/package/agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Thu Jun 27 07:02:29 UTC 2024 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Improve the prompt to introduce the password in the "auth login"
command (gh#openSUSE/agama#1271).

-------------------------------------------------------------------
Wed Jun 26 12:56:31 UTC 2024 - Knut Anderssen <kanderssen@suse.com>

Expand Down