Skip to content

Commit

Permalink
Fix var redefinition inside conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
vjacynycz committed Apr 4, 2024
1 parent 6dbb22e commit 378dcca
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions internal/ingress/annotations/authtls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"regexp"

"k8s.io/ingress-nginx/internal/ingress/annotations/parser"
"k8s.io/ingress-nginx/internal/ingress/errors"
ing_errors "k8s.io/ingress-nginx/internal/ingress/errors"
"k8s.io/ingress-nginx/internal/ingress/resolver"
"k8s.io/ingress-nginx/internal/k8s"
Expand Down Expand Up @@ -94,26 +95,28 @@ func (a authTLS) Parse(ing *networking.Ingress) (interface{}, error) {
var secretInVault bool = true
config := &Config{}

tlsauthsecret, _ := parser.GetStringAnnotation("auth-tls-vault", ing)

tlsauthsecret, err := parser.GetStringAnnotation("auth-tls-vault", ing)
if !errors.IsMissingAnnotations(err) {
return config, err
}
// If there is no secret in vault check for K8s secret
if tlsauthsecret == "" {
tlsauthsecret, err := parser.GetStringAnnotation("auth-tls-secret", ing)
tlsauthsecret, err = parser.GetStringAnnotation("auth-tls-secret", ing)
if err != nil {
return &Config{}, err
return config, err
}
secretInVault = false

_, _, err = k8s.ParseNameNS(tlsauthsecret)
if err != nil {
return &Config{}, ing_errors.NewLocationDenied(err.Error())
return config, ing_errors.NewLocationDenied(err.Error())
}
}

authCert, err := a.r.GetAuthCertificate(tlsauthsecret, secretInVault)
if err != nil {
e := fmt.Errorf("error obtaining certificate: %w", err)
return &Config{}, ing_errors.LocationDenied{Reason: e}
return config, ing_errors.LocationDenied{Reason: e}
}
config.AuthSSLCert = *authCert

Expand Down

0 comments on commit 378dcca

Please sign in to comment.