Skip to content

Commit

Permalink
Merge pull request #33 from ThorstenHans/feat/auto-confirm-token-rota…
Browse files Browse the repository at this point in the history
…tion

Add `--yes` (`-y`) flag to rotate-token to skip confirmation
  • Loading branch information
ThorstenHans authored Oct 14, 2024
2 parents ca7a686 + 6e94ecc commit 61e97cc
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ pub enum App {
/// Deploy the Fermyon Cloud GPU Spin App to act as a cloud GPU proxy.
Init,
/// Rotate the Auth Token for your existing Fermyon Cloud GPU
RotateToken,
RotateToken(RotateOptions),
/// Destroy the Fermyon Cloud GPU Spin App.
Destroy,
}

#[derive(Debug, Parser)]
pub struct RotateOptions {
#[clap(long = "yes", short = 'y', takes_value = false)]
pub yes: bool,
}

fn main() -> Result<(), anyhow::Error> {
match App::parse() {
App::Init => init(),
App::RotateToken => rotate_auth_token(),
App::RotateToken(options) => rotate_auth_token(options),
// App::Connect => connect(),
App::Destroy => destroy(),
}
Expand Down Expand Up @@ -65,15 +71,17 @@ fn init() -> Result<(), anyhow::Error> {
Ok(())
}

fn rotate_auth_token() -> Result<(), anyhow::Error> {
let confirmation = Confirm::new()
.with_prompt("Do you really want to rotate the Auth Token for Fermyon Cloud GPU? (Existing Spin Apps using your instance of Fermyon Cloud GPU must be updated)")
.interact()
.unwrap();

if !confirmation {
println!("Operation canceled! Auth Token for Fermyon Cloud GPU has not been rotated.");
return Ok(());
fn rotate_auth_token(options: RotateOptions) -> Result<(), anyhow::Error> {
if !options.yes {
let confirmation = Confirm::new()
.with_prompt("Do you really want to rotate the Auth Token for Fermyon Cloud GPU? (Existing Spin Apps using your instance of Fermyon Cloud GPU must be updated)")
.interact()
.unwrap();

if !confirmation {
println!("Operation canceled! Auth Token for Fermyon Cloud GPU has not been rotated.");
return Ok(());
}
}

let auth_token = generate_auth_token();
Expand Down

0 comments on commit 61e97cc

Please sign in to comment.