Skip to content

Commit

Permalink
Add progress spinner to auth status subcommand
Browse files Browse the repository at this point in the history
When an authenticated Oxide rack is unreachable, e.g. dogfood when the
VPN is disabled, `oxide auth status` may take tens of seconds to
complete. It is unclear to the user which rack is the source of the
delay.

Add a progress spinner that shows the rack currently being checked.

Closes #567
  • Loading branch information
wfchandler committed Jul 17, 2024
1 parent f472bce commit 52886a0
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions cli/src/cmd_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ use std::fs::File;
use anyhow::{anyhow, bail, Result};
use async_trait::async_trait;
use clap::Parser;
use indicatif::{ProgressBar, ProgressStyle};
use oauth2::{
basic::BasicClient, devicecode::StandardDeviceAuthorizationResponse, AuthType, AuthUrl,
ClientId, DeviceAuthorizationUrl, TokenResponse, TokenUrl,
};
use oxide::types::CurrentUser;
use oxide::{Client, ClientConfig, ClientSessionExt};
use std::time::Duration;
use toml_edit::{Item, Table};
use uuid::Uuid;

Expand Down Expand Up @@ -428,6 +430,13 @@ pub struct CmdAuthStatus {}

impl CmdAuthStatus {
pub async fn status(&self, ctx: &Context) -> Result<()> {
let spinner = ProgressBar::new_spinner();
spinner.set_style(
ProgressStyle::default_spinner()
.template("{spinner} {msg}")
.expect("Failed to set spinner template"),
);

// For backward compatibility, we'll check OXIDE_HOST and OXIDE_TOKEN
// first.
if let (Ok(host_env), Ok(token_env)) =
Expand All @@ -438,7 +447,13 @@ impl CmdAuthStatus {
)
.expect("client authentication from host/token failed");

match client.current_user_view().send().await {
spinner.set_message(format!("Checking {}...", host_env));
spinner.enable_steady_tick(Duration::from_millis(100));

let result = client.current_user_view().send().await;
spinner.finish_and_clear();

match result {
Ok(user) => {
log::debug!("success response for {} (env): {:?}", host_env, user);
println_nopipe!("Logged in to {} as {}", host_env, user.id)
Expand All @@ -456,7 +471,14 @@ impl CmdAuthStatus {
)
.expect("client authentication from host/token failed");

let status = match client.current_user_view().send().await {
spinner.reset();
spinner.set_message(format!("Checking {}...", &profile_info.host));
spinner.enable_steady_tick(Duration::from_millis(100));

let result = client.current_user_view().send().await;
spinner.finish_and_clear();

let status = match result {
Ok(v) => {
log::debug!("success response for {}: {:?}", profile_info.host, v);
"Authenticated".to_string()
Expand Down

0 comments on commit 52886a0

Please sign in to comment.