Skip to content

Commit

Permalink
simplify checks for emptiness
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Jan 29, 2025
1 parent 9d77951 commit 41ba73a
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions go/controller/internal/controller/gitrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controller
import (
"context"

"github.com/samber/lo"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"

Expand Down Expand Up @@ -200,25 +201,10 @@ func (r *GitRepositoryReconciler) getRepositoryAttributes(ctx context.Context, r
return nil, err
}

privateKey := string(secret.Data[privateKey])
passphrase := string(secret.Data[passphrase])
username := string(secret.Data[username])
password := string(secret.Data[password])
if privateKey != "" {
attrs.PrivateKey = &privateKey
}

if passphrase != "" {
attrs.Passphrase = &passphrase
}

if username != "" {
attrs.Username = &username
}

if password != "" {
attrs.Password = &password
}
attrs.PrivateKey = lo.EmptyableToPtr(string(secret.Data[privateKey]))
attrs.Passphrase = lo.EmptyableToPtr(string(secret.Data[passphrase]))
attrs.Username = lo.EmptyableToPtr(string(secret.Data[username]))
attrs.Password = lo.EmptyableToPtr(string(secret.Data[password]))
}

return &attrs, nil
Expand Down

0 comments on commit 41ba73a

Please sign in to comment.