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
18 changes: 13 additions & 5 deletions src/commands/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use anyhow::bail;
use is_terminal::IsTerminal;

use crate::{
consts::TWO_FACTOR_REQUIRES_INTERACTIVE,
errors::RailwayError,
util::{
progress::create_spinner_if,
Expand All @@ -26,6 +25,10 @@ pub struct Args {
#[clap(short = 'y', long = "yes")]
yes: bool,

/// 2FA code for verification (required if 2FA is enabled in non-interactive mode)
#[clap(long = "2fa-code")]
two_factor_code: Option<String>,

/// Output in JSON format
#[clap(long)]
json: bool,
Expand Down Expand Up @@ -73,10 +76,15 @@ pub async fn command(args: Args) -> Result<()> {
};

if is_two_factor_enabled {
if !is_terminal {
bail!(TWO_FACTOR_REQUIRES_INTERACTIVE);
}
let token = prompt_text("Enter your 2FA code")?;
let token = if let Some(code) = args.two_factor_code {
code
} else if is_terminal {
prompt_text("Enter your 2FA code")?
} else {
bail!(
"2FA is enabled. Use --2fa-code <CODE> to provide your verification code in non-interactive mode."
);
};
let vars = mutations::validate_two_factor::Variables { token };

let valid =
Expand Down
16 changes: 10 additions & 6 deletions src/commands/environment/delete.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use super::{Delete as Args, *};
use crate::{
Configs, GQLClient,
consts::TWO_FACTOR_REQUIRES_INTERACTIVE,
controllers::project::get_project,
util::{
progress::create_spinner_if,
prompt::{prompt_confirm_with_default, prompt_options},
prompt::{prompt_confirm_with_default, prompt_options, prompt_text},
},
};
use anyhow::{Result, bail};
Expand Down Expand Up @@ -81,10 +80,15 @@ pub async fn delete_environment(args: Args) -> Result<()> {
info.is_verified
};
if is_two_factor_enabled {
if !is_terminal {
bail!(TWO_FACTOR_REQUIRES_INTERACTIVE);
}
let token = prompt_text("Enter your 2FA code")?;
let token = if let Some(code) = args.two_factor_code {
code
} else if is_terminal {
prompt_text("Enter your 2FA code")?
} else {
bail!(
"2FA is enabled. Use --2fa-code <CODE> to provide your verification code in non-interactive mode."
);
};
let vars = mutations::validate_two_factor::Variables { token };

let valid =
Expand Down
4 changes: 4 additions & 0 deletions src/commands/environment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ structstruck::strike! {
/// The environment to delete
pub environment: Option<String>,

/// 2FA code for verification (required if 2FA is enabled in non-interactive mode)
#[clap(long = "2fa-code")]
pub two_factor_code: Option<String>,

/// Output in JSON format
#[clap(long)]
pub json: bool,
Expand Down
31 changes: 25 additions & 6 deletions src/commands/volume.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::*;
use crate::{
consts::TWO_FACTOR_REQUIRES_INTERACTIVE,
controllers::project::{ensure_project_and_environment_exist, get_project},
errors::RailwayError,
queries::project::{
Expand Down Expand Up @@ -64,6 +63,10 @@ structstruck::strike! {
#[clap(short = 'y', long = "yes")]
yes: bool,

/// 2FA code for verification (required if 2FA is enabled in non-interactive mode)
#[clap(long = "2fa-code")]
two_factor_code: Option<String>,

/// Output in JSON format
#[clap(long)]
json: bool,
Expand Down Expand Up @@ -138,7 +141,17 @@ pub async fn command(args: Args) -> Result<()> {
match args.command {
Commands::Add(a) => add(service, environment, a.mount_path, project, a.json).await?,
Commands::List(l) => list(environment, project, l.json).await?,
Commands::Delete(d) => delete(environment, d.volume, project, d.yes, d.json).await?,
Commands::Delete(d) => {
delete(
environment,
d.volume,
project,
d.yes,
d.two_factor_code,
d.json,
)
.await?
}
Commands::Update(u) => {
update(environment, u.volume, u.mount_path, u.name, project, u.json).await?
}
Expand Down Expand Up @@ -388,6 +401,7 @@ async fn delete(
volume: Option<String>,
project: ProjectProject,
yes: bool,
two_factor_code: Option<String>,
json: bool,
) -> Result<()> {
let configs = Configs::new()?;
Expand Down Expand Up @@ -424,10 +438,15 @@ async fn delete(
};

if is_two_factor_enabled {
if !is_terminal {
bail!(TWO_FACTOR_REQUIRES_INTERACTIVE);
}
let token = prompt_text("Enter your 2FA code")?;
let token = if let Some(code) = two_factor_code {
code
} else if is_terminal {
prompt_text("Enter your 2FA code")?
} else {
bail!(
"2FA is enabled. Use --2fa-code <CODE> to provide your verification code in non-interactive mode."
);
};
let vars = mutations::validate_two_factor::Variables { token };

let valid = post_graphql::<mutations::ValidateTwoFactor, _>(
Expand Down