if err := unmarshal((*plain)(s)); err != nil {
return err
}
+ if err := s.HTTPClientConfig.Validate(); err != nil {
+ return err
+ }
if err := checkOverflow(s.XXX, "http probe"); err != nil {
return err
}
ConfigFile: "testdata/blackbox-bad.yml",
ExpectedError: "Error parsing config file: unknown fields in dns probe: invalid_extra_field",
},
+ {
+ ConfigFile: "testdata/blackbox-bad2.yml",
+ ExpectedError: "Error parsing config file: at most one of bearer_token & bearer_token_file must be configured",
+ },
{
ConfigFile: "testdata/invalid-dns-module.yml",
ExpectedError: "Error parsing config file: Query name must be set for DNS module",
}
for i, test := range tests {
err := sc.ReloadConfig(test.ConfigFile)
+ if err == nil {
+ t.Errorf("In case %v:\nExpected:\n%v\nGot:\nnil", i, test.ExpectedError)
+ continue
+ }
if err.Error() != test.ExpectedError {
t.Errorf("In case %v:\nExpected:\n%v\nGot:\n%v", i, test.ExpectedError, err.Error())
}
--- /dev/null
+modules:
+ http_post_2xx:
+ prober: http
+ timeout: 5s
+ http:
+ method: POST
+ bearer_token: foo
+ bearer_token_file: foo
+ basic_auth:
+ username: "username"
+ password: "mysecret"
"net/url"
"strings"
- yaml "gopkg.in/yaml.v2"
+ "gopkg.in/yaml.v2"
)
// BasicAuth contains basic HTTP authentication credentials.
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")
}
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")
}
"revisionTime": "2017-02-16T18:52:47Z"
},
{
- "checksumSHA1": "4TLgSCgJZuS5gtytxNvcVk4h8/g=",
+ "checksumSHA1": "i+0TxE6bOpJdPNOeNHpO0vMzFh4=",
"path": "github.com/prometheus/common/config",
- "revision": "2f17f4a9d485bf34b4bfaccc273805040e4f86c8",
- "revisionTime": "2017-09-08T16:18:22Z"
+ "revision": "89604d197083d4781071d3c65855d24ecfb0a563",
+ "revisionTime": "2018-01-10T21:49:58Z"
},
{
"checksumSHA1": "xfnn0THnqNwjwimeTClsxahYrIo=",