Skip to content

Commit

Permalink
Domain is not required when using application credentials (#1938)
Browse files Browse the repository at this point in the history
Signed-off-by: Waleed Malik <ahmedwaleedmalik@gmail.com>
  • Loading branch information
ahmedwaleedmalik authored Apr 8, 2022
1 parent d4f5c59 commit 7f9d21e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 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"
20 changes: 12 additions & 8 deletions pkg/credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,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 errors.Errorf("key %v is required but is not present", key)
}
}
alwaysRequired := []string{OpenStackAuthURL, OpenStackRegionName}

var (
appCredsIDOkay bool
Expand All @@ -429,11 +423,21 @@ 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 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 7f9d21e

Please sign in to comment.