Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(playbook): Minor optimization of code #457

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 15 additions & 24 deletions pkg/playbook/app/domain/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,45 +122,36 @@ func isValidVaaS(c Connection) (bool, error) {
}

// Check if externalJWT has been provided
externalJWT := false
externaljwt := false
if c.Credentials.ExternalJWT != "" {
externalJWT = true
externaljwt = true
}

// There's a valid service account IF both externalJWT and tokenURL provided
svcaccount := false
if externalJWT && tokenurl {
if externaljwt && tokenurl {
svcaccount = true
} else if externalJWT && !tokenurl {
// JWT Provided without token url
} else if externaljwt && !tokenurl {
// JWT Provided without token URL
return false, ErrNoVCPTokenURL
} else if tokenurl && !externalJWT {
// Tokenurl without an external JWT
} else if tokenurl && !externaljwt {
// Token URL without an external JWT
return false, ErrNoExternalJWT
}

// If there's just an API key provided, that's good
if apikey && !accesstoken && !svcaccount {
return true, nil
}

// If there's just an accessToken provided, that's good
if !apikey && accesstoken && !svcaccount {
return true, nil
}

// If there's just a svcaccount defined, that's fine too
if !apikey && !accesstoken && svcaccount {
return true, nil
}

// At this point, there are no valid credentials. Figure out why.
if !apikey && !svcaccount && !accesstoken {
return false, ErrNoCredentials
}

// If we get here, it's because too many credentials were provided
return false, ErrAmbiguousVCPCreds
// if we got here then at least one of the credential options was provided
if (svcaccount && apikey) || (svcaccount && accesstoken) || (apikey && accesstoken) {
// more than one credential option is not acceptable
return false, ErrAmbiguousVCPCreds
}

// if we got here then only one credential option was provided (which is what we want)
return true, nil
}

func isValidFirefly(c Connection) (bool, error) {
Expand Down