Skip to content

Commit

Permalink
Merge pull request #191 from msmygit/feature/mask_token
Browse files Browse the repository at this point in the history
Re-introduce securely masking Astra token on the console feature
  • Loading branch information
msmygit authored Oct 28, 2024
2 parents 126c04e + 3eed177 commit 85479f0
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/main/java/com/dtsx/astra/cli/config/SetupCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,34 @@ public void execute() {
AstraEnvironment targetEnv = AstraCliUtils.parseEnvironment(env);
// As not token is provided we ask for it in the console
if (token == null || token.isBlank()) {
verbose = true;
AstraCliConsole.banner();
boolean validToken = false;
Console cons;
char[] tokenFromConsole;
while (!validToken) {
try {
if ((cons = System.console()) != null &&
(tokenFromConsole = cons.readPassword("[%s]", "$ Enter an Astra token:")) != null) {
token = String.valueOf(tokenFromConsole);

// Clear the password from memory immediately when done
Arrays.fill(tokenFromConsole, ' ');
} else {
try (Scanner scanner = new Scanner(System.in)) {
AstraCliConsole.println("$ Enter an Astra token:", CYAN_400);
token = scanner.nextLine();
}
}
createDefaultSection();
validToken = true;
} catch(InvalidTokenException ite) {
LoggerShell.error("Your token in invalid please retry " + ite.getMessage());
}
}
} else {
createDefaultSection();
}
createDefaultSection();
}

/**
Expand Down

0 comments on commit 85479f0

Please sign in to comment.