From 648b753da45b28be8c92f3d8e7d2a8c3c4b66a31 Mon Sep 17 00:00:00 2001 From: Daniel Kuntze Date: Wed, 5 Jul 2023 17:25:47 +0200 Subject: [PATCH] fix sonar issue --- internal/provider/provider.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 20d0a985..f1e1a99c 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -76,6 +76,8 @@ func (p *btpcliProvider) Metadata(_ context.Context, _ provider.MetadataRequest, } func (p *btpcliProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { + const unableToCreateClient = "unableToCreateClient" + // Retrieve provider data from configuration var config providerData diags := req.Config.Get(ctx, &config) @@ -93,7 +95,7 @@ func (p *btpcliProvider) Configure(ctx context.Context, req provider.ConfigureRe u, err := url.Parse(selectedCLIServerURL) // TODO move to NewV2Client if err != nil { - resp.Diagnostics.AddError("Unable to create Client", fmt.Sprintf("%s", err)) + resp.Diagnostics.AddError(unableToCreateClient, fmt.Sprintf("%s", err)) return } @@ -103,7 +105,7 @@ func (p *btpcliProvider) Configure(ctx context.Context, req provider.ConfigureRe // User may provide an idp to the provider var idp string if config.IdentityProvider.IsUnknown() { - resp.Diagnostics.AddWarning("Unable to create client", "Cannot use unknown value as identity provider") + resp.Diagnostics.AddWarning(unableToCreateClient, "Cannot use unknown value as identity provider") return } @@ -116,7 +118,7 @@ func (p *btpcliProvider) Configure(ctx context.Context, req provider.ConfigureRe // User must provide a username to the provider var username string if config.Username.IsUnknown() { - resp.Diagnostics.AddWarning("Unable to create client", "Cannot use unknown value as username") + resp.Diagnostics.AddWarning(unableToCreateClient, "Cannot use unknown value as username") return } @@ -129,7 +131,7 @@ func (p *btpcliProvider) Configure(ctx context.Context, req provider.ConfigureRe // User must provide a password to the provider var password string if config.Password.IsUnknown() { - resp.Diagnostics.AddWarning("Unable to create client", "Cannot use unknown value as password") + resp.Diagnostics.AddWarning(unableToCreateClient, "Cannot use unknown value as password") return } @@ -140,12 +142,12 @@ func (p *btpcliProvider) Configure(ctx context.Context, req provider.ConfigureRe } if len(username) == 0 || len(password) == 0 { - resp.Diagnostics.AddError("Unable to create Client", "globalaccount, username and password must be given.") + resp.Diagnostics.AddError(unableToCreateClient, "globalaccount, username and password must be given.") return } if _, err = client.Login(ctx, btpcli.NewLoginRequestWithCustomIDP(idp, config.GlobalAccount.ValueString(), username, password)); err != nil { - resp.Diagnostics.AddError("Unable to create Client", fmt.Sprintf("%s", err)) + resp.Diagnostics.AddError(unableToCreateClient, fmt.Sprintf("%s", err)) return }