mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 21:24:05 -08:00
promtool: Fix credentials file check (#9883)
The promtool check config command still uses the bearer_token_file field which is deprecated in favour of authorization.credentials_file. This commit modifies the command to use the new field insted. Fixes #9874 Signed-off-by: fpetkovski <filip.petkovsky@gmail.com>
This commit is contained in:
parent
56e5946a1a
commit
5849521e90
|
@ -353,8 +353,10 @@ func checkConfig(agentMode bool, filename string) ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, scfg := range cfg.ScrapeConfigs {
|
for _, scfg := range cfg.ScrapeConfigs {
|
||||||
if err := checkFileExists(scfg.HTTPClientConfig.BearerTokenFile); err != nil {
|
if scfg.HTTPClientConfig.Authorization != nil {
|
||||||
return nil, errors.Wrapf(err, "error checking bearer token file %q", scfg.HTTPClientConfig.BearerTokenFile)
|
if err := checkFileExists(scfg.HTTPClientConfig.Authorization.CredentialsFile); err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "error checking authorization credentials or bearer token file %q", scfg.HTTPClientConfig.Authorization.CredentialsFile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := checkTLSConfig(scfg.HTTPClientConfig.TLSConfig); err != nil {
|
if err := checkTLSConfig(scfg.HTTPClientConfig.TLSConfig); err != nil {
|
||||||
|
|
|
@ -203,3 +203,33 @@ func TestCheckTargetConfig(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAuthorizationConfig(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
file string
|
||||||
|
err string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "authorization_credentials_file.bad",
|
||||||
|
file: "authorization_credentials_file.bad.yml",
|
||||||
|
err: "error checking authorization credentials or bearer token file",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "authorization_credentials_file.good",
|
||||||
|
file: "authorization_credentials_file.good.yml",
|
||||||
|
err: "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range cases {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
_, err := checkConfig(false, "testdata/"+test.file)
|
||||||
|
if test.err != "" {
|
||||||
|
require.Contains(t, err.Error(), test.err, "Expected error to contain %q, got %q", test.err, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
require.NoError(t, err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
4
cmd/promtool/testdata/authorization_credentials_file.bad.yml
vendored
Normal file
4
cmd/promtool/testdata/authorization_credentials_file.bad.yml
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
scrape_configs:
|
||||||
|
- job_name: test
|
||||||
|
authorization:
|
||||||
|
credentials_file: "/random/file/which/does/not/exist.yml"
|
4
cmd/promtool/testdata/authorization_credentials_file.good.yml
vendored
Normal file
4
cmd/promtool/testdata/authorization_credentials_file.good.yml
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
scrape_configs:
|
||||||
|
- job_name: test
|
||||||
|
authorization:
|
||||||
|
credentials_file: "."
|
Loading…
Reference in a new issue