@@ -90,45 +90,41 @@ public Integer call() {
90
90
|| inputOptions .stdinOptions .credentials .isEmpty ()
91
91
? RootCredentialsSet .EMPTY
92
92
: 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 ;
103
101
}
104
102
}
105
103
106
- // Execute the bootstrap
107
104
Map <String , PrincipalSecretsResult > results =
108
105
metaStoreManagerFactory .bootstrapRealms (realms , rootCredentialsSet );
109
106
110
- // Log any errors:
111
107
boolean success = true ;
112
108
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 ()) {
115
112
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 ());
124
123
}
125
124
} else {
126
- String realm = result .getKey ();
127
125
spec .commandLine ()
128
126
.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 ());
132
128
success = false ;
133
129
}
134
130
}
0 commit comments