Skip to content

Commit

Permalink
fix: reflow tls detection to avoid potential nil dereference
Browse files Browse the repository at this point in the history
  • Loading branch information
theSuess committed Oct 28, 2024
1 parent 38b80bf commit 60b8fd6
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions controllers/client/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ var (

// build the tls.Config object based on the content of the Grafana CR object
func buildTLSConfiguration(ctx context.Context, c client.Client, grafana *v1beta1.Grafana) (*tls.Config, error) {
// if nothing is specified, ignore tls settings
if (grafana.Spec.Client == nil || grafana.Spec.Client.TLS == nil) && (grafana.Spec.External == nil || grafana.Spec.External.TLS == nil) {
return nil, nil
}
tlsConfigBlock := grafana.Spec.Client.TLS

// prefer top level if set, fall back to deprecated field
if tlsConfigBlock == nil && grafana.Spec.External != nil && grafana.Spec.External.TLS != nil {
var tlsConfigBlock *v1beta1.TLSConfig
if grafana.Spec.Client != nil && grafana.Spec.Client.TLS != nil {

Check failure on line 22 in controllers/client/tls.go

View workflow job for this annotation

GitHub Actions / go-lint

ifElseChain: rewrite if-else to switch statement (gocritic)
// prefer top level if set, fall back to deprecated field
tlsConfigBlock = grafana.Spec.Client.TLS
} else if grafana.Spec.External != nil && grafana.Spec.External.TLS != nil {
// fall back to external tls field if set
tlsConfigBlock = grafana.Spec.External.TLS
} else {
// if nothing is specified, ignore tls settings
return nil, nil
}

if tlsConfigBlock.InsecureSkipVerify {
Expand Down

0 comments on commit 60b8fd6

Please sign in to comment.