@@ -546,10 +546,10 @@ func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string, optFuncs ...HT
546
546
547
547
// If a authorization_credentials is provided, create a round tripper that will set the
548
548
// Authorization header correctly on each request.
549
- if cfg .Authorization != nil && len (cfg .Authorization .Credentials ) > 0 {
550
- rt = NewAuthorizationCredentialsRoundTripper (cfg .Authorization .Type , cfg .Authorization .Credentials , rt )
551
- } else if cfg .Authorization != nil && len (cfg .Authorization .CredentialsFile ) > 0 {
549
+ if cfg .Authorization != nil && len (cfg .Authorization .CredentialsFile ) > 0 {
552
550
rt = NewAuthorizationCredentialsFileRoundTripper (cfg .Authorization .Type , cfg .Authorization .CredentialsFile , rt )
551
+ } else if cfg .Authorization != nil {
552
+ rt = NewAuthorizationCredentialsRoundTripper (cfg .Authorization .Type , cfg .Authorization .Credentials , rt )
553
553
}
554
554
// Backwards compatibility, be nice with importers who would not have
555
555
// called Validate().
@@ -630,7 +630,7 @@ func (rt *authorizationCredentialsFileRoundTripper) RoundTrip(req *http.Request)
630
630
if len (req .Header .Get ("Authorization" )) == 0 {
631
631
b , err := os .ReadFile (rt .authCredentialsFile )
632
632
if err != nil {
633
- return nil , fmt .Errorf ("unable to read authorization credentials file %s: %s " , rt .authCredentialsFile , err )
633
+ return nil , fmt .Errorf ("unable to read authorization credentials file %s: %w " , rt .authCredentialsFile , err )
634
634
}
635
635
authCredentials := strings .TrimSpace (string (b ))
636
636
@@ -670,7 +670,7 @@ func (rt *basicAuthRoundTripper) RoundTrip(req *http.Request) (*http.Response, e
670
670
if rt .usernameFile != "" {
671
671
usernameBytes , err := os .ReadFile (rt .usernameFile )
672
672
if err != nil {
673
- return nil , fmt .Errorf ("unable to read basic auth username file %s: %s " , rt .usernameFile , err )
673
+ return nil , fmt .Errorf ("unable to read basic auth username file %s: %w " , rt .usernameFile , err )
674
674
}
675
675
username = strings .TrimSpace (string (usernameBytes ))
676
676
} else {
@@ -679,7 +679,7 @@ func (rt *basicAuthRoundTripper) RoundTrip(req *http.Request) (*http.Response, e
679
679
if rt .passwordFile != "" {
680
680
passwordBytes , err := os .ReadFile (rt .passwordFile )
681
681
if err != nil {
682
- return nil , fmt .Errorf ("unable to read basic auth password file %s: %s " , rt .passwordFile , err )
682
+ return nil , fmt .Errorf ("unable to read basic auth password file %s: %w " , rt .passwordFile , err )
683
683
}
684
684
password = strings .TrimSpace (string (passwordBytes ))
685
685
} else {
@@ -723,7 +723,7 @@ func (rt *oauth2RoundTripper) RoundTrip(req *http.Request) (*http.Response, erro
723
723
if rt .config .ClientSecretFile != "" {
724
724
data , err := os .ReadFile (rt .config .ClientSecretFile )
725
725
if err != nil {
726
- return nil , fmt .Errorf ("unable to read oauth2 client secret file %s: %s " , rt .config .ClientSecretFile , err )
726
+ return nil , fmt .Errorf ("unable to read oauth2 client secret file %s: %w " , rt .config .ClientSecretFile , err )
727
727
}
728
728
secret = strings .TrimSpace (string (data ))
729
729
rt .mtx .RLock ()
@@ -977,7 +977,7 @@ func (c *TLSConfig) getClientCertificate(_ *tls.CertificateRequestInfo) (*tls.Ce
977
977
if c .CertFile != "" {
978
978
certData , err = os .ReadFile (c .CertFile )
979
979
if err != nil {
980
- return nil , fmt .Errorf ("unable to read specified client cert (%s): %s " , c .CertFile , err )
980
+ return nil , fmt .Errorf ("unable to read specified client cert (%s): %w " , c .CertFile , err )
981
981
}
982
982
} else {
983
983
certData = []byte (c .Cert )
@@ -986,15 +986,15 @@ func (c *TLSConfig) getClientCertificate(_ *tls.CertificateRequestInfo) (*tls.Ce
986
986
if c .KeyFile != "" {
987
987
keyData , err = os .ReadFile (c .KeyFile )
988
988
if err != nil {
989
- return nil , fmt .Errorf ("unable to read specified client key (%s): %s " , c .KeyFile , err )
989
+ return nil , fmt .Errorf ("unable to read specified client key (%s): %w " , c .KeyFile , err )
990
990
}
991
991
} else {
992
992
keyData = []byte (c .Key )
993
993
}
994
994
995
995
cert , err := tls .X509KeyPair (certData , keyData )
996
996
if err != nil {
997
- return nil , fmt .Errorf ("unable to use specified client cert (%s) & key (%s): %s " , c .CertFile , c .KeyFile , err )
997
+ return nil , fmt .Errorf ("unable to use specified client cert (%s) & key (%s): %w " , c .CertFile , c .KeyFile , err )
998
998
}
999
999
1000
1000
return & cert , nil
@@ -1004,7 +1004,7 @@ func (c *TLSConfig) getClientCertificate(_ *tls.CertificateRequestInfo) (*tls.Ce
1004
1004
func readCAFile (f string ) ([]byte , error ) {
1005
1005
data , err := os .ReadFile (f )
1006
1006
if err != nil {
1007
- return nil , fmt .Errorf ("unable to load specified CA cert %s: %s " , f , err )
1007
+ return nil , fmt .Errorf ("unable to load specified CA cert %s: %w " , f , err )
1008
1008
}
1009
1009
return data , nil
1010
1010
}
0 commit comments