Skip to content

Commit

Permalink
Domain is not required when using application credentials (kubermatic…
Browse files Browse the repository at this point in the history
…#1896)

Signed-off-by: Waleed Malik <[email protected]>
  • Loading branch information
ahmedwaleedmalik authored Apr 7, 2022
1 parent 946a4ad commit 889a317
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ issues:
text: "`registry` always receives `\"127.0.0.1:5000\"`"

- path: pkg/credentials
text: "cyclomatic complexity 32 of func `openstackValidationFunc` is high"
text: "cyclomatic complexity 34 of func `openstackValidationFunc` is high"

- path: pkg/addons
text: "cyclomatic complexity 34 of func `newAddonsApplier` is high"
28 changes: 16 additions & 12 deletions pkg/credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,7 @@ func nutanixValidationFunc(creds map[string]string) error {
}

func openstackValidationFunc(creds map[string]string) error {
alwaysRequired := []string{OpenStackAuthURL, OpenStackDomainName, OpenStackRegionName}

for _, key := range alwaysRequired {
if v, ok := creds[key]; !ok || len(v) == 0 {
return fail.CredentialsError{
Op: "validating",
Provider: "Openstack",
Err: errors.Errorf("key %v is required but is not present", key),
}
}
}
alwaysRequired := []string{OpenStackAuthURL, OpenStackRegionName}

var (
appCredsIDOkay bool
Expand All @@ -472,11 +462,25 @@ func openstackValidationFunc(creds map[string]string) error {
if v, ok := creds[OpenStackApplicationCredentialID]; ok && len(v) != 0 {
appCredsIDOkay = true
}

if v, ok := creds[OpenStackApplicationCredentialSecret]; ok && len(v) != 0 {
appCredsSecretOkay = true
}

// Domain name is only required when using default credentials i.e. username and password
if !appCredsIDOkay && !appCredsSecretOkay {
alwaysRequired = append(alwaysRequired, OpenStackDomainName)
}

for _, key := range alwaysRequired {
if v, ok := creds[key]; !ok || len(v) == 0 {
return fail.CredentialsError{
Op: "validating",
Provider: "Openstack",
Err: errors.Errorf("key %v is required but is not present", key),
}
}
}

if v, ok := creds[OpenStackUserName]; ok && len(v) != 0 {
userCredsUsernameOkay = true
}
Expand Down

0 comments on commit 889a317

Please sign in to comment.