@@ -241,27 +241,24 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
241241 }
242242
243243 if validate {
244- if apiKey == "" {
245- if username == "" {
246- diags = append (diags , diag.Diagnostic {
247- Severity : diag .Error ,
248- Summary : "Initializing provider, username parameter is missing." ,
249- })
250- }
251-
252- if password == "" {
253- diags = append (diags , diag.Diagnostic {
254- Severity : diag .Error ,
255- Summary : "Initializing provider, password parameter is missing." ,
256- })
257- }
258- }
259244 if aquaURL == "" {
260245 diags = append (diags , diag.Diagnostic {
261246 Severity : diag .Error ,
262247 Summary : "Initializing provider, aqua_url parameter is missing." ,
263248 })
264249 }
250+ if username == "" {
251+ diags = append (diags , diag.Diagnostic {
252+ Severity : diag .Error ,
253+ Summary : "Initializing provider, username parameter is missing." ,
254+ })
255+ }
256+ if password == "" {
257+ diags = append (diags , diag.Diagnostic {
258+ Severity : diag .Error ,
259+ Summary : "Initializing provider, password parameter is missing." ,
260+ })
261+ }
265262 }
266263
267264 var caCertByte []byte
@@ -283,8 +280,24 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
283280 }
284281
285282 var aquaClient * client.Client
286- if apiKey != "" {
287- aquaClient = client .NewClientWithAPIKey (aquaURL , apiKey , secretkey , verifyTLS , caCertByte )
283+ if username != "" && password != "" {
284+ aquaClient , err = client .NewClientWithTokenAuth (aquaURL , username , password , verifyTLS , caCertByte )
285+ if err != nil {
286+ return nil , diag.Diagnostics {diag.Diagnostic {
287+ Severity : diag .Error ,
288+ Summary : "Error creating Aqua client with token authentication" ,
289+ Detail : err .Error (),
290+ }}
291+ }
292+ } else if apiKey != "" {
293+ aquaClient , err = client .NewClientWithAPIKey (aquaURL , apiKey , secretkey , verifyTLS , caCertByte )
294+ if err != nil {
295+ return nil , diag.Diagnostics {diag.Diagnostic {
296+ Severity : diag .Error ,
297+ Summary : "Error creating Aqua client with API key" ,
298+ Detail : err .Error (),
299+ }}
300+ }
288301 if v , ok := d .GetOk ("validity" ); ok {
289302 aquaClient .Validity = v .(int )
290303 }
@@ -295,7 +308,11 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
295308 aquaClient .CSPRoles = convertStringArr (v .([]interface {}))
296309 }
297310 } else {
298- aquaClient = client .NewClientWithTokenAuth (aquaURL , username , password , verifyTLS , caCertByte )
311+ return nil , diag.Diagnostics {diag.Diagnostic {
312+ Severity : diag .Error ,
313+ Summary : "Missing credentials" ,
314+ Detail : "Provide username+password or aqua_api_key+aqua_api_secret." ,
315+ }}
299316 }
300317
301318 if validate {
0 commit comments