2828import com .github .rvesse .airline .annotations .Command ;
2929import com .github .rvesse .airline .annotations .Option ;
3030
31+ import java .io .Console ;
32+ import java .util .Arrays ;
3133import java .util .Scanner ;
3234
3335import static com .dtsx .astra .cli .core .out .AstraAnsiColors .CYAN_400 ;
@@ -51,19 +53,29 @@ public class SetupCmd extends AbstractCmd {
5153 public void execute () {
5254 if (tokenParam == null || tokenParam .isBlank ()) {
5355 verbose = true ;
54- String token ;
56+ String token = null ;
5557 AstraCliConsole .banner ();
56- try (Scanner scanner = new Scanner (System .in )) {
57- boolean validToken = false ;
58- while (!validToken ) {
59- AstraCliConsole .println ("$ Enter an Astra token:" , CYAN_400 );
60- token = removeQuotesIfAny (scanner .nextLine ());
61- try {
62- createDefaultSection (token );
63- validToken = true ;
64- } catch (InvalidTokenException ite ) {
65- LoggerShell .error ("Your token in invalid please retry " + ite .getMessage ());
58+ boolean validToken = false ;
59+ Console cons ;
60+ char [] tokenFromConsole ;
61+ while (!validToken ) {
62+ try {
63+ if ((cons = System .console ()) != null &&
64+ (tokenFromConsole = cons .readPassword ("[%s]" , "$ Enter an Astra token:" )) != null ) {
65+ token = String .valueOf (tokenFromConsole );
66+
67+ // Clear the password from memory immediately when done
68+ Arrays .fill (tokenFromConsole , ' ' );
69+ } else {
70+ try (Scanner scanner = new Scanner (System .in )) {
71+ AstraCliConsole .println ("$ Enter an Astra token:" , CYAN_400 );
72+ token = scanner .nextLine ();
73+ }
6674 }
75+ createDefaultSection (removeQuotesIfAny (token ));
76+ validToken = true ;
77+ } catch (InvalidTokenException ite ) {
78+ LoggerShell .error ("Your token in invalid please retry " + ite .getMessage ());
6779 }
6880 }
6981 } else {
0 commit comments