@@ -47,8 +47,11 @@ import (
47
47
apiv1 "github.com/fluxcd/notification-controller/api/v1"
48
48
)
49
49
50
- var (
51
- WebhookPathIndexKey = ".metadata.webhookPath"
50
+ const (
51
+ WebhookPathIndexKey string = ".metadata.webhookPath"
52
+
53
+ // maxRequestSizeBytes is the maximum size of a request to the API server
54
+ maxRequestSizeBytes int64 = 3 * 1024 * 1024
52
55
)
53
56
54
57
// defaultFluxAPIVersions is a map of Flux API kinds to their API versions.
@@ -142,7 +145,7 @@ func (s *ReceiverServer) handlePayload(w http.ResponseWriter, r *http.Request) {
142
145
func (s * ReceiverServer ) notifySingleResource (ctx context.Context , logger logr.Logger , resource * metav1.PartialObjectMetadata , resourcePredicate resourcePredicate ) error {
143
146
objectKey := client .ObjectKeyFromObject (resource )
144
147
if err := s .kubeClient .Get (ctx , objectKey , resource ); err != nil {
145
- return fmt .Errorf ("unable to read %s '%s' error: %w" , resource .Kind , objectKey , err )
148
+ return fmt .Errorf ("unable to read %s %q error: %w" , resource .Kind , objectKey , err )
146
149
}
147
150
148
151
return s .notifyResource (ctx , logger , resource , resourcePredicate )
@@ -175,7 +178,7 @@ func (s *ReceiverServer) notifyDynamicResources(ctx context.Context, logger logr
175
178
return fmt .Errorf ("matchLabels field not set when using wildcard '*' as name" )
176
179
}
177
180
178
- logger .V (1 ).Info (fmt .Sprintf ("annotate resources by matchLabel for kind '%s' in '%s' " ,
181
+ logger .V (1 ).Info (fmt .Sprintf ("annotate resources by matchLabel for kind %q in %q " ,
179
182
resource .Kind , namespace ), "matchLabels" , resource .MatchLabels )
180
183
181
184
var resources metav1.PartialObjectMetadataList
@@ -193,7 +196,7 @@ func (s *ReceiverServer) notifyDynamicResources(ctx context.Context, logger logr
193
196
}
194
197
195
198
if len (resources .Items ) == 0 {
196
- noObjectsFoundErr := fmt .Errorf ("no '%s' resources found with matching labels '%s ' in '%s' namespace" , resource .Kind , resource .MatchLabels , namespace )
199
+ noObjectsFoundErr := fmt .Errorf ("no %q resources found with matching labels %q ' in %q namespace" , resource .Kind , resource .MatchLabels , namespace )
197
200
logger .Error (noObjectsFoundErr , "error annotating resources" )
198
201
return nil
199
202
}
@@ -218,6 +221,7 @@ func (s *ReceiverServer) validate(ctx context.Context, receiver apiv1.Receiver,
218
221
"name" , receiver .Name ,
219
222
"namespace" , receiver .Namespace )
220
223
224
+ r .Body = io .NopCloser (io .LimitReader (r .Body , maxRequestSizeBytes ))
221
225
switch receiver .Spec .Type {
222
226
case apiv1 .GenericReceiver :
223
227
return nil
@@ -254,7 +258,7 @@ func (s *ReceiverServer) validate(ctx context.Context, receiver apiv1.Receiver,
254
258
}
255
259
}
256
260
if ! allowed {
257
- return fmt .Errorf ("the GitHub event '%s' is not authorised" , event )
261
+ return fmt .Errorf ("the GitHub event %q is not authorised" , event )
258
262
}
259
263
}
260
264
@@ -276,7 +280,7 @@ func (s *ReceiverServer) validate(ctx context.Context, receiver apiv1.Receiver,
276
280
}
277
281
}
278
282
if ! allowed {
279
- return fmt .Errorf ("the GitLab event '%s' is not authorised" , event )
283
+ return fmt .Errorf ("the GitLab event %q is not authorised" , event )
280
284
}
281
285
}
282
286
@@ -308,7 +312,7 @@ func (s *ReceiverServer) validate(ctx context.Context, receiver apiv1.Receiver,
308
312
}
309
313
}
310
314
if ! allowed {
311
- return fmt .Errorf ("the CDEvent '%s' is not authorised" , event )
315
+ return fmt .Errorf ("the CDEvent %q is not authorised" , event )
312
316
}
313
317
}
314
318
@@ -336,7 +340,7 @@ func (s *ReceiverServer) validate(ctx context.Context, receiver apiv1.Receiver,
336
340
}
337
341
}
338
342
if ! allowed {
339
- return fmt .Errorf ("the Bitbucket server event '%s' is not authorised" , event )
343
+ return fmt .Errorf ("the Bitbucket server event %q is not authorised" , event )
340
344
}
341
345
}
342
346
@@ -489,7 +493,7 @@ func (s *ReceiverServer) validate(ctx context.Context, receiver apiv1.Receiver,
489
493
return nil
490
494
}
491
495
492
- return fmt .Errorf ("recevier type '%s' not supported" , receiver .Spec .Type )
496
+ return fmt .Errorf ("recevier type %q not supported" , receiver .Spec .Type )
493
497
}
494
498
495
499
func (s * ReceiverServer ) token (ctx context.Context , receiver apiv1.Receiver ) (string , error ) {
@@ -502,13 +506,13 @@ func (s *ReceiverServer) token(ctx context.Context, receiver apiv1.Receiver) (st
502
506
var secret corev1.Secret
503
507
err := s .kubeClient .Get (ctx , secretName , & secret )
504
508
if err != nil {
505
- return "" , fmt .Errorf ("unable to read token from secret '%s' error: %w" , secretName , err )
509
+ return "" , fmt .Errorf ("unable to read token from secret %q error: %w" , secretName , err )
506
510
}
507
511
508
512
if val , ok := secret .Data ["token" ]; ok {
509
513
token = string (val )
510
514
} else {
511
- return "" , fmt .Errorf ("invalid '%s' secret data: required field 'token'" , secretName )
515
+ return "" , fmt .Errorf ("invalid %q secret data: required field 'token'" , secretName )
512
516
}
513
517
514
518
return token , nil
@@ -526,7 +530,7 @@ func (s *ReceiverServer) requestReconciliation(ctx context.Context, logger logr.
526
530
apiVersion := resource .APIVersion
527
531
if apiVersion == "" {
528
532
if defaultFluxAPIVersions [resource .Kind ] == "" {
529
- return fmt .Errorf ("apiVersion must be specified for kind '%s' " , resource .Kind )
533
+ return fmt .Errorf ("apiVersion must be specified for kind %q " , resource .Kind )
530
534
}
531
535
apiVersion = defaultFluxAPIVersions [resource .Kind ]
532
536
}
@@ -561,7 +565,7 @@ func (s *ReceiverServer) annotate(ctx context.Context, resource *metav1.PartialO
561
565
resource .SetAnnotations (sourceAnnotations )
562
566
563
567
if err := s .kubeClient .Patch (ctx , resource , patch ); err != nil {
564
- return fmt .Errorf ("unable to annotate %s '%s' error: %w" , resource .Kind , client.ObjectKey {
568
+ return fmt .Errorf ("unable to annotate %s %q error: %w" , resource .Kind , client.ObjectKey {
565
569
Namespace : resource .Namespace ,
566
570
Name : resource .Name ,
567
571
}, err )
0 commit comments