Skip to content

Commit

Permalink
fix sonar issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kuntzed committed Jul 6, 2023
1 parent 34704f2 commit 648b753
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 648b753

Please sign in to comment.