Skip to content

Commit

Permalink
add partial credentials validation
Browse files Browse the repository at this point in the history
  • Loading branch information
bcmdarroch committed Aug 30, 2022
1 parent 92ab62f commit efa80b7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions config/hcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ func (c *hcpConfig) SCADATLSConfig() *tls.Config {

func (c *hcpConfig) validate() error {

// Ensure both client credentials provided
if (c.clientCredentialsConfig.ClientID == "" && c.clientCredentialsConfig.ClientSecret != "") ||
(c.clientCredentialsConfig.ClientID != "" && c.clientCredentialsConfig.ClientSecret == "") {
return fmt.Errorf("both client ID and secret must be provided")
}

// Ensure at least one auth method configured
if c.clientCredentialsConfig.ClientID == "" && c.clientCredentialsConfig.ClientSecret == "" && c.oauth2Config.ClientID == "" {
return fmt.Errorf("either client credentials or oauth2 client ID must be provided")
}

// Ensure the auth URL is valid
if c.authURL.Host == "" {
return fmt.Errorf("the auth URL has to be non-empty")
Expand Down

0 comments on commit efa80b7

Please sign in to comment.