Skip to content

Commit ebd63c7

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 ebd63c7

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
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
}

quarkus/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTestBase.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,16 @@ public void testBootstrapFromInvalidFile(QuarkusMainLauncher launcher) {
127127
@Test
128128
@Launch(
129129
value = {"bootstrap", "-r", "realm1", "-c", "realm1,client1d,s3cr3t", "--print-credentials"})
130-
public void testPrintCredentials(LaunchResult result) {
130+
public void testPrintCredentialsProvided(LaunchResult result) {
131+
assertThat(result.exitCode()).isEqualTo(0);
131132
assertThat(result.getOutput()).contains("Bootstrap completed successfully.");
132-
assertThat(result.getOutput()).contains("realm: realm1 root principal credentials: client1d:");
133+
assertThat(result.getOutput()).doesNotContain("root principal credentials");
133134
}
134135

135136
@Test
136137
@Launch(value = {"bootstrap", "-r", "realm1", "--print-credentials"})
137138
public void testPrintCredentialsSystemGenerated(LaunchResult result) {
139+
assertThat(result.exitCode()).isEqualTo(0);
138140
assertThat(result.getOutput()).contains("Bootstrap completed successfully.");
139141
assertThat(result.getOutput()).contains("realm: realm1 root principal credentials: ");
140142
}

0 commit comments

Comments
 (0)