diff --git a/go.mod b/go.mod index 9fbbaa1a2f8..286cf97f6fa 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( cloud.google.com/go v0.47.0 // indirect contrib.go.opencensus.io/exporter/stackdriver v0.12.8 // indirect github.com/GoogleCloudPlatform/cloud-builders/gcs-fetcher v0.0.0-20191203181535-308b93ad1f39 - github.com/cloudevents/sdk-go/v2 v2.0.0-preview5 + github.com/cloudevents/sdk-go/v2 v2.0.0-preview6 github.com/ghodss/yaml v1.0.0 github.com/go-openapi/spec v0.19.4 // indirect github.com/gogo/protobuf v1.3.1 // indirect diff --git a/go.sum b/go.sum index b0770209026..3546e06712e 100644 --- a/go.sum +++ b/go.sum @@ -115,8 +115,8 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudevents/sdk-go v1.1.2 h1:mg/7d+BzubBPrPpH1bdeF85BQZYV85j7Ljqat3+m+qE= github.com/cloudevents/sdk-go v1.1.2/go.mod h1:ss+jWJ88wypiewnPEzChSBzTYXGpdcILoN9YHk8uhTQ= -github.com/cloudevents/sdk-go/v2 v2.0.0-preview5 h1:O4NDb6qiBck2TX/5RVs4xsn72nPbT4EfJSa5Wt7mL9w= -github.com/cloudevents/sdk-go/v2 v2.0.0-preview5/go.mod h1:1Bg+Ps3/JUl/c7PUYEmG/nixhH10dBWKa/BPUNopu0M= +github.com/cloudevents/sdk-go/v2 v2.0.0-preview6 h1:IYRl0IoWKRZE+1f9Zlm8qtc6zKg/wq4k7TKBDbIq1rg= +github.com/cloudevents/sdk-go/v2 v2.0.0-preview6/go.mod h1:zbpxUOAoR8b4Shvo1GyHbcL/S/hgr1WJ3rNuMUgrlh0= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/containerd/containerd v1.3.0 h1:xjvXQWABwS2uiv3TWgQt5Uth60Gu86LTGZXMJkjc7rY= github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= @@ -558,6 +558,7 @@ github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhV github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/vdemeester/k8s-pkg-credentialprovider v0.0.0-20200107171650-7c61ffa44238 h1:o+AFkRxPBxf23y/mH9RM5doyTxQHRFpq6psWi7012X0= github.com/vdemeester/k8s-pkg-credentialprovider v0.0.0-20200107171650-7c61ffa44238/go.mod h1:JwQJCMWpUDqjZrB5jpw0f5VbN7U95zxFy1ZDpoEarGo= diff --git a/third_party/github.com/hashicorp/errwrap/go.mod b/third_party/github.com/hashicorp/errwrap/go.mod index d7ed369809b..c9b84022cf7 100644 --- a/third_party/github.com/hashicorp/errwrap/go.mod +++ b/third_party/github.com/hashicorp/errwrap/go.mod @@ -1,3 +1 @@ module github.com/hashicorp/errwrap - -go 1.13 diff --git a/third_party/github.com/hashicorp/go-multierror/go.mod b/third_party/github.com/hashicorp/go-multierror/go.mod index 8c91af65b26..2534331d5f9 100644 --- a/third_party/github.com/hashicorp/go-multierror/go.mod +++ b/third_party/github.com/hashicorp/go-multierror/go.mod @@ -1,5 +1,3 @@ module github.com/hashicorp/go-multierror require github.com/hashicorp/errwrap v1.0.0 - -go 1.13 diff --git a/vendor/github.com/cloudevents/sdk-go/v2/alias.go b/vendor/github.com/cloudevents/sdk-go/v2/alias.go index e66835dd1ac..6d15c4e1abe 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/alias.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/alias.go @@ -137,9 +137,9 @@ var ( WithShutdownTimeout = http.WithShutdownTimeout //WithEncoding = http.WithEncoding //WithStructuredEncoding = http.WithStructuredEncoding // TODO: expose new way - WithPort = http.WithPort - WithPath = http.WithPath - WithMiddleware = http.WithMiddleware - WithListener = http.WithListener - WithHTTPTransport = http.WithHTTPTransport + WithPort = http.WithPort + WithPath = http.WithPath + WithMiddleware = http.WithMiddleware + WithListener = http.WithListener + WithRoundTripper = http.WithRoundTripper ) diff --git a/vendor/github.com/cloudevents/sdk-go/v2/binding/spec/attributes.go b/vendor/github.com/cloudevents/sdk-go/v2/binding/spec/attributes.go index f08084d9b06..20ec1ce92fe 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/binding/spec/attributes.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/binding/spec/attributes.go @@ -72,7 +72,7 @@ type accessor interface { var acc = [nAttrs]accessor{ &aStr{aKind(ID), event.EventContextReader.GetID, event.EventContextWriter.SetID}, &aStr{aKind(Source), event.EventContextReader.GetSource, event.EventContextWriter.SetSource}, - &aStr{aKind(SpecVersion), event.EventContextReader.GetSpecVersion, event.EventContextWriter.SetSpecVersion}, + &aStr{aKind(SpecVersion), event.EventContextReader.GetSpecVersion, func(writer event.EventContextWriter, s string) error { return nil }}, &aStr{aKind(Type), event.EventContextReader.GetType, event.EventContextWriter.SetType}, &aStr{aKind(DataContentType), event.EventContextReader.GetDataContentType, event.EventContextWriter.SetDataContentType}, &aStr{aKind(DataSchema), event.EventContextReader.GetDataSchema, event.EventContextWriter.SetDataSchema}, diff --git a/vendor/github.com/cloudevents/sdk-go/v2/binding/spec/spec.go b/vendor/github.com/cloudevents/sdk-go/v2/binding/spec/spec.go index 2468165eb85..4de589185e5 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/binding/spec/spec.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/binding/spec/spec.go @@ -4,7 +4,6 @@ import ( "strings" "github.com/cloudevents/sdk-go/v2/event" - "github.com/cloudevents/sdk-go/v2/types" ) // Version provides meta-data for a single spec-version. @@ -93,11 +92,8 @@ func (v *version) SetAttribute(c event.EventContextWriter, name string, value in } name = strings.ToLower(name) var err error - if strings.HasPrefix(name, v.prefix) { // Extension attribute - value, err = types.Validate(value) - if err == nil { - err = c.SetExtension(strings.TrimPrefix(name, v.prefix), value) - } + if v.HasPrefix(name) { // Extension attribute + return c.SetExtension(strings.TrimPrefix(name, v.prefix), value) } return err } diff --git a/vendor/github.com/cloudevents/sdk-go/v2/binding/to_event.go b/vendor/github.com/cloudevents/sdk-go/v2/binding/to_event.go index 9e20d8a9cf6..603b999ef10 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/binding/to_event.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/binding/to_event.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "errors" + "fmt" "io" "github.com/cloudevents/sdk-go/v2/binding/format" @@ -108,6 +109,8 @@ func (b *messageToEventBuilder) SetAttribute(attribute spec.Attribute, value int b.event.Context = b.event.Context.AsV03() case event.CloudEventsVersionV1: b.event.Context = b.event.Context.AsV1() + default: + return fmt.Errorf("unrecognized event version %s", str) } return nil } diff --git a/vendor/github.com/cloudevents/sdk-go/v2/event/event_marshal.go b/vendor/github.com/cloudevents/sdk-go/v2/event/event_marshal.go index 38e6a6d8e14..a2f248c9054 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/event/event_marshal.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/event/event_marshal.go @@ -261,8 +261,8 @@ func (e *Event) JsonDecodeV1(body []byte, raw map[string]json.RawMessage) error return nil } -func marshalEvent(event interface{}, extensions map[string]interface{}) (map[string]json.RawMessage, error) { - b, err := json.Marshal(event) +func marshalEvent(eventCtx EventContextReader, extensions map[string]interface{}) (map[string]json.RawMessage, error) { + b, err := json.Marshal(eventCtx) if err != nil { return nil, err } @@ -272,6 +272,13 @@ func marshalEvent(event interface{}, extensions map[string]interface{}) (map[str return nil, err } + sv, err := json.Marshal(eventCtx.GetSpecVersion()) + if err != nil { + return nil, err + } + + brm["specversion"] = sv + for k, v := range extensions { k = strings.ToLower(k) vb, err := json.Marshal(v) diff --git a/vendor/github.com/cloudevents/sdk-go/v2/event/event_writer.go b/vendor/github.com/cloudevents/sdk-go/v2/event/event_writer.go index a6bf6977a6f..3d392d5601e 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/event/event_writer.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/event/event_writer.go @@ -9,25 +9,26 @@ var _ EventWriter = (*Event)(nil) // SetSpecVersion implements EventWriter.SetSpecVersion func (e *Event) SetSpecVersion(v string) { - if e.Context == nil { - switch v { - case CloudEventsVersionV03: - e.Context = EventContextV03{}.AsV03() - case CloudEventsVersionV1: - e.Context = EventContextV1{}.AsV1() - default: - e.fieldError("specversion", fmt.Errorf("a valid spec version is required: [%s, %s]", - CloudEventsVersionV03, CloudEventsVersionV1)) - return + switch v { + case CloudEventsVersionV03: + if e.Context == nil { + e.Context = &EventContextV03{} + } else { + e.Context = e.Context.AsV03() } - e.fieldOK("specversion") + case CloudEventsVersionV1: + if e.Context == nil { + e.Context = &EventContextV1{} + } else { + e.Context = e.Context.AsV1() + } + default: + e.fieldError("specversion", fmt.Errorf("a valid spec version is required: [%s, %s]", + CloudEventsVersionV03, CloudEventsVersionV1)) return } - if err := e.Context.SetSpecVersion(v); err != nil { - e.fieldError("specversion", err) - } else { - e.fieldOK("specversion") - } + e.fieldOK("specversion") + return } // SetType implements EventWriter.SetType diff --git a/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext.go b/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext.go index 7af650d35c5..5ad2374349f 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext.go @@ -57,8 +57,6 @@ type EventContextReader interface { // EventContextWriter are the methods required to be a writer of context // attributes. type EventContextWriter interface { - // SetSpecVersion sets the spec version of the context. - SetSpecVersion(string) error // SetType sets the type of the context. SetType(string) error // SetSource sets the source of the context. diff --git a/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v03.go b/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v03.go index 27177448135..51b64a77041 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v03.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v03.go @@ -17,8 +17,6 @@ const ( // EventContextV03 represents the non-data attributes of a CloudEvents v0.3 // event. type EventContextV03 struct { - // SpecVersion - The version of the CloudEvents specification used by the event. - SpecVersion string `json:"specversion"` // Type - The type of the occurrence which has happened. Type string `json:"type"` // Source - A URI describing the event producer. @@ -123,14 +121,12 @@ func (ec *EventContextV03) cloneExtensions() map[string]interface{} { // AsV03 implements EventContextConverter.AsV03 func (ec EventContextV03) AsV03() *EventContextV03 { - ec.SpecVersion = CloudEventsVersionV03 return &ec } // AsV04 implements EventContextConverter.AsV04 func (ec EventContextV03) AsV1() *EventContextV1 { ret := EventContextV1{ - SpecVersion: CloudEventsVersionV1, ID: ec.ID, Time: ec.Time, Type: ec.Type, @@ -179,16 +175,6 @@ func (ec EventContextV03) Validate() error { errors = append(errors, "type: MUST be a non-empty string") } - // specversion - // Type: String - // Constraints: - // REQUIRED - // MUST be a non-empty string - specVersion := strings.TrimSpace(ec.SpecVersion) - if specVersion == "" { - errors = append(errors, "specversion: MUST be a non-empty string") - } - // source // Type: URI-reference // Constraints: @@ -282,7 +268,7 @@ func (ec EventContextV03) String() string { b.WriteString("Context Attributes,\n") - b.WriteString(" specversion: " + ec.SpecVersion + "\n") + b.WriteString(" specversion: " + CloudEventsVersionV03 + "\n") b.WriteString(" type: " + ec.Type + "\n") b.WriteString(" source: " + ec.Source.String() + "\n") if ec.Subject != nil { diff --git a/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v03_reader.go b/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v03_reader.go index ed8890369dc..8e6eec5caa3 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v03_reader.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v03_reader.go @@ -8,9 +8,6 @@ import ( // GetSpecVersion implements EventContextReader.GetSpecVersion func (ec EventContextV03) GetSpecVersion() string { - if ec.SpecVersion != "" { - return ec.SpecVersion - } return CloudEventsVersionV03 } diff --git a/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v03_writer.go b/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v03_writer.go index 8c9ddfe0765..94748c67c59 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v03_writer.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v03_writer.go @@ -2,7 +2,6 @@ package event import ( "errors" - "fmt" "net/url" "strings" "time" @@ -13,15 +12,6 @@ import ( // Adhere to EventContextWriter var _ EventContextWriter = (*EventContextV03)(nil) -// SetSpecVersion implements EventContextWriter.SetSpecVersion -func (ec *EventContextV03) SetSpecVersion(v string) error { - if v != CloudEventsVersionV03 { - return fmt.Errorf("invalid version %q, expecting %q", v, CloudEventsVersionV03) - } - ec.SpecVersion = CloudEventsVersionV03 - return nil -} - // SetDataContentType implements EventContextWriter.SetDataContentType func (ec *EventContextV03) SetDataContentType(ct string) error { ct = strings.TrimSpace(ct) diff --git a/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v1.go b/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v1.go index a459bdae176..41ed59a09c4 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v1.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v1.go @@ -26,9 +26,6 @@ type EventContextV1 struct { // Source - A URI describing the event producer. // +required Source types.URIRef `json:"source"` - // SpecVersion - The version of the CloudEvents specification used by the event. - // +required - SpecVersion string `json:"specversion"` // Type - The type of the occurrence which has happened. // +required Type string `json:"type"` @@ -127,7 +124,6 @@ func (ec *EventContextV1) cloneExtensions() map[string]interface{} { // AsV03 implements EventContextConverter.AsV03 func (ec EventContextV1) AsV03() *EventContextV03 { ret := EventContextV03{ - SpecVersion: CloudEventsVersionV03, ID: ec.ID, Time: ec.Time, Type: ec.Type, @@ -164,7 +160,6 @@ func (ec EventContextV1) AsV03() *EventContextV03 { // AsV04 implements EventContextConverter.AsV04 func (ec EventContextV1) AsV1() *EventContextV1 { - ec.SpecVersion = CloudEventsVersionV1 return &ec } @@ -196,16 +191,6 @@ func (ec EventContextV1) Validate() error { errors = append(errors, "source: REQUIRED") } - // specversion - // Type: String - // Constraints: - // REQUIRED - // MUST be a non-empty string - specVersion := strings.TrimSpace(ec.SpecVersion) - if specVersion == "" { - errors = append(errors, "specversion: MUST be a non-empty string") - } - // type // Type: String // Constraints: @@ -280,7 +265,7 @@ func (ec EventContextV1) String() string { b.WriteString("Context Attributes,\n") - b.WriteString(" specversion: " + ec.SpecVersion + "\n") + b.WriteString(" specversion: " + CloudEventsVersionV1 + "\n") b.WriteString(" type: " + ec.Type + "\n") b.WriteString(" source: " + ec.Source.String() + "\n") if ec.Subject != nil { diff --git a/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v1_reader.go b/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v1_reader.go index 562839936a5..64f1a919b32 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v1_reader.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v1_reader.go @@ -8,10 +8,7 @@ import ( // GetSpecVersion implements EventContextReader.GetSpecVersion func (ec EventContextV1) GetSpecVersion() string { - if ec.SpecVersion != "" { - return ec.SpecVersion - } - return CloudEventsVersionV03 + return CloudEventsVersionV1 } // GetDataContentType implements EventContextReader.GetDataContentType diff --git a/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v1_writer.go b/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v1_writer.go index e2bd18cf2be..1ec29e65e42 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v1_writer.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext_v1_writer.go @@ -2,7 +2,6 @@ package event import ( "errors" - "fmt" "net/url" "strings" "time" @@ -13,15 +12,6 @@ import ( // Adhere to EventContextWriter var _ EventContextWriter = (*EventContextV1)(nil) -// SetSpecVersion implements EventContextWriter.SetSpecVersion -func (ec *EventContextV1) SetSpecVersion(v string) error { - if v != CloudEventsVersionV1 { - return fmt.Errorf("invalid version %q, expecting %q", v, CloudEventsVersionV1) - } - ec.SpecVersion = CloudEventsVersionV1 - return nil -} - // SetDataContentType implements EventContextWriter.SetDataContentType func (ec *EventContextV1) SetDataContentType(ct string) error { ct = strings.TrimSpace(ct) diff --git a/vendor/github.com/cloudevents/sdk-go/v2/go.mod b/vendor/github.com/cloudevents/sdk-go/v2/go.mod index 9716c1b4ad4..242594b6d63 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/go.mod +++ b/vendor/github.com/cloudevents/sdk-go/v2/go.mod @@ -1,6 +1,7 @@ module github.com/cloudevents/sdk-go/v2 require ( + cloud.google.com/go v0.40.0 contrib.go.opencensus.io/exporter/prometheus v0.1.0 github.com/Shopify/sarama v1.19.0 github.com/cloudevents/sdk-go v1.1.2 @@ -17,6 +18,8 @@ require ( go.opencensus.io v0.22.0 go.uber.org/zap v1.10.0 golang.org/x/sync v0.0.0-20190423024810-112230192c58 + google.golang.org/api v0.15.0 + google.golang.org/grpc v1.26.0 pack.ag/amqp v0.11.0 ) diff --git a/vendor/github.com/cloudevents/sdk-go/v2/go.sum b/vendor/github.com/cloudevents/sdk-go/v2/go.sum index dbabf2329db..1272fb964e8 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/go.sum +++ b/vendor/github.com/cloudevents/sdk-go/v2/go.sum @@ -2,6 +2,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.38.0 h1:ROfEUZz+Gh5pa62DJWXSaonyu3StP6EA6lPEXPI6mCo= cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.40.0 h1:FjSY7bOj+WzJe6TZRVtXI2b9kAYvtNg4lMbcH2+MUkk= cloud.google.com/go v0.40.0/go.mod h1:Tk58MuI9rbLMKlAjeO/bDnteAx7tX2gJIXw4T5Jwlro= contrib.go.opencensus.io/exporter/ocagent v0.4.12 h1:jGFvw3l57ViIVEPKKEUXPcLYIXJmQxLUh6ey1eJhwyc= contrib.go.opencensus.io/exporter/ocagent v0.4.12/go.mod h1:450APlNTSR6FrvC3CTRqYosuDstRB9un7SOx2k/9ckA= diff --git a/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/message.go b/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/message.go index 278d43890c1..5777fd9c1f4 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/message.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/message.go @@ -49,13 +49,19 @@ func NewMessage(header nethttp.Header, body io.ReadCloser) *Message { // NewMessageFromHttpRequest returns a binding.Message with header and data. // The returned binding.Message *cannot* be read several times. In order to read it more times, buffer it using binding/buffering methods func NewMessageFromHttpRequest(req *nethttp.Request) *Message { + if req == nil { + return nil + } return NewMessage(req.Header, req.Body) } // NewMessageFromHttpResponse returns a binding.Message with header and data. // The returned binding.Message *cannot* be read several times. In order to read it more times, buffer it using binding/buffering methods -func NewMessageFromHttpResponse(req *nethttp.Response) *Message { - return NewMessage(req.Header, req.Body) +func NewMessageFromHttpResponse(resp *nethttp.Response) *Message { + if resp == nil { + return nil + } + return NewMessage(resp.Header, resp.Body) } func (m *Message) ReadEncoding() binding.Encoding { diff --git a/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/options.go b/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/options.go index 82032d6b680..5ced0748b30 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/options.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/options.go @@ -17,7 +17,7 @@ type Option func(*Protocol) error func WithTarget(targetUrl string) Option { return func(p *Protocol) error { if p == nil { - return fmt.Errorf("http protocol option can not set nil protocol") + return fmt.Errorf("http target option can not set nil protocol") } targetUrl = strings.TrimSpace(targetUrl) if targetUrl != "" { @@ -48,7 +48,7 @@ func WithTarget(targetUrl string) Option { func WithHeader(key, value string) Option { return func(p *Protocol) error { if p == nil { - return fmt.Errorf("http header option can not set nil transport") + return fmt.Errorf("http header option can not set nil protocol") } key = strings.TrimSpace(key) if key != "" { @@ -71,7 +71,7 @@ func WithHeader(key, value string) Option { func WithShutdownTimeout(timeout time.Duration) Option { return func(t *Protocol) error { if t == nil { - return fmt.Errorf("http shutdown timeout option can not set nil transport") + return fmt.Errorf("http shutdown timeout option can not set nil protocol") } t.ShutdownTimeout = &timeout return nil @@ -93,7 +93,7 @@ func checkListen(t *Protocol, prefix string) error { func WithPort(port int) Option { return func(t *Protocol) error { if t == nil { - return fmt.Errorf("http port option can not set nil transport") + return fmt.Errorf("http port option can not set nil protocol") } if port < 0 || port > 65535 { return fmt.Errorf("http port option was given an invalid port: %d", port) @@ -111,7 +111,7 @@ func WithPort(port int) Option { func WithListener(l net.Listener) Option { return func(t *Protocol) error { if t == nil { - return fmt.Errorf("http listener option can not set nil transport") + return fmt.Errorf("http listener option can not set nil protocol") } if err := checkListen(t, "http port option"); err != nil { return err @@ -126,7 +126,7 @@ func WithListener(l net.Listener) Option { func WithPath(path string) Option { return func(t *Protocol) error { if t == nil { - return fmt.Errorf("http path option can not set nil transport") + return fmt.Errorf("http path option can not set nil protocol") } path = strings.TrimSpace(path) if len(path) == 0 { @@ -137,6 +137,25 @@ func WithPath(path string) Option { } } +// WithMethod sets the HTTP verb (GET, POST, PUT, etc.) to use +// when using an HTTP request. +func WithMethod(method string) Option { + return func(p *Protocol) error { + if p == nil { + return fmt.Errorf("http method option can not set nil protocol") + } + method = strings.TrimSpace(method) + if method != "" { + if p.RequestTemplate == nil { + p.RequestTemplate = &nethttp.Request{} + } + p.RequestTemplate.Method = method + return nil + } + return fmt.Errorf("http method option was empty string") + } +} + // // Middleware is a function that takes an existing http.Handler and wraps it in middleware, // returning the wrapped http.Handler. @@ -148,17 +167,20 @@ type Middleware func(next nethttp.Handler) nethttp.Handler func WithMiddleware(middleware Middleware) Option { return func(t *Protocol) error { if t == nil { - return fmt.Errorf("http middleware option can not set nil transport") + return fmt.Errorf("http middleware option can not set nil protocol") } t.middleware = append(t.middleware, middleware) return nil } } -// WithHTTPTransport sets the HTTP client transport. -func WithHTTPTransport(httpTransport nethttp.RoundTripper) Option { +// WithRoundTripper sets the HTTP RoundTripper. +func WithRoundTripper(roundTripper nethttp.RoundTripper) Option { return func(t *Protocol) error { - t.transport = httpTransport + if t == nil { + return fmt.Errorf("http round tripper option can not set nil protocol") + } + t.roundTripper = roundTripper return nil } } diff --git a/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/protocol.go b/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/protocol.go index 3feabf077ca..5591f9700db 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/protocol.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/protocol.go @@ -46,7 +46,7 @@ type Protocol struct { // http server. If nil, the Protocol will create a one. Handler *http.ServeMux listener net.Listener - transport http.RoundTripper // TODO: use this. + roundTripper http.RoundTripper // TODO: use this. server *http.Server handlerRegistered bool middleware []Middleware @@ -84,12 +84,24 @@ func (p *Protocol) applyOptions(opts ...Option) error { // Send implements binding.Sender func (p *Protocol) Send(ctx context.Context, m binding.Message) error { + if ctx == nil { + return fmt.Errorf("nil Context") + } else if m == nil { + return fmt.Errorf("nil Message") + } + _, err := p.Request(ctx, m) return err } // Request implements binding.Requester func (p *Protocol) Request(ctx context.Context, m binding.Message) (binding.Message, error) { + if ctx == nil { + return nil, fmt.Errorf("nil Context") + } else if m == nil { + return nil, fmt.Errorf("nil Message") + } + var err error defer func() { _ = m.Finish(err) }() @@ -165,6 +177,10 @@ func copyHeaders(from, to http.Header) { // Returns non-nil error if the incoming HTTP request fails to parse as a CloudEvent // Returns io.EOF if the receiver is closed. func (p *Protocol) Receive(ctx context.Context) (binding.Message, error) { + if ctx == nil { + return nil, fmt.Errorf("nil Context") + } + msg, fn, err := p.Respond(ctx) // No-op the response. defer func() { @@ -180,11 +196,19 @@ func (p *Protocol) Receive(ctx context.Context) (binding.Message, error) { // Returns non-nil error if the incoming HTTP request fails to parse as a CloudEvent // Returns io.EOF if the receiver is closed. func (p *Protocol) Respond(ctx context.Context) (binding.Message, protocol.ResponseFn, error) { - in, ok := <-p.incoming - if !ok { + if ctx == nil { + return nil, nil, fmt.Errorf("nil Context") + } + + select { + case in, ok := <-p.incoming: + if !ok { + return nil, nil, io.EOF + } + return in.msg, in.respFn, in.err + case <-ctx.Done(): return nil, nil, io.EOF } - return in.msg, in.respFn, in.err } type msgErr struct { @@ -196,11 +220,13 @@ type msgErr struct { // ServeHTTP implements http.Handler. // Blocks until Message.Finish is called. func (p *Protocol) ServeHTTP(rw http.ResponseWriter, req *http.Request) { - var err error + m := NewMessageFromHttpRequest(req) - if m.ReadEncoding() == binding.EncodingUnknown { + if m == nil || m.ReadEncoding() == binding.EncodingUnknown { p.incoming <- msgErr{msg: nil, err: binding.ErrUnknownEncoding} + return // if there was no message, return. } + done := make(chan error) m.OnFinish = func(err error) error { @@ -227,8 +253,8 @@ func (p *Protocol) ServeHTTP(rw http.ResponseWriter, req *http.Request) { return nil } - p.incoming <- msgErr{msg: m, respFn: fn, err: err} // Send to Respond() - if err = <-done; err != nil { + p.incoming <- msgErr{msg: m, respFn: fn} // Send to Request + if err := <-done; err != nil { fmt.Println("attempting to write an error out on response writer:", err) http.Error(rw, fmt.Sprintf("cannot forward CloudEvent: %v", err), http.StatusInternalServerError) } diff --git a/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/engine.go b/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/protocol_lifecycle.go similarity index 94% rename from vendor/github.com/cloudevents/sdk-go/v2/protocol/http/engine.go rename to vendor/github.com/cloudevents/sdk-go/v2/protocol/http/protocol_lifecycle.go index 1a41300df99..039ccfa02cb 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/engine.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/protocol_lifecycle.go @@ -53,11 +53,17 @@ func (e *Protocol) OpenInbound(ctx context.Context) error { errChan <- e.server.Serve(e.listener) }() + // nil check and default + shutdown := DefaultShutdownTimeout + if e.ShutdownTimeout != nil { + shutdown = *e.ShutdownTimeout + } + // wait for the server to return or ctx.Done(). select { case <-ctx.Done(): // Try a gracefully shutdown. - timeout := *e.ShutdownTimeout + timeout := shutdown ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() err := e.server.Shutdown(ctx) @@ -68,11 +74,6 @@ func (e *Protocol) OpenInbound(ctx context.Context) error { } } -// HasTracePropagation implements Protocol.HasTracePropagation -func (e *Protocol) HasTracePropagation() bool { // TODO: clean this all up. - return false -} - // GetPort returns the listening port. // Returns -1 if there is a listening error. // Note this will call net.Listen() if the listener is not already started. diff --git a/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/response.go b/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/result.go similarity index 90% rename from vendor/github.com/cloudevents/sdk-go/v2/protocol/http/response.go rename to vendor/github.com/cloudevents/sdk-go/v2/protocol/http/result.go index a2ff0cce269..f88534c4c0c 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/response.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/protocol/http/result.go @@ -29,8 +29,11 @@ var _ error = (*Result)(nil) // Is returns if the target error is a Result type checking target. func (e *Result) Is(target error) bool { - if _, ok := target.(*Result); ok { - return true + if o, ok := target.(*Result); ok { + if e.Status == o.Status { + return true + } + return false } // Allow for wrapped errors. err := fmt.Errorf(e.Format, e.Args...) diff --git a/vendor/github.com/cloudevents/sdk-go/v2/protocol/outbound.go b/vendor/github.com/cloudevents/sdk-go/v2/protocol/outbound.go index 2963c1daad6..ff5f3973a66 100644 --- a/vendor/github.com/cloudevents/sdk-go/v2/protocol/outbound.go +++ b/vendor/github.com/cloudevents/sdk-go/v2/protocol/outbound.go @@ -13,9 +13,10 @@ type Sender interface { // Send returns when the "outbound" message has been sent. The Sender may // still be expecting acknowledgment or holding other state for the message. // - // m.Finish() is called when sending is finished: expected acknowledgments (or - // errors) have been received, the Sender is no longer holding any state for - // the message. m.Finish() may be called during or after Send(). + // m.Finish() is called when sending is finished (both succeeded or failed): + // expected acknowledgments (or errors) have been received, the Sender is + // no longer holding any state for the message. + // m.Finish() may be called during or after Send(). Send(ctx context.Context, m binding.Message) error } diff --git a/vendor/modules.txt b/vendor/modules.txt index 1e8a17fdecd..e846455cdb7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -92,7 +92,7 @@ github.com/census-instrumentation/opencensus-proto/gen-go/agent/trace/v1 github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1 github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1 github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1 -# github.com/cloudevents/sdk-go/v2 v2.0.0-preview5 +# github.com/cloudevents/sdk-go/v2 v2.0.0-preview6 github.com/cloudevents/sdk-go/v2 github.com/cloudevents/sdk-go/v2/binding github.com/cloudevents/sdk-go/v2/binding/format