Skip to content

Commit

Permalink
interceptors: small changes to types
Browse files Browse the repository at this point in the history
1. Change body from []byte to json.RawMessage
2. Remove omitempty tag for boolean type so that it marshals when false
3. Change context.url to context.event_url to match struct type

Part of tektoncd#271

Signed-off-by: Dibyo Mukherjee <dibyo@google.com>
  • Loading branch information
dibyom committed Dec 8, 2020
1 parent 3ea7d14 commit c104e09
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
9 changes: 5 additions & 4 deletions pkg/apis/triggers/v1alpha1/interceptor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1alpha1

import (
"context"
"encoding/json"
"fmt"
"strings"

Expand All @@ -16,7 +17,7 @@ type InterceptorInterface interface {
// +k8s:deepcopy-gen=false
type InterceptorRequest struct {
// Body is the incoming HTTP event body
Body []byte `json:"body,omitempty"`
Body json.RawMessage `json:"body,omitempty"`
// Header are the headers for the incoming HTTP event
Header map[string][]string `json:"header,omitempty"`
// Extensions are extra values that are added by previous interceptors in a chain
Expand All @@ -26,12 +27,12 @@ type InterceptorRequest struct {
InterceptorParams map[string]interface{} `json:"interceptor_params,omitempty"`

// Context contains additional metadata about the event being processed
Context *TriggerContext
Context *TriggerContext `json:"context"`
}

type TriggerContext struct {
// EventURL is the URL of the incoming event
EventURL string `json:"url,omitempty"`
EventURL string `json:"event_url,omitempty"`
// EventID is a unique ID assigned by Triggers to each event
EventID string `json:"event_id,omitempty"`
// TriggerID is of the form namespace/$ns/triggers/$name
Expand All @@ -45,7 +46,7 @@ type InterceptorResponse struct {
// See TEP-0022. Naming TBD.
Extensions map[string]interface{} `json:"extensions,omitempty"`
// Continue indicates if the EventListener should continue processing the Trigger or not
Continue bool `json:"continue,omitempty"`
Continue bool `json:"continue"` //Don't add omitempty -- it will remove the continue field when the value is false.
// Status is an Error status containing details on any interceptor processing errors
Status Status `json:"status"`
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/interceptors/cel/cel.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var (
)

// NewInterceptor creates a prepopulated Interceptor.
func NewInterceptor(k kubernetes.Interface, l *zap.SugaredLogger) *Interceptor {
func NewInterceptor(k kubernetes.Interface, l *zap.SugaredLogger) interceptors.Interceptor {
return &Interceptor{
Logger: l,
KubeClientSet: k,
Expand Down
5 changes: 4 additions & 1 deletion pkg/interceptors/cel/cel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ func TestInterceptor_Process(t *testing.T) {
if _, err := kubeClient.CoreV1().Secrets(testNS).Create(ctx, makeSecret(), metav1.CreateOptions{}); err != nil {
rt.Error(err)
}
w := NewInterceptor(kubeClient, logger.Sugar())
w := &Interceptor{
KubeClientSet: kubeClient,
Logger: logger.Sugar(),
}
res := w.Process(ctx, &triggersv1.InterceptorRequest{
Body: tt.body,
Header: http.Header{
Expand Down

0 comments on commit c104e09

Please sign in to comment.