@@ -111,9 +111,6 @@ type HTTPClientConfig struct {
111111 ProxyURL URL `yaml:"proxy_url,omitempty"`
112112 // TLSConfig to use to connect to the targets.
113113 TLSConfig TLSConfig `yaml:"tls_config,omitempty"`
114- // Used to make sure that the configuration is valid and that BearerToken to
115- // Authorization.Credentials change has been handled.
116- valid bool
117114}
118115
119116// SetDirectory joins any relative file paths with dir.
@@ -169,8 +166,6 @@ func (c *HTTPClientConfig) Validate() error {
169166 c .BearerTokenFile = ""
170167 }
171168 }
172-
173- c .valid = true
174169 return nil
175170}
176171
@@ -207,12 +202,6 @@ func NewClientFromConfig(cfg HTTPClientConfig, name string, disableKeepAlives, e
207202// NewRoundTripperFromConfig returns a new HTTP RoundTripper configured for the
208203// given config.HTTPClientConfig. The name is used as go-conntrack metric label.
209204func NewRoundTripperFromConfig (cfg HTTPClientConfig , name string , disableKeepAlives , enableHTTP2 bool ) (http.RoundTripper , error ) {
210- // Make sure that the configuration is valid.
211- if ! cfg .valid {
212- if err := cfg .Validate (); err != nil {
213- return nil , err
214- }
215- }
216205 newRT := func (tlsConfig * tls.Config ) (http.RoundTripper , error ) {
217206 // The only timeout we care about is the configured scrape timeout.
218207 // It is applied on request. So we leave out any timings here.
@@ -254,6 +243,13 @@ func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string, disableKeepAli
254243 } else if cfg .Authorization != nil && len (cfg .Authorization .CredentialsFile ) > 0 {
255244 rt = NewAuthorizationCredentialsFileRoundTripper (cfg .Authorization .Type , cfg .Authorization .CredentialsFile , rt )
256245 }
246+ // Backwards compatibility, be nice with importers who would not have
247+ // called Validate().
248+ if len (cfg .BearerToken ) > 0 {
249+ rt = NewAuthorizationCredentialsRoundTripper ("Bearer" , cfg .BearerToken , rt )
250+ } else if len (cfg .BearerTokenFile ) > 0 {
251+ rt = NewAuthorizationCredentialsFileRoundTripper ("Bearer" , cfg .BearerTokenFile , rt )
252+ }
257253
258254 if cfg .BasicAuth != nil {
259255 rt = NewBasicAuthRoundTripper (cfg .BasicAuth .Username , cfg .BasicAuth .Password , cfg .BasicAuth .PasswordFile , rt )
0 commit comments