Skip to content

Commit 5b21888

Browse files
authored
chore: only add auth and pubkeys when they're not empty (#260)
## Issue N/A ## Description We were always populating the auth and allPubKeys maps which meant that we were unneccesarily calling the oci clients `WithVerificationPublicKeys` and `WithBasicAuth` functions for every rule (even those with no auth or pubkeys). Nothing was actually broken, but this is a more correct implementation
1 parent 4161664 commit 5b21888

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

internal/controller/ocivalidator_controller.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,18 @@ func (r *OciValidatorReconciler) Reconcile(ctx context.Context, req ctrl.Request
104104
l.Error(err, "failed to get secret auth", "ruleName", rule.Name())
105105
return ctrl.Result{}, err
106106
}
107-
auths[rule.Name()] = []string{username, password}
107+
if username != "" || password != "" {
108+
auths[rule.Name()] = []string{username, password}
109+
}
108110

109111
pubKeys, err := r.signaturePubKeys(req, rule)
110112
if err != nil {
111113
l.Error(err, "failed to get signature verification public keys", "ruleName", rule.Name())
112114
return ctrl.Result{}, err
113115
}
114-
allPubKeys[rule.Name()] = pubKeys
116+
if pubKeys != nil {
117+
allPubKeys[rule.Name()] = pubKeys
118+
}
115119
}
116120

117121
// Validate the rules

0 commit comments

Comments
 (0)