diff --git a/implementations/rust/ockam/ockam_api/src/cloud/space.rs b/implementations/rust/ockam/ockam_api/src/cloud/space.rs index ab82fde391c..14985fd81fc 100644 --- a/implementations/rust/ockam/ockam_api/src/cloud/space.rs +++ b/implementations/rust/ockam/ockam_api/src/cloud/space.rs @@ -10,9 +10,9 @@ use ockam_node::Context; use crate::cloud::email_address::EmailAddress; use crate::cloud::project::models::AdminInfo; use crate::cloud::project::{Project, ProjectsOrchestratorApi}; -use crate::cloud::subscription::Subscription; +use crate::cloud::subscription::{Subscription, SUBSCRIPTION_PAGE}; use crate::cloud::{ControllerClient, HasSecureClient}; -use crate::colors::{color_primary, color_uri, color_warn}; +use crate::colors::{color_primary, color_uri, color_warn, OckamColor}; use crate::fmt_log; use crate::nodes::InMemoryNode; use crate::output::{comma_separated, Output}; @@ -39,8 +39,11 @@ impl Space { self.name.clone() } - pub fn has_subscription(&self) -> bool { - self.subscription.is_some() + pub fn has_valid_subscription(&self) -> bool { + self.subscription + .as_ref() + .map(|s| s.is_valid()) + .unwrap_or(false) } pub fn is_in_free_trial_subscription(&self) -> bool { @@ -52,46 +55,44 @@ impl Space { .unwrap_or_default() } - pub fn subscription_status_message(&self, space_is_new: bool) -> crate::Result { + pub fn subscription_status_message(&self) -> crate::Result { + use colorful::{Colorful, RGB}; + let mut f = String::new(); if let Some(subscription) = &self.subscription { + let color = match subscription.name.as_str() { + "gold" => RGB::new(255, 215, 0), + "silver" => RGB::new(230, 232, 250), + "bronze" => RGB::new(140, 120, 83), + _ => OckamColor::PrimaryResource.color(), + }; + let trial_text = if subscription.is_free_trial { + " (trial)" + } else { + "" + }; writeln!( f, "{}", fmt_log!( - "This Space has a {} Subscription attached to it.", - color_primary(&subscription.name) + "This Space has a {}{} Subscription attached to it.", + subscription.name.clone().color(color), + trial_text ) )?; + if let (Some(start_date), Some(end_date)) = + (&subscription.start_date(), &subscription.end_date()) + { + writeln!( + f, + "{}", + fmt_log!("Started on {} and will end on {}.", start_date, end_date) + )?; + } if subscription.is_free_trial { - if space_is_new { - writeln!(f)?; - writeln!(f, "{}", fmt_log!("As a courtesy, we created a temporary Space for you, so you can continue to build.\n"))?; - writeln!( - f, - "{}", - fmt_log!( - "Please subscribe to an Ockam plan within two weeks {}", - color_uri("https://www.ockam.io/pricing") - ) - )?; - writeln!(f, "{}", fmt_log!("{}", color_warn("If you don't subscribe in that time, your Space and all associated Projects will be permanently deleted.")))?; - } else if let (Some(start_date), Some(end_date)) = - (&subscription.start_date(), &subscription.end_date()) - { - writeln!(f)?; - writeln!( - f, - "{}", - fmt_log!( - "Your free trial started on {} and will end on {}.\n", - start_date, - end_date - ) - )?; - writeln!(f, "{}", fmt_log!("Please subscribe to an Ockam plan before the trial ends to avoid any service interruptions {}", color_uri("https://www.ockam.io/pricing")))?; - writeln!(f, "{}", fmt_log!("{}", color_warn("If you don't subscribe in that time, your Space and all associated Projects will be permanently deleted.")))?; - } + writeln!(f)?; + writeln!(f, "{}", fmt_log!("Please subscribe to an Ockam plan before the trial ends to avoid any service interruptions {}", color_uri(SUBSCRIPTION_PAGE)))?; + writeln!(f, "{}", fmt_log!("{}", color_warn("If you don't subscribe in that time, your Space and all associated Projects will be permanently deleted.")))?; } } else { writeln!( @@ -362,10 +363,11 @@ impl ControllerClient { #[cfg(test)] pub mod tests { - use quickcheck::{quickcheck, Arbitrary, Gen, TestResult}; - use crate::cloud::space::CreateSpace; use crate::schema::tests::validate_with_schema; + use quickcheck::{quickcheck, Arbitrary, Gen, TestResult}; + use time::format_description::well_known::Iso8601; + use time::OffsetDateTime; use super::*; @@ -402,4 +404,57 @@ pub mod tests { } } } + + #[test] + fn valid_subscription_check() { + let mut g = Gen::new(100); + let mut space = Space::arbitrary(&mut g); + + // No subscription + space.subscription = None; + assert!(!space.has_valid_subscription()); + + // Paid subscription + let mut sub = Subscription::arbitrary(&mut g); + sub.is_free_trial = false; + space.subscription = Some(sub.clone()); + assert!(space.has_valid_subscription()); + + // Trial subscription with no dates + let mut sub = Subscription::arbitrary(&mut g); + sub.is_free_trial = true; + sub.start_date = None; + sub.end_date = None; + space.subscription = Some(sub.clone()); + assert!(!space.has_valid_subscription()); + + // Trial subscription with date values + sub.start_date = Some( + (OffsetDateTime::now_utc() - time::Duration::days(1)) + .format(&Iso8601::DEFAULT) + .unwrap() + .to_string(), + ); + sub.end_date = None; + space.subscription = Some(sub.clone()); + assert!(!space.has_valid_subscription()); + + sub.end_date = Some( + (OffsetDateTime::now_utc() - time::Duration::hours(1)) + .format(&Iso8601::DEFAULT) + .unwrap() + .to_string(), + ); + space.subscription = Some(sub.clone()); + assert!(!space.has_valid_subscription()); + + sub.end_date = Some( + (OffsetDateTime::now_utc() + time::Duration::hours(1)) + .format(&Iso8601::DEFAULT) + .unwrap() + .to_string(), + ); + space.subscription = Some(sub.clone()); + assert!(space.has_valid_subscription()); + } } diff --git a/implementations/rust/ockam/ockam_api/src/cloud/subscription.rs b/implementations/rust/ockam/ockam_api/src/cloud/subscription.rs index e2eff71ca4f..0da000cad3c 100644 --- a/implementations/rust/ockam/ockam_api/src/cloud/subscription.rs +++ b/implementations/rust/ockam/ockam_api/src/cloud/subscription.rs @@ -16,6 +16,8 @@ use ockam_node::Context; const TARGET: &str = "ockam_api::cloud::subscription"; const API_SERVICE: &str = "subscriptions"; +pub const SUBSCRIPTION_PAGE: &str = "https://orchestrator.ockam.io"; + #[derive(Encode, Decode, CborLen, Debug)] #[cfg_attr(test, derive(Clone))] #[rustfmt::skip] @@ -58,15 +60,15 @@ impl ActivateSubscription { #[cbor(map)] pub struct Subscription { #[n(1)] - pub name: String, + pub name: String, // TODO: Use enum for known values? #[n(2)] pub is_free_trial: bool, #[n(3)] pub marketplace: Option, #[n(4)] - start_date: Option, + pub(crate) start_date: Option, #[n(5)] - end_date: Option, + pub(crate) end_date: Option, } impl PartialEq for Subscription { @@ -116,6 +118,19 @@ impl Subscription { .as_ref() .and_then(|date| parse_date(date).ok()) } + + /// A subscription is valid if: + /// - is in a trial period and end date is in the future + /// - a plan is not in trial status + pub fn is_valid(&self) -> bool { + if self.is_free_trial { + self.end_date() + .map(|end_date| end_date >= OffsetDateTime::now_utc()) + .unwrap_or(false) + } else { + true + } + } } impl Display for Subscription { diff --git a/implementations/rust/ockam/ockam_api/src/ui/terminal/mod.rs b/implementations/rust/ockam/ockam_api/src/ui/terminal/mod.rs index ffc401371f3..89d83c03763 100644 --- a/implementations/rust/ockam/ockam_api/src/ui/terminal/mod.rs +++ b/implementations/rust/ockam/ockam_api/src/ui/terminal/mod.rs @@ -394,7 +394,7 @@ impl Terminal { self.stderr.is_tty() && self.can_write_to_stderr() } - pub fn progress_bar(&self) -> Option { + pub fn spinner(&self) -> Option { if !self.can_use_progress_bar() { return None; } @@ -424,7 +424,7 @@ impl Terminal { if output_messages.is_empty() { return Ok(()); } - let pb = match self.progress_bar() { + let pb = match self.spinner() { Some(pb) => pb, None => return Ok(()), }; diff --git a/implementations/rust/ockam/ockam_api/src/ui/terminal/notification.rs b/implementations/rust/ockam/ockam_api/src/ui/terminal/notification.rs index 039193bd389..0524986b588 100644 --- a/implementations/rust/ockam/ockam_api/src/ui/terminal/notification.rs +++ b/implementations/rust/ockam/ockam_api/src/ui/terminal/notification.rs @@ -120,7 +120,7 @@ impl NotificationHandler { Notification::Progress(contents) => { if self.terminal.can_use_progress_bar() { if self.progress_bar.is_none() { - self.progress_bar = self.terminal.progress_bar(); + self.progress_bar = self.terminal.spinner(); } if let Some(pb) = self.progress_bar.as_ref() { pb.set_message(contents); diff --git a/implementations/rust/ockam/ockam_command/src/enroll/command.rs b/implementations/rust/ockam/ockam_command/src/enroll/command.rs index 2921b7accdd..4e346b5e3cb 100644 --- a/implementations/rust/ockam/ockam_command/src/enroll/command.rs +++ b/implementations/rust/ockam/ockam_command/src/enroll/command.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::io::stdin; use std::process; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; @@ -22,18 +23,18 @@ use crate::util::async_cmd; use crate::{docs, CommandGlobalOpts, Result}; use ockam::Context; use ockam_api::cli_state::journeys::{JourneyEvent, USER_EMAIL, USER_NAME}; -use ockam_api::cli_state::random_name; use ockam_api::cloud::enroll::auth0::*; use ockam_api::cloud::project::Project; use ockam_api::cloud::project::ProjectsOrchestratorApi; use ockam_api::cloud::space::{Space, Spaces}; +use ockam_api::cloud::subscription::SUBSCRIPTION_PAGE; use ockam_api::cloud::ControllerClient; use ockam_api::colors::{color_primary, color_uri, OckamColor}; use ockam_api::enroll::enrollment::{EnrollStatus, Enrollment}; use ockam_api::enroll::oidc_service::OidcService; use ockam_api::nodes::InMemoryNode; use ockam_api::terminal::notification::NotificationHandler; -use ockam_api::{fmt_log, fmt_ok, fmt_warn}; +use ockam_api::{fmt_err, fmt_log, fmt_ok, fmt_warn}; use ockam_api::{fmt_separator, CliState}; const LONG_ABOUT: &str = include_str!("./static/long_about.txt"); @@ -205,7 +206,7 @@ impl EnrollCommand { cli_state: &CliState, opts: &CommandGlobalOpts, ) -> miette::Result { - let is_already_enrolled = !cli_state + let mut is_already_enrolled = !cli_state .identity_should_enroll(&self.identity, false) .await?; if is_already_enrolled { @@ -244,6 +245,17 @@ impl EnrollCommand { } }; } + + // Check if the default space is available and has a valid subscription + let default_space = match cli_state.get_default_space().await { + Ok(space) => space, + Err(_) => { + // If there is no default space, we want to continue with the enrollment process + return Ok(false); + } + }; + is_already_enrolled &= default_space.has_valid_subscription(); + Ok(is_already_enrolled) } @@ -403,74 +415,145 @@ async fn get_user_space( skip_orchestrator_resources_creation: bool, ) -> miette::Result> { // Get the available spaces for node's identity - // Those spaces might have been created previously and all the local state reset opts.terminal.write_line(fmt_log!( "Getting available Spaces accessible to your account." ))?; - let is_finished = Mutex::new(false); - let get_spaces = async { - let spaces = node.get_spaces(ctx).await?; - *is_finished.lock().await = true; - Ok(spaces) - }; - let message = vec!["Checking for any existing Spaces...".to_string()]; - let progress_output = opts.terminal.loop_messages(&message, &is_finished); + let spaces = { + let sp = opts.terminal.spinner(); + if let Some(spinner) = sp.as_ref() { + spinner.set_message("Checking for any existing Spaces..."); + } + node.get_spaces(ctx).await? + }; - let (spaces, _) = try_join!(get_spaces, progress_output)?; - let mut is_new = false; - // If the identity has no spaces, create one let space = match spaces.first() { + // If the identity has no spaces, create one None => { - if skip_orchestrator_resources_creation { - opts.terminal - .write_line(fmt_log!("No Spaces are accessible to your account.\n"))?; - return Ok(None); - } - + // send user to subscription page + opts.terminal + .write_line(fmt_log!("No Spaces are accessible to your account.\n"))?; opts.terminal.write_line(fmt_log!( - "No Spaces are accessible to your account, creating a new one..." + "Please go to {} and subscribe to an Ockam plan to create a new Space.", + color_uri(SUBSCRIPTION_PAGE) ))?; - let is_finished = Mutex::new(false); - let space_name = random_name(); - let create_space = async { - let space = node.create_space(ctx, &space_name, vec![]).await?; - *is_finished.lock().await = true; - Ok(space) - }; + if skip_orchestrator_resources_creation { + return Ok(None); + } - let message = vec![format!( - "Creating a new Space {}...", - color_primary(space_name.clone()) - )]; - let progress_output = opts.terminal.loop_messages(&message, &is_finished); - let (space, _) = try_join!(create_space, progress_output)?; - opts.terminal.write_line(fmt_ok!( - "Created a new Space named {}.", - color_primary(space.name.clone()) - ))?; - is_new = true; - space + ask_user_to_subscribe_and_wait_for_space_to_be_ready(opts, ctx, node).await? } Some(space) => { opts.terminal.write_line(fmt_log!( - "Found existing Space {}.", - color_primary(space.name.clone()) + "Found existing Space {}.\n", + color_primary(&space.name) ))?; - space.clone() + match &space.subscription { + // if no subscription is attached to the space, ask the user to subscribe + None => { + opts.terminal.write_line(fmt_log!( + "Your Space {} doesn't have a subscription plan attached to it.", + color_primary(&space.name) + ))?; + opts.terminal.write_line(fmt_log!( + "Please go to {} and subscribe to an Ockam plan to use your Space.", + color_uri(SUBSCRIPTION_PAGE) + ))?; + ask_user_to_subscribe_and_wait_for_space_to_be_ready(opts, ctx, node).await? + } + Some(subscription) => { + // if there is a subscription, check that it's not expired + if !subscription.is_valid() { + opts.terminal.write_line(fmt_log!( + "Your Space {} has an expired subscription plan attached to it.", + color_primary(&space.name) + ))?; + opts.terminal.write_line(fmt_log!( + "Please go to {} and update your Ockam subscription plan to use your Space.", + color_uri(SUBSCRIPTION_PAGE) + ))?; + ask_user_to_subscribe_and_wait_for_space_to_be_ready(opts, ctx, node) + .await? + } + // otherwise return the space as is + else { + space.clone() + } + } + } } }; + space.subscription.as_ref().ok_or_else(|| { + // At this point, the space should have a subscription, but just in case + miette!( + "Please go to {} and try again", + color_uri(SUBSCRIPTION_PAGE) + ) + .wrap_err("The Space does not have a subscription plan attached.") + })?; opts.terminal.write_line(fmt_ok!( "Marked {} as your default Space, on this machine.\n", - color_primary(space.name.clone()) + color_primary(&space.name) ))?; - if let Ok(msg) = space.subscription_status_message(is_new) { + if let Ok(msg) = space.subscription_status_message() { opts.terminal.write_line(msg)?; } Ok(Some(space)) } +async fn ask_user_to_subscribe_and_wait_for_space_to_be_ready( + opts: &CommandGlobalOpts, + ctx: &Context, + node: &InMemoryNode, +) -> Result { + if opts.terminal.can_ask_for_user_input() { + opts.terminal.write(fmt_log!( + "Press {} to open {} in your browser.", + " ENTER ↵ ".bg_white().black().blink(), + color_uri(SUBSCRIPTION_PAGE) + ))?; + + let mut input = String::new(); + match stdin().read_line(&mut input) { + Ok(_) => { + opts.terminal + .write_line(fmt_log!("Opening your browser..."))?; + } + Err(_e) => { + return Err(miette!( + "Couldn't read user input or enter keypress from stdin" + ))?; + } + } + } + if open::that(SUBSCRIPTION_PAGE).is_err() { + opts.terminal.write_line(fmt_err!( + "Couldn't open your browser from the terminal. Please open {} manually.", + color_uri(SUBSCRIPTION_PAGE) + ))?; + } + + opts.terminal.write_line("")?; + + // wait until the user has subscribed and a space is created + let sp = opts.terminal.spinner(); + if let Some(spinner) = sp.as_ref() { + let msg = "Waiting for you to subscribe to an Ockam plan using your browser..."; + spinner.set_message(msg); + } + let space = loop { + let spaces = node.get_spaces(ctx).await?; + if let Some(space) = spaces.into_iter().next() { + if space.has_valid_subscription() { + break space; + } + } + tokio::time::sleep(std::time::Duration::from_secs(5)).await; + }; + Ok(space) +} + async fn get_user_project( opts: &CommandGlobalOpts, ctx: &Context, @@ -478,24 +561,20 @@ async fn get_user_project( skip_orchestrator_resources_creation: bool, space: &Space, ) -> Result> { - // Get available project for the given space + // Get available projects for the given space opts.terminal.write_line(fmt_log!( "Getting available Projects in the Space {}...", color_primary(&space.name) ))?; - let is_finished = Mutex::new(false); - let get_projects = async { - let projects = node.get_admin_projects(ctx).await?; - *is_finished.lock().await = true; - Ok(projects) + let projects = { + let sp = opts.terminal.spinner(); + if let Some(spinner) = sp.as_ref() { + spinner.set_message("Checking for any existing Projects..."); + } + node.get_admin_projects(ctx).await? }; - let message = vec!["Checking for existing Projects...".to_string()]; - let progress_output = opts.terminal.loop_messages(&message, &is_finished); - - let (projects, _) = try_join!(get_projects, progress_output)?; - // If the space has no projects, create one let project = match projects.first() { None => { diff --git a/implementations/rust/ockam/ockam_command/src/enroll/oidc_service.rs b/implementations/rust/ockam/ockam_command/src/enroll/oidc_service.rs index 13649ece096..d87902257da 100644 --- a/implementations/rust/ockam/ockam_command/src/enroll/oidc_service.rs +++ b/implementations/rust/ockam/ockam_command/src/enroll/oidc_service.rs @@ -144,7 +144,7 @@ impl OidcServiceExt for OidcService { token: &OidcToken, terminal: Option<&Terminal>>, ) -> Result { - let pb = terminal.and_then(|t| t.progress_bar()); + let pb = terminal.and_then(|t| t.spinner()); if let Some(spinner) = pb.as_ref() { spinner.set_message("Verifying email..."); sleep(Duration::from_millis(500)).await; @@ -184,7 +184,7 @@ impl OidcServiceExt for OidcService { ) -> Result { if open::that(uri.clone()).is_err() { opts.terminal.write_line(fmt_err!( - "Couldn't open activation URL automatically [URL={}]", + "Couldn't open your browser from the terminal. Please open {} manually.", color_uri(&uri) ))?; } @@ -200,8 +200,8 @@ impl OidcServiceExt for OidcService { let provider = self.provider(); let client = provider.build_http_client()?; let token; - let pb = opts.terminal.progress_bar(); - if let Some(spinner) = pb.as_ref() { + let sp = opts.terminal.spinner(); + if let Some(spinner) = sp.as_ref() { let msg = format!( "{} {} {}", "Waiting for you to complete activating", @@ -229,7 +229,7 @@ impl OidcServiceExt for OidcService { StatusCode::OK => { token = res.json::().await.into_diagnostic()?; debug!(?token, "token response received"); - if let Some(spinner) = pb.as_ref() { + if let Some(spinner) = sp.as_ref() { spinner.finish_and_clear(); } return Ok(token); diff --git a/implementations/rust/ockam/ockam_command/src/influxdb/inlet/create.rs b/implementations/rust/ockam/ockam_command/src/influxdb/inlet/create.rs index b939dc619ed..02e5770bd80 100644 --- a/implementations/rust/ockam/ockam_command/src/influxdb/inlet/create.rs +++ b/implementations/rust/ockam/ockam_command/src/influxdb/inlet/create.rs @@ -47,7 +47,7 @@ impl Command for InfluxDBCreateCommand { .map(|t| node.set_timeout_mut(t)); let inlet_status = { - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(pb) = pb.as_ref() { pb.set_message(format!( "Creating a InfluxDB Inlet at {}...\n", diff --git a/implementations/rust/ockam/ockam_command/src/influxdb/outlet/create.rs b/implementations/rust/ockam/ockam_command/src/influxdb/outlet/create.rs index bc1a5752abe..947242e78ba 100644 --- a/implementations/rust/ockam/ockam_command/src/influxdb/outlet/create.rs +++ b/implementations/rust/ockam/ockam_command/src/influxdb/outlet/create.rs @@ -72,7 +72,7 @@ impl Command for InfluxDBCreateCommand { let node = BackgroundNodeClient::create(ctx, &opts.state, &self.tcp_outlet.at).await?; let outlet_status = { - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(pb) = pb.as_ref() { pb.set_message(format!( "Creating a new InfluxDB Outlet to {}...\n", diff --git a/implementations/rust/ockam/ockam_command/src/kafka/inlet/create.rs b/implementations/rust/ockam/ockam_command/src/kafka/inlet/create.rs index b0fed96b913..aafd142fbaf 100644 --- a/implementations/rust/ockam/ockam_command/src/kafka/inlet/create.rs +++ b/implementations/rust/ockam/ockam_command/src/kafka/inlet/create.rs @@ -151,7 +151,7 @@ impl Command for CreateCommand { let to = process_nodes_multiaddr(&self.to, &opts.state).await?; let inlet = { - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(pb) = pb.as_ref() { pb.set_message(format!( "Creating Kafka Inlet at {}...\n", diff --git a/implementations/rust/ockam/ockam_command/src/kafka/outlet/create.rs b/implementations/rust/ockam/ockam_command/src/kafka/outlet/create.rs index 60bd2cf9b06..8bd0ab14ca0 100644 --- a/implementations/rust/ockam/ockam_command/src/kafka/outlet/create.rs +++ b/implementations/rust/ockam/ockam_command/src/kafka/outlet/create.rs @@ -58,7 +58,7 @@ impl Command for CreateCommand { initialize_default_node(ctx, &opts).await?; let outlet = { - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(pb) = pb.as_ref() { pb.set_message(format!( "Creating Kafka Outlet to bootstrap server {}...\n", diff --git a/implementations/rust/ockam/ockam_command/src/node/show.rs b/implementations/rust/ockam/ockam_command/src/node/show.rs index 273216aa83d..e97dcfd4d7a 100644 --- a/implementations/rust/ockam/ockam_command/src/node/show.rs +++ b/implementations/rust/ockam/ockam_command/src/node/show.rs @@ -217,7 +217,7 @@ async fn is_node_ready( // Test if node is ready // If the node is down, we expect it won't reply and the timeout will trigger the next loop let result = node - .ask_with_timeout::<(), NodeStatus>(ctx, api::query_status(), timeout_duration) + .ask_with_timeout::<(), NodeStatus>(ctx, api::query_status(), Duration::from_secs(1)) .await; if let Ok(node_status) = result { if node_status.status.is_running() { diff --git a/implementations/rust/ockam/ockam_command/src/operation/util.rs b/implementations/rust/ockam/ockam_command/src/operation/util.rs index a9adfa5e103..572b39d0d3e 100644 --- a/implementations/rust/ockam/ockam_command/src/operation/util.rs +++ b/implementations/rust/ockam/ockam_command/src/operation/util.rs @@ -16,7 +16,7 @@ pub async fn check_for_project_completion( node: &InMemoryNode, project: Project, ) -> miette::Result { - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(spinner) = pb.as_ref() { let message = format!( "Configuring project...\n{}\n{}", @@ -48,7 +48,7 @@ pub async fn check_for_operation_completion( operation_id: &str, operation_name: &str, ) -> miette::Result<()> { - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(spinner) = pb.as_ref() { let message = format!( "Waiting for {operation_name} to finish ...\n{}", diff --git a/implementations/rust/ockam/ockam_command/src/project/enroll.rs b/implementations/rust/ockam/ockam_command/src/project/enroll.rs index 1fad50c37bc..f58524b9978 100644 --- a/implementations/rust/ockam/ockam_command/src/project/enroll.rs +++ b/implementations/rust/ockam/ockam_command/src/project/enroll.rs @@ -134,7 +134,7 @@ impl Command for EnrollCommand { // Issue credential let credential = { - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(pb) = pb.as_ref() { pb.set_message("Issuing credential..."); } @@ -182,7 +182,7 @@ impl EnrollCommand { enrollment_ticket: EnrollmentTicket, ) -> Result<()> { let enroll_status = { - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(pb) = pb.as_ref() { pb.set_message("Using enrollment ticket to enroll identity..."); } @@ -231,7 +231,7 @@ impl EnrollCommand { .ok_or(miette!("Okta addon not configured"))? .into(); - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(pb) = pb.as_ref() { pb.set_message("Authenticating with Okta..."); } diff --git a/implementations/rust/ockam/ockam_command/src/project/ticket.rs b/implementations/rust/ockam/ockam_command/src/project/ticket.rs index 25961a2612d..619a5e8248b 100644 --- a/implementations/rust/ockam/ockam_command/src/project/ticket.rs +++ b/implementations/rust/ockam/ockam_command/src/project/ticket.rs @@ -121,7 +121,7 @@ impl Command for TicketCommand { // Request an enrollment token that a future member can use to get a // credential. let token = { - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(pb) = pb.as_ref() { pb.set_message("Creating an enrollment ticket..."); } diff --git a/implementations/rust/ockam/ockam_command/src/project/util.rs b/implementations/rust/ockam/ockam_command/src/project/util.rs index c39ec6ef315..1894cc6125e 100644 --- a/implementations/rust/ockam/ockam_command/src/project/util.rs +++ b/implementations/rust/ockam/ockam_command/src/project/util.rs @@ -109,7 +109,7 @@ pub async fn check_project_readiness( let retry_strategy = FixedInterval::from_millis(5000) .take((ORCHESTRATOR_AWAIT_TIMEOUT.as_millis() / 5000) as usize); - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); let project = check_project_ready(ctx, node, project, retry_strategy.clone(), pb.clone()).await?; let project = diff --git a/implementations/rust/ockam/ockam_command/src/project_member/delete.rs b/implementations/rust/ockam/ockam_command/src/project_member/delete.rs index 709882fec11..9c9b5de3745 100644 --- a/implementations/rust/ockam/ockam_command/src/project_member/delete.rs +++ b/implementations/rust/ockam/ockam_command/src/project_member/delete.rs @@ -101,7 +101,7 @@ impl Command for DeleteCommand { .filter(|id| id != &self_identifier) .collect::>(); - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(pb) = &pb { pb.set_message("Deleting members..."); } diff --git a/implementations/rust/ockam/ockam_command/src/relay/create.rs b/implementations/rust/ockam/ockam_command/src/relay/create.rs index cf7e15e2f33..aad706aa7d7 100644 --- a/implementations/rust/ockam/ockam_command/src/relay/create.rs +++ b/implementations/rust/ockam/ockam_command/src/relay/create.rs @@ -99,7 +99,7 @@ impl Command for CreateCommand { ))?; }; info!("creating a relay at {} to {}", at, node.node_name()); - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(pb) = pb.as_ref() { pb.set_message(format!( "Creating relay at {}...", diff --git a/implementations/rust/ockam/ockam_command/src/relay/list.rs b/implementations/rust/ockam/ockam_command/src/relay/list.rs index 88743e9b1d8..79c539fcae6 100644 --- a/implementations/rust/ockam/ockam_command/src/relay/list.rs +++ b/implementations/rust/ockam/ockam_command/src/relay/list.rs @@ -42,7 +42,7 @@ impl ListCommand { async fn async_run(&self, ctx: &Context, opts: CommandGlobalOpts) -> miette::Result<()> { let node = BackgroundNodeClient::create(ctx, &opts.state, &self.to).await?; let relays: Vec = { - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(pb) = pb { pb.set_message(format!( "Listing Relays on {}...\n", diff --git a/implementations/rust/ockam/ockam_command/src/reset.rs b/implementations/rust/ockam/ockam_command/src/reset.rs index 1b4dc6291ee..3b4877b364b 100644 --- a/implementations/rust/ockam/ockam_command/src/reset.rs +++ b/implementations/rust/ockam/ockam_command/src/reset.rs @@ -104,7 +104,7 @@ async fn delete_orchestrator_resources_impl( if spaces.is_empty() { return Ok(()); } - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(s) = pb.as_ref() { s.set_message("Deleting spaces from the Orchestrator..") }; diff --git a/implementations/rust/ockam/ockam_command/src/space/create.rs b/implementations/rust/ockam/ockam_command/src/space/create.rs index 69e7bbce28c..04883fe0e89 100644 --- a/implementations/rust/ockam/ockam_command/src/space/create.rs +++ b/implementations/rust/ockam/ockam_command/src/space/create.rs @@ -52,7 +52,7 @@ impl Command for CreateCommand { let node = InMemoryNode::start(ctx, &opts.state).await?; let space = { - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(pb) = pb.as_ref() { pb.set_message("Creating a Space for you..."); } @@ -63,7 +63,7 @@ impl Command for CreateCommand { ) .await? }; - if let Ok(msg) = space.subscription_status_message(true) { + if let Ok(msg) = space.subscription_status_message() { opts.terminal.write_line(msg)?; } opts.terminal diff --git a/implementations/rust/ockam/ockam_command/src/space/list.rs b/implementations/rust/ockam/ockam_command/src/space/list.rs index f9a59269b34..a676c84275c 100644 --- a/implementations/rust/ockam/ockam_command/src/space/list.rs +++ b/implementations/rust/ockam/ockam_command/src/space/list.rs @@ -32,7 +32,7 @@ impl Command for ListCommand { let node = InMemoryNode::start(ctx, &opts.state).await?; let spaces = { - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(pb) = pb.as_ref() { pb.set_message("Listing spaces..."); } diff --git a/implementations/rust/ockam/ockam_command/src/status.rs b/implementations/rust/ockam/ockam_command/src/status.rs index a38c30f303c..704d3d02d92 100644 --- a/implementations/rust/ockam/ockam_command/src/status.rs +++ b/implementations/rust/ockam/ockam_command/src/status.rs @@ -74,7 +74,7 @@ impl StatusCommand { opts: &CommandGlobalOpts, ) -> Result> { let mut nodes_resources = vec![]; - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); let nodes = opts.state.get_nodes().await?; for node in nodes { if let Some(ref pb) = pb { diff --git a/implementations/rust/ockam/ockam_command/src/tcp/inlet/create.rs b/implementations/rust/ockam/ockam_command/src/tcp/inlet/create.rs index a7548a08da0..f8ca201b158 100644 --- a/implementations/rust/ockam/ockam_command/src/tcp/inlet/create.rs +++ b/implementations/rust/ockam/ockam_command/src/tcp/inlet/create.rs @@ -173,7 +173,7 @@ impl Command for CreateCommand { cmd.timeout.timeout.map(|t| node.set_timeout_mut(t)); let inlet_status = { - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(pb) = pb.as_ref() { pb.set_message(format!( "Creating TCP Inlet at {}...\n", diff --git a/implementations/rust/ockam/ockam_command/src/tcp/inlet/list.rs b/implementations/rust/ockam/ockam_command/src/tcp/inlet/list.rs index 97a2fa9ae31..d46d0fc8e3e 100644 --- a/implementations/rust/ockam/ockam_command/src/tcp/inlet/list.rs +++ b/implementations/rust/ockam/ockam_command/src/tcp/inlet/list.rs @@ -36,7 +36,7 @@ impl ListCommand { async fn async_run(&self, ctx: &Context, opts: CommandGlobalOpts) -> miette::Result<()> { let node = BackgroundNodeClient::create(ctx, &opts.state, &self.node.at_node).await?; let inlets: Vec = { - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(pb) = pb.as_ref() { pb.set_message(format!("Listing TCP Inlets on {}...", node.node_name())); } diff --git a/implementations/rust/ockam/ockam_command/src/tcp/outlet/create.rs b/implementations/rust/ockam/ockam_command/src/tcp/outlet/create.rs index bf4925c07d8..af8ba26aed8 100644 --- a/implementations/rust/ockam/ockam_command/src/tcp/outlet/create.rs +++ b/implementations/rust/ockam/ockam_command/src/tcp/outlet/create.rs @@ -84,7 +84,7 @@ impl Command for CreateCommand { let node = BackgroundNodeClient::create(ctx, &opts.state, &self.at).await?; let node_name = node.node_name(); let outlet_status = { - let pb = opts.terminal.progress_bar(); + let pb = opts.terminal.spinner(); if let Some(pb) = pb.as_ref() { pb.set_message(format!( "Creating a new TCP Outlet to {}...\n",