Skip to content

Commit

Permalink
login: conceal pasted token
Browse files Browse the repository at this point in the history
  • Loading branch information
cole-h committed Dec 11, 2023
1 parent b79c8fd commit dad4c13
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/cli/cmd/init/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fmt::Display, process::exit};

use inquire::{
ui::{Color, RenderConfig, StyleSheet, Styled},
Confirm, MultiSelect, Select, Text,
Confirm, MultiSelect, Password, Select, Text,
};
use once_cell::sync::Lazy;

Expand Down Expand Up @@ -102,6 +102,25 @@ impl Prompt {
}
}

// Prompts for a FlakeHub token without confirmation.
pub(crate) fn maybe_token(msg: &str) -> Option<String> {
let result = Password::new(msg)
.with_render_config(*PROMPT_CONFIG)
.without_confirmation()
.prompt();

match result {
Ok(s) => {
if s.is_empty() {
None
} else {
Some(s)
}
}
Err(_) => exit(1),
}
}

pub(crate) fn for_language(lang: &str) -> bool {
Self::bool(&format!("This seems to be a {lang} project. Would you like to initialize your flake with some standard dependencies for {lang}?"))
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cmd/login/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl LoginSubcommand {
println!("And then follow the prompts below:");
println!();

let token = crate::cli::cmd::init::prompt::Prompt::maybe_string("Paste your token here:");
let token = crate::cli::cmd::init::prompt::Prompt::maybe_token("Paste your token here:");
let (token, status) = match token {
Some(token) => {
// This serves as validating that provided token is actually a JWT, and is valid.
Expand Down

0 comments on commit dad4c13

Please sign in to comment.