Skip to content

Commit 4346048

Browse files
committed
dont print provided creds in BootstrapCommand
`bootstrapRealms` is called from `BootstrapCommand.call` and `QuarkusProducers.maybeBootstrap`. The latter is already only printing credentials that were not in the provided `RootCredentialsSet`. we adjust `BootstrapCommand` to do the same. the general idea is to only print credentials that were generated as part of the bootstrap.
1 parent a1b2ae7 commit 4346048

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -90,45 +90,41 @@ public Integer call() {
9090
|| inputOptions.stdinOptions.credentials.isEmpty()
9191
? RootCredentialsSet.EMPTY
9292
: RootCredentialsSet.fromList(inputOptions.stdinOptions.credentials);
93-
if (inputOptions.stdinOptions.credentials == null
94-
|| inputOptions.stdinOptions.credentials.isEmpty()) {
95-
if (!inputOptions.stdinOptions.printCredentials) {
96-
spec.commandLine()
97-
.getErr()
98-
.println(
99-
"Specify either `--credentials` or `--print-credentials` to ensure"
100-
+ " the root user is accessible after bootstrapping.");
101-
return EXIT_CODE_BOOTSTRAP_ERROR;
102-
}
93+
if (rootCredentialsSet.credentials().isEmpty()
94+
&& !inputOptions.stdinOptions.printCredentials) {
95+
spec.commandLine()
96+
.getErr()
97+
.println(
98+
"Specify either `--credentials` or `--print-credentials` to ensure"
99+
+ " the root user is accessible after bootstrapping.");
100+
return EXIT_CODE_BOOTSTRAP_ERROR;
103101
}
104102
}
105103

106-
// Execute the bootstrap
107104
Map<String, PrincipalSecretsResult> results =
108105
metaStoreManagerFactory.bootstrapRealms(realms, rootCredentialsSet);
109106

110-
// Log any errors:
111107
boolean success = true;
112108
for (Map.Entry<String, PrincipalSecretsResult> result : results.entrySet()) {
113-
if (result.getValue().isSuccess()) {
114-
String realm = result.getKey();
109+
String realm = result.getKey();
110+
PrincipalSecretsResult secretsResult = result.getValue();
111+
if (secretsResult.isSuccess()) {
115112
spec.commandLine().getOut().printf("Realm '%s' successfully bootstrapped.%n", realm);
116-
if (inputOptions.stdinOptions != null && inputOptions.stdinOptions.printCredentials) {
117-
String msg =
118-
String.format(
119-
"realm: %1s root principal credentials: %2s:%3s",
120-
result.getKey(),
121-
result.getValue().getPrincipalSecrets().getPrincipalClientId(),
122-
result.getValue().getPrincipalSecrets().getMainSecret());
123-
spec.commandLine().getOut().println(msg);
113+
if (inputOptions.stdinOptions != null
114+
&& inputOptions.stdinOptions.printCredentials
115+
&& !rootCredentialsSet.credentials().containsKey(realm)) {
116+
spec.commandLine()
117+
.getOut()
118+
.printf(
119+
"realm: %s root principal credentials: %s:%s%n",
120+
realm,
121+
secretsResult.getPrincipalSecrets().getPrincipalClientId(),
122+
secretsResult.getPrincipalSecrets().getMainSecret());
124123
}
125124
} else {
126-
String realm = result.getKey();
127125
spec.commandLine()
128126
.getErr()
129-
.printf(
130-
"Bootstrapping '%s' failed: %s%n",
131-
realm, result.getValue().getReturnStatus().toString());
127+
.printf("Bootstrapping '%s' failed: %s%n", realm, secretsResult.getReturnStatus());
132128
success = false;
133129
}
134130
}

0 commit comments

Comments
 (0)