Copilot commented on code in PR #2809:
URL:
https://github.com/apache/apisix-ingress-controller/pull/2809#discussion_r3627920120
##########
internal/adc/translator/apisixconsumer_test.go:
##########
@@ -23,13 +23,64 @@ import (
"github.com/go-logr/logr"
"github.com/stretchr/testify/require"
+ corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ k8stypes "k8s.io/apimachinery/pkg/types"
+ adctypes "github.com/apache/apisix-ingress-controller/api/adc"
apiv2 "github.com/apache/apisix-ingress-controller/api/v2"
"github.com/apache/apisix-ingress-controller/internal/controller/label"
"github.com/apache/apisix-ingress-controller/internal/provider"
)
+func hmacConsumerWithSecret(name string) *apiv2.ApisixConsumer {
+ return &apiv2.ApisixConsumer{
+ ObjectMeta: metav1.ObjectMeta{Name: "demo", Namespace:
"default"},
+ Spec: apiv2.ApisixConsumerSpec{
+ AuthParameter: &apiv2.ApisixConsumerAuthParameter{
+ HMACAuth: &apiv2.ApisixConsumerHMACAuth{
+ SecretRef:
&corev1.LocalObjectReference{Name: name},
+ },
+ },
+ },
+ }
+}
Review Comment:
The helper parameter name `name` is ambiguous (it’s the SecretRef name, not
the consumer name). Renaming it improves readability of the new tests.
##########
internal/adc/translator/apisixconsumer.go:
##########
@@ -355,7 +366,14 @@ func (t *Translator) translateConsumerHMACAuthPlugin(tctx
*provider.TranslateCon
}
maxReqBodyRaw := sec.Data["max_req_body"]
- maxReqBody, _ := strconv.ParseInt(string(maxReqBodyRaw), 10, 64)
+ var maxReqBody int64
+ if len(maxReqBodyRaw) > 0 {
+ var err error
+ maxReqBody, err = strconv.ParseInt(string(maxReqBodyRaw), 10,
64)
+ if err != nil {
+ return nil, fmt.Errorf("hmac-auth: invalid max_req_body
%q in secret: %w", string(maxReqBodyRaw), err)
+ }
Review Comment:
The parse error message doesn’t identify which Secret contained the invalid
value. Including the Secret namespace/name would make it much easier to trace
misconfiguration.
##########
internal/adc/translator/apisixconsumer.go:
##########
@@ -307,15 +308,25 @@ func (t *Translator) translateConsumerHMACAuthPlugin(tctx
*provider.TranslateCon
}
clockSkewRaw := sec.Data["clock_skew"]
- clockSkew, _ := strconv.ParseInt(string(clockSkewRaw), 10, 64)
+ var clockSkew int64
+ if len(clockSkewRaw) > 0 {
+ var err error
+ clockSkew, err = strconv.ParseInt(string(clockSkewRaw), 10, 64)
+ if err != nil {
+ return nil, fmt.Errorf("hmac-auth: invalid clock_skew
%q in secret: %w", string(clockSkewRaw), err)
+ }
Review Comment:
The parse error message doesn’t identify which Secret contained the invalid
value, which can make debugging harder when multiple consumers reference
different secrets. Including namespace/name would make the error actionable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]