@@ -146,7 +146,7 @@ func initCredentialsCheck(
146
146
}
147
147
148
148
// Initialize the credentials.
149
- n . credentials = prismgoclient.Credentials {
149
+ credentials : = prismgoclient.Credentials {
150
150
Endpoint : fmt .Sprintf ("%s:%d" , host , port ),
151
151
URL : fmt .Sprintf ("https://%s:%d" , host , port ),
152
152
Username : usernamePassword .Username ,
@@ -155,7 +155,7 @@ func initCredentialsCheck(
155
155
}
156
156
157
157
// Initialize the clients.
158
- n . v4client , err = n .v4clientFactory (n . credentials )
158
+ v4client , err : = n .v4clientFactory (credentials )
159
159
if err != nil {
160
160
result .Allowed = false
161
161
result .Error = true
@@ -167,7 +167,7 @@ func initCredentialsCheck(
167
167
)
168
168
}
169
169
170
- n . v3client , err = n .v3clientFactory (n . credentials )
170
+ v3client , err : = n .v3clientFactory (credentials )
171
171
if err != nil {
172
172
result .Allowed = false
173
173
result .Error = true
@@ -177,21 +177,35 @@ func initCredentialsCheck(
177
177
Field : "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.credentials" ,
178
178
},
179
179
)
180
- } else {
181
- // Validate the credentials using an API call.
182
- _ , err = n .v3client .GetCurrentLoggedInUser (ctx )
183
- if err != nil {
184
- result .Allowed = false
185
- result .Error = true
186
- result .Causes = append (result .Causes ,
187
- preflight.Cause {
188
- Message : fmt .Sprintf ("failed to validate credentials using the v3 API client: %s" , err ),
189
- Field : "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint.credentials" ,
190
- },
191
- )
180
+ }
181
+
182
+ if v3client == nil || v4client == nil {
183
+ return func (ctx context.Context ) preflight.CheckResult {
184
+ return result
192
185
}
193
186
}
194
187
188
+ // Validate the credentials using an API call.
189
+ _ , err = v3client .GetCurrentLoggedInUser (ctx )
190
+ if err != nil {
191
+ result .Allowed = false
192
+ result .Error = true
193
+ result .Causes = append (result .Causes ,
194
+ preflight.Cause {
195
+ Message : fmt .Sprintf ("Failed to validate credentials using the v3 API client. " +
196
+ "The URL and/or credentials may be incorrect. (Error: %q)" , err ),
197
+ Field : "cluster.spec.topology.variables[.name=clusterConfig].nutanix.prismCentralEndpoint" ,
198
+ },
199
+ )
200
+ return func (ctx context.Context ) preflight.CheckResult {
201
+ return result
202
+ }
203
+ }
204
+
205
+ // We initialized both clients, and verified the credentials using the v3 client.
206
+ n .v3client = v3client
207
+ n .v4client = v4client
208
+
195
209
return func (ctx context.Context ) preflight.CheckResult {
196
210
return result
197
211
}
0 commit comments