Skip to content

Commit

Permalink
Merge pull request #115 from shubheksha/move-shared-types
Browse files Browse the repository at this point in the history
Export `HTTPClientConfig.validate()`
  • Loading branch information
juliusv authored Jan 10, 2018
2 parents 2e54d0b + 9b1efff commit 89604d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions config/http_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"net/url"
"strings"

yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"
)

// BasicAuth contains basic HTTP authentication credentials.
Expand Down Expand Up @@ -79,7 +79,9 @@ type HTTPClientConfig struct {
XXX map[string]interface{} `yaml:",inline"`
}

func (c *HTTPClientConfig) validate() error {
// Validate validates the HTTPClientConfig to check only one of BearerToken,
// BasicAuth and BearerTokenFile is configured.
func (c *HTTPClientConfig) Validate() error {
if len(c.BearerToken) > 0 && len(c.BearerTokenFile) > 0 {
return fmt.Errorf("at most one of bearer_token & bearer_token_file must be configured")
}
Expand All @@ -96,9 +98,9 @@ func (c *HTTPClientConfig) UnmarshalYAML(unmarshal func(interface{}) error) erro
if err != nil {
return err
}
err = c.validate()
err = c.Validate()
if err != nil {
return c.validate()
return c.Validate()
}
return checkOverflow(c.XXX, "http_client_config")
}
Expand Down
2 changes: 1 addition & 1 deletion config/http_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestValidateHTTPConfig(t *testing.T) {
if err != nil {
t.Errorf("Error loading HTTP client config: %v", err)
}
err = cfg.validate()
err = cfg.Validate()
if err != nil {
t.Fatalf("Error validating %s: %s", "testdata/http.conf.good.yml", err)
}
Expand Down

0 comments on commit 89604d1

Please sign in to comment.