Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sentry

import (
"context"
"crypto/tls"
"crypto/x509"
"fmt"
"io"
Expand Down Expand Up @@ -229,6 +230,8 @@ type ClientOptions struct {
// This will default to the HTTPS_PROXY environment variable.
// HTTPS_PROXY takes precedence over HTTP_PROXY for https requests.
HTTPSProxy string
// An optional tls config.
TLSConfig *tls.Config
// An optional set of SSL certificates to use.
CaCerts *x509.CertPool
// MaxErrorDepth is the maximum number of errors reported in a chain of errors.
Expand Down
13 changes: 0 additions & 13 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sentry
import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -60,18 +59,6 @@ func getProxyConfig(options ClientOptions) func(*http.Request) (*url.URL, error)
return http.ProxyFromEnvironment
}

func getTLSConfig(options ClientOptions) *tls.Config {
if options.CaCerts != nil {
// #nosec G402 -- We should be using `MinVersion: tls.VersionTLS12`,
// but we don't want to break peoples code without the major bump.
return &tls.Config{
RootCAs: options.CaCerts,
}
}

return nil
}

func getRequestBodyFromEvent(event *Event) []byte {
body, err := json.Marshal(event)
if err == nil {
Expand Down
22 changes: 22 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sentry

import (
"crypto/tls"
"encoding/json"
"fmt"
"os"
Expand Down Expand Up @@ -109,3 +110,24 @@ func revisionFromBuildInfo(info *debug.BuildInfo) string {
func Pointer[T any](v T) *T {
return &v
}

func getTLSConfig(options ClientOptions) *tls.Config {
if options.TLSConfig == nil && options.CaCerts == nil {
return nil
}

var tlsConfig *tls.Config
if options.TLSConfig != nil {
tlsConfig = options.TLSConfig.Clone()
} else {
// #nosec G402 -- We should be using `MinVersion: tls.VersionTLS12`,
// but we don't want to break peoples code without the major bump.
tlsConfig = &tls.Config{}
}

if tlsConfig.RootCAs == nil && options.CaCerts != nil {
tlsConfig.RootCAs = options.CaCerts
}

return tlsConfig
}
Loading