From 1db7e265b1683462181ca987a4a4011acc0c66ad Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Wed, 6 May 2020 13:10:55 -0400 Subject: [PATCH] feat: add headers http trigger (#642) --- api/openapi-spec/swagger.json | 14 ++++++++-- api/sensor.html | 12 +++++++++ api/sensor.md | 22 ++++++++++++++++ pkg/apis/sensor/v1alpha1/openapi_generated.go | 26 +++++++++++++++++-- pkg/apis/sensor/v1alpha1/types.go | 8 ++++-- .../sensor/v1alpha1/zz_generated.deepcopy.go | 15 +++++++++++ sensors/triggers/http/http.go | 4 +++ 7 files changed, 95 insertions(+), 6 deletions(-) diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index fa70a0af6f..885861605c 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -1494,6 +1494,16 @@ "description": "BasicAuth configuration for the http request.", "$ref": "#/definitions/io.argoproj.sensor.v1alpha1.BasicAuth" }, + "headers": { + "description": "Headers for the HTTP request.", + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } + }, "method": { "description": "Method refers to the type of the HTTP request. Refer https://golang.org/src/net/http/method.go for more info. Default value is POST.", "type": "string" @@ -1504,7 +1514,7 @@ "items": { "$ref": "#/definitions/io.argoproj.sensor.v1alpha1.TriggerParameter" }, - "x-kubernetes-list-type": "triggerParameters" + "x-kubernetes-list-type": "atomic" }, "payload": { "description": "Payload is the list of key-value extracted from an event payload to construct the HTTP request payload.", @@ -1512,7 +1522,7 @@ "items": { "$ref": "#/definitions/io.argoproj.sensor.v1alpha1.TriggerParameter" }, - "x-kubernetes-list-type": "payloadParameters" + "x-kubernetes-list-type": "atomic" }, "timeout": { "description": "Timeout refers to the HTTP request timeout in seconds. Default value is 60 seconds.", diff --git a/api/sensor.html b/api/sensor.html index 5edc8fa33f..ecc39c9a2a 100644 --- a/api/sensor.html +++ b/api/sensor.html @@ -1382,6 +1382,18 @@

HTTPTrigger

BasicAuth configuration for the http request.

+ + +headers
+ +map[string][]string + + + +(Optional) +

Headers for the HTTP request.

+ +

JSONType diff --git a/api/sensor.md b/api/sensor.md index eac60a6eee..9a848888db 100644 --- a/api/sensor.md +++ b/api/sensor.md @@ -2779,6 +2779,28 @@ BasicAuth configuration for the http request. + + + + +headers
map\[string\]\[\]string + + + + + +(Optional) + +

+ +Headers for the HTTP request. + +

+ + + + + diff --git a/pkg/apis/sensor/v1alpha1/openapi_generated.go b/pkg/apis/sensor/v1alpha1/openapi_generated.go index e2a6dda3e6..d5addcc1ec 100644 --- a/pkg/apis/sensor/v1alpha1/openapi_generated.go +++ b/pkg/apis/sensor/v1alpha1/openapi_generated.go @@ -960,7 +960,7 @@ func schema_pkg_apis_sensor_v1alpha1_HTTPTrigger(ref common.ReferenceCallback) c "payload": { VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{ - "x-kubernetes-list-type": "payloadParameters", + "x-kubernetes-list-type": "atomic", }, }, SchemaProps: spec.SchemaProps{ @@ -991,7 +991,7 @@ func schema_pkg_apis_sensor_v1alpha1_HTTPTrigger(ref common.ReferenceCallback) c "parameters": { VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{ - "x-kubernetes-list-type": "triggerParameters", + "x-kubernetes-list-type": "atomic", }, }, SchemaProps: spec.SchemaProps{ @@ -1019,6 +1019,28 @@ func schema_pkg_apis_sensor_v1alpha1_HTTPTrigger(ref common.ReferenceCallback) c Ref: ref("github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1.BasicAuth"), }, }, + "headers": { + SchemaProps: spec.SchemaProps{ + Description: "Headers for the HTTP request.", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + }, + }, + }, }, Required: []string{"url", "payload"}, }, diff --git a/pkg/apis/sensor/v1alpha1/types.go b/pkg/apis/sensor/v1alpha1/types.go index 9295dfc0d8..97cbda6038 100644 --- a/pkg/apis/sensor/v1alpha1/types.go +++ b/pkg/apis/sensor/v1alpha1/types.go @@ -388,7 +388,7 @@ type HTTPTrigger struct { // URL refers to the URL to send HTTP request to. URL string `json:"url" protobuf:"bytes,1,name=url"` // Payload is the list of key-value extracted from an event payload to construct the HTTP request payload. - // +listType=payloadParameters + // +listType=atomic Payload []TriggerParameter `json:"payload" protobuf:"bytes,2,rep,name=payload"` // TLS configuration for the HTTP client. // +optional @@ -400,7 +400,7 @@ type HTTPTrigger struct { Method string `json:"method,omitempty" protobuf:"bytes,4,opt,name=method"` // Parameters is the list of key-value extracted from event's payload that are applied to // the HTTP trigger resource. - // +listType=triggerParameters + // +listType=atomic Parameters []TriggerParameter `json:"parameters,omitempty" protobuf:"bytes,5,rep,name=parameters"` // Timeout refers to the HTTP request timeout in seconds. // Default value is 60 seconds. @@ -409,6 +409,10 @@ type HTTPTrigger struct { // BasicAuth configuration for the http request. // +optional BasicAuth *BasicAuth `json:"basicAuth,omitempty" protobuf:"bytes,7,opt,name=basicAuth"` + // Headers for the HTTP request. + // +mapType=granular + // +optional + Headers map[string][]string `json:"headers,omitempty" protobuf:"bytes,8,opt,name=headers"` } // TLSConfig refers to TLS configuration for the HTTP client diff --git a/pkg/apis/sensor/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/sensor/v1alpha1/zz_generated.deepcopy.go index 7f94aa550c..f8da7f46bb 100644 --- a/pkg/apis/sensor/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/sensor/v1alpha1/zz_generated.deepcopy.go @@ -516,6 +516,21 @@ func (in *HTTPTrigger) DeepCopyInto(out *HTTPTrigger) { *out = new(BasicAuth) (*in).DeepCopyInto(*out) } + if in.Headers != nil { + in, out := &in.Headers, &out.Headers + *out = make(map[string][]string, len(*in)) + for key, val := range *in { + var outVal []string + if val == nil { + (*out)[key] = nil + } else { + in, out := &val, &outVal + *out = make([]string, len(*in)) + copy(*out, *in) + } + (*out)[key] = outVal + } + } return } diff --git a/sensors/triggers/http/http.go b/sensors/triggers/http/http.go index bdac438019..832b7f3ed1 100644 --- a/sensors/triggers/http/http.go +++ b/sensors/triggers/http/http.go @@ -155,6 +155,10 @@ func (t *HTTPTrigger) Execute(resource interface{}) (interface{}, error) { return nil, errors.Wrapf(err, "failed to construct request for %s", trigger.URL) } + if trigger.Headers != nil { + request.Header = trigger.Headers + } + basicAuth := trigger.BasicAuth if basicAuth != nil {