From 045b21be494f07035427b0fbb25247d0f908a900 Mon Sep 17 00:00:00 2001 From: savitaashture Date: Thu, 4 Jun 2020 20:44:59 +0530 Subject: [PATCH] Modify BitBucketInterceptor to BitbucketInterceptor and update README --- docs/eventlisteners.md | 5 ++--- .../triggers/v1alpha1/event_listener_types.go | 6 +++--- .../event_listener_validation_test.go | 2 +- .../v1alpha1/zz_generated.deepcopy.go | 10 +++++----- pkg/interceptors/bitbucket/bitbucket.go | 4 ++-- pkg/interceptors/bitbucket/bitbucket_test.go | 20 +++++++++---------- pkg/sink/sink_test.go | 4 ++-- 7 files changed, 25 insertions(+), 26 deletions(-) diff --git a/docs/eventlisteners.md b/docs/eventlisteners.md index 49f367990..57cc5cf52 100644 --- a/docs/eventlisteners.md +++ b/docs/eventlisteners.md @@ -420,9 +420,8 @@ spec: ### Bitbucket Interceptors -Bitbucket Interceptors contain logic to validate and filter webhooks that come from -Bitbucket server or cloud. Supported features include validating webhooks actually came from Bitbucket as well as -filtering incoming events. +The Bitbucket interceptor provides support for hooks originating in [Bitbucket server](https://confluence.atlassian.com/bitbucketserver), providing server hook signature validation and event-filtering. +[Bitbucket cloud](https://support.atlassian.com/bitbucket-cloud/) is not currently supported by this interceptor, as it has no secret validation, so you could match on the incoming requests using the CEL interceptor. To use this Interceptor as a validator, create a secret string using the method of your choice, and configure the Bitbucket webhook to use that secret value. diff --git a/pkg/apis/triggers/v1alpha1/event_listener_types.go b/pkg/apis/triggers/v1alpha1/event_listener_types.go index d091edc07..950a8f618 100644 --- a/pkg/apis/triggers/v1alpha1/event_listener_types.go +++ b/pkg/apis/triggers/v1alpha1/event_listener_types.go @@ -85,7 +85,7 @@ type EventInterceptor struct { GitHub *GitHubInterceptor `json:"github,omitempty"` GitLab *GitLabInterceptor `json:"gitlab,omitempty"` CEL *CELInterceptor `json:"cel,omitempty"` - Bitbucket *BitBucketInterceptor `json:"bitbucket,omitempty"` + Bitbucket *BitbucketInterceptor `json:"bitbucket,omitempty"` } // WebhookInterceptor provides a webhook to intercept and pre-process events @@ -100,8 +100,8 @@ type WebhookInterceptor struct { Header []v1beta1.Param `json:"header,omitempty"` } -// BitBucketInterceptor provides a webhook to intercept and pre-process events -type BitBucketInterceptor struct { +// BitbucketInterceptor provides a webhook to intercept and pre-process events +type BitbucketInterceptor struct { SecretRef *SecretRef `json:"secretRef,omitempty"` EventTypes []string `json:"eventTypes,omitempty"` } diff --git a/pkg/apis/triggers/v1alpha1/event_listener_validation_test.go b/pkg/apis/triggers/v1alpha1/event_listener_validation_test.go index 05f1b4f81..14c5d0e42 100644 --- a/pkg/apis/triggers/v1alpha1/event_listener_validation_test.go +++ b/pkg/apis/triggers/v1alpha1/event_listener_validation_test.go @@ -349,7 +349,7 @@ func TestEventListenerValidate_error(t *testing.T) { Interceptors: []*v1alpha1.EventInterceptor{{ GitHub: &v1alpha1.GitHubInterceptor{}, GitLab: &v1alpha1.GitLabInterceptor{}, - Bitbucket: &v1alpha1.BitBucketInterceptor{}, + Bitbucket: &v1alpha1.BitbucketInterceptor{}, }}, }}, }, diff --git a/pkg/apis/triggers/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/triggers/v1alpha1/zz_generated.deepcopy.go index 09a021b90..6762118de 100644 --- a/pkg/apis/triggers/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/triggers/v1alpha1/zz_generated.deepcopy.go @@ -27,7 +27,7 @@ import ( ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *BitBucketInterceptor) DeepCopyInto(out *BitBucketInterceptor) { +func (in *BitbucketInterceptor) DeepCopyInto(out *BitbucketInterceptor) { *out = *in if in.SecretRef != nil { in, out := &in.SecretRef, &out.SecretRef @@ -42,12 +42,12 @@ func (in *BitBucketInterceptor) DeepCopyInto(out *BitBucketInterceptor) { return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BitBucketInterceptor. -func (in *BitBucketInterceptor) DeepCopy() *BitBucketInterceptor { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BitbucketInterceptor. +func (in *BitbucketInterceptor) DeepCopy() *BitbucketInterceptor { if in == nil { return nil } - out := new(BitBucketInterceptor) + out := new(BitbucketInterceptor) in.DeepCopyInto(out) return out } @@ -175,7 +175,7 @@ func (in *EventInterceptor) DeepCopyInto(out *EventInterceptor) { } if in.Bitbucket != nil { in, out := &in.Bitbucket, &out.Bitbucket - *out = new(BitBucketInterceptor) + *out = new(BitbucketInterceptor) (*in).DeepCopyInto(*out) } return diff --git a/pkg/interceptors/bitbucket/bitbucket.go b/pkg/interceptors/bitbucket/bitbucket.go index ed7995ea6..1007ae8dc 100644 --- a/pkg/interceptors/bitbucket/bitbucket.go +++ b/pkg/interceptors/bitbucket/bitbucket.go @@ -33,11 +33,11 @@ import ( type Interceptor struct { KubeClientSet kubernetes.Interface Logger *zap.SugaredLogger - Bitbucket *triggersv1.BitBucketInterceptor + Bitbucket *triggersv1.BitbucketInterceptor EventListenerNamespace string } -func NewInterceptor(bh *triggersv1.BitBucketInterceptor, k kubernetes.Interface, ns string, l *zap.SugaredLogger) interceptors.Interceptor { +func NewInterceptor(bh *triggersv1.BitbucketInterceptor, k kubernetes.Interface, ns string, l *zap.SugaredLogger) interceptors.Interceptor { return &Interceptor{ Logger: l, Bitbucket: bh, diff --git a/pkg/interceptors/bitbucket/bitbucket_test.go b/pkg/interceptors/bitbucket/bitbucket_test.go index 8dafe97b4..c32c28dbd 100644 --- a/pkg/interceptors/bitbucket/bitbucket_test.go +++ b/pkg/interceptors/bitbucket/bitbucket_test.go @@ -42,14 +42,14 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) { } tests := []struct { name string - Bitbucket *triggersv1.BitBucketInterceptor + Bitbucket *triggersv1.BitbucketInterceptor args args want []byte wantErr bool }{ { name: "no secret", - Bitbucket: &triggersv1.BitBucketInterceptor{}, + Bitbucket: &triggersv1.BitbucketInterceptor{}, args: args{ payload: ioutil.NopCloser(bytes.NewBufferString("somepayload")), signature: "foo", @@ -59,7 +59,7 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) { }, { name: "invalid header for secret", - Bitbucket: &triggersv1.BitBucketInterceptor{ + Bitbucket: &triggersv1.BitbucketInterceptor{ SecretRef: &triggersv1.SecretRef{ SecretName: "mysecret", SecretKey: "token", @@ -81,7 +81,7 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) { }, { name: "valid header for secret", - Bitbucket: &triggersv1.BitBucketInterceptor{ + Bitbucket: &triggersv1.BitbucketInterceptor{ SecretRef: &triggersv1.SecretRef{ SecretName: "mysecret", SecretKey: "token", @@ -106,7 +106,7 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) { }, { name: "matching event", - Bitbucket: &triggersv1.BitBucketInterceptor{ + Bitbucket: &triggersv1.BitbucketInterceptor{ EventTypes: []string{"pr:opened", "repo:refs_changed"}, }, args: args{ @@ -118,7 +118,7 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) { }, { name: "no matching event", - Bitbucket: &triggersv1.BitBucketInterceptor{ + Bitbucket: &triggersv1.BitbucketInterceptor{ EventTypes: []string{"pr:opened", "repo:refs_changed"}, }, args: args{ @@ -129,7 +129,7 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) { }, { name: "valid header for secret and matching event", - Bitbucket: &triggersv1.BitBucketInterceptor{ + Bitbucket: &triggersv1.BitbucketInterceptor{ SecretRef: &triggersv1.SecretRef{ SecretName: "mysecret", SecretKey: "token", @@ -156,7 +156,7 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) { }, { name: "valid header for secret, but no matching event", - Bitbucket: &triggersv1.BitBucketInterceptor{ + Bitbucket: &triggersv1.BitbucketInterceptor{ SecretRef: &triggersv1.SecretRef{ SecretName: "mysecret", SecretKey: "token", @@ -182,7 +182,7 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) { }, { name: "invalid header for secret, but matching event", - Bitbucket: &triggersv1.BitBucketInterceptor{ + Bitbucket: &triggersv1.BitbucketInterceptor{ SecretRef: &triggersv1.SecretRef{ SecretName: "mysecret", SecretKey: "token", @@ -205,7 +205,7 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) { wantErr: true, }, { name: "nil body does not panic", - Bitbucket: &triggersv1.BitBucketInterceptor{}, + Bitbucket: &triggersv1.BitbucketInterceptor{}, args: args{ payload: nil, signature: "foo", diff --git a/pkg/sink/sink_test.go b/pkg/sink/sink_test.go index b1550d41a..81e043b10 100644 --- a/pkg/sink/sink_test.go +++ b/pkg/sink/sink_test.go @@ -898,7 +898,7 @@ func TestHandleEventWithInterceptorsAndTriggerAuth(t *testing.T) { } -func TestHandleEventWithBitBucketInterceptors(t *testing.T) { +func TestHandleEventWithBitbucketInterceptors(t *testing.T) { eventBody := json.RawMessage(`{"repository": {"links": {"clone": [{"href": "testurl", "name": "ssh"}, {"href": "testurl", "name": "http"}]}}, "changes": [{"ref": {"displayId": "test-branch"}}]}`) tb, tt := getResources(t, "$(body.repository.links.clone[1].href)") @@ -924,7 +924,7 @@ func TestHandleEventWithBitBucketInterceptors(t *testing.T) { Bindings: []*triggersv1.EventListenerBinding{{Name: "tb", Kind: "TriggerBinding"}}, Template: triggersv1.EventListenerTemplate{Name: "tt"}, Interceptors: []*triggersv1.EventInterceptor{{ - Bitbucket: &triggersv1.BitBucketInterceptor{ + Bitbucket: &triggersv1.BitbucketInterceptor{ SecretRef: &triggersv1.SecretRef{ SecretKey: "secretKey", SecretName: "secret",