diff --git a/go.mod b/go.mod index 847bc8efcd4..ed7552bb4db 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.14 require ( contrib.go.opencensus.io/exporter/stackdriver v0.13.1 // indirect - github.com/cloudevents/sdk-go v1.2.0 github.com/cloudevents/sdk-go/v2 v2.0.1-0.20200608152019-2ab697c8fc0b github.com/ghodss/yaml v1.0.0 github.com/golang/protobuf v1.3.5 diff --git a/go.sum b/go.sum index 3f807e2242e..aa90000c44e 100644 --- a/go.sum +++ b/go.sum @@ -202,9 +202,8 @@ github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575/go.mod h1:9d6lWj8KzO/ github.com/clarketm/json v1.13.4/go.mod h1:ynr2LRfb0fQU34l07csRNBTcivjySLLiY1YzQqKVfdo= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudevents/sdk-go v0.0.0-20190509003705-56931988abe3/go.mod h1:j1nZWMLGg3om8SswStBoY6/SHvcLM19MuZqwDtMtmzs= +github.com/cloudevents/sdk-go v1.0.0 h1:gS5I0s2qPmdc4GBPlUmzZU7RH30BaiOdcRJ1RkXnPrc= github.com/cloudevents/sdk-go v1.0.0/go.mod h1:3TkmM0cFqkhCHOq5JzzRU/RxRkwzoS8TZ+G448qVTog= -github.com/cloudevents/sdk-go v1.2.0 h1:2AxI14EJUw1PclJ5gZJtzbxnHIfNMdi76Qq3P3G1BRU= -github.com/cloudevents/sdk-go v1.2.0/go.mod h1:ss+jWJ88wypiewnPEzChSBzTYXGpdcILoN9YHk8uhTQ= github.com/cloudevents/sdk-go/v2 v2.0.1-0.20200608152019-2ab697c8fc0b h1:JuajVVvOdNSXhVlI5Aks9m4+y5i4rM8EOaLhIytotYc= github.com/cloudevents/sdk-go/v2 v2.0.1-0.20200608152019-2ab697c8fc0b/go.mod h1:3CTrpB4+u7Iaj6fd7E2Xvm5IxMdRoaAhqaRVnOr2rCU= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= @@ -970,7 +969,6 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= diff --git a/pkg/adapter/config.go b/pkg/adapter/config.go deleted file mode 100644 index 0fd6b3ca3eb..00000000000 --- a/pkg/adapter/config.go +++ /dev/null @@ -1,91 +0,0 @@ -/* -Copyright 2019 The Knative Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package adapter - -type EnvConfigConstructor func() EnvConfigAccessor - -// EnvConfig is the minimal set of configuration parameters -// source adapters should support. -type EnvConfig struct { - // SinkURI is the URI messages will be forwarded to. - // DEPRECATED: use K_SINK - SinkURI string `envconfig:"SINK_URI"` - - // Sink is the URI messages will be sent. - Sink string `envconfig:"K_SINK"` - - // Environment variable containing the namespace of the adapter. - Namespace string `envconfig:"NAMESPACE" required:"true"` - - // MetricsConfigJson is a json string of metrics.ExporterOptions. - // This is used to configure the metrics exporter options, - // the config is stored in a config map inside the controllers - // namespace and copied here. - MetricsConfigJson string `envconfig:"K_METRICS_CONFIG" required:"true"` - - // LoggingConfigJson is a json string of logging.Config. - // This is used to configure the logging config, the config is stored in - // a config map inside the controllers namespace and copied here. - LoggingConfigJson string `envconfig:"K_LOGGING_CONFIG" required:"true"` - - // TracingConfigJson is a json string of tracing.Config. - // This is used to configure the tracing config, the config is stored in - // a config map inside the controllers namespace and copied here. - // Default is no-op. - TracingConfigJson string `envconfig:"K_TRACING_CONFIG"` -} - -// EnvConfigAccessor defines accessors for the minimal -// set of source adapter configuration parameters. -type EnvConfigAccessor interface { - // Get the URI where messages will be forwarded to. - GetSinkURI() string - - // Get the namespace of the adapter. - GetNamespace() string - - // Get the json string of metrics.ExporterOptions. - GetMetricsConfigJson() string - - // Get the json string of logging.Config. - GetLoggingConfigJson() string - - // Get the json string of tracubg.Config. - GetTracingConfigJson() string -} - -func (e *EnvConfig) GetMetricsConfigJson() string { - return e.MetricsConfigJson -} - -func (e *EnvConfig) GetLoggingConfigJson() string { - return e.LoggingConfigJson -} - -func (e *EnvConfig) GetTracingConfigJson() string { - return e.TracingConfigJson -} - -func (e *EnvConfig) GetSinkURI() string { - if e.Sink != "" { - return e.Sink - } - return e.SinkURI -} - -func (e *EnvConfig) GetNamespace() string { - return e.Namespace -} diff --git a/pkg/adapter/config_test.go b/pkg/adapter/config_test.go deleted file mode 100644 index afe9d14604f..00000000000 --- a/pkg/adapter/config_test.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2019 The Knative Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package adapter - -import ( - "os" - "testing" - - "github.com/kelseyhightower/envconfig" -) - -type myEnvConfig struct { - EnvConfig - - Mode string `envconfig:"MODE"` -} - -func TestEnvConfig(t *testing.T) { - os.Setenv("SINK_URI", "http://sink") - os.Setenv("NAMESPACE", "ns") - os.Setenv("K_METRICS_CONFIG", "metrics") - os.Setenv("K_LOGGING_CONFIG", "logging") - os.Setenv("K_TRACING_CONFIG", "tracing") - os.Setenv("MODE", "mymode") - - var env myEnvConfig - err := envconfig.Process("", &env) - if err != nil { - t.Errorf("Expected no error: %v", err) - } - - if env.Mode != "mymode" { - t.Errorf("Expected mode mymode, got: %s", env.Mode) - } - - if env.SinkURI != "http://sink" { - t.Errorf("Expected sinkURI http://sink, got: %s", env.SinkURI) - } -} diff --git a/pkg/adapter/main.go b/pkg/adapter/main.go deleted file mode 100644 index 84b17747259..00000000000 --- a/pkg/adapter/main.go +++ /dev/null @@ -1,148 +0,0 @@ -/* -Copyright 2019 The Knative Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package adapter - -import ( - "context" - "flag" - "fmt" - "log" - "net/http" - "time" - - // Uncomment the following line to load the gcp plugin - // (only required to authenticate against GKE clusters). - // _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" - cloudevents "github.com/cloudevents/sdk-go" - "github.com/kelseyhightower/envconfig" - "go.opencensus.io/stats/view" - "go.uber.org/zap" - "knative.dev/pkg/logging" - "knative.dev/pkg/metrics" - "knative.dev/pkg/profiling" - "knative.dev/pkg/signals" - "knative.dev/pkg/source" - tracingconfig "knative.dev/pkg/tracing/config" - - "knative.dev/eventing/pkg/kncloudevents" - "knative.dev/eventing/pkg/tracing" -) - -type Adapter interface { - Start(stopCh <-chan struct{}) error -} - -type AdapterConstructor func(ctx context.Context, env EnvConfigAccessor, client cloudevents.Client, reporter source.StatsReporter) Adapter - -func Main(component string, ector EnvConfigConstructor, ctor AdapterConstructor) { - MainWithContext(signals.NewContext(), component, ector, ctor) -} - -func MainWithContext(ctx context.Context, component string, ector EnvConfigConstructor, ctor AdapterConstructor) { - flag.Parse() - - env := ector() - if err := envconfig.Process("", env); err != nil { - log.Fatalf("Error processing env var: %s", err) - } - - // Convert json logging.Config to logging.Config. - loggingConfig, err := logging.JsonToLoggingConfig(env.GetLoggingConfigJson()) - if err != nil { - fmt.Printf("[ERROR] failed to process logging config: %s", err.Error()) - // Use default logging config. - if loggingConfig, err = logging.NewConfigFromMap(map[string]string{}); err != nil { - // If this fails, there is no recovering. - panic(err) - } - } - - logger, _ := logging.NewLoggerFromConfig(loggingConfig, component) - defer flush(logger) - ctx = logging.WithLogger(ctx, logger) - - // Report stats on Go memory usage every 30 seconds. - msp := metrics.NewMemStatsAll() - msp.Start(ctx, 30*time.Second) - if err := view.Register(msp.DefaultViews()...); err != nil { - logger.Fatal("Error exporting go memstats view: %v", zap.Error(err)) - } - - // Convert json metrics.ExporterOptions to metrics.ExporterOptions. - metricsConfig, err := metrics.JsonToMetricsOptions(env.GetMetricsConfigJson()) - if err != nil { - logger.Error("failed to process metrics options", zap.Error(err)) - } else { - if err := metrics.UpdateExporter(*metricsConfig, logger); err != nil { - logger.Error("failed to create the metrics exporter", zap.Error(err)) - } - } - - // Check if metrics config contains profiling flag - if metricsConfig != nil && metricsConfig.ConfigMap != nil { - if enabled, err := profiling.ReadProfilingFlag(metricsConfig.ConfigMap); err == nil { - if enabled { - // Start a goroutine to server profiling metrics - logger.Info("Profiling enabled") - go func() { - server := profiling.NewServer(profiling.NewHandler(logger, true)) - // Don't forward ErrServerClosed as that indicates we're already shutting down. - if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { - logger.Error("profiling server failed", zap.Error(err)) - } - }() - } - } else { - logger.Error("error while reading profiling flag", zap.Error(err)) - } - } - - reporter, err := source.NewStatsReporter() - if err != nil { - logger.Error("error building statsreporter", zap.Error(err)) - } - - // Retrieve tracing config - config, err := tracingconfig.JsonToTracingConfig(env.GetTracingConfigJson()) - if err != nil { - logger.Warn("Tracing configuration is invalid, using the no-op default", zap.Error(err)) - } - if err := tracing.SetupStaticPublishing(logger, component, config); err != nil { - // If tracing doesn't work, we will log an error, but allow the adapter - // to continue to start. - logger.Error("Error setting up trace publishing", zap.Error(err)) - } - - eventsClient, err := kncloudevents.NewDefaultClient(env.GetSinkURI()) - if err != nil { - logger.Fatal("error building cloud event client", zap.Error(err)) - } - - // Configuring the adapter - adapter := ctor(ctx, env, eventsClient, reporter) - - logger.Info("Starting Receive Adapter", zap.Any("adapter", adapter)) - - if err := adapter.Start(ctx.Done()); err != nil { - logger.Warn("start returned an error", zap.Error(err)) - } -} - -func flush(logger *zap.SugaredLogger) { - _ = logger.Sync() - metrics.FlushExporter() -} diff --git a/pkg/adapter/main_test.go b/pkg/adapter/main_test.go deleted file mode 100644 index 91c6e6ea421..00000000000 --- a/pkg/adapter/main_test.go +++ /dev/null @@ -1,66 +0,0 @@ -/* -Copyright 2019 The Knative Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package adapter - -import ( - "context" - "os" - "testing" - - // Uncomment the following line to load the gcp plugin - // (only required to authenticate against GKE clusters). - // _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" - cloudevents "github.com/cloudevents/sdk-go" - "go.opencensus.io/stats/view" - "knative.dev/pkg/metrics" - "knative.dev/pkg/source" -) - -type myAdapter struct{} - -func TestMainWithContext(t *testing.T) { - os.Setenv("SINK_URI", "http://sink") - os.Setenv("NAMESPACE", "ns") - os.Setenv("K_METRICS_CONFIG", "metrics") - os.Setenv("K_LOGGING_CONFIG", "logging") - os.Setenv("MODE", "mymode") - - ctx, cancel := context.WithCancel(context.TODO()) - - MainWithContext(ctx, - "mycomponent", - func() EnvConfigAccessor { return &myEnvConfig{} }, - func(ctx context.Context, processed EnvConfigAccessor, client cloudevents.Client, reporter source.StatsReporter) Adapter { - env := processed.(*myEnvConfig) - if env.Mode != "mymode" { - t.Errorf("Expected mode mymode, got: %s", env.Mode) - } - - if env.SinkURI != "http://sink" { - t.Errorf("Expected sinkURI http://sink, got: %s", env.SinkURI) - } - return &myAdapter{} - }) - - cancel() - - defer view.Unregister(metrics.NewMemStatsAll().DefaultViews()...) -} - -func (m *myAdapter) Start(stopCh <-chan struct{}) error { - return nil -} diff --git a/pkg/kncloudevents/good_client.go b/pkg/kncloudevents/good_client.go deleted file mode 100644 index c25308dd4ef..00000000000 --- a/pkg/kncloudevents/good_client.go +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2019 The Knative Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package kncloudevents - -import ( - nethttp "net/http" - - cloudevents "github.com/cloudevents/sdk-go" - "github.com/cloudevents/sdk-go/pkg/cloudevents/client" - "github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http" -) - -// ConnectionArgs allow to configure connection parameters to the underlying -// HTTP Client transport. -type ConnectionArgs struct { - // MaxIdleConns refers to the max idle connections, as in net/http/transport. - MaxIdleConns int - // MaxIdleConnsPerHost refers to the max idle connections per host, as in net/http/transport. - MaxIdleConnsPerHost int -} - -func (ca *ConnectionArgs) ConfigureTransport(transport *nethttp.Transport) { - if ca == nil { - return - } - transport.MaxIdleConns = ca.MaxIdleConns - transport.MaxIdleConnsPerHost = ca.MaxIdleConnsPerHost -} - -func (ca *ConnectionArgs) NewDefaultHTTPTransport() *nethttp.Transport { - var base = nethttp.DefaultTransport.(*nethttp.Transport).Clone() - ca.ConfigureTransport(base) - return base -} - -func NewDefaultClient(target ...string) (cloudevents.Client, error) { - tOpts := []http.Option{ - cloudevents.WithBinaryEncoding(), - } - if len(target) > 0 && target[0] != "" { - tOpts = append(tOpts, cloudevents.WithTarget(target[0])) - } - - // Make an http transport for the CloudEvents client. - t, err := cloudevents.NewHTTPTransport(tOpts...) - if err != nil { - return nil, err - } - return NewDefaultHTTPClient(t) -} - -// NewDefaultHTTPClient creates a new client from an HTTP transport. -func NewDefaultHTTPClient(t *cloudevents.HTTPTransport, opts ...client.Option) (cloudevents.Client, error) { - if opts == nil { - opts = make([]client.Option, 0, 2) - } - opts = append(opts, cloudevents.WithUUIDs(), cloudevents.WithTimeNow()) - - // Use the transport to make a new CloudEvents client. - c, err := cloudevents.NewClient(t, opts...) - - if err != nil { - return nil, err - } - return c, nil -} diff --git a/pkg/kncloudevents/message_sender.go b/pkg/kncloudevents/message_sender.go index e33200021f6..bc110781553 100644 --- a/pkg/kncloudevents/message_sender.go +++ b/pkg/kncloudevents/message_sender.go @@ -24,6 +24,23 @@ import ( "go.opencensus.io/plugin/ochttp/propagation/tracecontext" ) +// ConnectionArgs allow to configure connection parameters to the underlying +// HTTP Client transport. +type ConnectionArgs struct { + // MaxIdleConns refers to the max idle connections, as in net/http/transport. + MaxIdleConns int + // MaxIdleConnsPerHost refers to the max idle connections per host, as in net/http/transport. + MaxIdleConnsPerHost int +} + +func (ca *ConnectionArgs) ConfigureTransport(transport *nethttp.Transport) { + if ca == nil { + return + } + transport.MaxIdleConns = ca.MaxIdleConns + transport.MaxIdleConnsPerHost = ca.MaxIdleConnsPerHost +} + type HttpMessageSender struct { Client *nethttp.Client Target string diff --git a/pkg/kncloudevents/testing/test_client.go b/pkg/kncloudevents/testing/test_client.go deleted file mode 100644 index 528c909bac9..00000000000 --- a/pkg/kncloudevents/testing/test_client.go +++ /dev/null @@ -1,53 +0,0 @@ -package testing - -import ( - "context" - "sync" - - cloudevents "github.com/cloudevents/sdk-go" -) - -type TestCloudEventsClient struct { - lock sync.Mutex - sent []cloudevents.Event -} - -var _ cloudevents.Client = (*TestCloudEventsClient)(nil) - -func (c *TestCloudEventsClient) Send(ctx context.Context, event cloudevents.Event) (context.Context, *cloudevents.Event, error) { - c.lock.Lock() - defer c.lock.Unlock() - // TODO: improve later. - c.sent = append(c.sent, event) - return ctx, nil, nil -} - -func (c *TestCloudEventsClient) StartReceiver(ctx context.Context, fn interface{}) error { - // TODO: improve later. - <-ctx.Done() - return nil -} - -func (c *TestCloudEventsClient) Reset() { - c.lock.Lock() - defer c.lock.Unlock() - c.sent = make([]cloudevents.Event, 0) -} - -func (c *TestCloudEventsClient) Sent() []cloudevents.Event { - c.lock.Lock() - defer c.lock.Unlock() - r := make([]cloudevents.Event, len(c.sent)) - for i := range c.sent { - r[i] = c.sent[i] - } - return r -} - -func NewTestClient() *TestCloudEventsClient { - c := &TestCloudEventsClient{ - sent: make([]cloudevents.Event, 0), - } - - return c -} diff --git a/pkg/utils/context.go b/pkg/utils/headers.go similarity index 62% rename from pkg/utils/context.go rename to pkg/utils/headers.go index 68372bf6399..81123f529e5 100644 --- a/pkg/utils/context.go +++ b/pkg/utils/headers.go @@ -17,13 +17,9 @@ package utils import ( - "context" "net/http" - "net/url" "strings" - cloudevents "github.com/cloudevents/sdk-go" - cehttp "github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http" "k8s.io/apimachinery/pkg/util/sets" ) @@ -45,31 +41,6 @@ var ( } ) -// SendingContextFrom creates the context to use when sending a Cloud Event with cloudevents.Client. It -// sets the target if specified, and attaches a filtered set of headers from the initial request. -func SendingContextFrom(ctx context.Context, tctx cloudevents.HTTPTransportContext, targetURI *url.URL) context.Context { - // Get the allowed set of headers. - h := PassThroughHeaders(tctx.Header) - ctx = cloudevents.SetContextHeaders(ctx, h) - - if targetURI != nil { - ctx = cloudevents.ContextWithTarget(ctx, targetURI.String()) - } - - return ctx -} - -// ReceivingContextFrom filters the transport context headers using -// PassThroughHeaders after receiving an event using -// cloudevents.Client -func ReceivingContextFrom(ctx context.Context) context.Context { - tctx := cloudevents.HTTPTransportContextFrom(ctx) - // Get the allowed set of headers. - h := PassThroughHeaders(tctx.Header) - tctx.Header = h - return cehttp.WithTransportContext(ctx, tctx) -} - // PassThroughHeaders extracts the headers from headers that are in the `forwardHeaders` set // or has any of the prefixes in `forwardPrefixes`. func PassThroughHeaders(headers http.Header) http.Header { diff --git a/third_party/VENDOR-LICENSE/github.com/cloudevents/sdk-go/LICENSE b/third_party/VENDOR-LICENSE/github.com/cloudevents/sdk-go/LICENSE deleted file mode 100644 index 261eeb9e9f8..00000000000 --- a/third_party/VENDOR-LICENSE/github.com/cloudevents/sdk-go/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/github.com/cloudevents/sdk-go/.gitignore b/vendor/github.com/cloudevents/sdk-go/.gitignore deleted file mode 100644 index d42a7691537..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -# Operating system temporary files -.DS_Store - -# Editor/IDE specific settings -.idea -.vscode/ - -# Temporary output of build tools -bazel-* - -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib - -# Test binary, build with `go test -c` -*.test - -# Output of the go coverage tool -*.out - -# Others -## IDE-specific -*.iml -test/benchmark/e2e/http/results/ -tmp/ - diff --git a/vendor/github.com/cloudevents/sdk-go/LICENSE b/vendor/github.com/cloudevents/sdk-go/LICENSE deleted file mode 100644 index 261eeb9e9f8..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/github.com/cloudevents/sdk-go/README.md b/vendor/github.com/cloudevents/sdk-go/README.md deleted file mode 100644 index 6cfc8c3c330..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/README.md +++ /dev/null @@ -1,149 +0,0 @@ -# Go SDK for [CloudEvents](https://github.com/cloudevents/spec) - -[![go-doc](https://godoc.org/github.com/cloudevents/sdk-go?status.svg)](https://godoc.org/github.com/cloudevents/sdk-go) -[![Go Report Card](https://goreportcard.com/badge/github.com/cloudevents/sdk-go)](https://goreportcard.com/report/github.com/cloudevents/sdk-go) -[![CircleCI](https://circleci.com/gh/cloudevents/sdk-go.svg?style=svg)](https://circleci.com/gh/cloudevents/sdk-go) -[![Releases](https://img.shields.io/github/release-pre/cloudevents/sdk-go.svg)](https://github.com/cloudevents/sdk-go/releases) -[![LICENSE](https://img.shields.io/github/license/cloudevents/sdk-go.svg)](https://github.com/cloudevents/sdk-go/blob/master/LICENSE) - -## Status - -This SDK is still considered work in progress. - -**With v1.1.0:** - -[Master](https://github.com/cloudevents/sdk-go/tree/master) will now be the base -of the effort for v2.0.0 of this SDK and will contain breaking changes or -missing libraries. - -Future work on v1.X.Y releases will branch off of -[release-1.y.z](https://github.com/cloudevents/sdk-go/tree/release-1.y.z). To -add a bugfix to a v1.X.Y release, please make a PR to that branch and we can do -releases as needed on the v1 SDK. No date for EOL on v1 support yet, that will -be determined by the progress on v2. - -The CloudEvents golang team is working hard to bring you v2.0.0 of the SDK. - -**With v1.0.0:** - -The API that exists under [`pkg/cloudevents`](./pkg/cloudevents) will follow -semver rules. This applies to the root [`./alias.go`](./alias.go) file as well. - -Even though `pkg/cloudevents` is v1.0.0, there could still be minor bugs and -performance issues. We will continue to track and fix these issues as they come -up. Please file a pull request or issue if you experience problems. - -The API that exists under [`pkg/bindings`](./pkg/bindings) is a new API that -will become SDK v2.x, and will replace `pkg/cloudevents`. This area is still -under heavy development and will not be following the same semver rules as -`pkg/cloudevents`. If a release is required to ship changes to `pkg/bindings`, a -bug fix release will be issued (x.y.z+1). - -We will target ~2 months of development to release v2 of this SDK with an end -date of March 27, 2020. You can read more about the plan for SDK v2 in the -[SDK v2 planning doc](./docs/SDK_v2.md). - -This SDK current supports the following versions of CloudEvents: - -- v1.0 -- v0.3 -- v0.2 -- v0.1 - -## Working with CloudEvents - -Package [cloudevents](./pkg/cloudevents) provides primitives to work with -CloudEvents specification: https://github.com/cloudevents/spec. - -Import this repo to get the `cloudevents` package: - -```go -import "github.com/cloudevents/sdk-go" -``` - -Receiving a cloudevents.Event via the HTTP Transport: - -```go -func Receive(event cloudevents.Event) { - // do something with event.Context and event.Data (via event.DataAs(foo) -} - -func main() { - c, err := cloudevents.NewDefaultClient() - if err != nil { - log.Fatalf("failed to create client, %v", err) - } - log.Fatal(c.StartReceiver(context.Background(), Receive)); -} -``` - -Creating a minimal CloudEvent in version 1.0: - -```go -event := cloudevents.NewEvent() -event.SetID("ABC-123") -event.SetType("com.cloudevents.readme.sent") -event.SetSource("http://localhost:8080/") -event.SetData(data) -``` - -Sending a cloudevents.Event via the HTTP Transport with Binary v1.0 encoding: - -```go -t, err := cloudevents.NewHTTPTransport( - cloudevents.WithTarget("http://localhost:8080/"), - cloudevents.WithEncoding(cloudevents.HTTPBinaryV1), -) -if err != nil { - panic("failed to create transport, " + err.Error()) -} - -c, err := cloudevents.NewClient(t) -if err != nil { - panic("unable to create cloudevent client: " + err.Error()) -} -if err := c.Send(ctx, event); err != nil { - panic("failed to send cloudevent: " + err.Error()) -} -``` - -Or, the transport can be set to produce CloudEvents using the selected encoding -but not change the provided event version, here the client is set to output -structured encoding: - -```go -t, err := cloudevents.NewHTTPTransport( - cloudevents.WithTarget("http://localhost:8080/"), - cloudevents.WithStructuredEncoding(), -) -``` - -If you are using advanced transport features or have implemented your own -transport integration, provide it to a client so your integration does not -change: - -```go -t, err := cloudevents.NewHTTPTransport( - cloudevents.WithPort(8181), - cloudevents.WithPath("/events/") -) -// or a custom transport: t := &custom.MyTransport{Cool:opts} - -c, err := cloudevents.NewClient(t, opts...) -``` - -Checkout the sample [sender](./cmd/samples/http/sender) and -[receiver](./cmd/samples/http/receiver) applications for working demo. - -## Community - -- There are bi-weekly calls immediately following the - [Serverless/CloudEvents call](https://github.com/cloudevents/spec#meeting-time) - at 9am PT (US Pacific). Which means they will typically start at 10am PT, but - if the other call ends early then the SDK call will start early as well. See - the - [CloudEvents meeting minutes](https://docs.google.com/document/d/1OVF68rpuPK5shIHILK9JOqlZBbfe91RNzQ7u_P7YCDE/edit#) - to determine which week will have the call. -- Slack: #cloudeventssdk channel under - [CNCF's Slack workspace](https://slack.cncf.io/). -- Contact for additional information: Scott Nichols (`@Scott Nichols` on slack). diff --git a/vendor/github.com/cloudevents/sdk-go/alias.go b/vendor/github.com/cloudevents/sdk-go/alias.go deleted file mode 100644 index ef957d72a61..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/alias.go +++ /dev/null @@ -1,153 +0,0 @@ -package cloudevents - -// Package cloudevents alias' common functions and types to improve discoverability and reduce -// the number of imports for simple HTTP clients. - -import ( - "github.com/cloudevents/sdk-go/pkg/cloudevents" - "github.com/cloudevents/sdk-go/pkg/cloudevents/client" - "github.com/cloudevents/sdk-go/pkg/cloudevents/context" - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" - "github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http" - "github.com/cloudevents/sdk-go/pkg/cloudevents/types" -) - -// Client - -type ClientOption client.Option -type Client = client.Client -type ConvertFn = client.ConvertFn - -// Event - -type Event = cloudevents.Event -type EventResponse = cloudevents.EventResponse - -// Context - -type EventContext = cloudevents.EventContext -type EventContextV1 = cloudevents.EventContextV1 -type EventContextV01 = cloudevents.EventContextV01 -type EventContextV02 = cloudevents.EventContextV02 -type EventContextV03 = cloudevents.EventContextV03 - -// Custom Types - -type Timestamp = types.Timestamp -type URLRef = types.URLRef - -// HTTP Transport - -type HTTPOption http.Option -type HTTPTransport = http.Transport -type HTTPTransportContext = http.TransportContext -type HTTPTransportResponseContext = http.TransportResponseContext -type HTTPEncoding = http.Encoding - -const ( - // Encoding - - ApplicationXML = cloudevents.ApplicationXML - ApplicationJSON = cloudevents.ApplicationJSON - ApplicationCloudEventsJSON = cloudevents.ApplicationCloudEventsJSON - ApplicationCloudEventsBatchJSON = cloudevents.ApplicationCloudEventsBatchJSON - Base64 = cloudevents.Base64 - - // Event Versions - - VersionV1 = cloudevents.CloudEventsVersionV1 - VersionV01 = cloudevents.CloudEventsVersionV01 - VersionV02 = cloudevents.CloudEventsVersionV02 - VersionV03 = cloudevents.CloudEventsVersionV03 - - // HTTP Transport Encodings - - HTTPBinaryV1 = http.BinaryV1 - HTTPStructuredV1 = http.StructuredV1 - HTTPBatchedV1 = http.BatchedV1 - HTTPBinaryV01 = http.BinaryV01 - HTTPStructuredV01 = http.StructuredV01 - HTTPBinaryV02 = http.BinaryV02 - HTTPStructuredV02 = http.StructuredV02 - HTTPBinaryV03 = http.BinaryV03 - HTTPStructuredV03 = http.StructuredV03 - HTTPBatchedV03 = http.BatchedV03 - - // Context HTTP Transport Encodings - - Binary = http.Binary - Structured = http.Structured -) - -var ( - // ContentType Helpers - - StringOfApplicationJSON = cloudevents.StringOfApplicationJSON - StringOfApplicationXML = cloudevents.StringOfApplicationXML - StringOfApplicationCloudEventsJSON = cloudevents.StringOfApplicationCloudEventsJSON - StringOfApplicationCloudEventsBatchJSON = cloudevents.StringOfApplicationCloudEventsBatchJSON - StringOfBase64 = cloudevents.StringOfBase64 - - // Client Creation - - NewClient = client.New - NewDefaultClient = client.NewDefault - - // Client Options - - WithEventDefaulter = client.WithEventDefaulter - WithUUIDs = client.WithUUIDs - WithTimeNow = client.WithTimeNow - WithConverterFn = client.WithConverterFn - WithDataContentType = client.WithDataContentType - WithoutTracePropagation = client.WithoutTracePropagation - - // Event Creation - - NewEvent = cloudevents.New - - // Tracing - - EnableTracing = observability.EnableTracing - - // Context - - ContextWithTarget = context.WithTarget - TargetFromContext = context.TargetFrom - ContextWithEncoding = context.WithEncoding - EncodingFromContext = context.EncodingFrom - - // Custom Types - - ParseTimestamp = types.ParseTimestamp - ParseURLRef = types.ParseURLRef - ParseURIRef = types.ParseURIRef - ParseURI = types.ParseURI - - // HTTP Transport - - NewHTTPTransport = http.New - - // HTTP Transport Options - - WithTarget = http.WithTarget - WithMethod = http.WithMethod - WitHHeader = http.WithHeader - WithShutdownTimeout = http.WithShutdownTimeout - WithEncoding = http.WithEncoding - WithContextBasedEncoding = http.WithContextBasedEncoding - WithBinaryEncoding = http.WithBinaryEncoding - WithStructuredEncoding = http.WithStructuredEncoding - WithPort = http.WithPort - WithPath = http.WithPath - WithMiddleware = http.WithMiddleware - WithLongPollTarget = http.WithLongPollTarget - WithListener = http.WithListener - WithHTTPTransport = http.WithHTTPTransport - - // HTTP Context - - HTTPTransportContextFrom = http.TransportContextFrom - ContextWithHeader = http.ContextWithHeader - SetContextHeaders = http.SetContextHeaders -) diff --git a/vendor/github.com/cloudevents/sdk-go/go.mod b/vendor/github.com/cloudevents/sdk-go/go.mod deleted file mode 100644 index 8e03d72f5f8..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/go.mod +++ /dev/null @@ -1,36 +0,0 @@ -module github.com/cloudevents/sdk-go - -require ( - cloud.google.com/go v0.40.0 - contrib.go.opencensus.io/exporter/prometheus v0.1.0 - github.com/Azure/azure-sdk-for-go v30.1.0+incompatible // indirect - github.com/Azure/go-autorest/autorest v0.2.0 // indirect - github.com/Azure/go-autorest/autorest/to v0.2.0 // indirect - github.com/Azure/go-autorest/autorest/validation v0.1.0 // indirect - github.com/Shopify/sarama v1.19.0 - github.com/fortytw2/leaktest v1.3.0 // indirect - github.com/google/go-cmp v0.4.0 - github.com/google/uuid v1.1.1 - github.com/kelseyhightower/envconfig v1.4.0 - github.com/kr/pretty v0.2.0 // indirect - github.com/lightstep/tracecontext.go v0.0.0-20181129014701-1757c391b1ac - github.com/nats-io/nats-server/v2 v2.1.2 - github.com/nats-io/nats.go v1.9.1 - github.com/pkg/errors v0.8.1 - github.com/stretchr/testify v1.4.0 - github.com/valyala/bytebufferpool v1.0.0 - go.opencensus.io v0.22.0 - go.uber.org/atomic v1.4.0 // indirect - go.uber.org/multierr v1.1.0 // indirect - go.uber.org/zap v1.10.0 - golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72 // indirect - golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect - golang.org/x/sync v0.0.0-20190423024810-112230192c58 - google.golang.org/api v0.15.0 - google.golang.org/grpc v1.26.0 - gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect - gopkg.in/yaml.v2 v2.2.8 // indirect - pack.ag/amqp v0.11.0 -) - -go 1.13 diff --git a/vendor/github.com/cloudevents/sdk-go/go.sum b/vendor/github.com/cloudevents/sdk-go/go.sum deleted file mode 100644 index 80b4c71a1cc..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/go.sum +++ /dev/null @@ -1,306 +0,0 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -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= -contrib.go.opencensus.io/exporter/prometheus v0.1.0 h1:SByaIoWwNgMdPSgl5sMqM2KDE5H/ukPWBRo314xiDvg= -contrib.go.opencensus.io/exporter/prometheus v0.1.0/go.mod h1:cGFniUXGZlKRjzOyuZJ6mgB+PgBcCIa79kEKR8YCW+A= -github.com/Azure/azure-sdk-for-go v30.1.0+incompatible h1:HyYPft8wXpxMd0kfLtXo6etWcO+XuPbLkcgx9g2cqxU= -github.com/Azure/azure-sdk-for-go v30.1.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= -github.com/Azure/go-autorest/autorest v0.2.0 h1:zBtSTOQTtjzHVRe+mhkiHvHwRTKHhjBEyo1m6DfI3So= -github.com/Azure/go-autorest/autorest v0.2.0/go.mod h1:AKyIcETwSUFxIcs/Wnq/C+kwCtlEYGUVd7FPNb2slmg= -github.com/Azure/go-autorest/autorest/adal v0.1.0 h1:RSw/7EAullliqwkZvgIGDYZWQm1PGKXI8c4aY/87yuU= -github.com/Azure/go-autorest/autorest/adal v0.1.0/go.mod h1:MeS4XhScH55IST095THyTxElntu7WqB7pNbZo8Q5G3E= -github.com/Azure/go-autorest/autorest/date v0.1.0 h1:YGrhWfrgtFs84+h0o46rJrlmsZtyZRg470CqAXTZaGM= -github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA= -github.com/Azure/go-autorest/autorest/mocks v0.1.0 h1:Kx+AUU2Te+A3JIyYn6Dfs+cFgx5XorQKuIXrZGoq/SI= -github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= -github.com/Azure/go-autorest/autorest/to v0.2.0 h1:nQOZzFCudTh+TvquAtCRjM01VEYx85e9qbwt5ncW4L8= -github.com/Azure/go-autorest/autorest/to v0.2.0/go.mod h1:GunWKJp1AEqgMaGLV+iocmRAJWqST1wQYhyyjXJ3SJc= -github.com/Azure/go-autorest/autorest/validation v0.1.0 h1:ISSNzGUh+ZSzizJWOWzs8bwpXIePbGLW4z/AmUFGH5A= -github.com/Azure/go-autorest/autorest/validation v0.1.0/go.mod h1:Ha3z/SqBeaalWQvokg3NZAlQTalVMtOIAs1aGK7G6u8= -github.com/Azure/go-autorest/logger v0.1.0 h1:ruG4BSDXONFRrZZJ2GUXDiUyVpayPmb1GnWeHDdaNKY= -github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= -github.com/Azure/go-autorest/tracing v0.1.0 h1:TRBxC5Pj/fIuh4Qob0ZpkggbfT8RC0SubHbpV3p4/Vc= -github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvdeRAgDr0izn4z5Ij88= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Shopify/sarama v1.19.0 h1:9oksLxC6uxVPHPVYUmq6xhr1BOF/hHobWH2UzO67z1s= -github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= -github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc= -github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/census-instrumentation/opencensus-proto v0.2.0 h1:LzQXZOgg4CQfE6bFvXGM30YZL1WW/M337pXml+GrcZ4= -github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/census-instrumentation/opencensus-proto v0.2.1 h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/eapache/go-resiliency v1.1.0 h1:1NtRmCAqadE2FN4ZcN6g90TP3uk8cg9rn9eNK2197aU= -github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= -github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 h1:YEetp8/yCZMuEPMUDHG0CW/brkkEp8mzqk2+ODEitlw= -github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= -github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= -github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= -github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= -github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= -github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= -github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/googleapis/gax-go/v2 v2.0.4 h1:hU4mGcQI4DaAYW+IbTun+2qEZVFxK0ySjQLTbS0VQKc= -github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= -github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM= -github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= -github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -github.com/grpc-ecosystem/grpc-gateway v1.8.5 h1:2+KSC78XiO6Qy0hIjfc1OD9H+hsaJdJlb8Kqsd41CTE= -github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= -github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= -github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= -github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/lightstep/tracecontext.go v0.0.0-20181129014701-1757c391b1ac h1:+2b6iGRJe3hvV/yVXrd41yVEjxuFHxasJqDhkIjS4gk= -github.com/lightstep/tracecontext.go v0.0.0-20181129014701-1757c391b1ac/go.mod h1:Frd2bnT3w5FB5q49ENTfVlztJES+1k/7lyWX2+9gq/M= -github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= -github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= -github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= -github.com/nats-io/nats-server/v2 v2.1.2 h1:i2Ly0B+1+rzNZHHWtD4ZwKi+OU5l+uQo1iDHZ2PmiIc= -github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= -github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ= -github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= -github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= -github.com/nats-io/nkeys v0.1.3 h1:6JrEfig+HzTH85yxzhSVbjHRJv9cn0p6n3IngIcM5/k= -github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= -github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= -github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= -github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= -github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= -github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I= -github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v0.9.2 h1:awm861/B8OKDd2I/6o1dy3ra4BamzKhYOiGItCeZ740= -github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= -github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829 h1:D+CiwcpGTW6pL6bv6KI3KbyEyCKyS+1JWS2h8PNDnGA= -github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f h1:BVwpUVJDADN2ufcGik7W992pyps0wZ888b/y9GXcLTU= -github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 h1:PnBWHBf+6L0jOqq0gIVUe6Yk0/QMZ640k6NvkxcBf+8= -github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.2.0 h1:kUZDBDTdBVBYBj5Tmh2NZLlF60mfjA27rM34b+cVwNU= -github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nLJdBg+pBmGgkJlSaKC2KaQmTCk1XDtE= -github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1 h1:/K3IL0Z1quvmJ7X0A1AwNEK7CRkVK3YwfOU/QAL4WGg= -github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a h1:9ZKAASQSHhDYGoxY8uLVpewe1GDZ2vu2Tr/vTdVAkFQ= -github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= -go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= -go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= -go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4= -go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= -go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= -go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72 h1:+ELyKg6m8UBf0nPFSqD0mi7zUfwPyXo23HNjMnXPz7w= -golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c h1:uOCk1iQW6Vc18bnC13MfzScl+wdKBmM9Y9kU7Z83/lw= -golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b h1:ag/x1USPSsqHud38I9BAC88qdNLDHHtQ4mlgQIZPPNA= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e h1:D5TXcfTk7xF7hvieo4QErS3qqCB4teTffacDWr7CI+0= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= -google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= -google.golang.org/api v0.6.0 h1:2tJEkRfnZL5g1GeBUlITh/rqT5HG3sFcoVCUUxmgJ2g= -google.golang.org/api v0.6.0/go.mod h1:btoxGiFvQNVUZQ8W08zLtrVS08CNpINPEfxXxgJL1Q4= -google.golang.org/api v0.15.0 h1:yzlyyDW/J0w8yNFJIhiAJy4kq74S+1DOLdawELNxFMA= -google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.5.0 h1:KxkO13IPW4Lslp2bz+KHP2E3gtFlrIGNThxkZQ3g+4c= -google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190530194941-fb225487d101 h1:wuGevabY6r+ivPNagjUXGGxF+GqgMd+dBhjsxW4q9u4= -google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.1 h1:Hz2g2wirWK7H0qIIhGIqRGTuMwTE8HEKFnDZZ7lm9NU= -google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= -google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= -gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -pack.ag/amqp v0.11.0 h1:ot/IA0enDkt4/c8xfbCO7AZzjM4bHys/UffnFmnHUnU= -pack.ag/amqp v0.11.0/go.mod h1:4/cbmt4EJXSKlG6LCfWHoqmN0uFdy5i/+YFz+fTfhV4= -rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/client.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/client.go deleted file mode 100644 index 209eb8f77a6..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/client.go +++ /dev/null @@ -1,226 +0,0 @@ -package client - -import ( - "context" - "fmt" - "sync" - - "github.com/cloudevents/sdk-go/pkg/cloudevents" - "github.com/cloudevents/sdk-go/pkg/cloudevents/extensions" - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" - "github.com/cloudevents/sdk-go/pkg/cloudevents/transport" - "github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http" - "go.opencensus.io/trace" -) - -// Client interface defines the runtime contract the CloudEvents client supports. -type Client interface { - // Send will transmit the given event over the client's configured transport. - Send(ctx context.Context, event cloudevents.Event) (context.Context, *cloudevents.Event, error) - - // StartReceiver will register the provided function for callback on receipt - // of a cloudevent. It will also start the underlying transport as it has - // been configured. - // This call is blocking. - // Valid fn signatures are: - // * func() - // * func() error - // * func(context.Context) - // * func(context.Context) error - // * func(cloudevents.Event) - // * func(cloudevents.Event) error - // * func(context.Context, cloudevents.Event) - // * func(context.Context, cloudevents.Event) error - // * func(cloudevents.Event, *cloudevents.EventResponse) - // * func(cloudevents.Event, *cloudevents.EventResponse) error - // * func(context.Context, cloudevents.Event, *cloudevents.EventResponse) - // * func(context.Context, cloudevents.Event, *cloudevents.EventResponse) error - // Note: if fn returns an error, it is treated as a critical and - // EventResponse will not be processed. - StartReceiver(ctx context.Context, fn interface{}) error -} - -// New produces a new client with the provided transport object and applied -// client options. -func New(t transport.Transport, opts ...Option) (Client, error) { - c := &ceClient{ - transport: t, - } - if err := c.applyOptions(opts...); err != nil { - return nil, err - } - t.SetReceiver(c) - return c, nil -} - -// NewDefault provides the good defaults for the common case using an HTTP -// Transport client. The http transport has had WithBinaryEncoding http -// transport option applied to it. The client will always send Binary -// encoding but will inspect the outbound event context and match the version. -// The WithTimeNow, WithUUIDs and WithDataContentType("application/json") -// client options are also applied to the client, all outbound events will have -// a time and id set if not already present. -func NewDefault() (Client, error) { - t, err := http.New(http.WithBinaryEncoding()) - if err != nil { - return nil, err - } - c, err := New(t, WithTimeNow(), WithUUIDs(), WithDataContentType(cloudevents.ApplicationJSON)) - if err != nil { - return nil, err - } - return c, nil -} - -type ceClient struct { - transport transport.Transport - fn *receiverFn - - convertFn ConvertFn - - receiverMu sync.Mutex - eventDefaulterFns []EventDefaulter - - disableTracePropagation bool -} - -// Send transmits the provided event on a preconfigured Transport. -// Send returns a response event if there is a response or an error if there -// was an an issue validating the outbound event or the transport returns an -// error. -func (c *ceClient) Send(ctx context.Context, event cloudevents.Event) (context.Context, *cloudevents.Event, error) { - ctx, r := observability.NewReporter(ctx, reportSend) - - ctx, span := trace.StartSpan(ctx, clientSpanName, trace.WithSpanKind(trace.SpanKindClient)) - defer span.End() - if span.IsRecordingEvents() { - span.AddAttributes(eventTraceAttributes(event.Context)...) - } - - rctx, resp, err := c.obsSend(ctx, event) - if err != nil { - r.Error() - } else { - r.OK() - } - return rctx, resp, err -} - -func (c *ceClient) obsSend(ctx context.Context, event cloudevents.Event) (context.Context, *cloudevents.Event, error) { - // Confirm we have a transport set. - if c.transport == nil { - return ctx, nil, fmt.Errorf("client not ready, transport not initialized") - } - // Apply the defaulter chain to the incoming event. - if len(c.eventDefaulterFns) > 0 { - for _, fn := range c.eventDefaulterFns { - event = fn(ctx, event) - } - } - - // Set distributed tracing extension. - if !c.disableTracePropagation { - if span := trace.FromContext(ctx); span != nil { - event.Context = event.Context.Clone() - if err := extensions.FromSpanContext(span.SpanContext()).AddTracingAttributes(event.Context); err != nil { - return ctx, nil, fmt.Errorf("error setting distributed tracing extension: %w", err) - } - } - } - - // Validate the event conforms to the CloudEvents Spec. - if err := event.Validate(); err != nil { - return ctx, nil, err - } - // Send the event over the transport. - return c.transport.Send(ctx, event) -} - -// Receive is called from from the transport on event delivery. -func (c *ceClient) Receive(ctx context.Context, event cloudevents.Event, resp *cloudevents.EventResponse) error { - ctx, r := observability.NewReporter(ctx, reportReceive) - - var span *trace.Span - if !c.transport.HasTracePropagation() { - if ext, ok := extensions.GetDistributedTracingExtension(event); ok { - ctx, span = ext.StartChildSpan(ctx, clientSpanName, trace.WithSpanKind(trace.SpanKindServer)) - } - } - if span == nil { - ctx, span = trace.StartSpan(ctx, clientSpanName, trace.WithSpanKind(trace.SpanKindServer)) - } - defer span.End() - if span.IsRecordingEvents() { - span.AddAttributes(eventTraceAttributes(event.Context)...) - } - - err := c.obsReceive(ctx, event, resp) - if err != nil { - r.Error() - } else { - r.OK() - } - return err -} - -func (c *ceClient) obsReceive(ctx context.Context, event cloudevents.Event, resp *cloudevents.EventResponse) error { - if c.fn != nil { - err := c.fn.invoke(ctx, event, resp) - - // Apply the defaulter chain to the outgoing event. - if err == nil && resp != nil && resp.Event != nil && len(c.eventDefaulterFns) > 0 { - for _, fn := range c.eventDefaulterFns { - *resp.Event = fn(ctx, *resp.Event) - } - // Validate the event conforms to the CloudEvents Spec. - if err := resp.Event.Validate(); err != nil { - return fmt.Errorf("cloudevent validation failed on response event: %v", err) - } - } - return err - } - return nil -} - -// StartReceiver sets up the given fn to handle Receive. -// See Client.StartReceiver for details. This is a blocking call. -func (c *ceClient) StartReceiver(ctx context.Context, fn interface{}) error { - c.receiverMu.Lock() - defer c.receiverMu.Unlock() - - if c.transport == nil { - return fmt.Errorf("client not ready, transport not initialized") - } - if c.fn != nil { - return fmt.Errorf("client already has a receiver") - } - - if fn, err := receiver(fn); err != nil { - return err - } else { - c.fn = fn - } - - defer func() { - c.fn = nil - }() - - return c.transport.StartReceiver(ctx) -} - -func (c *ceClient) applyOptions(opts ...Option) error { - for _, fn := range opts { - if err := fn(c); err != nil { - return err - } - } - return nil -} - -// Convert implements transport Converter.Convert. -func (c *ceClient) Convert(ctx context.Context, m transport.Message, err error) (*cloudevents.Event, error) { - if c.convertFn != nil { - return c.convertFn(ctx, m, err) - } - return nil, err -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/defaulters.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/defaulters.go deleted file mode 100644 index e827dec23d9..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/defaulters.go +++ /dev/null @@ -1,51 +0,0 @@ -package client - -import ( - "context" - "time" - - "github.com/cloudevents/sdk-go/pkg/cloudevents" - "github.com/google/uuid" -) - -// EventDefaulter is the function signature for extensions that are able -// to perform event defaulting. -type EventDefaulter func(ctx context.Context, event cloudevents.Event) cloudevents.Event - -// DefaultIDToUUIDIfNotSet will inspect the provided event and assign a UUID to -// context.ID if it is found to be empty. -func DefaultIDToUUIDIfNotSet(ctx context.Context, event cloudevents.Event) cloudevents.Event { - if event.Context != nil { - if event.ID() == "" { - event.Context = event.Context.Clone() - event.SetID(uuid.New().String()) - } - } - return event -} - -// DefaultTimeToNowIfNotSet will inspect the provided event and assign a new -// Timestamp to context.Time if it is found to be nil or zero. -func DefaultTimeToNowIfNotSet(ctx context.Context, event cloudevents.Event) cloudevents.Event { - if event.Context != nil { - if event.Time().IsZero() { - event.Context = event.Context.Clone() - event.SetTime(time.Now()) - } - } - return event -} - -// NewDefaultDataContentTypeIfNotSet returns a defaulter that will inspect the -// provided event and set the provided content type if content type is found -// to be empty. -func NewDefaultDataContentTypeIfNotSet(contentType string) EventDefaulter { - return func(ctx context.Context, event cloudevents.Event) cloudevents.Event { - if event.Context != nil { - if event.DataContentType() == "" { - event.SetDataContentType(contentType) - } - } - return event - } -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/doc.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/doc.go deleted file mode 100644 index a6a602bb410..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/doc.go +++ /dev/null @@ -1,6 +0,0 @@ -/* -Package client holds the recommended entry points for interacting with the CloudEvents Golang SDK. The client wraps -a selected transport. The client adds validation and defaulting for sending events, and flexible receiver method -registration. For full details, read the `client.Client` documentation. -*/ -package client diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/observability.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/observability.go deleted file mode 100644 index 9b67627c260..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/observability.go +++ /dev/null @@ -1,76 +0,0 @@ -package client - -import ( - "github.com/cloudevents/sdk-go/pkg/cloudevents" - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" - "go.opencensus.io/trace" -) - -var ( - // LatencyMs measures the latency in milliseconds for the CloudEvents - // client methods. - LatencyMs = stats.Float64("cloudevents.io/sdk-go/client/latency", "The latency in milliseconds for the CloudEvents client methods.", "ms") -) - -var ( - // LatencyView is an OpenCensus view that shows client method latency. - LatencyView = &view.View{ - Name: "client/latency", - Measure: LatencyMs, - Description: "The distribution of latency inside of client for CloudEvents.", - Aggregation: view.Distribution(0, .01, .1, 1, 10, 100, 1000, 10000), - TagKeys: observability.LatencyTags(), - } -) - -type observed int32 - -// Adheres to Observable -var _ observability.Observable = observed(0) - -const ( - clientSpanName = "cloudevents.client" - - specversionAttr = "cloudevents.specversion" - typeAttr = "cloudevents.type" - sourceAttr = "cloudevents.source" - subjectAttr = "cloudevents.subject" - datacontenttypeAttr = "cloudevents.datacontenttype" - - reportSend observed = iota - reportReceive -) - -// MethodName implements Observable.MethodName -func (o observed) MethodName() string { - switch o { - case reportSend: - return "send" - case reportReceive: - return "receive" - default: - return "unknown" - } -} - -// LatencyMs implements Observable.LatencyMs -func (o observed) LatencyMs() *stats.Float64Measure { - return LatencyMs -} - -func eventTraceAttributes(e cloudevents.EventContextReader) []trace.Attribute { - as := []trace.Attribute{ - trace.StringAttribute(specversionAttr, e.GetSpecVersion()), - trace.StringAttribute(typeAttr, e.GetType()), - trace.StringAttribute(sourceAttr, e.GetSource()), - } - if sub := e.GetSubject(); sub != "" { - as = append(as, trace.StringAttribute(subjectAttr, sub)) - } - if dct := e.GetDataContentType(); dct != "" { - as = append(as, trace.StringAttribute(datacontenttypeAttr, dct)) - } - return as -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/options.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/options.go deleted file mode 100644 index a9364f6ad7c..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/options.go +++ /dev/null @@ -1,72 +0,0 @@ -package client - -import ( - "fmt" -) - -// Option is the function signature required to be considered an client.Option. -type Option func(*ceClient) error - -// WithEventDefaulter adds an event defaulter to the end of the defaulter chain. -func WithEventDefaulter(fn EventDefaulter) Option { - return func(c *ceClient) error { - if fn == nil { - return fmt.Errorf("client option was given an nil event defaulter") - } - c.eventDefaulterFns = append(c.eventDefaulterFns, fn) - return nil - } -} - -// WithUUIDs adds DefaultIDToUUIDIfNotSet event defaulter to the end of the -// defaulter chain. -func WithUUIDs() Option { - return func(c *ceClient) error { - c.eventDefaulterFns = append(c.eventDefaulterFns, DefaultIDToUUIDIfNotSet) - return nil - } -} - -// WithDataContentType adds the resulting defaulter from -// NewDefaultDataContentTypeIfNotSet event defaulter to the end of the -// defaulter chain. -func WithDataContentType(contentType string) Option { - return func(c *ceClient) error { - c.eventDefaulterFns = append(c.eventDefaulterFns, NewDefaultDataContentTypeIfNotSet(contentType)) - return nil - } -} - -// WithTimeNow adds DefaultTimeToNowIfNotSet event defaulter to the end of the -// defaulter chain. -func WithTimeNow() Option { - return func(c *ceClient) error { - c.eventDefaulterFns = append(c.eventDefaulterFns, DefaultTimeToNowIfNotSet) - return nil - } -} - -// WithConverterFn defines the function the transport will use to delegate -// conversion of non-decodable messages. -func WithConverterFn(fn ConvertFn) Option { - return func(c *ceClient) error { - if fn == nil { - return fmt.Errorf("client option was given an nil message converter") - } - if c.transport.HasConverter() { - return fmt.Errorf("transport converter already set") - } - c.convertFn = fn - c.transport.SetConverter(c) - return nil - } -} - -// WithoutTracePropagation disables automatic trace propagation via -// the distributed tracing extension. -func WithoutTracePropagation() Option { - return func(c *ceClient) error { - c.disableTracePropagation = true - return nil - } -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/receiver.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/receiver.go deleted file mode 100644 index 9734341d43f..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/client/receiver.go +++ /dev/null @@ -1,193 +0,0 @@ -package client - -import ( - "context" - "errors" - "fmt" - "reflect" - - "github.com/cloudevents/sdk-go/pkg/cloudevents" - "github.com/cloudevents/sdk-go/pkg/cloudevents/transport" -) - -// Receive is the signature of a fn to be invoked for incoming cloudevents. -// If fn returns an error, EventResponse will not be considered by the client or -// or transport. -// This is just an FYI: -type ReceiveFull func(context.Context, cloudevents.Event, *cloudevents.EventResponse) error - -type receiverFn struct { - numIn int - fnValue reflect.Value - - hasContextIn bool - hasEventIn bool - hasEventResponseIn bool - - hasErrorOut bool -} - -// ConvertFn defines the signature the client expects to enable conversion -// delegation. -type ConvertFn func(context.Context, transport.Message, error) (*cloudevents.Event, error) - -const ( - inParamUsage = "expected a function taking either no parameters, one or more of (context.Context, cloudevents.Event, *cloudevents.EventResponse) ordered" - outParamUsage = "expected a function returning either nothing or an error" -) - -var ( - contextType = reflect.TypeOf((*context.Context)(nil)).Elem() - eventType = reflect.TypeOf((*cloudevents.Event)(nil)).Elem() - eventResponseType = reflect.TypeOf((*cloudevents.EventResponse)(nil)) // want the ptr type - errorType = reflect.TypeOf((*error)(nil)).Elem() -) - -// receiver creates a receiverFn wrapper class that is used by the client to -// validate and invoke the provided function. -// Valid fn signatures are: -// * func() -// * func() error -// * func(context.Context) -// * func(context.Context) error -// * func(cloudevents.Event) -// * func(cloudevents.Event) error -// * func(context.Context, cloudevents.Event) -// * func(context.Context, cloudevents.Event) error -// * func(cloudevents.Event, *cloudevents.EventResponse) -// * func(cloudevents.Event, *cloudevents.EventResponse) error -// * func(context.Context, cloudevents.Event, *cloudevents.EventResponse) -// * func(context.Context, cloudevents.Event, *cloudevents.EventResponse) error -// -func receiver(fn interface{}) (*receiverFn, error) { - fnType := reflect.TypeOf(fn) - if fnType.Kind() != reflect.Func { - return nil, errors.New("must pass a function to handle events") - } - - r := &receiverFn{ - fnValue: reflect.ValueOf(fn), - numIn: fnType.NumIn(), - } - if err := r.validate(fnType); err != nil { - return nil, err - } - - return r, nil -} - -func (r *receiverFn) invoke(ctx context.Context, event cloudevents.Event, resp *cloudevents.EventResponse) error { - args := make([]reflect.Value, 0, r.numIn) - - if r.numIn > 0 { - if r.hasContextIn { - args = append(args, reflect.ValueOf(ctx)) - } - if r.hasEventIn { - args = append(args, reflect.ValueOf(event)) - } - if r.hasEventResponseIn { - args = append(args, reflect.ValueOf(resp)) - } - } - v := r.fnValue.Call(args) - if r.hasErrorOut && len(v) >= 1 { - if err, ok := v[0].Interface().(error); ok { - return err - } - } - return nil -} - -// Verifies that the inputs to a function have a valid signature -// Valid input is to be [0, all] of -// context.Context, cloudevents.Event, *cloudevents.EventResponse in this order. -func (r *receiverFn) validateInParamSignature(fnType reflect.Type) error { - r.hasContextIn = false - r.hasEventIn = false - r.hasEventResponseIn = false - - switch fnType.NumIn() { - case 3: - // has to be cloudevents.Event, *cloudevents.EventResponse - if !fnType.In(2).ConvertibleTo(eventResponseType) { - return fmt.Errorf("%s; cannot convert parameter 2 from %s to *cloudevents.EventResponse", inParamUsage, fnType.In(2)) - } else { - r.hasEventResponseIn = true - } - fallthrough - case 2: - // can be cloudevents.Event or *cloudevents.EventResponse - if !fnType.In(1).ConvertibleTo(eventResponseType) { - if !fnType.In(1).ConvertibleTo(eventType) { - return fmt.Errorf("%s; cannot convert parameter 1 from %s to cloudevents.Event or *cloudevents.EventResponse", inParamUsage, fnType.In(1)) - } else { - r.hasEventIn = true - } - } else if r.hasEventResponseIn { - return fmt.Errorf("%s; duplicate parameter of type *cloudevents.EventResponse", inParamUsage) - } else { - r.hasEventResponseIn = true - } - fallthrough - case 1: - if !fnType.In(0).ConvertibleTo(contextType) { - if !fnType.In(0).ConvertibleTo(eventResponseType) { - if !fnType.In(0).ConvertibleTo(eventType) { - return fmt.Errorf("%s; cannot convert parameter 0 from %s to context.Context, cloudevents.Event or *cloudevents.EventResponse", inParamUsage, fnType.In(0)) - } else if r.hasEventIn { - return fmt.Errorf("%s; duplicate parameter of type cloudevents.Event", inParamUsage) - } else { - r.hasEventIn = true - } - } else if r.hasEventResponseIn { - return fmt.Errorf("%s; duplicate parameter of type *cloudevents.EventResponse", inParamUsage) - } else if r.hasEventIn { - return fmt.Errorf("%s; out of order parameter 0 for %s", inParamUsage, fnType.In(1)) - } else { - r.hasEventResponseIn = true - } - } else { - r.hasContextIn = true - } - fallthrough - case 0: - return nil - default: - return fmt.Errorf("%s; function has too many parameters (%d)", inParamUsage, fnType.NumIn()) - } -} - -// Verifies that the outputs of a function have a valid signature -// Valid output signatures: -// (), (error) -func (r *receiverFn) validateOutParamSignature(fnType reflect.Type) error { - r.hasErrorOut = false - switch fnType.NumOut() { - case 1: - paramNo := fnType.NumOut() - 1 - paramType := fnType.Out(paramNo) - if !paramType.ConvertibleTo(errorType) { - return fmt.Errorf("%s; cannot convert return type %d from %s to error", outParamUsage, paramNo, paramType) - } else { - r.hasErrorOut = true - } - fallthrough - case 0: - return nil - default: - return fmt.Errorf("%s; function has too many return types (%d)", outParamUsage, fnType.NumOut()) - } -} - -// validateReceiverFn validates that a function has the right number of in and -// out params and that they are of allowed types. -func (r *receiverFn) validate(fnType reflect.Type) error { - if err := r.validateInParamSignature(fnType); err != nil { - return err - } - if err := r.validateOutParamSignature(fnType); err != nil { - return err - } - return nil -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/content_type.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/content_type.go deleted file mode 100644 index e4e0e17f2b7..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/content_type.go +++ /dev/null @@ -1,35 +0,0 @@ -package cloudevents - -const ( - TextJSON = "text/json" - ApplicationJSON = "application/json" - ApplicationXML = "application/xml" - ApplicationCloudEventsJSON = "application/cloudevents+json" - ApplicationCloudEventsBatchJSON = "application/cloudevents-batch+json" -) - -// StringOfApplicationJSON returns a string pointer to "application/json" -func StringOfApplicationJSON() *string { - a := ApplicationJSON - return &a -} - -// StringOfApplicationXML returns a string pointer to "application/xml" -func StringOfApplicationXML() *string { - a := ApplicationXML - return &a -} - -// StringOfApplicationCloudEventsJSON returns a string pointer to -// "application/cloudevents+json" -func StringOfApplicationCloudEventsJSON() *string { - a := ApplicationCloudEventsJSON - return &a -} - -// StringOfApplicationCloudEventsBatchJSON returns a string pointer to -// "application/cloudevents-batch+json" -func StringOfApplicationCloudEventsBatchJSON() *string { - a := ApplicationCloudEventsBatchJSON - return &a -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/context/context.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/context/context.go deleted file mode 100644 index e580360f130..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/context/context.go +++ /dev/null @@ -1,76 +0,0 @@ -package context - -import ( - "context" - "net/url" - "strings" -) - -// Opaque key type used to store target -type targetKeyType struct{} - -var targetKey = targetKeyType{} - -// WithTarget returns back a new context with the given target. Target is intended to be transport dependent. -// For http transport, `target` should be a full URL and will be injected into the outbound http request. -func WithTarget(ctx context.Context, target string) context.Context { - return context.WithValue(ctx, targetKey, target) -} - -// TargetFrom looks in the given context and returns `target` as a parsed url if found and valid, otherwise nil. -func TargetFrom(ctx context.Context) *url.URL { - c := ctx.Value(targetKey) - if c != nil { - if s, ok := c.(string); ok && s != "" { - if target, err := url.Parse(s); err == nil { - return target - } - } - } - return nil -} - -// Opaque key type used to store topic -type topicKeyType struct{} - -var topicKey = topicKeyType{} - -// WithTopic returns back a new context with the given topic. Topic is intended to be transport dependent. -// For pubsub transport, `topic` should be a Pub/Sub Topic ID. -func WithTopic(ctx context.Context, topic string) context.Context { - return context.WithValue(ctx, topicKey, topic) -} - -// TopicFrom looks in the given context and returns `topic` as a string if found and valid, otherwise "". -func TopicFrom(ctx context.Context) string { - c := ctx.Value(topicKey) - if c != nil { - if s, ok := c.(string); ok { - return s - } - } - return "" -} - -// Opaque key type used to store encoding -type encodingKeyType struct{} - -var encodingKey = encodingKeyType{} - -// WithEncoding returns back a new context with the given encoding. Encoding is intended to be transport dependent. -// For http transport, `encoding` should be one of [binary, structured] and will be used to override the outbound -// codec encoding setting. If the transport does not understand the encoding, it will be ignored. -func WithEncoding(ctx context.Context, encoding string) context.Context { - return context.WithValue(ctx, encodingKey, strings.ToLower(encoding)) -} - -// EncodingFrom looks in the given context and returns `target` as a parsed url if found and valid, otherwise nil. -func EncodingFrom(ctx context.Context) string { - c := ctx.Value(encodingKey) - if c != nil { - if s, ok := c.(string); ok && s != "" { - return s - } - } - return "" -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/context/doc.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/context/doc.go deleted file mode 100644 index 377cab850fc..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/context/doc.go +++ /dev/null @@ -1,5 +0,0 @@ -/* -Package context holds the last resort overrides and fyi objects that can be passed to clients and transports added to -context.Context objects. -*/ -package context diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/context/logger.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/context/logger.go deleted file mode 100644 index 996f720572e..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/context/logger.go +++ /dev/null @@ -1,43 +0,0 @@ -package context - -import ( - "context" - - "go.uber.org/zap" -) - -// Opaque key type used to store logger -type loggerKeyType struct{} - -var loggerKey = loggerKeyType{} - -// fallbackLogger is the logger is used when there is no logger attached to the context. -var fallbackLogger *zap.SugaredLogger - -func init() { - if logger, err := zap.NewProduction(); err != nil { - // We failed to create a fallback logger. - fallbackLogger = zap.NewNop().Sugar() - } else { - fallbackLogger = logger.Named("fallback").Sugar() - } -} - -// WithLogger returns a new context with the logger injected into the given context. -func WithLogger(ctx context.Context, logger *zap.SugaredLogger) context.Context { - if logger == nil { - return context.WithValue(ctx, loggerKey, fallbackLogger) - } - return context.WithValue(ctx, loggerKey, logger) -} - -// LoggerFrom returns the logger stored in context. -func LoggerFrom(ctx context.Context) *zap.SugaredLogger { - l := ctx.Value(loggerKey) - if l != nil { - if logger, ok := l.(*zap.SugaredLogger); ok { - return logger - } - } - return fallbackLogger -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/data_content_encoding.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/data_content_encoding.go deleted file mode 100644 index 180102ee3fa..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/data_content_encoding.go +++ /dev/null @@ -1,11 +0,0 @@ -package cloudevents - -const ( - Base64 = "base64" -) - -// StringOfBase64 returns a string pointer to "Base64" -func StringOfBase64() *string { - a := Base64 - return &a -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/codec.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/codec.go deleted file mode 100644 index b9674889c62..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/codec.go +++ /dev/null @@ -1,96 +0,0 @@ -package datacodec - -import ( - "context" - "fmt" - - "github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/json" - "github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/text" - "github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/xml" - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" -) - -// Decoder is the expected function signature for decoding `in` to `out`. What -// `in` is could be decoder dependent. For example, `in` could be bytes, or a -// base64 string. -type Decoder func(ctx context.Context, in, out interface{}) error - -// Encoder is the expected function signature for encoding `in` to bytes. -// Returns an error if the encoder has an issue encoding `in`. -type Encoder func(ctx context.Context, in interface{}) ([]byte, error) - -var decoder map[string]Decoder -var encoder map[string]Encoder - -func init() { - decoder = make(map[string]Decoder, 10) - encoder = make(map[string]Encoder, 10) - - AddDecoder("", json.Decode) - AddDecoder("application/json", json.Decode) - AddDecoder("text/json", json.Decode) - AddDecoder("application/xml", xml.Decode) - AddDecoder("text/xml", xml.Decode) - AddDecoder("text/plain", text.Decode) - - AddEncoder("", json.Encode) - AddEncoder("application/json", json.Encode) - AddEncoder("text/json", json.Encode) - AddEncoder("application/xml", xml.Encode) - AddEncoder("text/xml", xml.Encode) - AddEncoder("text/plain", text.Encode) -} - -// AddDecoder registers a decoder for a given content type. The codecs will use -// these to decode the data payload from a cloudevent.Event object. -func AddDecoder(contentType string, fn Decoder) { - decoder[contentType] = fn -} - -// AddEncoder registers an encoder for a given content type. The codecs will -// use these to encode the data payload for a cloudevent.Event object. -func AddEncoder(contentType string, fn Encoder) { - encoder[contentType] = fn -} - -// Decode looks up and invokes the decoder registered for the given content -// type. An error is returned if no decoder is registered for the given -// content type. -func Decode(ctx context.Context, contentType string, in, out interface{}) error { - _, r := observability.NewReporter(ctx, reportDecode) - err := obsDecode(ctx, contentType, in, out) - if err != nil { - r.Error() - } else { - r.OK() - } - return err -} - -func obsDecode(ctx context.Context, contentType string, in, out interface{}) error { - if fn, ok := decoder[contentType]; ok { - return fn(ctx, in, out) - } - return fmt.Errorf("[decode] unsupported content type: %q", contentType) -} - -// Encode looks up and invokes the encoder registered for the given content -// type. An error is returned if no encoder is registered for the given -// content type. -func Encode(ctx context.Context, contentType string, in interface{}) ([]byte, error) { - _, r := observability.NewReporter(ctx, reportEncode) - b, err := obsEncode(ctx, contentType, in) - if err != nil { - r.Error() - } else { - r.OK() - } - return b, err -} - -func obsEncode(ctx context.Context, contentType string, in interface{}) ([]byte, error) { - if fn, ok := encoder[contentType]; ok { - return fn(ctx, in) - } - return nil, fmt.Errorf("[encode] unsupported content type: %q", contentType) -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/doc.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/doc.go deleted file mode 100644 index 9e401534e27..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/doc.go +++ /dev/null @@ -1,5 +0,0 @@ -/* -Package datacodec holds the data codec registry and adds known encoders and decoders supporting media types such as -`application/json` and `application/xml`. -*/ -package datacodec diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/json/data.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/json/data.go deleted file mode 100644 index 926c344fed0..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/json/data.go +++ /dev/null @@ -1,97 +0,0 @@ -package json - -import ( - "context" - "encoding/json" - "fmt" - "reflect" - "strconv" - - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" -) - -// Decode takes `in` as []byte, or base64 string, normalizes in to unquoted and -// base64 decoded []byte if required, and then attempts to use json.Unmarshal -// to convert those bytes to `out`. Returns and error if this process fails. -func Decode(ctx context.Context, in, out interface{}) error { - _, r := observability.NewReporter(ctx, reportDecode) - err := obsDecode(ctx, in, out) - if err != nil { - r.Error() - } else { - r.OK() - } - return err -} - -func obsDecode(ctx context.Context, in, out interface{}) error { - if in == nil { - return nil - } - if out == nil { - return fmt.Errorf("out is nil") - } - - b, ok := in.([]byte) // TODO: I think there is fancy marshaling happening here. Fix with reflection? - if !ok { - var err error - b, err = json.Marshal(in) - if err != nil { - return fmt.Errorf("[json] failed to marshal in: %s", err.Error()) - } - } - - // TODO: the spec says json could be just data... At the moment we expect wrapped. - if len(b) > 1 && (b[0] == byte('"') || (b[0] == byte('\\') && b[1] == byte('"'))) { - s, err := strconv.Unquote(string(b)) - if err != nil { - return fmt.Errorf("[json] failed to unquote in: %s", err.Error()) - } - if len(s) > 0 && (s[0] == '{' || s[0] == '[') { - // looks like json, use it - b = []byte(s) - } - } - - if err := json.Unmarshal(b, out); err != nil { - return fmt.Errorf("[json] found bytes \"%s\", but failed to unmarshal: %s", string(b), err.Error()) - } - return nil -} - -// Encode attempts to json.Marshal `in` into bytes. Encode will inspect `in` -// and returns `in` unmodified if it is detected that `in` is already a []byte; -// Or json.Marshal errors. -func Encode(ctx context.Context, in interface{}) ([]byte, error) { - _, r := observability.NewReporter(ctx, reportEncode) - b, err := obsEncode(ctx, in) - if err != nil { - r.Error() - } else { - r.OK() - } - return b, err -} - -func obsEncode(ctx context.Context, in interface{}) ([]byte, error) { - if in == nil { - return nil, nil - } - - it := reflect.TypeOf(in) - switch it.Kind() { - case reflect.Slice: - if it.Elem().Kind() == reflect.Uint8 { - - if b, ok := in.([]byte); ok && len(b) > 0 { - // check to see if it is a pre-encoded byte string. - if b[0] == byte('"') || b[0] == byte('{') || b[0] == byte('[') { - return b, nil - } - } - - } - } - - return json.Marshal(in) -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/json/doc.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/json/doc.go deleted file mode 100644 index 86772c2e339..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/json/doc.go +++ /dev/null @@ -1,4 +0,0 @@ -/* -Package json holds the encoder/decoder implementation for `application/json`. -*/ -package json diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/json/observability.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/json/observability.go deleted file mode 100644 index 1d5c3fee74a..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/json/observability.go +++ /dev/null @@ -1,51 +0,0 @@ -package json - -import ( - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" -) - -var ( - // LatencyMs measures the latency in milliseconds for the CloudEvents json - // data codec methods. - LatencyMs = stats.Float64("cloudevents.io/sdk-go/datacodec/json/latency", "The latency in milliseconds for the CloudEvents json data codec methods.", "ms") -) - -var ( - // LatencyView is an OpenCensus view that shows data codec json method latency. - LatencyView = &view.View{ - Name: "datacodec/json/latency", - Measure: LatencyMs, - Description: "The distribution of latency inside of the json data codec for CloudEvents.", - Aggregation: view.Distribution(0, .01, .1, 1, 10, 100, 1000, 10000), - TagKeys: observability.LatencyTags(), - } -) - -type observed int32 - -// Adheres to Observable -var _ observability.Observable = observed(0) - -const ( - reportEncode observed = iota - reportDecode -) - -// MethodName implements Observable.MethodName -func (o observed) MethodName() string { - switch o { - case reportEncode: - return "encode" - case reportDecode: - return "decode" - default: - return "unknown" - } -} - -// LatencyMs implements Observable.LatencyMs -func (o observed) LatencyMs() *stats.Float64Measure { - return LatencyMs -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/observability.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/observability.go deleted file mode 100644 index a8daf5ea60b..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/observability.go +++ /dev/null @@ -1,51 +0,0 @@ -package datacodec - -import ( - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" -) - -var ( - // LatencyMs measures the latency in milliseconds for the CloudEvents generic - // codec data methods. - LatencyMs = stats.Float64("cloudevents.io/sdk-go/datacodec/latency", "The latency in milliseconds for the CloudEvents generic data codec methods.", "ms") -) - -var ( - // LatencyView is an OpenCensus view that shows data codec method latency. - LatencyView = &view.View{ - Name: "datacodec/latency", - Measure: LatencyMs, - Description: "The distribution of latency inside of the generic data codec for CloudEvents.", - Aggregation: view.Distribution(0, .01, .1, 1, 10, 100, 1000, 10000), - TagKeys: observability.LatencyTags(), - } -) - -type observed int32 - -// Adheres to Observable -var _ observability.Observable = observed(0) - -const ( - reportEncode observed = iota - reportDecode -) - -// MethodName implements Observable.MethodName -func (o observed) MethodName() string { - switch o { - case reportEncode: - return "encode" - case reportDecode: - return "decode" - default: - return "unknown" - } -} - -// LatencyMs implements Observable.LatencyMs -func (o observed) LatencyMs() *stats.Float64Measure { - return LatencyMs -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/text/text.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/text/text.go deleted file mode 100644 index 3c37c5b13d1..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/text/text.go +++ /dev/null @@ -1,33 +0,0 @@ -// Text codec converts []byte or string to string and vice-versa. -package text - -import ( - "context" - "fmt" -) - -func Decode(_ context.Context, in, out interface{}) error { - p, _ := out.(*string) - if p == nil { - return fmt.Errorf("text.Decode out: want *string, got %T", out) - } - switch s := in.(type) { - case string: - *p = s - case []byte: - *p = string(s) - case nil: // treat nil like []byte{} - *p = "" - default: - return fmt.Errorf("text.Decode in: want []byte or string, got %T", in) - } - return nil -} - -func Encode(_ context.Context, in interface{}) ([]byte, error) { - s, ok := in.(string) - if !ok { - return nil, fmt.Errorf("text.Encode in: want string, got %T", in) - } - return []byte(s), nil -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/xml/data.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/xml/data.go deleted file mode 100644 index 6339e444337..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/xml/data.go +++ /dev/null @@ -1,90 +0,0 @@ -package xml - -import ( - "context" - "encoding/base64" - "encoding/xml" - "fmt" - "strconv" - - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" -) - -// Decode takes `in` as []byte, or base64 string, normalizes in to unquoted and -// base64 decoded []byte if required, and then attempts to use xml.Unmarshal -// to convert those bytes to `out`. Returns and error if this process fails. -func Decode(ctx context.Context, in, out interface{}) error { - _, r := observability.NewReporter(ctx, reportDecode) - err := obsDecode(ctx, in, out) - if err != nil { - r.Error() - } else { - r.OK() - } - return err -} - -func obsDecode(ctx context.Context, in, out interface{}) error { - if in == nil { - return nil - } - - b, ok := in.([]byte) - if !ok { - var err error - b, err = xml.Marshal(in) - if err != nil { - return fmt.Errorf("[xml] failed to marshal in: %s", err.Error()) - } - } - - // If the message is encoded as a base64 block as a string, we need to - // decode that first before trying to unmarshal the bytes - if len(b) > 1 && (b[0] == byte('"') || (b[0] == byte('\\') && b[1] == byte('"'))) { - s, err := strconv.Unquote(string(b)) - if err != nil { - return fmt.Errorf("[xml] failed to unquote quoted data: %s", err.Error()) - } - if len(s) > 0 && s[0] == '<' { - // looks like xml, use it - b = []byte(s) - } else if len(s) > 0 { - // looks like base64, decode - bs, err := base64.StdEncoding.DecodeString(s) - if err != nil { - return fmt.Errorf("[xml] failed to decode base64 encoded string: %s", err.Error()) - } - b = bs - } - } - - if err := xml.Unmarshal(b, out); err != nil { - return fmt.Errorf("[xml] found bytes, but failed to unmarshal: %s %s", err.Error(), string(b)) - } - return nil -} - -// Encode attempts to xml.Marshal `in` into bytes. Encode will inspect `in` -// and returns `in` unmodified if it is detected that `in` is already a []byte; -// Or xml.Marshal errors. -func Encode(ctx context.Context, in interface{}) ([]byte, error) { - _, r := observability.NewReporter(ctx, reportEncode) - b, err := obsEncode(ctx, in) - if err != nil { - r.Error() - } else { - r.OK() - } - return b, err -} - -func obsEncode(ctx context.Context, in interface{}) ([]byte, error) { - if b, ok := in.([]byte); ok { - // check to see if it is a pre-encoded byte string. - if len(b) > 0 && b[0] == byte('"') { - return b, nil - } - } - - return xml.Marshal(in) -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/xml/doc.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/xml/doc.go deleted file mode 100644 index d90b7c444da..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/xml/doc.go +++ /dev/null @@ -1,4 +0,0 @@ -/* -Package xml holds the encoder/decoder implementation for `application/xml`. -*/ -package xml diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/xml/observability.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/xml/observability.go deleted file mode 100644 index 32b3a5ff991..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/xml/observability.go +++ /dev/null @@ -1,51 +0,0 @@ -package xml - -import ( - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" -) - -var ( - // LatencyMs measures the latency in milliseconds for the CloudEvents xml data - // codec methods. - LatencyMs = stats.Float64("cloudevents.io/sdk-go/datacodec/xml/latency", "The latency in milliseconds for the CloudEvents xml data codec methods.", "ms") -) - -var ( - // LatencyView is an OpenCensus view that shows data codec xml method latency. - LatencyView = &view.View{ - Name: "datacodec/xml/latency", - Measure: LatencyMs, - Description: "The distribution of latency inside of the xml data codec for CloudEvents.", - Aggregation: view.Distribution(0, .01, .1, 1, 10, 100, 1000, 10000), - TagKeys: observability.LatencyTags(), - } -) - -type observed int32 - -// Adheres to Observable -var _ observability.Observable = observed(0) - -const ( - reportEncode observed = iota - reportDecode -) - -// MethodName implements Observable.MethodName -func (o observed) MethodName() string { - switch o { - case reportEncode: - return "encode" - case reportDecode: - return "decode" - default: - return "unknown" - } -} - -// LatencyMs implements Observable.LatencyMs -func (o observed) LatencyMs() *stats.Float64Measure { - return LatencyMs -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/doc.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/doc.go deleted file mode 100644 index cc2201da915..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/doc.go +++ /dev/null @@ -1,4 +0,0 @@ -/* -Package cloudevents provides primitives to work with CloudEvents specification: https://github.com/cloudevents/spec. -*/ -package cloudevents diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event.go deleted file mode 100644 index 2f605fd3c63..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event.go +++ /dev/null @@ -1,132 +0,0 @@ -package cloudevents - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" -) - -// Event represents the canonical representation of a CloudEvent. -type Event struct { - Context EventContext - Data interface{} - DataEncoded bool - DataBinary bool - FieldErrors map[string]error -} - -const ( - defaultEventVersion = CloudEventsVersionV1 -) - -func (e *Event) fieldError(field string, err error) { - if e.FieldErrors == nil { - e.FieldErrors = make(map[string]error, 0) - } - e.FieldErrors[field] = err -} - -func (e *Event) fieldOK(field string) { - if e.FieldErrors != nil { - delete(e.FieldErrors, field) - } -} - -// New returns a new Event, an optional version can be passed to change the -// default spec version from 1.0 to the provided version. -func New(version ...string) Event { - specVersion := defaultEventVersion // TODO: should there be a default? or set a default? - if len(version) >= 1 { - specVersion = version[0] - } - e := &Event{} - e.SetSpecVersion(specVersion) - return *e -} - -// DEPRECATED: Access extensions directly via the e.Extensions() map. -// Use functions in the types package to convert extension values. -// For example replace this: -// -// var i int -// err := e.ExtensionAs("foo", &i) -// -// With this: -// -// i, err := types.ToInteger(e.Extensions["foo"]) -// -func (e Event) ExtensionAs(name string, obj interface{}) error { - return e.Context.ExtensionAs(name, obj) -} - -// Validate performs a spec based validation on this event. -// Validation is dependent on the spec version specified in the event context. -func (e Event) Validate() error { - if e.Context == nil { - return fmt.Errorf("every event conforming to the CloudEvents specification MUST include a context") - } - - if e.FieldErrors != nil { - errs := make([]string, 0) - for f, e := range e.FieldErrors { - errs = append(errs, fmt.Sprintf("%q: %s,", f, e)) - } - if len(errs) > 0 { - return fmt.Errorf("previous field errors: [%s]", strings.Join(errs, "\n")) - } - } - - if err := e.Context.Validate(); err != nil { - return err - } - - // TODO: validate data. - - return nil -} - -// String returns a pretty-printed representation of the Event. -func (e Event) String() string { - b := strings.Builder{} - - b.WriteString("Validation: ") - - valid := e.Validate() - if valid == nil { - b.WriteString("valid\n") - } else { - b.WriteString("invalid\n") - } - if valid != nil { - b.WriteString(fmt.Sprintf("Validation Error: \n%s\n", valid.Error())) - } - - b.WriteString(e.Context.String()) - - if e.Data != nil { - b.WriteString("Data,\n ") - if strings.HasPrefix(e.DataContentType(), ApplicationJSON) { - var prettyJSON bytes.Buffer - - data, ok := e.Data.([]byte) - if !ok { - var err error - data, err = json.Marshal(e.Data) - if err != nil { - data = []byte(err.Error()) - } - } - err := json.Indent(&prettyJSON, data, " ", " ") - if err != nil { - b.Write(e.Data.([]byte)) - } else { - b.Write(prettyJSON.Bytes()) - } - } else { - b.Write(e.Data.([]byte)) - } - b.WriteString("\n") - } - return b.String() -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_data.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_data.go deleted file mode 100644 index 26ce70ea33d..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_data.go +++ /dev/null @@ -1,135 +0,0 @@ -package cloudevents - -import ( - "context" - "encoding/base64" - "errors" - "fmt" - "strconv" - - "github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec" -) - -// Data is special. Break it out into it's own file. - -// SetData implements EventWriter.SetData -func (e *Event) SetData(obj interface{}) error { - if e.SpecVersion() != CloudEventsVersionV1 { - return e.legacySetData(obj) - } - - // Version 1.0 and above. - - // TODO: we will have to be smarter about how data relates to media type. - // but the issue is we can not just encode data anymore without understanding - // what the encoding will be on the outbound event. Structured will use - // data_base64, binary will not (if the transport supports binary mode). - - // TODO: look at content encoding too. - - switch obj.(type) { - case []byte: - e.Data = obj - e.DataEncoded = true - e.DataBinary = true - default: - data, err := datacodec.Encode(context.Background(), e.DataMediaType(), obj) - if err != nil { - return err - } - e.Data = data - e.DataEncoded = true - e.DataBinary = false - } - - return nil -} - -func (e *Event) legacySetData(obj interface{}) error { - data, err := datacodec.Encode(context.Background(), e.DataMediaType(), obj) - if err != nil { - return err - } - if e.DeprecatedDataContentEncoding() == Base64 { - buf := make([]byte, base64.StdEncoding.EncodedLen(len(data))) - base64.StdEncoding.Encode(buf, data) - e.Data = string(buf) - } else { - e.Data = data - } - e.DataEncoded = true - return nil -} - -func (e *Event) DataBytes() ([]byte, error) { - if !e.DataEncoded { - if err := e.SetData(e.Data); err != nil { - return nil, err - } - } - - b, ok := e.Data.([]byte) - if !ok { - if s, ok := e.Data.(string); ok { - b = []byte(s) - } else { - // No data. - return []byte(nil), nil - } - } - return b, nil -} - -const ( - quotes = `"'` -) - -// DataAs attempts to populate the provided data object with the event payload. -// data should be a pointer type. -func (e Event) DataAs(data interface{}) error { // TODO: Clean this function up - if e.Data == nil { - return nil - } - obj, ok := e.Data.([]byte) - if !ok { - if s, ok := e.Data.(string); ok { - obj = []byte(s) - } else { - return errors.New("data was not a byte slice or string") - } - } - if len(obj) == 0 { - // No data. - return nil - } - if e.Context.DeprecatedGetDataContentEncoding() == Base64 { - var bs []byte - // test to see if we need to unquote the data. - if obj[0] == quotes[0] || obj[0] == quotes[1] { - str, err := strconv.Unquote(string(obj)) - if err != nil { - return err - } - bs = []byte(str) - } else { - bs = obj - } - - buf := make([]byte, base64.StdEncoding.DecodedLen(len(bs))) - n, err := base64.StdEncoding.Decode(buf, bs) - if err != nil { - return fmt.Errorf("failed to decode data from base64: %s", err.Error()) - } - obj = buf[:n] - } - - mediaType := "" - if e.Context.GetDataContentType() != "" { - var err error - mediaType, err = e.Context.GetDataMediaType() - if err != nil { - return err - } - } - return datacodec.Decode(context.Background(), mediaType, obj, data) -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_interface.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_interface.go deleted file mode 100644 index 37bb82ab5af..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_interface.go +++ /dev/null @@ -1,79 +0,0 @@ -package cloudevents - -import ( - "time" -) - -// EventWriter is the interface for reading through an event from attributes. -type EventReader interface { - // SpecVersion returns event.Context.GetSpecVersion(). - SpecVersion() string - // Type returns event.Context.GetType(). - Type() string - // Source returns event.Context.GetSource(). - Source() string - // Subject returns event.Context.GetSubject(). - Subject() string - // ID returns event.Context.GetID(). - ID() string - // Time returns event.Context.GetTime(). - Time() time.Time - // DataSchema returns event.Context.GetDataSchema(). - DataSchema() string - // DataContentType returns event.Context.GetDataContentType(). - DataContentType() string - // DataMediaType returns event.Context.GetDataMediaType(). - DataMediaType() string - // DeprecatedDataContentEncoding returns event.Context.DeprecatedGetDataContentEncoding(). - DeprecatedDataContentEncoding() string - - // Extension Attributes - - // Extensions returns the event.Context.GetExtensions(). - // Extensions use the CloudEvents type system, details in package cloudevents/types. - Extensions() map[string]interface{} - - // DEPRECATED: see event.Context.ExtensionAs - // ExtensionAs returns event.Context.ExtensionAs(name, obj). - ExtensionAs(string, interface{}) error - - // Data Attribute - - // DataAs attempts to populate the provided data object with the event payload. - // data should be a pointer type. - DataAs(interface{}) error -} - -// EventWriter is the interface for writing through an event onto attributes. -// If an error is thrown by a sub-component, EventWriter caches the error -// internally and exposes errors with a call to event.Validate(). -type EventWriter interface { - // Context Attributes - - // SetSpecVersion performs event.Context.SetSpecVersion. - SetSpecVersion(string) - // SetType performs event.Context.SetType. - SetType(string) - // SetSource performs event.Context.SetSource. - SetSource(string) - // SetSubject( performs event.Context.SetSubject. - SetSubject(string) - // SetID performs event.Context.SetID. - SetID(string) - // SetTime performs event.Context.SetTime. - SetTime(time.Time) - // SetDataSchema performs event.Context.SetDataSchema. - SetDataSchema(string) - // SetDataContentType performs event.Context.SetDataContentType. - SetDataContentType(string) - // DeprecatedSetDataContentEncoding performs event.Context.DeprecatedSetDataContentEncoding. - SetDataContentEncoding(string) - - // Extension Attributes - - // SetExtension performs event.Context.SetExtension. - SetExtension(string, interface{}) - - // SetData encodes the given payload with the current encoding settings. - SetData(interface{}) error -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_marshal.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_marshal.go deleted file mode 100644 index 49a8de2cab6..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_marshal.go +++ /dev/null @@ -1,394 +0,0 @@ -package cloudevents - -import ( - "context" - "encoding/base64" - "encoding/json" - "errors" - "fmt" - "strconv" - "strings" - - errors2 "github.com/pkg/errors" - - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" -) - -// MarshalJSON implements a custom json marshal method used when this type is -// marshaled using json.Marshal. -func (e Event) MarshalJSON() ([]byte, error) { - _, r := observability.NewReporter(context.Background(), eventJSONObserved{o: reportMarshal, v: e.SpecVersion()}) - - if err := e.Validate(); err != nil { - r.Error() - return nil, err - } - - var b []byte - var err error - - switch e.SpecVersion() { - case CloudEventsVersionV01, CloudEventsVersionV02, CloudEventsVersionV03: - b, err = JsonEncodeLegacy(e) - case CloudEventsVersionV1: - b, err = JsonEncode(e) - default: - return nil, fmt.Errorf("unnknown spec version: %q", e.SpecVersion()) - } - - // Report the observable - if err != nil { - r.Error() - return nil, err - } else { - r.OK() - } - - return b, nil -} - -// UnmarshalJSON implements the json unmarshal method used when this type is -// unmarshaled using json.Unmarshal. -func (e *Event) UnmarshalJSON(b []byte) error { - raw := make(map[string]json.RawMessage) - if err := json.Unmarshal(b, &raw); err != nil { - return err - } - - version := versionFromRawMessage(raw) - - _, r := observability.NewReporter(context.Background(), eventJSONObserved{o: reportUnmarshal, v: version}) - - var err error - switch version { - case CloudEventsVersionV01: - err = e.JsonDecodeV01(b, raw) - case CloudEventsVersionV02: - err = e.JsonDecodeV02(b, raw) - case CloudEventsVersionV03: - err = e.JsonDecodeV03(b, raw) - case CloudEventsVersionV1: - err = e.JsonDecodeV1(b, raw) - default: - return fmt.Errorf("unnknown spec version: %q", version) - } - - // Report the observable - if err != nil { - r.Error() - return err - } else { - r.OK() - } - return nil -} - -func versionFromRawMessage(raw map[string]json.RawMessage) string { - // v0.1 - if v, ok := raw["cloudEventsVersion"]; ok { - var version string - if err := json.Unmarshal(v, &version); err != nil { - return "" - } - return version - } - - // v0.2 and after - if v, ok := raw["specversion"]; ok { - var version string - if err := json.Unmarshal(v, &version); err != nil { - return "" - } - return version - } - return "" -} - -// JsonEncode -func JsonEncode(e Event) ([]byte, error) { - data, err := e.DataBytes() - if err != nil { - return nil, err - } - return jsonEncode(e.Context, data, e.DataBinary) -} - -// JsonEncodeLegacy -func JsonEncodeLegacy(e Event) ([]byte, error) { - var data []byte - isBase64 := e.Context.DeprecatedGetDataContentEncoding() == Base64 - var err error - data, err = e.DataBytes() - if err != nil { - return nil, err - } - return jsonEncode(e.Context, data, isBase64) -} - -func jsonEncode(ctx EventContextReader, data []byte, isBase64 bool) ([]byte, error) { - var b map[string]json.RawMessage - var err error - - if ctx.GetSpecVersion() == CloudEventsVersionV01 { - b, err = marshalEventLegacy(ctx) - } else { - b, err = marshalEvent(ctx, ctx.GetExtensions()) - } - if err != nil { - return nil, err - } - - if data != nil { - // data is passed in as an encoded []byte. That slice might be any - // number of things but for json encoding of the envelope all we care - // is if the payload is either a string or a json object. If it is a - // json object, it can be inserted into the body without modification. - // Otherwise we need to quote it if not already quoted. - mediaType, err := ctx.GetDataMediaType() - if err != nil { - return nil, err - } - isJson := mediaType == "" || mediaType == ApplicationJSON || mediaType == TextJSON - // TODO(#60): we do not support json values at the moment, only objects and lists. - if isJson && !isBase64 { - b["data"] = data - } else { - var dataKey string - if ctx.GetSpecVersion() == CloudEventsVersionV1 { - dataKey = "data_base64" - buf := make([]byte, base64.StdEncoding.EncodedLen(len(data))) - base64.StdEncoding.Encode(buf, data) - data = buf - } else { - dataKey = "data" - } - if data[0] != byte('"') { - b[dataKey] = []byte(strconv.QuoteToASCII(string(data))) - } else { - // already quoted - b[dataKey] = data - } - } - } - - body, err := json.Marshal(b) - if err != nil { - return nil, err - } - - return body, nil -} - -// JsonDecodeV01 takes in the byte representation of a version 0.1 structured json CloudEvent and returns a -// cloudevent.Event or an error if there are parsing errors. -func (e *Event) JsonDecodeV01(body []byte, raw map[string]json.RawMessage) error { - ec := EventContextV01{} - if err := json.Unmarshal(body, &ec); err != nil { - return err - } - - var data interface{} - if d, ok := raw["data"]; ok { - data = []byte(d) - } - - e.Context = &ec - e.Data = data - e.DataEncoded = data != nil - - return nil -} - -// JsonDecodeV02 takes in the byte representation of a version 0.2 structured json CloudEvent and returns a -// cloudevent.Event or an error if there are parsing errors. -func (e *Event) JsonDecodeV02(body []byte, raw map[string]json.RawMessage) error { - ec := EventContextV02{} - if err := json.Unmarshal(body, &ec); err != nil { - return err - } - - // TODO: could use reflection to get these. - delete(raw, "specversion") - delete(raw, "type") - delete(raw, "source") - delete(raw, "id") - delete(raw, "time") - delete(raw, "schemaurl") - delete(raw, "contenttype") - - var data interface{} - if d, ok := raw["data"]; ok { - data = []byte(d) - } - delete(raw, "data") - - if len(raw) > 0 { - extensions := make(map[string]interface{}, len(raw)) - ec.Extensions = extensions - for k, v := range raw { - k = strings.ToLower(k) - var tmp interface{} - if err := json.Unmarshal(v, &tmp); err != nil { - return err - } - if err := ec.SetExtension(k, tmp); err != nil { - return errors2.Wrap(err, "Cannot set extension with key "+k) - } - } - } - - e.Context = &ec - e.Data = data - e.DataEncoded = data != nil - - return nil -} - -// JsonDecodeV03 takes in the byte representation of a version 0.3 structured json CloudEvent and returns a -// cloudevent.Event or an error if there are parsing errors. -func (e *Event) JsonDecodeV03(body []byte, raw map[string]json.RawMessage) error { - ec := EventContextV03{} - if err := json.Unmarshal(body, &ec); err != nil { - return err - } - - // TODO: could use reflection to get these. - delete(raw, "specversion") - delete(raw, "type") - delete(raw, "source") - delete(raw, "subject") - delete(raw, "id") - delete(raw, "time") - delete(raw, "schemaurl") - delete(raw, "datacontenttype") - delete(raw, "datacontentencoding") - - var data interface{} - if d, ok := raw["data"]; ok { - data = []byte(d) - } - delete(raw, "data") - - if len(raw) > 0 { - extensions := make(map[string]interface{}, len(raw)) - ec.Extensions = extensions - for k, v := range raw { - k = strings.ToLower(k) - var tmp interface{} - if err := json.Unmarshal(v, &tmp); err != nil { - return err - } - if err := ec.SetExtension(k, tmp); err != nil { - return errors2.Wrap(err, "Cannot set extension with key "+k) - } - } - } - - e.Context = &ec - e.Data = data - e.DataEncoded = data != nil - - return nil -} - -// JsonDecodeV1 takes in the byte representation of a version 1.0 structured json CloudEvent and returns a -// cloudevent.Event or an error if there are parsing errors. -func (e *Event) JsonDecodeV1(body []byte, raw map[string]json.RawMessage) error { - ec := EventContextV1{} - if err := json.Unmarshal(body, &ec); err != nil { - return err - } - - delete(raw, "specversion") - delete(raw, "type") - delete(raw, "source") - delete(raw, "subject") - delete(raw, "id") - delete(raw, "time") - delete(raw, "dataschema") - delete(raw, "datacontenttype") - - var data interface{} - if d, ok := raw["data"]; ok { - data = []byte(d) - } - delete(raw, "data") - - var dataBase64 []byte - if d, ok := raw["data_base64"]; ok { - var tmp []byte - if err := json.Unmarshal(d, &tmp); err != nil { - return err - } - dataBase64 = tmp - } - delete(raw, "data_base64") - - if len(raw) > 0 { - extensions := make(map[string]interface{}, len(raw)) - ec.Extensions = extensions - for k, v := range raw { - k = strings.ToLower(k) - var tmp interface{} - if err := json.Unmarshal(v, &tmp); err != nil { - return err - } - if err := ec.SetExtension(k, tmp); err != nil { - return errors2.Wrap(err, "Cannot set extension with key "+k) - } - } - } - - e.Context = &ec - if data != nil && dataBase64 != nil { - return errors.New("parsing error: JSON decoder found both 'data', and 'data_base64' in JSON payload") - } - if data != nil { - e.Data = data - } else if dataBase64 != nil { - e.Data = dataBase64 - } - e.DataEncoded = data != nil - - return nil -} - -func marshalEventLegacy(event interface{}) (map[string]json.RawMessage, error) { - b, err := json.Marshal(event) - if err != nil { - return nil, err - } - - brm := map[string]json.RawMessage{} - if err := json.Unmarshal(b, &brm); err != nil { - return nil, err - } - - return brm, nil -} - -func marshalEvent(event interface{}, extensions map[string]interface{}) (map[string]json.RawMessage, error) { - b, err := json.Marshal(event) - if err != nil { - return nil, err - } - - brm := map[string]json.RawMessage{} - if err := json.Unmarshal(b, &brm); err != nil { - return nil, err - } - - for k, v := range extensions { - k = strings.ToLower(k) - vb, err := json.Marshal(v) - if err != nil { - return nil, err - } - // Don't overwrite spec keys. - if _, ok := brm[k]; !ok { - brm[k] = vb - } - } - - return brm, nil -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_observability.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_observability.go deleted file mode 100644 index bf1c5c5d7cb..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_observability.go +++ /dev/null @@ -1,77 +0,0 @@ -package cloudevents - -import ( - "fmt" - - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" -) - -var ( - // EventMarshalLatencyMs measures the latency in milliseconds for the - // CloudEvents.Event marshal/unmarshalJSON methods. - EventMarshalLatencyMs = stats.Float64( - "cloudevents.io/sdk-go/event/json/latency", - "The latency in milliseconds of (un)marshalJSON methods for CloudEvents.Event.", - "ms") -) - -var ( - // LatencyView is an OpenCensus view that shows CloudEvents.Event (un)marshalJSON method latency. - EventMarshalLatencyView = &view.View{ - Name: "event/json/latency", - Measure: EventMarshalLatencyMs, - Description: "The distribution of latency inside of (un)marshalJSON methods for CloudEvents.Event.", - Aggregation: view.Distribution(0, .01, .1, 1, 10, 100, 1000, 10000), - TagKeys: observability.LatencyTags(), - } -) - -type observed int32 - -// Adheres to Observable -var _ observability.Observable = observed(0) - -const ( - reportMarshal observed = iota - reportUnmarshal -) - -// MethodName implements Observable.MethodName -func (o observed) MethodName() string { - switch o { - case reportMarshal: - return "marshaljson" - case reportUnmarshal: - return "unmarshaljson" - default: - return "unknown" - } -} - -// LatencyMs implements Observable.LatencyMs -func (o observed) LatencyMs() *stats.Float64Measure { - return EventMarshalLatencyMs -} - -// eventJSONObserved is a wrapper to append version to observed. -type eventJSONObserved struct { - // Method - o observed - // Version - v string -} - -// Adheres to Observable -var _ observability.Observable = (*eventJSONObserved)(nil) - -// MethodName implements Observable.MethodName -func (c eventJSONObserved) MethodName() string { - return fmt.Sprintf("%s/%s", c.o.MethodName(), c.v) -} - -// LatencyMs implements Observable.LatencyMs -func (c eventJSONObserved) LatencyMs() *stats.Float64Measure { - return c.o.LatencyMs() -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_reader.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_reader.go deleted file mode 100644 index fe49e8424dc..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_reader.go +++ /dev/null @@ -1,98 +0,0 @@ -package cloudevents - -import ( - "time" -) - -var _ EventReader = (*Event)(nil) - -// SpecVersion implements EventReader.SpecVersion -func (e Event) SpecVersion() string { - if e.Context != nil { - return e.Context.GetSpecVersion() - } - return "" -} - -// Type implements EventReader.Type -func (e Event) Type() string { - if e.Context != nil { - return e.Context.GetType() - } - return "" -} - -// Source implements EventReader.Source -func (e Event) Source() string { - if e.Context != nil { - return e.Context.GetSource() - } - return "" -} - -// Subject implements EventReader.Subject -func (e Event) Subject() string { - if e.Context != nil { - return e.Context.GetSubject() - } - return "" -} - -// ID implements EventReader.ID -func (e Event) ID() string { - if e.Context != nil { - return e.Context.GetID() - } - return "" -} - -// Time implements EventReader.Time -func (e Event) Time() time.Time { - if e.Context != nil { - return e.Context.GetTime() - } - return time.Time{} -} - -// DataSchema implements EventReader.DataSchema -func (e Event) DataSchema() string { - if e.Context != nil { - return e.Context.GetDataSchema() - } - return "" -} - -// DataContentType implements EventReader.DataContentType -func (e Event) DataContentType() string { - if e.Context != nil { - return e.Context.GetDataContentType() - } - return "" -} - -// DataMediaType returns the parsed DataMediaType of the event. If parsing -// fails, the empty string is returned. To retrieve the parsing error, use -// `Context.GetDataMediaType` instead. -func (e Event) DataMediaType() string { - if e.Context != nil { - mediaType, _ := e.Context.GetDataMediaType() - return mediaType - } - return "" -} - -// DeprecatedDataContentEncoding implements EventReader.DeprecatedDataContentEncoding -func (e Event) DeprecatedDataContentEncoding() string { - if e.Context != nil { - return e.Context.DeprecatedGetDataContentEncoding() - } - return "" -} - -// Extensions implements EventReader.Extensions -func (e Event) Extensions() map[string]interface{} { - if e.Context != nil { - return e.Context.GetExtensions() - } - return map[string]interface{}(nil) -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_response.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_response.go deleted file mode 100644 index 0e5f7ce75d4..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_response.go +++ /dev/null @@ -1,37 +0,0 @@ -package cloudevents - -// EventResponse represents the canonical representation of a Response to a -// CloudEvent from a receiver. Response implementation is Transport dependent. -type EventResponse struct { - Status int - Event *Event - Reason string - // Context is transport specific struct to allow for controlling transport - // response details. - // For example, see http.TransportResponseContext. - Context interface{} -} - -// RespondWith sets up the instance of EventResponse to be set with status and -// an event. Response implementation is Transport dependent. -func (e *EventResponse) RespondWith(status int, event *Event) { - if e == nil { - // if nil, response not supported - return - } - e.Status = status - if event != nil { - e.Event = event - } -} - -// Error sets the instance of EventResponse to be set with an error code and -// reason string. Response implementation is Transport dependent. -func (e *EventResponse) Error(status int, reason string) { - if e == nil { - // if nil, response not supported - return - } - e.Status = status - e.Reason = reason -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_writer.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_writer.go deleted file mode 100644 index 19982ca5b3e..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/event_writer.go +++ /dev/null @@ -1,116 +0,0 @@ -package cloudevents - -import ( - "fmt" - "time" -) - -var _ EventWriter = (*Event)(nil) - -// SetSpecVersion implements EventWriter.SetSpecVersion -func (e *Event) SetSpecVersion(v string) { - if e.Context == nil { - switch v { - case CloudEventsVersionV01: - e.Context = EventContextV01{}.AsV01() - case CloudEventsVersionV02: - e.Context = EventContextV02{}.AsV02() - 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, %s, %s]", - CloudEventsVersionV01, CloudEventsVersionV02, CloudEventsVersionV03, CloudEventsVersionV1)) - return - } - e.fieldOK("specversion") - return - } - if err := e.Context.SetSpecVersion(v); err != nil { - e.fieldError("specversion", err) - } else { - e.fieldOK("specversion") - } -} - -// SetType implements EventWriter.SetType -func (e *Event) SetType(t string) { - if err := e.Context.SetType(t); err != nil { - e.fieldError("type", err) - } else { - e.fieldOK("type") - } -} - -// SetSource implements EventWriter.SetSource -func (e *Event) SetSource(s string) { - if err := e.Context.SetSource(s); err != nil { - e.fieldError("source", err) - } else { - e.fieldOK("source") - } -} - -// SetSubject implements EventWriter.SetSubject -func (e *Event) SetSubject(s string) { - if err := e.Context.SetSubject(s); err != nil { - e.fieldError("subject", err) - } else { - e.fieldOK("subject") - } -} - -// SetID implements EventWriter.SetID -func (e *Event) SetID(id string) { - if err := e.Context.SetID(id); err != nil { - e.fieldError("id", err) - } else { - e.fieldOK("id") - } -} - -// SetTime implements EventWriter.SetTime -func (e *Event) SetTime(t time.Time) { - if err := e.Context.SetTime(t); err != nil { - e.fieldError("time", err) - } else { - e.fieldOK("time") - } -} - -// SetDataSchema implements EventWriter.SetDataSchema -func (e *Event) SetDataSchema(s string) { - if err := e.Context.SetDataSchema(s); err != nil { - e.fieldError("dataschema", err) - } else { - e.fieldOK("dataschema") - } -} - -// SetDataContentType implements EventWriter.SetDataContentType -func (e *Event) SetDataContentType(ct string) { - if err := e.Context.SetDataContentType(ct); err != nil { - e.fieldError("datacontenttype", err) - } else { - e.fieldOK("datacontenttype") - } -} - -// DeprecatedSetDataContentEncoding implements EventWriter.DeprecatedSetDataContentEncoding -func (e *Event) SetDataContentEncoding(enc string) { - if err := e.Context.DeprecatedSetDataContentEncoding(enc); err != nil { - e.fieldError("datacontentencoding", err) - } else { - e.fieldOK("datacontentencoding") - } -} - -// SetExtension implements EventWriter.SetExtension -func (e *Event) SetExtension(name string, obj interface{}) { - if err := e.Context.SetExtension(name, obj); err != nil { - e.fieldError("extension:"+name, err) - } else { - e.fieldOK("extension:" + name) - } -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext.go deleted file mode 100644 index 5683a82929d..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext.go +++ /dev/null @@ -1,132 +0,0 @@ -package cloudevents - -import "time" - -// EventContextReader are the methods required to be a reader of context -// attributes. -type EventContextReader interface { - // GetSpecVersion returns the native CloudEvents Spec version of the event - // context. - GetSpecVersion() string - // GetType returns the CloudEvents type from the context. - GetType() string - // GetSource returns the CloudEvents source from the context. - GetSource() string - // GetSubject returns the CloudEvents subject from the context. - GetSubject() string - // GetID returns the CloudEvents ID from the context. - GetID() string - // GetTime returns the CloudEvents creation time from the context. - GetTime() time.Time - // GetDataSchema returns the CloudEvents schema URL (if any) from the - // context. - GetDataSchema() string - // GetDataContentType returns content type on the context. - GetDataContentType() string - // DeprecatedGetDataContentEncoding returns content encoding on the context. - DeprecatedGetDataContentEncoding() string - - // GetDataMediaType returns the MIME media type for encoded data, which is - // needed by both encoding and decoding. This is a processed form of - // GetDataContentType and it may return an error. - GetDataMediaType() (string, error) - - // DEPRECATED: Access extensions directly via the GetExtensions() - // For example replace this: - // - // var i int - // err := ec.ExtensionAs("foo", &i) - // - // With this: - // - // i, err := types.ToInteger(ec.GetExtensions["foo"]) - // - ExtensionAs(string, interface{}) error - - // GetExtensions returns the full extensions map. - // - // Extensions use the CloudEvents type system, details in package cloudevents/types. - GetExtensions() map[string]interface{} - - // GetExtension returns the extension associated with with the given key. - // The given key is case insensitive. If the extension can not be found, - // an error will be returned. - GetExtension(string) (interface{}, error) -} - -// 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. - SetSource(string) error - // SetSubject sets the subject of the context. - SetSubject(string) error - // SetID sets the ID of the context. - SetID(string) error - // SetTime sets the time of the context. - SetTime(time time.Time) error - // SetDataSchema sets the schema url of the context. - SetDataSchema(string) error - // SetDataContentType sets the data content type of the context. - SetDataContentType(string) error - // DeprecatedSetDataContentEncoding sets the data context encoding of the context. - DeprecatedSetDataContentEncoding(string) error - - // SetExtension sets the given interface onto the extension attributes - // determined by the provided name. - // - // This function fails in V1 if the name doesn't respect the regex ^[a-zA-Z0-9]+$ - // - // Package ./types documents the types that are allowed as extension values. - SetExtension(string, interface{}) error -} - -// EventContextConverter are the methods that allow for event version -// conversion. -type EventContextConverter interface { - // AsV01 provides a translation from whatever the "native" encoding of the - // CloudEvent was to the equivalent in v0.1 field names, moving fields to or - // from extensions as necessary. - AsV01() *EventContextV01 - - // AsV02 provides a translation from whatever the "native" encoding of the - // CloudEvent was to the equivalent in v0.2 field names, moving fields to or - // from extensions as necessary. - AsV02() *EventContextV02 - - // AsV03 provides a translation from whatever the "native" encoding of the - // CloudEvent was to the equivalent in v0.3 field names, moving fields to or - // from extensions as necessary. - AsV03() *EventContextV03 - - // AsV1 provides a translation from whatever the "native" encoding of the - // CloudEvent was to the equivalent in v1.0 field names, moving fields to or - // from extensions as necessary. - AsV1() *EventContextV1 -} - -// EventContext is conical interface for a CloudEvents Context. -type EventContext interface { - // EventContextConverter allows for conversion between versions. - EventContextConverter - - // EventContextReader adds methods for reading context. - EventContextReader - - // EventContextWriter adds methods for writing to context. - EventContextWriter - - // Validate the event based on the specifics of the CloudEvents spec version - // represented by this event context. - Validate() error - - // Clone clones the event context. - Clone() EventContext - - // String returns a pretty-printed representation of the EventContext. - String() string -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v01.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v01.go deleted file mode 100644 index f48459cdf51..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v01.go +++ /dev/null @@ -1,286 +0,0 @@ -package cloudevents - -import ( - "fmt" - "sort" - "strings" - - "github.com/cloudevents/sdk-go/pkg/cloudevents/types" -) - -const ( - // CloudEventsVersionV01 represents the version 0.1 of the CloudEvents spec. - CloudEventsVersionV01 = "0.1" -) - -// EventContextV01 holds standard metadata about an event. See -// https://github.com/cloudevents/spec/blob/v0.1/spec.md#context-attributes for -// details on these fields. -type EventContextV01 struct { - // The version of the CloudEvents specification used by the event. - CloudEventsVersion string `json:"cloudEventsVersion,omitempty"` - // ID of the event; must be non-empty and unique within the scope of the producer. - EventID string `json:"eventID"` - // Timestamp when the event happened. - EventTime *types.Timestamp `json:"eventTime,omitempty"` - // Type of occurrence which has happened. - EventType string `json:"eventType"` - // The version of the `eventType`; this is producer-specific. - EventTypeVersion *string `json:"eventTypeVersion,omitempty"` - // A link to the schema that the `data` attribute adheres to. - SchemaURL *types.URLRef `json:"schemaURL,omitempty"` - // A MIME (RFC 2046) string describing the media type of `data`. - // TODO: Should an empty string assume `application/json`, or auto-detect the content? - ContentType *string `json:"contentType,omitempty"` - // A URI describing the event producer. - Source types.URLRef `json:"source"` - // Additional metadata without a well-defined structure. - Extensions map[string]interface{} `json:"extensions,omitempty"` -} - -// Adhere to EventContext -var _ EventContext = (*EventContextV01)(nil) - -// ExtensionAs implements EventContextReader.ExtensionAs -func (ec EventContextV01) ExtensionAs(name string, obj interface{}) error { - value, ok := ec.Extensions[name] - if !ok { - return fmt.Errorf("extension %q does not exist", name) - } - // Only support *string for now. - switch v := obj.(type) { - case *string: - if valueAsString, ok := value.(string); ok { - *v = valueAsString - return nil - } else { - return fmt.Errorf("invalid type for extension %q", name) - } - default: - return fmt.Errorf("unknown extension type %T", obj) - } -} - -// SetExtension adds the extension 'name' with value 'value' to the CloudEvents context. -func (ec *EventContextV01) SetExtension(name string, value interface{}) error { - if ec.Extensions == nil { - ec.Extensions = make(map[string]interface{}) - } - if value == nil { - delete(ec.Extensions, name) - } else { - ec.Extensions[name] = value - } - return nil -} - -// Clone implements EventContextConverter.Clone -func (ec EventContextV01) Clone() EventContext { - ev01 := ec.AsV01() - ev01.Extensions = ev01.cloneExtensions() - return ev01 -} - -func (ec *EventContextV01) cloneExtensions() map[string]interface{} { - old := ec.Extensions - if old == nil { - return nil - } - new := make(map[string]interface{}, len(ec.Extensions)) - for k, v := range old { - new[k] = v - } - return new -} - -// AsV01 implements EventContextConverter.AsV01 -func (ec EventContextV01) AsV01() *EventContextV01 { - ec.CloudEventsVersion = CloudEventsVersionV01 - return &ec -} - -// AsV02 implements EventContextConverter.AsV02 -func (ec EventContextV01) AsV02() *EventContextV02 { - ret := EventContextV02{ - SpecVersion: CloudEventsVersionV02, - Type: ec.EventType, - Source: ec.Source, - ID: ec.EventID, - Time: ec.EventTime, - SchemaURL: ec.SchemaURL, - ContentType: ec.ContentType, - Extensions: make(map[string]interface{}), - } - - // eventTypeVersion was retired in v0.2, so put it in an extension. - if ec.EventTypeVersion != nil { - _ = ret.SetExtension(EventTypeVersionKey, *ec.EventTypeVersion) - } - if ec.Extensions != nil { - for k, v := range ec.Extensions { - ret.Extensions[k] = v - } - } - if len(ret.Extensions) == 0 { - ret.Extensions = nil - } - return &ret -} - -// AsV03 implements EventContextConverter.AsV03 -func (ec EventContextV01) AsV03() *EventContextV03 { - return ec.AsV02().AsV03() -} - -// AsV1 implements EventContextConverter.AsV1 -func (ec EventContextV01) AsV1() *EventContextV1 { - return ec.AsV02().AsV03().AsV1() -} - -// Validate returns errors based on requirements from the CloudEvents spec. -// For more details, see https://github.com/cloudevents/spec/blob/v0.1/spec.md -func (ec EventContextV01) Validate() error { - errors := []string(nil) - - // eventType - // Type: String - // Constraints: - // REQUIRED - // MUST be a non-empty string - // SHOULD be prefixed with a reverse-DNS name. The prefixed domain dictates the organization which defines the semantics of this event type. - eventType := strings.TrimSpace(ec.EventType) - if eventType == "" { - errors = append(errors, "eventType: MUST be a non-empty string") - } - - // eventTypeVersion - // Type: String - // Constraints: - // OPTIONAL - // If present, MUST be a non-empty string - if ec.EventTypeVersion != nil { - eventTypeVersion := strings.TrimSpace(*ec.EventTypeVersion) - if eventTypeVersion == "" { - errors = append(errors, "eventTypeVersion: if present, MUST be a non-empty string") - } - } - - // cloudEventsVersion - // Type: String - // Constraints: - // REQUIRED - // MUST be a non-empty string - cloudEventsVersion := strings.TrimSpace(ec.CloudEventsVersion) - if cloudEventsVersion == "" { - errors = append(errors, "cloudEventsVersion: MUST be a non-empty string") - } - - // source - // Type: URI - // Constraints: - // REQUIRED - source := strings.TrimSpace(ec.Source.String()) - if source == "" { - errors = append(errors, "source: REQUIRED") - } - - // eventID - // Type: String - // Constraints: - // REQUIRED - // MUST be a non-empty string - // MUST be unique within the scope of the producer - eventID := strings.TrimSpace(ec.EventID) - if eventID == "" { - errors = append(errors, "eventID: MUST be a non-empty string") - - // no way to test "MUST be unique within the scope of the producer" - } - - // eventTime - // Type: Timestamp - // Constraints: - // OPTIONAL - // If present, MUST adhere to the format specified in RFC 3339 - // --> no need to test this, no way to set the eventTime without it being valid. - - // schemaURL - // Type: URI - // Constraints: - // OPTIONAL - // If present, MUST adhere to the format specified in RFC 3986 - if ec.SchemaURL != nil { - schemaURL := strings.TrimSpace(ec.SchemaURL.String()) - // empty string is not RFC 3986 compatible. - if schemaURL == "" { - errors = append(errors, "schemaURL: if present, MUST adhere to the format specified in RFC 3986") - } - } - - // contentType - // Type: String per RFC 2046 - // Constraints: - // OPTIONAL - // If present, MUST adhere to the format specified in RFC 2046 - if ec.ContentType != nil { - contentType := strings.TrimSpace(*ec.ContentType) - if contentType == "" { - // TODO: need to test for RFC 2046 - errors = append(errors, "contentType: if present, MUST adhere to the format specified in RFC 2046") - } - } - - // extensions - // Type: Map - // Constraints: - // OPTIONAL - // If present, MUST contain at least one entry - if ec.Extensions != nil { - if len(ec.Extensions) == 0 { - errors = append(errors, "extensions: if present, MUST contain at least one entry") - } - } - - if len(errors) > 0 { - return fmt.Errorf(strings.Join(errors, "\n")) - } - return nil -} - -// String returns a pretty-printed representation of the EventContext. -func (ec EventContextV01) String() string { - b := strings.Builder{} - - b.WriteString("Context Attributes,\n") - - b.WriteString(" cloudEventsVersion: " + ec.CloudEventsVersion + "\n") - b.WriteString(" eventType: " + ec.EventType + "\n") - if ec.EventTypeVersion != nil { - b.WriteString(" eventTypeVersion: " + *ec.EventTypeVersion + "\n") - } - b.WriteString(" source: " + ec.Source.String() + "\n") - b.WriteString(" eventID: " + ec.EventID + "\n") - if ec.EventTime != nil { - b.WriteString(" eventTime: " + ec.EventTime.String() + "\n") - } - if ec.SchemaURL != nil { - b.WriteString(" schemaURL: " + ec.SchemaURL.String() + "\n") - } - if ec.ContentType != nil { - b.WriteString(" contentType: " + *ec.ContentType + "\n") - } - - if ec.Extensions != nil && len(ec.Extensions) > 0 { - b.WriteString("Extensions,\n") - keys := make([]string, 0, len(ec.Extensions)) - for k := range ec.Extensions { - keys = append(keys, k) - } - sort.Strings(keys) - for _, key := range keys { - b.WriteString(fmt.Sprintf(" %s: %v\n", key, ec.Extensions[key])) - } - } - - return b.String() -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v01_reader.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v01_reader.go deleted file mode 100644 index 8d75ea70c4c..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v01_reader.go +++ /dev/null @@ -1,101 +0,0 @@ -package cloudevents - -import ( - "fmt" - "mime" - "time" -) - -// Adhere to EventContextReader -var _ EventContextReader = (*EventContextV01)(nil) - -// GetSpecVersion implements EventContextReader.GetSpecVersion -func (ec EventContextV01) GetSpecVersion() string { - if ec.CloudEventsVersion != "" { - return ec.CloudEventsVersion - } - return CloudEventsVersionV01 -} - -// GetDataContentType implements EventContextReader.GetDataContentType -func (ec EventContextV01) GetDataContentType() string { - if ec.ContentType != nil { - return *ec.ContentType - } - return "" -} - -// GetDataMediaType implements EventContextReader.GetDataMediaType -func (ec EventContextV01) GetDataMediaType() (string, error) { - if ec.ContentType != nil { - mediaType, _, err := mime.ParseMediaType(*ec.ContentType) - if err != nil { - return "", err - } - return mediaType, nil - } - return "", nil -} - -// GetType implements EventContextReader.GetType -func (ec EventContextV01) GetType() string { - return ec.EventType -} - -// GetSource implements EventContextReader.GetSource -func (ec EventContextV01) GetSource() string { - return ec.Source.String() -} - -// GetSubject implements EventContextReader.GetSubject -func (ec EventContextV01) GetSubject() string { - var sub string - if err := ec.ExtensionAs(SubjectKey, &sub); err != nil { - return "" - } - return sub -} - -// GetID implements EventContextReader.GetID -func (ec EventContextV01) GetID() string { - return ec.EventID -} - -// GetTime implements EventContextReader.GetTime -func (ec EventContextV01) GetTime() time.Time { - if ec.EventTime != nil { - return ec.EventTime.Time - } - return time.Time{} -} - -// GetDataSchema implements EventContextReader.GetDataSchema -func (ec EventContextV01) GetDataSchema() string { - if ec.SchemaURL != nil { - return ec.SchemaURL.String() - } - return "" -} - -// DeprecatedGetDataContentEncoding implements EventContextReader.DeprecatedGetDataContentEncoding -func (ec EventContextV01) DeprecatedGetDataContentEncoding() string { - var enc string - if err := ec.ExtensionAs(DataContentEncodingKey, &enc); err != nil { - return "" - } - return enc -} - -// GetExtensions implements EventContextReader.GetExtensions -func (ec EventContextV01) GetExtensions() map[string]interface{} { - return ec.Extensions -} - -// GetExtension implements EventContextReader.GetExtension -func (ec EventContextV01) GetExtension(key string) (interface{}, error) { - v, ok := caseInsensitiveSearch(key, ec.Extensions) - if !ok { - return "", fmt.Errorf("%q not found", key) - } - return v, nil -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v01_writer.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v01_writer.go deleted file mode 100644 index e49d3cca727..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v01_writer.go +++ /dev/null @@ -1,104 +0,0 @@ -package cloudevents - -import ( - "errors" - "fmt" - "net/url" - "strings" - "time" - - "github.com/cloudevents/sdk-go/pkg/cloudevents/types" -) - -// Adhere to EventContextWriter -var _ EventContextWriter = (*EventContextV01)(nil) - -// SetSpecVersion implements EventContextWriter.SetSpecVersion -func (ec *EventContextV01) SetSpecVersion(v string) error { - if v != CloudEventsVersionV01 { - return fmt.Errorf("invalid version %q, expecting %q", v, CloudEventsVersionV01) - } - ec.CloudEventsVersion = CloudEventsVersionV01 - return nil -} - -// SetDataContentType implements EventContextWriter.SetDataContentType -func (ec *EventContextV01) SetDataContentType(ct string) error { - ct = strings.TrimSpace(ct) - if ct == "" { - ec.ContentType = nil - } else { - ec.ContentType = &ct - } - return nil -} - -// SetType implements EventContextWriter.SetType -func (ec *EventContextV01) SetType(t string) error { - t = strings.TrimSpace(t) - ec.EventType = t - return nil -} - -// SetSource implements EventContextWriter.SetSource -func (ec *EventContextV01) SetSource(u string) error { - pu, err := url.Parse(u) - if err != nil { - return err - } - ec.Source = types.URLRef{URL: *pu} - return nil -} - -// SetSubject implements EventContextWriter.SetSubject -func (ec *EventContextV01) SetSubject(s string) error { - s = strings.TrimSpace(s) - if s == "" { - return ec.SetExtension(SubjectKey, nil) - } - return ec.SetExtension(SubjectKey, s) -} - -// SetID implements EventContextWriter.SetID -func (ec *EventContextV01) SetID(id string) error { - id = strings.TrimSpace(id) - if id == "" { - return errors.New("event id is required to be a non-empty string") - } - ec.EventID = id - return nil -} - -// SetTime implements EventContextWriter.SetTime -func (ec *EventContextV01) SetTime(t time.Time) error { - if t.IsZero() { - ec.EventTime = nil - } else { - ec.EventTime = &types.Timestamp{Time: t} - } - return nil -} - -// SetDataSchema implements EventContextWriter.SetDataSchema -func (ec *EventContextV01) SetDataSchema(u string) error { - u = strings.TrimSpace(u) - if u == "" { - ec.SchemaURL = nil - return nil - } - pu, err := url.Parse(u) - if err != nil { - return err - } - ec.SchemaURL = &types.URLRef{URL: *pu} - return nil -} - -// DeprecatedSetDataContentEncoding implements EventContextWriter.DeprecatedSetDataContentEncoding -func (ec *EventContextV01) DeprecatedSetDataContentEncoding(e string) error { - e = strings.ToLower(strings.TrimSpace(e)) - if e == "" { - return ec.SetExtension(DataContentEncodingKey, nil) - } - return ec.SetExtension(DataContentEncodingKey, e) -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v02.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v02.go deleted file mode 100644 index 7b936bd81ac..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v02.go +++ /dev/null @@ -1,305 +0,0 @@ -package cloudevents - -import ( - "encoding/json" - "fmt" - "sort" - "strings" - - "github.com/cloudevents/sdk-go/pkg/cloudevents/types" -) - -const ( - // CloudEventsVersionV02 represents the version 0.2 of the CloudEvents spec. - CloudEventsVersionV02 = "0.2" -) - -// EventContextV02 represents the non-data attributes of a CloudEvents v0.2 -// event. -type EventContextV02 struct { - // The version of the CloudEvents specification used by the event. - SpecVersion string `json:"specversion"` - // The type of the occurrence which has happened. - Type string `json:"type"` - // A URI describing the event producer. - Source types.URLRef `json:"source"` - // ID of the event; must be non-empty and unique within the scope of the producer. - ID string `json:"id"` - // Timestamp when the event happened. - Time *types.Timestamp `json:"time,omitempty"` - // A link to the schema that the `data` attribute adheres to. - SchemaURL *types.URLRef `json:"schemaurl,omitempty"` - // A MIME (RFC2046) string describing the media type of `data`. - // TODO: Should an empty string assume `application/json`, `application/octet-stream`, or auto-detect the content? - ContentType *string `json:"contenttype,omitempty"` - // Additional extension metadata beyond the base spec. - Extensions map[string]interface{} `json:"-"` -} - -// Adhere to EventContext -var _ EventContext = (*EventContextV02)(nil) - -// ExtensionAs implements EventContext.ExtensionAs -func (ec EventContextV02) ExtensionAs(name string, obj interface{}) error { - value, ok := ec.Extensions[name] - if !ok { - return fmt.Errorf("extension %q does not exist", name) - } - - // Try to unmarshal extension if we find it as a RawMessage. - switch v := value.(type) { - case json.RawMessage: - if err := json.Unmarshal(v, obj); err == nil { - // if that worked, return with obj set. - return nil - } - } - // else try as a string ptr. - - // Only support *string for now. - switch v := obj.(type) { - case *string: - if valueAsString, ok := value.(string); ok { - *v = valueAsString - return nil - } else { - return fmt.Errorf("invalid type for extension %q", name) - } - default: - return fmt.Errorf("unknown extension type %T", obj) - } -} - -// SetExtension adds the extension 'name' with value 'value' to the CloudEvents context. -func (ec *EventContextV02) SetExtension(name string, value interface{}) error { - if ec.Extensions == nil { - ec.Extensions = make(map[string]interface{}) - } - if value == nil { - delete(ec.Extensions, name) - } else { - ec.Extensions[name] = value - } - return nil -} - -// Clone implements EventContextConverter.Clone -func (ec EventContextV02) Clone() EventContext { - ec02 := ec.AsV02() - ec02.Extensions = ec02.cloneExtensions() - return ec02 -} - -func (ec *EventContextV02) cloneExtensions() map[string]interface{} { - old := ec.Extensions - if old == nil { - return nil - } - new := make(map[string]interface{}, len(ec.Extensions)) - for k, v := range old { - new[k] = v - } - return new -} - -// AsV01 implements EventContextConverter.AsV01 -func (ec EventContextV02) AsV01() *EventContextV01 { - ret := EventContextV01{ - CloudEventsVersion: CloudEventsVersionV01, - EventID: ec.ID, - EventTime: ec.Time, - EventType: ec.Type, - SchemaURL: ec.SchemaURL, - Source: ec.Source, - ContentType: ec.ContentType, - Extensions: make(map[string]interface{}), - } - - for k, v := range ec.Extensions { - // eventTypeVersion was retired in v0.2 - if strings.EqualFold(k, EventTypeVersionKey) { - etv, ok := v.(string) - if ok && etv != "" { - ret.EventTypeVersion = &etv - } - continue - } - ret.Extensions[k] = v - } - if len(ret.Extensions) == 0 { - ret.Extensions = nil - } - return &ret -} - -// AsV02 implements EventContextConverter.AsV02 -func (ec EventContextV02) AsV02() *EventContextV02 { - ec.SpecVersion = CloudEventsVersionV02 - return &ec -} - -// AsV03 implements EventContextConverter.AsV03 -func (ec EventContextV02) AsV03() *EventContextV03 { - ret := EventContextV03{ - SpecVersion: CloudEventsVersionV03, - ID: ec.ID, - Time: ec.Time, - Type: ec.Type, - SchemaURL: ec.SchemaURL, - DataContentType: ec.ContentType, - Source: ec.Source, - Extensions: make(map[string]interface{}), - } - - for k, v := range ec.Extensions { - // Subject was introduced in 0.3 - if strings.EqualFold(k, SubjectKey) { - sub, ok := v.(string) - if ok && sub != "" { - ret.Subject = &sub - } - continue - } - // DeprecatedDataContentEncoding was introduced in 0.3 - if strings.EqualFold(k, DataContentEncodingKey) { - etv, ok := v.(string) - if ok && etv != "" { - ret.DataContentEncoding = &etv - } - continue - } - ret.Extensions[k] = v - } - if len(ret.Extensions) == 0 { - ret.Extensions = nil - } - - return &ret -} - -// AsV1 implements EventContextConverter.AsV1 -func (ec EventContextV02) AsV1() *EventContextV1 { - return ec.AsV03().AsV1() -} - -// Validate returns errors based on requirements from the CloudEvents spec. -// For more details, see https://github.com/cloudevents/spec/blob/v0.2/spec.md -func (ec EventContextV02) Validate() error { - errors := []string(nil) - - // type - // Type: String - // Constraints: - // REQUIRED - // MUST be a non-empty string - // SHOULD be prefixed with a reverse-DNS name. The prefixed domain dictates the organization which defines the semantics of this event type. - eventType := strings.TrimSpace(ec.Type) - if eventType == "" { - 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: - // REQUIRED - source := strings.TrimSpace(ec.Source.String()) - if source == "" { - errors = append(errors, "source: REQUIRED") - } - - // id - // Type: String - // Constraints: - // REQUIRED - // MUST be a non-empty string - // MUST be unique within the scope of the producer - id := strings.TrimSpace(ec.ID) - if id == "" { - errors = append(errors, "id: MUST be a non-empty string") - - // no way to test "MUST be unique within the scope of the producer" - } - - // time - // Type: Timestamp - // Constraints: - // OPTIONAL - // If present, MUST adhere to the format specified in RFC 3339 - // --> no need to test this, no way to set the time without it being valid. - - // schemaurl - // Type: URI - // Constraints: - // OPTIONAL - // If present, MUST adhere to the format specified in RFC 3986 - if ec.SchemaURL != nil { - schemaURL := strings.TrimSpace(ec.SchemaURL.String()) - // empty string is not RFC 3986 compatible. - if schemaURL == "" { - errors = append(errors, "schemaurl: if present, MUST adhere to the format specified in RFC 3986") - } - } - - // contenttype - // Type: String per RFC 2046 - // Constraints: - // OPTIONAL - // If present, MUST adhere to the format specified in RFC 2046 - if ec.ContentType != nil { - contentType := strings.TrimSpace(*ec.ContentType) - if contentType == "" { - // TODO: need to test for RFC 2046 - errors = append(errors, "contenttype: if present, MUST adhere to the format specified in RFC 2046") - } - } - - if len(errors) > 0 { - return fmt.Errorf(strings.Join(errors, "\n")) - } - return nil -} - -// String returns a pretty-printed representation of the EventContext. -func (ec EventContextV02) String() string { - b := strings.Builder{} - - b.WriteString("Context Attributes,\n") - - b.WriteString(" specversion: " + ec.SpecVersion + "\n") - b.WriteString(" type: " + ec.Type + "\n") - b.WriteString(" source: " + ec.Source.String() + "\n") - b.WriteString(" id: " + ec.ID + "\n") - if ec.Time != nil { - b.WriteString(" time: " + ec.Time.String() + "\n") - } - if ec.SchemaURL != nil { - b.WriteString(" schemaurl: " + ec.SchemaURL.String() + "\n") - } - if ec.ContentType != nil { - b.WriteString(" contenttype: " + *ec.ContentType + "\n") - } - - if ec.Extensions != nil && len(ec.Extensions) > 0 { - b.WriteString("Extensions,\n") - keys := make([]string, 0, len(ec.Extensions)) - for k := range ec.Extensions { - keys = append(keys, k) - } - sort.Strings(keys) - for _, key := range keys { - b.WriteString(fmt.Sprintf(" %s: %v\n", key, ec.Extensions[key])) - } - } - - return b.String() -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v02_reader.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v02_reader.go deleted file mode 100644 index 120cdb87ec6..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v02_reader.go +++ /dev/null @@ -1,101 +0,0 @@ -package cloudevents - -import ( - "fmt" - "mime" - "time" -) - -// Adhere to EventContextReader -var _ EventContextReader = (*EventContextV02)(nil) - -// GetSpecVersion implements EventContextReader.GetSpecVersion -func (ec EventContextV02) GetSpecVersion() string { - if ec.SpecVersion != "" { - return ec.SpecVersion - } - return CloudEventsVersionV02 -} - -// GetType implements EventContextReader.GetType -func (ec EventContextV02) GetType() string { - return ec.Type -} - -// GetSource implements EventContextReader.GetSource -func (ec EventContextV02) GetSource() string { - return ec.Source.String() -} - -// GetSubject implements EventContextReader.GetSubject -func (ec EventContextV02) GetSubject() string { - var sub string - if err := ec.ExtensionAs(SubjectKey, &sub); err != nil { - return "" - } - return sub -} - -// GetID implements EventContextReader.GetID -func (ec EventContextV02) GetID() string { - return ec.ID -} - -// GetTime implements EventContextReader.GetTime -func (ec EventContextV02) GetTime() time.Time { - if ec.Time != nil { - return ec.Time.Time - } - return time.Time{} -} - -// GetDataSchema implements EventContextReader.GetDataSchema -func (ec EventContextV02) GetDataSchema() string { - if ec.SchemaURL != nil { - return ec.SchemaURL.String() - } - return "" -} - -// GetDataContentType implements EventContextReader.GetDataContentType -func (ec EventContextV02) GetDataContentType() string { - if ec.ContentType != nil { - return *ec.ContentType - } - return "" -} - -// GetDataMediaType implements EventContextReader.GetDataMediaType -func (ec EventContextV02) GetDataMediaType() (string, error) { - if ec.ContentType != nil { - mediaType, _, err := mime.ParseMediaType(*ec.ContentType) - if err != nil { - return "", err - } - return mediaType, nil - } - return "", nil -} - -// DeprecatedGetDataContentEncoding implements EventContextReader.DeprecatedGetDataContentEncoding -func (ec EventContextV02) DeprecatedGetDataContentEncoding() string { - var enc string - if err := ec.ExtensionAs(DataContentEncodingKey, &enc); err != nil { - return "" - } - return enc -} - -// GetExtensions implements EventContextReader.GetExtensions -func (ec EventContextV02) GetExtensions() map[string]interface{} { - return ec.Extensions -} - -// GetExtension implements EventContextReader.GetExtension -func (ec EventContextV02) GetExtension(key string) (interface{}, error) { - v, ok := caseInsensitiveSearch(key, ec.Extensions) - if !ok { - return "", fmt.Errorf("%q not found", key) - } - return v, nil -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v02_writer.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v02_writer.go deleted file mode 100644 index 25b8a16c8d3..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v02_writer.go +++ /dev/null @@ -1,104 +0,0 @@ -package cloudevents - -import ( - "errors" - "fmt" - "net/url" - "strings" - "time" - - "github.com/cloudevents/sdk-go/pkg/cloudevents/types" -) - -// Adhere to EventContextWriter -var _ EventContextWriter = (*EventContextV02)(nil) - -// SetSpecVersion implements EventContextWriter.SetSpecVersion -func (ec *EventContextV02) SetSpecVersion(v string) error { - if v != CloudEventsVersionV02 { - return fmt.Errorf("invalid version %q, expecting %q", v, CloudEventsVersionV02) - } - ec.SpecVersion = CloudEventsVersionV02 - return nil -} - -// SetDataContentType implements EventContextWriter.SetDataContentType -func (ec *EventContextV02) SetDataContentType(ct string) error { - ct = strings.TrimSpace(ct) - if ct == "" { - ec.ContentType = nil - } else { - ec.ContentType = &ct - } - return nil -} - -// SetType implements EventContextWriter.SetType -func (ec *EventContextV02) SetType(t string) error { - t = strings.TrimSpace(t) - ec.Type = t - return nil -} - -// SetSource implements EventContextWriter.SetSource -func (ec *EventContextV02) SetSource(u string) error { - pu, err := url.Parse(u) - if err != nil { - return err - } - ec.Source = types.URLRef{URL: *pu} - return nil -} - -// SetSubject implements EventContextWriter.SetSubject -func (ec *EventContextV02) SetSubject(s string) error { - s = strings.TrimSpace(s) - if s == "" { - return ec.SetExtension(SubjectKey, nil) - } - return ec.SetExtension(SubjectKey, s) -} - -// SetID implements EventContextWriter.SetID -func (ec *EventContextV02) SetID(id string) error { - id = strings.TrimSpace(id) - if id == "" { - return errors.New("id is required to be a non-empty string") - } - ec.ID = id - return nil -} - -// SetTime implements EventContextWriter.SetTime -func (ec *EventContextV02) SetTime(t time.Time) error { - if t.IsZero() { - ec.Time = nil - } else { - ec.Time = &types.Timestamp{Time: t} - } - return nil -} - -// SetDataSchema implements EventContextWriter.SetDataSchema -func (ec *EventContextV02) SetDataSchema(u string) error { - u = strings.TrimSpace(u) - if u == "" { - ec.SchemaURL = nil - return nil - } - pu, err := url.Parse(u) - if err != nil { - return err - } - ec.SchemaURL = &types.URLRef{URL: *pu} - return nil -} - -// DeprecatedSetDataContentEncoding implements EventContextWriter.DeprecatedSetDataContentEncoding -func (ec *EventContextV02) DeprecatedSetDataContentEncoding(e string) error { - e = strings.ToLower(strings.TrimSpace(e)) - if e == "" { - return ec.SetExtension(DataContentEncodingKey, nil) - } - return ec.SetExtension(DataContentEncodingKey, e) -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v03.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v03.go deleted file mode 100644 index 6fc776539ea..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v03.go +++ /dev/null @@ -1,345 +0,0 @@ -package cloudevents - -import ( - "encoding/json" - "fmt" - "sort" - "strings" - - "github.com/cloudevents/sdk-go/pkg/cloudevents/types" -) - -const ( - // CloudEventsVersionV03 represents the version 0.3 of the CloudEvents spec. - CloudEventsVersionV03 = "0.3" -) - -// 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. - Source types.URLRef `json:"source"` - // Subject - The subject of the event in the context of the event producer - // (identified by `source`). - Subject *string `json:"subject,omitempty"` - // ID of the event; must be non-empty and unique within the scope of the producer. - ID string `json:"id"` - // Time - A Timestamp when the event happened. - Time *types.Timestamp `json:"time,omitempty"` - // DataSchema - A link to the schema that the `data` attribute adheres to. - SchemaURL *types.URLRef `json:"schemaurl,omitempty"` - // GetDataMediaType - A MIME (RFC2046) string describing the media type of `data`. - // TODO: Should an empty string assume `application/json`, `application/octet-stream`, or auto-detect the content? - DataContentType *string `json:"datacontenttype,omitempty"` - // DeprecatedDataContentEncoding describes the content encoding for the `data` attribute. Valid: nil, `Base64`. - DataContentEncoding *string `json:"datacontentencoding,omitempty"` - // Extensions - Additional extension metadata beyond the base spec. - Extensions map[string]interface{} `json:"-"` -} - -// Adhere to EventContext -var _ EventContext = (*EventContextV03)(nil) - -// ExtensionAs implements EventContext.ExtensionAs -func (ec EventContextV03) ExtensionAs(name string, obj interface{}) error { - value, ok := ec.Extensions[name] - if !ok { - return fmt.Errorf("extension %q does not exist", name) - } - - // Try to unmarshal extension if we find it as a RawMessage. - switch v := value.(type) { - case json.RawMessage: - if err := json.Unmarshal(v, obj); err == nil { - // if that worked, return with obj set. - return nil - } - } - // else try as a string ptr. - - // Only support *string for now. - switch v := obj.(type) { - case *string: - if valueAsString, ok := value.(string); ok { - *v = valueAsString - return nil - } else { - return fmt.Errorf("invalid type for extension %q", name) - } - default: - return fmt.Errorf("unknown extension type %T", obj) - } -} - -// SetExtension adds the extension 'name' with value 'value' to the CloudEvents context. -func (ec *EventContextV03) SetExtension(name string, value interface{}) error { - if ec.Extensions == nil { - ec.Extensions = make(map[string]interface{}) - } - if value == nil { - delete(ec.Extensions, name) - } else { - v, err := types.Validate(value) - if err == nil { - ec.Extensions[name] = v - } - return err - } - return nil -} - -// Clone implements EventContextConverter.Clone -func (ec EventContextV03) Clone() EventContext { - ec03 := ec.AsV03() - ec03.Extensions = ec03.cloneExtensions() - return ec03 -} - -func (ec *EventContextV03) cloneExtensions() map[string]interface{} { - old := ec.Extensions - if old == nil { - return nil - } - new := make(map[string]interface{}, len(ec.Extensions)) - for k, v := range old { - new[k] = v - } - return new -} - -// AsV01 implements EventContextConverter.AsV01 -func (ec EventContextV03) AsV01() *EventContextV01 { - ecv2 := ec.AsV02() - return ecv2.AsV01() -} - -// AsV02 implements EventContextConverter.AsV02 -func (ec EventContextV03) AsV02() *EventContextV02 { - ret := EventContextV02{ - SpecVersion: CloudEventsVersionV02, - ID: ec.ID, - Time: ec.Time, - Type: ec.Type, - SchemaURL: ec.SchemaURL, - ContentType: ec.DataContentType, - Source: ec.Source, - Extensions: make(map[string]interface{}), - } - // Subject was introduced in 0.3, so put it in an extension for 0.2. - if ec.Subject != nil { - _ = ret.SetExtension(SubjectKey, *ec.Subject) - } - // DeprecatedDataContentEncoding was introduced in 0.3, so put it in an extension for 0.2. - if ec.DataContentEncoding != nil { - _ = ret.SetExtension(DataContentEncodingKey, *ec.DataContentEncoding) - } - if ec.Extensions != nil { - for k, v := range ec.Extensions { - ret.Extensions[k] = v - } - } - if len(ret.Extensions) == 0 { - ret.Extensions = nil - } - return &ret -} - -// 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, - DataContentType: ec.DataContentType, - Source: types.URIRef{URL: ec.Source.URL}, - Subject: ec.Subject, - Extensions: make(map[string]interface{}), - } - if ec.SchemaURL != nil { - ret.DataSchema = &types.URI{URL: ec.SchemaURL.URL} - } - - // DataContentEncoding was removed in 1.0, so put it in an extension for 1.0. - if ec.DataContentEncoding != nil { - _ = ret.SetExtension(DataContentEncodingKey, *ec.DataContentEncoding) - } - - if ec.Extensions != nil { - for k, v := range ec.Extensions { - k = strings.ToLower(k) - ret.Extensions[k] = v - } - } - if len(ret.Extensions) == 0 { - ret.Extensions = nil - } - return &ret -} - -// Validate returns errors based on requirements from the CloudEvents spec. -// For more details, see https://github.com/cloudevents/spec/blob/master/spec.md -// As of Feb 26, 2019, commit 17c32ea26baf7714ad027d9917d03d2fff79fc7e -// + https://github.com/cloudevents/spec/pull/387 -> datacontentencoding -// + https://github.com/cloudevents/spec/pull/406 -> subject -func (ec EventContextV03) Validate() error { - errors := []string(nil) - - // type - // Type: String - // Constraints: - // REQUIRED - // MUST be a non-empty string - // SHOULD be prefixed with a reverse-DNS name. The prefixed domain dictates the organization which defines the semantics of this event type. - eventType := strings.TrimSpace(ec.Type) - if eventType == "" { - 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: - // REQUIRED - source := strings.TrimSpace(ec.Source.String()) - if source == "" { - errors = append(errors, "source: REQUIRED") - } - - // subject - // Type: String - // Constraints: - // OPTIONAL - // MUST be a non-empty string - if ec.Subject != nil { - subject := strings.TrimSpace(*ec.Subject) - if subject == "" { - errors = append(errors, "subject: if present, MUST be a non-empty string") - } - } - - // id - // Type: String - // Constraints: - // REQUIRED - // MUST be a non-empty string - // MUST be unique within the scope of the producer - id := strings.TrimSpace(ec.ID) - if id == "" { - errors = append(errors, "id: MUST be a non-empty string") - - // no way to test "MUST be unique within the scope of the producer" - } - - // time - // Type: Timestamp - // Constraints: - // OPTIONAL - // If present, MUST adhere to the format specified in RFC 3339 - // --> no need to test this, no way to set the time without it being valid. - - // schemaurl - // Type: URI - // Constraints: - // OPTIONAL - // If present, MUST adhere to the format specified in RFC 3986 - if ec.SchemaURL != nil { - schemaURL := strings.TrimSpace(ec.SchemaURL.String()) - // empty string is not RFC 3986 compatible. - if schemaURL == "" { - errors = append(errors, "schemaurl: if present, MUST adhere to the format specified in RFC 3986") - } - } - - // datacontenttype - // Type: String per RFC 2046 - // Constraints: - // OPTIONAL - // If present, MUST adhere to the format specified in RFC 2046 - if ec.DataContentType != nil { - dataContentType := strings.TrimSpace(*ec.DataContentType) - if dataContentType == "" { - // TODO: need to test for RFC 2046 - errors = append(errors, "datacontenttype: if present, MUST adhere to the format specified in RFC 2046") - } - } - - // datacontentencoding - // Type: String per RFC 2045 Section 6.1 - // Constraints: - // The attribute MUST be set if the data attribute contains string-encoded binary data. - // Otherwise the attribute MUST NOT be set. - // If present, MUST adhere to RFC 2045 Section 6.1 - if ec.DataContentEncoding != nil { - dataContentEncoding := strings.ToLower(strings.TrimSpace(*ec.DataContentEncoding)) - if dataContentEncoding != Base64 { - // TODO: need to test for RFC 2046 - errors = append(errors, "datacontentencoding: if present, MUST adhere to RFC 2045 Section 6.1") - } - } - - if len(errors) > 0 { - return fmt.Errorf(strings.Join(errors, "\n")) - } - return nil -} - -// String returns a pretty-printed representation of the EventContext. -func (ec EventContextV03) String() string { - b := strings.Builder{} - - b.WriteString("Context Attributes,\n") - - b.WriteString(" specversion: " + ec.SpecVersion + "\n") - b.WriteString(" type: " + ec.Type + "\n") - b.WriteString(" source: " + ec.Source.String() + "\n") - if ec.Subject != nil { - b.WriteString(" subject: " + *ec.Subject + "\n") - } - b.WriteString(" id: " + ec.ID + "\n") - if ec.Time != nil { - b.WriteString(" time: " + ec.Time.String() + "\n") - } - if ec.SchemaURL != nil { - b.WriteString(" schemaurl: " + ec.SchemaURL.String() + "\n") - } - if ec.DataContentType != nil { - b.WriteString(" datacontenttype: " + *ec.DataContentType + "\n") - } - if ec.DataContentEncoding != nil { - b.WriteString(" datacontentencoding: " + *ec.DataContentEncoding + "\n") - } - - if ec.Extensions != nil && len(ec.Extensions) > 0 { - b.WriteString("Extensions,\n") - keys := make([]string, 0, len(ec.Extensions)) - for k := range ec.Extensions { - keys = append(keys, k) - } - sort.Strings(keys) - for _, key := range keys { - b.WriteString(fmt.Sprintf(" %s: %v\n", key, ec.Extensions[key])) - } - } - - return b.String() -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v03_reader.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v03_reader.go deleted file mode 100644 index 2b3cc207fc2..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v03_reader.go +++ /dev/null @@ -1,96 +0,0 @@ -package cloudevents - -import ( - "fmt" - "mime" - "time" -) - -// GetSpecVersion implements EventContextReader.GetSpecVersion -func (ec EventContextV03) GetSpecVersion() string { - if ec.SpecVersion != "" { - return ec.SpecVersion - } - return CloudEventsVersionV03 -} - -// GetDataContentType implements EventContextReader.GetDataContentType -func (ec EventContextV03) GetDataContentType() string { - if ec.DataContentType != nil { - return *ec.DataContentType - } - return "" -} - -// GetDataMediaType implements EventContextReader.GetDataMediaType -func (ec EventContextV03) GetDataMediaType() (string, error) { - if ec.DataContentType != nil { - mediaType, _, err := mime.ParseMediaType(*ec.DataContentType) - if err != nil { - return "", err - } - return mediaType, nil - } - return "", nil -} - -// GetType implements EventContextReader.GetType -func (ec EventContextV03) GetType() string { - return ec.Type -} - -// GetSource implements EventContextReader.GetSource -func (ec EventContextV03) GetSource() string { - return ec.Source.String() -} - -// GetSubject implements EventContextReader.GetSubject -func (ec EventContextV03) GetSubject() string { - if ec.Subject != nil { - return *ec.Subject - } - return "" -} - -// GetTime implements EventContextReader.GetTime -func (ec EventContextV03) GetTime() time.Time { - if ec.Time != nil { - return ec.Time.Time - } - return time.Time{} -} - -// GetID implements EventContextReader.GetID -func (ec EventContextV03) GetID() string { - return ec.ID -} - -// GetDataSchema implements EventContextReader.GetDataSchema -func (ec EventContextV03) GetDataSchema() string { - if ec.SchemaURL != nil { - return ec.SchemaURL.String() - } - return "" -} - -// DeprecatedGetDataContentEncoding implements EventContextReader.DeprecatedGetDataContentEncoding -func (ec EventContextV03) DeprecatedGetDataContentEncoding() string { - if ec.DataContentEncoding != nil { - return *ec.DataContentEncoding - } - return "" -} - -// GetExtensions implements EventContextReader.GetExtensions -func (ec EventContextV03) GetExtensions() map[string]interface{} { - return ec.Extensions -} - -// GetExtension implements EventContextReader.GetExtension -func (ec EventContextV03) GetExtension(key string) (interface{}, error) { - v, ok := caseInsensitiveSearch(key, ec.Extensions) - if !ok { - return "", fmt.Errorf("%q not found", key) - } - return v, nil -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v03_writer.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v03_writer.go deleted file mode 100644 index 0c1bb8428e4..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v03_writer.go +++ /dev/null @@ -1,108 +0,0 @@ -package cloudevents - -import ( - "errors" - "fmt" - "net/url" - "strings" - "time" - - "github.com/cloudevents/sdk-go/pkg/cloudevents/types" -) - -// 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) - if ct == "" { - ec.DataContentType = nil - } else { - ec.DataContentType = &ct - } - return nil -} - -// SetType implements EventContextWriter.SetType -func (ec *EventContextV03) SetType(t string) error { - t = strings.TrimSpace(t) - ec.Type = t - return nil -} - -// SetSource implements EventContextWriter.SetSource -func (ec *EventContextV03) SetSource(u string) error { - pu, err := url.Parse(u) - if err != nil { - return err - } - ec.Source = types.URLRef{URL: *pu} - return nil -} - -// SetSubject implements EventContextWriter.SetSubject -func (ec *EventContextV03) SetSubject(s string) error { - s = strings.TrimSpace(s) - if s == "" { - ec.Subject = nil - } else { - ec.Subject = &s - } - return nil -} - -// SetID implements EventContextWriter.SetID -func (ec *EventContextV03) SetID(id string) error { - id = strings.TrimSpace(id) - if id == "" { - return errors.New("id is required to be a non-empty string") - } - ec.ID = id - return nil -} - -// SetTime implements EventContextWriter.SetTime -func (ec *EventContextV03) SetTime(t time.Time) error { - if t.IsZero() { - ec.Time = nil - } else { - ec.Time = &types.Timestamp{Time: t} - } - return nil -} - -// SetDataSchema implements EventContextWriter.SetDataSchema -func (ec *EventContextV03) SetDataSchema(u string) error { - u = strings.TrimSpace(u) - if u == "" { - ec.SchemaURL = nil - return nil - } - pu, err := url.Parse(u) - if err != nil { - return err - } - ec.SchemaURL = &types.URLRef{URL: *pu} - return nil -} - -// DeprecatedSetDataContentEncoding implements EventContextWriter.DeprecatedSetDataContentEncoding -func (ec *EventContextV03) DeprecatedSetDataContentEncoding(e string) error { - e = strings.ToLower(strings.TrimSpace(e)) - if e == "" { - ec.DataContentEncoding = nil - } else { - ec.DataContentEncoding = &e - } - return nil -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v1.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v1.go deleted file mode 100644 index 320f47e0d9a..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v1.go +++ /dev/null @@ -1,315 +0,0 @@ -package cloudevents - -import ( - "errors" - "fmt" - "mime" - "sort" - "strings" - - "github.com/cloudevents/sdk-go/pkg/cloudevents/types" -) - -// WIP: AS OF SEP 20, 2019 - -const ( - // CloudEventsVersionV1 represents the version 1.0 of the CloudEvents spec. - CloudEventsVersionV1 = "1.0" -) - -// EventContextV1 represents the non-data attributes of a CloudEvents v1.0 -// event. -type EventContextV1 struct { - // ID of the event; must be non-empty and unique within the scope of the producer. - // +required - ID string `json:"id"` - // 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"` - - // DataContentType - A MIME (RFC2046) string describing the media type of `data`. - // +optional - DataContentType *string `json:"datacontenttype,omitempty"` - // Subject - The subject of the event in the context of the event producer - // (identified by `source`). - // +optional - Subject *string `json:"subject,omitempty"` - // Time - A Timestamp when the event happened. - // +optional - Time *types.Timestamp `json:"time,omitempty"` - // DataSchema - A link to the schema that the `data` attribute adheres to. - // +optional - DataSchema *types.URI `json:"dataschema,omitempty"` - - // Extensions - Additional extension metadata beyond the base spec. - // +optional - Extensions map[string]interface{} `json:"-"` -} - -// Adhere to EventContext -var _ EventContext = (*EventContextV1)(nil) - -// ExtensionAs implements EventContext.ExtensionAs -func (ec EventContextV1) ExtensionAs(name string, obj interface{}) error { - name = strings.ToLower(name) - value, ok := ec.Extensions[name] - if !ok { - return fmt.Errorf("extension %q does not exist", name) - } - - // Only support *string for now. - if v, ok := obj.(*string); ok { - if *v, ok = value.(string); ok { - return nil - } - } - return fmt.Errorf("unknown extension type %T", obj) -} - -// SetExtension adds the extension 'name' with value 'value' to the CloudEvents context. -// This function fails if the name doesn't respect the regex ^[a-zA-Z0-9]+$ -func (ec *EventContextV1) SetExtension(name string, value interface{}) error { - if !IsAlphaNumeric(name) { - return errors.New("bad key, CloudEvents attribute names MUST consist of lower-case letters ('a' to 'z') or digits ('0' to '9') from the ASCII character set") - } - - name = strings.ToLower(name) - if ec.Extensions == nil { - ec.Extensions = make(map[string]interface{}) - } - if value == nil { - delete(ec.Extensions, name) - return nil - } else { - v, err := types.Validate(value) // Ensure it's a legal CE attribute value - if err == nil { - ec.Extensions[name] = v - } - return err - } -} - -// Clone implements EventContextConverter.Clone -func (ec EventContextV1) Clone() EventContext { - ec1 := ec.AsV1() - ec1.Extensions = ec1.cloneExtensions() - return ec1 -} - -func (ec *EventContextV1) cloneExtensions() map[string]interface{} { - old := ec.Extensions - if old == nil { - return nil - } - new := make(map[string]interface{}, len(ec.Extensions)) - for k, v := range old { - new[k] = v - } - return new -} - -// AsV01 implements EventContextConverter.AsV01 -func (ec EventContextV1) AsV01() *EventContextV01 { - ecv2 := ec.AsV02() - return ecv2.AsV01() -} - -// AsV02 implements EventContextConverter.AsV02 -func (ec EventContextV1) AsV02() *EventContextV02 { - ecv3 := ec.AsV03() - return ecv3.AsV02() -} - -// AsV03 implements EventContextConverter.AsV03 -func (ec EventContextV1) AsV03() *EventContextV03 { - ret := EventContextV03{ - SpecVersion: CloudEventsVersionV03, - ID: ec.ID, - Time: ec.Time, - Type: ec.Type, - DataContentType: ec.DataContentType, - Source: types.URLRef{URL: ec.Source.URL}, - Subject: ec.Subject, - Extensions: make(map[string]interface{}), - } - - if ec.DataSchema != nil { - ret.SchemaURL = &types.URLRef{URL: ec.DataSchema.URL} - } - - // TODO: DeprecatedDataContentEncoding needs to be moved to extensions. - if ec.Extensions != nil { - for k, v := range ec.Extensions { - k = strings.ToLower(k) - // DeprecatedDataContentEncoding was introduced in 0.3, removed in 1.0 - if strings.EqualFold(k, DataContentEncodingKey) { - etv, ok := v.(string) - if ok && etv != "" { - ret.DataContentEncoding = &etv - } - continue - } - ret.Extensions[k] = v - } - } - if len(ret.Extensions) == 0 { - ret.Extensions = nil - } - return &ret -} - -// AsV04 implements EventContextConverter.AsV04 -func (ec EventContextV1) AsV1() *EventContextV1 { - ec.SpecVersion = CloudEventsVersionV1 - return &ec -} - -// Validate returns errors based on requirements from the CloudEvents spec. -// For more details, see https://github.com/cloudevents/spec/blob/v1.0-rc1/spec.md. -func (ec EventContextV1) Validate() error { - errors := []string(nil) - - // id - // Type: String - // Constraints: - // REQUIRED - // MUST be a non-empty string - // MUST be unique within the scope of the producer - id := strings.TrimSpace(ec.ID) - if id == "" { - errors = append(errors, "id: MUST be a non-empty string") - // no way to test "MUST be unique within the scope of the producer" - } - - // source - // Type: URI-reference - // Constraints: - // REQUIRED - // MUST be a non-empty URI-reference - // An absolute URI is RECOMMENDED - source := strings.TrimSpace(ec.Source.String()) - if source == "" { - 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: - // REQUIRED - // MUST be a non-empty string - // SHOULD be prefixed with a reverse-DNS name. The prefixed domain dictates the organization which defines the semantics of this event type. - eventType := strings.TrimSpace(ec.Type) - if eventType == "" { - errors = append(errors, "type: MUST be a non-empty string") - } - - // The following attributes are optional but still have validation. - - // datacontenttype - // Type: String per RFC 2046 - // Constraints: - // OPTIONAL - // If present, MUST adhere to the format specified in RFC 2046 - if ec.DataContentType != nil { - dataContentType := strings.TrimSpace(*ec.DataContentType) - if dataContentType == "" { - errors = append(errors, "datacontenttype: if present, MUST adhere to the format specified in RFC 2046") - } else { - _, _, err := mime.ParseMediaType(dataContentType) - if err != nil { - errors = append(errors, fmt.Sprintf("datacontenttype: failed to parse media type, %s", err.Error())) - } - } - } - - // dataschema - // Type: URI - // Constraints: - // OPTIONAL - // If present, MUST adhere to the format specified in RFC 3986 - if ec.DataSchema != nil { - dataSchema := strings.TrimSpace(ec.DataSchema.String()) - // empty string is not RFC 3986 compatible. - if dataSchema == "" { - errors = append(errors, "dataschema: if present, MUST adhere to the format specified in RFC 3986") - } - } - - // subject - // Type: String - // Constraints: - // OPTIONAL - // MUST be a non-empty string - if ec.Subject != nil { - subject := strings.TrimSpace(*ec.Subject) - if subject == "" { - errors = append(errors, "subject: if present, MUST be a non-empty string") - } - } - - // time - // Type: Timestamp - // Constraints: - // OPTIONAL - // If present, MUST adhere to the format specified in RFC 3339 - // --> no need to test this, no way to set the time without it being valid. - - if len(errors) > 0 { - return fmt.Errorf(strings.Join(errors, "\n")) - } - return nil -} - -// String returns a pretty-printed representation of the EventContext. -func (ec EventContextV1) String() string { - b := strings.Builder{} - - b.WriteString("Context Attributes,\n") - - b.WriteString(" specversion: " + ec.SpecVersion + "\n") - b.WriteString(" type: " + ec.Type + "\n") - b.WriteString(" source: " + ec.Source.String() + "\n") - if ec.Subject != nil { - b.WriteString(" subject: " + *ec.Subject + "\n") - } - b.WriteString(" id: " + ec.ID + "\n") - if ec.Time != nil { - b.WriteString(" time: " + ec.Time.String() + "\n") - } - if ec.DataSchema != nil { - b.WriteString(" dataschema: " + ec.DataSchema.String() + "\n") - } - if ec.DataContentType != nil { - b.WriteString(" datacontenttype: " + *ec.DataContentType + "\n") - } - - if ec.Extensions != nil && len(ec.Extensions) > 0 { - b.WriteString("Extensions,\n") - keys := make([]string, 0, len(ec.Extensions)) - for k := range ec.Extensions { - keys = append(keys, k) - } - sort.Strings(keys) - for _, key := range keys { - b.WriteString(fmt.Sprintf(" %s: %v\n", key, ec.Extensions[key])) - } - } - - return b.String() -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v1_reader.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v1_reader.go deleted file mode 100644 index e3f329d31b0..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v1_reader.go +++ /dev/null @@ -1,98 +0,0 @@ -package cloudevents - -import ( - "fmt" - "mime" - "time" -) - -// GetSpecVersion implements EventContextReader.GetSpecVersion -func (ec EventContextV1) GetSpecVersion() string { - if ec.SpecVersion != "" { - return ec.SpecVersion - } - return CloudEventsVersionV03 -} - -// GetDataContentType implements EventContextReader.GetDataContentType -func (ec EventContextV1) GetDataContentType() string { - if ec.DataContentType != nil { - return *ec.DataContentType - } - return "" -} - -// GetDataMediaType implements EventContextReader.GetDataMediaType -func (ec EventContextV1) GetDataMediaType() (string, error) { - if ec.DataContentType != nil { - mediaType, _, err := mime.ParseMediaType(*ec.DataContentType) - if err != nil { - return "", err - } - return mediaType, nil - } - return "", nil -} - -// GetType implements EventContextReader.GetType -func (ec EventContextV1) GetType() string { - return ec.Type -} - -// GetSource implements EventContextReader.GetSource -func (ec EventContextV1) GetSource() string { - return ec.Source.String() -} - -// GetSubject implements EventContextReader.GetSubject -func (ec EventContextV1) GetSubject() string { - if ec.Subject != nil { - return *ec.Subject - } - return "" -} - -// GetTime implements EventContextReader.GetTime -func (ec EventContextV1) GetTime() time.Time { - if ec.Time != nil { - return ec.Time.Time - } - return time.Time{} -} - -// GetID implements EventContextReader.GetID -func (ec EventContextV1) GetID() string { - return ec.ID -} - -// GetDataSchema implements EventContextReader.GetDataSchema -func (ec EventContextV1) GetDataSchema() string { - if ec.DataSchema != nil { - return ec.DataSchema.String() - } - return "" -} - -// DeprecatedGetDataContentEncoding implements EventContextReader.DeprecatedGetDataContentEncoding -func (ec EventContextV1) DeprecatedGetDataContentEncoding() string { - return "" -} - -// GetExtensions implements EventContextReader.GetExtensions -func (ec EventContextV1) GetExtensions() map[string]interface{} { - // For now, convert the extensions of v1.0 to the pre-v1.0 style. - ext := make(map[string]interface{}, len(ec.Extensions)) - for k, v := range ec.Extensions { - ext[k] = v - } - return ext -} - -// GetExtension implements EventContextReader.GetExtension -func (ec EventContextV1) GetExtension(key string) (interface{}, error) { - v, ok := caseInsensitiveSearch(key, ec.Extensions) - if !ok { - return "", fmt.Errorf("%q not found", key) - } - return v, nil -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v1_writer.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v1_writer.go deleted file mode 100644 index dc33ba2f6bb..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/eventcontext_v1_writer.go +++ /dev/null @@ -1,102 +0,0 @@ -package cloudevents - -import ( - "errors" - "fmt" - "net/url" - "strings" - "time" - - "github.com/cloudevents/sdk-go/pkg/cloudevents/types" -) - -// 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) - if ct == "" { - ec.DataContentType = nil - } else { - ec.DataContentType = &ct - } - return nil -} - -// SetType implements EventContextWriter.SetType -func (ec *EventContextV1) SetType(t string) error { - t = strings.TrimSpace(t) - ec.Type = t - return nil -} - -// SetSource implements EventContextWriter.SetSource -func (ec *EventContextV1) SetSource(u string) error { - pu, err := url.Parse(u) - if err != nil { - return err - } - ec.Source = types.URIRef{URL: *pu} - return nil -} - -// SetSubject implements EventContextWriter.SetSubject -func (ec *EventContextV1) SetSubject(s string) error { - s = strings.TrimSpace(s) - if s == "" { - ec.Subject = nil - } else { - ec.Subject = &s - } - return nil -} - -// SetID implements EventContextWriter.SetID -func (ec *EventContextV1) SetID(id string) error { - id = strings.TrimSpace(id) - if id == "" { - return errors.New("id is required to be a non-empty string") - } - ec.ID = id - return nil -} - -// SetTime implements EventContextWriter.SetTime -func (ec *EventContextV1) SetTime(t time.Time) error { - if t.IsZero() { - ec.Time = nil - } else { - ec.Time = &types.Timestamp{Time: t} - } - return nil -} - -// SetDataSchema implements EventContextWriter.SetDataSchema -func (ec *EventContextV1) SetDataSchema(u string) error { - u = strings.TrimSpace(u) - if u == "" { - ec.DataSchema = nil - return nil - } - pu, err := url.Parse(u) - if err != nil { - return err - } - ec.DataSchema = &types.URI{URL: *pu} - return nil -} - -// DeprecatedSetDataContentEncoding implements EventContextWriter.DeprecatedSetDataContentEncoding -func (ec *EventContextV1) DeprecatedSetDataContentEncoding(e string) error { - return errors.New("deprecated: SetDataContentEncoding is not supported in v1.0 of CloudEvents") -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/extensions.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/extensions.go deleted file mode 100644 index e6a7d5325c0..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/extensions.go +++ /dev/null @@ -1,30 +0,0 @@ -package cloudevents - -import ( - "regexp" - "strings" -) - -const ( - // DataContentEncodingKey is the key to DeprecatedDataContentEncoding for versions that do not support data content encoding - // directly. - DataContentEncodingKey = "datacontentencoding" - - // EventTypeVersionKey is the key to EventTypeVersion for versions that do not support event type version directly. - EventTypeVersionKey = "eventtypeversion" - - // SubjectKey is the key to Subject for versions that do not support subject directly. - SubjectKey = "subject" -) - -func caseInsensitiveSearch(key string, space map[string]interface{}) (interface{}, bool) { - lkey := strings.ToLower(key) - for k, v := range space { - if strings.EqualFold(lkey, strings.ToLower(k)) { - return v, true - } - } - return nil, false -} - -var IsAlphaNumeric = regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/extensions/distributed_tracing_extension.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/extensions/distributed_tracing_extension.go deleted file mode 100644 index 2015c5449f0..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/extensions/distributed_tracing_extension.go +++ /dev/null @@ -1,135 +0,0 @@ -package extensions - -import ( - "context" - "reflect" - "strings" - - "github.com/cloudevents/sdk-go/pkg/cloudevents" - "github.com/cloudevents/sdk-go/pkg/cloudevents/types" - "github.com/lightstep/tracecontext.go/traceparent" - "github.com/lightstep/tracecontext.go/tracestate" - "go.opencensus.io/trace" - octs "go.opencensus.io/trace/tracestate" -) - -const ( - TraceParentExtension = "traceparent" - TraceStateExtension = "tracestate" -) - -// EventTracer interface allows setting extension for cloudevents context. -type EventTracer interface { - SetExtension(k string, v interface{}) error -} - -// DistributedTracingExtension represents the extension for cloudevents context -type DistributedTracingExtension struct { - TraceParent string `json:"traceparent"` - TraceState string `json:"tracestate"` -} - -// AddTracingAttributes adds the tracing attributes traceparent and tracestate to the cloudevents context -func (d DistributedTracingExtension) AddTracingAttributes(ec EventTracer) error { - if d.TraceParent != "" { - value := reflect.ValueOf(d) - typeOf := value.Type() - - for i := 0; i < value.NumField(); i++ { - k := strings.ToLower(typeOf.Field(i).Name) - v := value.Field(i).Interface() - if k == TraceStateExtension && v == "" { - continue - } - if err := ec.SetExtension(k, v); err != nil { - return err - } - } - } - return nil -} - -func GetDistributedTracingExtension(event cloudevents.Event) (DistributedTracingExtension, bool) { - if tp, ok := event.Extensions()[TraceParentExtension]; ok { - if tpStr, err := types.ToString(tp); err == nil { - var tsStr string - if ts, ok := event.Extensions()[TraceStateExtension]; ok { - tsStr, _ = types.ToString(ts) - } - return DistributedTracingExtension{TraceParent: tpStr, TraceState: tsStr}, true - } - } - return DistributedTracingExtension{}, false -} - -// FromSpanContext populates DistributedTracingExtension from a SpanContext. -func FromSpanContext(sc trace.SpanContext) DistributedTracingExtension { - tp := traceparent.TraceParent{ - TraceID: sc.TraceID, - SpanID: sc.SpanID, - Flags: traceparent.Flags{ - Recorded: sc.IsSampled(), - }, - } - - entries := make([]string, 0, len(sc.Tracestate.Entries())) - for _, entry := range sc.Tracestate.Entries() { - entries = append(entries, strings.Join([]string{entry.Key, entry.Value}, "=")) - } - - return DistributedTracingExtension{ - TraceParent: tp.String(), - TraceState: strings.Join(entries, ","), - } -} - -// ToSpanContext creates a SpanContext from a DistributedTracingExtension instance. -func (d DistributedTracingExtension) ToSpanContext() (trace.SpanContext, error) { - tp, err := traceparent.ParseString(d.TraceParent) - if err != nil { - return trace.SpanContext{}, err - } - sc := trace.SpanContext{ - TraceID: tp.TraceID, - SpanID: tp.SpanID, - } - if tp.Flags.Recorded { - sc.TraceOptions |= 1 - } - - if ts, err := tracestate.ParseString(d.TraceState); err == nil { - entries := make([]octs.Entry, 0, len(ts)) - for _, member := range ts { - var key string - if member.Tenant != "" { - // Due to github.com/lightstep/tracecontext.go/issues/6, - // the meaning of Vendor and Tenant are swapped here. - key = member.Vendor + "@" + member.Tenant - } else { - key = member.Vendor - } - entries = append(entries, octs.Entry{Key: key, Value: member.Value}) - } - sc.Tracestate, _ = octs.New(nil, entries...) - } - - return sc, nil -} - -func (d DistributedTracingExtension) StartChildSpan(ctx context.Context, name string, opts ...trace.StartOption) (context.Context, *trace.Span) { - if sc, err := d.ToSpanContext(); err == nil { - tSpan := trace.FromContext(ctx) - ctx, span := trace.StartSpanWithRemoteParent(ctx, name, sc, opts...) - if tSpan != nil { - // Add link to the previous in-process trace. - tsc := tSpan.SpanContext() - span.AddLink(trace.Link{ - TraceID: tsc.TraceID, - SpanID: tsc.SpanID, - Type: trace.LinkTypeParent, - }) - } - return ctx, span - } - return ctx, nil -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/observability/doc.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/observability/doc.go deleted file mode 100644 index 3067ebe7e5d..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/observability/doc.go +++ /dev/null @@ -1,4 +0,0 @@ -/* -Package observability holds metrics and tracing recording implementations. -*/ -package observability diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/observability/keys.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/observability/keys.go deleted file mode 100644 index f032b10ecf7..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/observability/keys.go +++ /dev/null @@ -1,19 +0,0 @@ -package observability - -import ( - "go.opencensus.io/tag" -) - -var ( - // KeyMethod is the tag used for marking method on a metric. - KeyMethod, _ = tag.NewKey("method") - // KeyResult is the tag used for marking result on a metric. - KeyResult, _ = tag.NewKey("result") -) - -const ( - // ResultError is a shared result tag value for error. - ResultError = "error" - // ResultOK is a shared result tag value for success. - ResultOK = "success" -) diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/observability/observer.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/observability/observer.go deleted file mode 100644 index b27ffa97357..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/observability/observer.go +++ /dev/null @@ -1,87 +0,0 @@ -package observability - -import ( - "context" - "sync" - "time" - - "go.opencensus.io/stats" - "go.opencensus.io/tag" -) - -// Observable represents the the customization used by the Reporter for a given -// measurement and trace for a single method. -type Observable interface { - MethodName() string - LatencyMs() *stats.Float64Measure -} - -// Reporter represents a running latency counter. When Error or OK are -// called, the latency is calculated. Error or OK are only allowed to -// be called once. -type Reporter interface { - Error() - OK() -} - -type reporter struct { - ctx context.Context - on Observable - start time.Time - once sync.Once -} - -// All tags used for Latency measurements. -func LatencyTags() []tag.Key { - return []tag.Key{KeyMethod, KeyResult} -} - -// Deprecated. Tracing is always enabled. -func EnableTracing(enabled bool) {} - -// NewReporter creates and returns a reporter wrapping the provided Observable. -func NewReporter(ctx context.Context, on Observable) (context.Context, Reporter) { - r := &reporter{ - ctx: ctx, - on: on, - start: time.Now(), - } - r.tagMethod() - return ctx, r -} - -func (r *reporter) tagMethod() { - var err error - r.ctx, err = tag.New(r.ctx, tag.Insert(KeyMethod, r.on.MethodName())) - if err != nil { - panic(err) // or ignore? - } -} - -func (r *reporter) record() { - ms := float64(time.Since(r.start) / time.Millisecond) - stats.Record(r.ctx, r.on.LatencyMs().M(ms)) -} - -// Error records the result as an error. -func (r *reporter) Error() { - r.once.Do(func() { - r.result(ResultError) - }) -} - -// OK records the result as a success. -func (r *reporter) OK() { - r.once.Do(func() { - r.result(ResultOK) - }) -} - -func (r *reporter) result(v string) { - var err error - r.ctx, err = tag.New(r.ctx, tag.Insert(KeyResult, v)) - if err != nil { - panic(err) // or ignore? - } - r.record() -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/codec.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/codec.go deleted file mode 100644 index 091064c9155..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/codec.go +++ /dev/null @@ -1,35 +0,0 @@ -package transport - -import ( - "context" - "fmt" - - "github.com/cloudevents/sdk-go/pkg/cloudevents" -) - -// Codec is the interface for transport codecs to convert between transport -// specific payloads and the Message interface. -type Codec interface { - Encode(context.Context, cloudevents.Event) (Message, error) - Decode(context.Context, Message) (*cloudevents.Event, error) -} - -// ErrMessageEncodingUnknown is an error produced when the encoding for an incoming -// message can not be understood. -type ErrMessageEncodingUnknown struct { - codec string - transport string -} - -// NewErrMessageEncodingUnknown makes a new ErrMessageEncodingUnknown. -func NewErrMessageEncodingUnknown(codec, transport string) *ErrMessageEncodingUnknown { - return &ErrMessageEncodingUnknown{ - codec: codec, - transport: transport, - } -} - -// Error implements error.Error -func (e *ErrMessageEncodingUnknown) Error() string { - return fmt.Sprintf("message encoding unknown for %s codec on %s transport", e.codec, e.transport) -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/doc.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/doc.go deleted file mode 100644 index c2cbadde0d2..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/doc.go +++ /dev/null @@ -1,12 +0,0 @@ -/* - -Package transport defines interfaces to decouple the client package -from transport implementations. - -Most event sender and receiver applications should not use this -package, they should use the client package. This package is for -infrastructure developers implementing new transports, or intermediary -components like importers, channels or brokers. - -*/ -package transport diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/error.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/error.go deleted file mode 100644 index bb4e8ec9f82..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/error.go +++ /dev/null @@ -1,37 +0,0 @@ -package transport - -import "fmt" - -// ErrTransportMessageConversion is an error produced when the transport -// message can not be converted. -type ErrTransportMessageConversion struct { - fatal bool - handled bool - transport string - message string -} - -// NewErrMessageEncodingUnknown makes a new ErrMessageEncodingUnknown. -func NewErrTransportMessageConversion(transport, message string, handled, fatal bool) *ErrTransportMessageConversion { - return &ErrTransportMessageConversion{ - transport: transport, - message: message, - handled: handled, - fatal: fatal, - } -} - -// IsFatal reports if this error should be considered fatal. -func (e *ErrTransportMessageConversion) IsFatal() bool { - return e.fatal -} - -// Handled reports if this error should be considered accepted and no further action. -func (e *ErrTransportMessageConversion) Handled() bool { - return e.handled -} - -// Error implements error.Error -func (e *ErrTransportMessageConversion) Error() string { - return fmt.Sprintf("transport %s failed to convert message: %s", e.transport, e.message) -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec.go deleted file mode 100644 index 05b8cdb1564..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec.go +++ /dev/null @@ -1,152 +0,0 @@ -package http - -import ( - "context" - "errors" - "fmt" - "sync" - - "github.com/cloudevents/sdk-go/pkg/cloudevents" - cecontext "github.com/cloudevents/sdk-go/pkg/cloudevents/context" - "github.com/cloudevents/sdk-go/pkg/cloudevents/transport" -) - -// Codec is the wrapper for all versions of codecs supported by the http -// transport. -type Codec struct { - // Encoding is the setting to inform the DefaultEncodingSelectionFn for - // selecting a codec. - Encoding Encoding - - // DefaultEncodingSelectionFn allows for encoding selection strategies to be injected. - DefaultEncodingSelectionFn EncodingSelector - - v01 *CodecV01 - v02 *CodecV02 - v03 *CodecV03 - v1 *CodecV1 - - _v01 sync.Once - _v02 sync.Once - _v03 sync.Once - _v1 sync.Once -} - -// Adheres to Codec -var _ transport.Codec = (*Codec)(nil) - -func (c *Codec) loadCodec(encoding Encoding) (transport.Codec, error) { - switch encoding { - case BinaryV01, StructuredV01: - c._v01.Do(func() { - c.v01 = &CodecV01{DefaultEncoding: c.Encoding} - }) - return c.v01, nil - case BinaryV02, StructuredV02: - c._v02.Do(func() { - c.v02 = &CodecV02{DefaultEncoding: c.Encoding} - }) - return c.v02, nil - case BinaryV03, StructuredV03, BatchedV03: - c._v03.Do(func() { - c.v03 = &CodecV03{DefaultEncoding: c.Encoding} - }) - return c.v03, nil - case BinaryV1, StructuredV1, BatchedV1, Default: - c._v1.Do(func() { - c.v1 = &CodecV1{DefaultEncoding: c.Encoding} - }) - return c.v1, nil - } - return nil, fmt.Errorf("unknown encoding: %s", encoding) -} - -// Encode encodes the provided event into a transport message. -func (c *Codec) Encode(ctx context.Context, e cloudevents.Event) (transport.Message, error) { - encoding := c.Encoding - if encoding == Default && c.DefaultEncodingSelectionFn != nil { - encoding = c.DefaultEncodingSelectionFn(ctx, e) - } - codec, err := c.loadCodec(encoding) - if err != nil { - return nil, err - } - ctx = cecontext.WithEncoding(ctx, encoding.Name()) - return codec.Encode(ctx, e) -} - -// Decode converts a provided transport message into an Event, or error. -func (c *Codec) Decode(ctx context.Context, msg transport.Message) (*cloudevents.Event, error) { - codec, err := c.loadCodec(c.inspectEncoding(ctx, msg)) - if err != nil { - return nil, err - } - event, err := codec.Decode(ctx, msg) - if err != nil { - return nil, err - } - return c.convertEvent(event) -} - -// Give the context back as the user expects -func (c *Codec) convertEvent(event *cloudevents.Event) (*cloudevents.Event, error) { - if event == nil { - return nil, errors.New("event is nil, can not convert") - } - - switch c.Encoding { - case Default: - return event, nil - case BinaryV01, StructuredV01: - ca := event.Context.AsV01() - event.Context = ca - return event, nil - case BinaryV02, StructuredV02: - ca := event.Context.AsV02() - event.Context = ca - return event, nil - case BinaryV03, StructuredV03, BatchedV03: - ca := event.Context.AsV03() - event.Context = ca - return event, nil - case BinaryV1, StructuredV1, BatchedV1: - ca := event.Context.AsV1() - event.Context = ca - return event, nil - default: - return nil, fmt.Errorf("unknown encoding: %s", c.Encoding) - } -} - -func (c *Codec) inspectEncoding(ctx context.Context, msg transport.Message) Encoding { - // Try v1.0. - _, _ = c.loadCodec(BinaryV1) - encoding := c.v1.inspectEncoding(ctx, msg) - if encoding != Unknown { - return encoding - } - - // Try v0.3. - _, _ = c.loadCodec(BinaryV03) - encoding = c.v03.inspectEncoding(ctx, msg) - if encoding != Unknown { - return encoding - } - - // Try v0.2. - _, _ = c.loadCodec(BinaryV02) - encoding = c.v02.inspectEncoding(ctx, msg) - if encoding != Unknown { - return encoding - } - - // Try v0.1 first. - _, _ = c.loadCodec(BinaryV01) - encoding = c.v01.inspectEncoding(ctx, msg) - if encoding != Unknown { - return encoding - } - - // We do not understand the message encoding. - return Unknown -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec_structured.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec_structured.go deleted file mode 100644 index d67d7186ee6..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec_structured.go +++ /dev/null @@ -1,44 +0,0 @@ -package http - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/cloudevents/sdk-go/pkg/cloudevents" - "github.com/cloudevents/sdk-go/pkg/cloudevents/transport" -) - -// CodecStructured represents an structured http transport codec for all versions. -// Intended to be used as a base class. -type CodecStructured struct { - DefaultEncoding Encoding -} - -func (v CodecStructured) encodeStructured(ctx context.Context, e cloudevents.Event) (transport.Message, error) { - header := http.Header{} - header.Set("Content-Type", cloudevents.ApplicationCloudEventsJSON) - - body, err := json.Marshal(e) - if err != nil { - return nil, err - } - - msg := &Message{ - Header: header, - Body: body, - } - - return msg, nil -} - -func (v CodecStructured) decodeStructured(ctx context.Context, version string, msg transport.Message) (*cloudevents.Event, error) { - m, ok := msg.(*Message) - if !ok { - return nil, fmt.Errorf("failed to convert transport.Message to http.Message") - } - event := cloudevents.New(version) - err := json.Unmarshal(m.Body, &event) - return &event, err -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec_v01.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec_v01.go deleted file mode 100644 index 435ba93fb5d..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec_v01.go +++ /dev/null @@ -1,232 +0,0 @@ -package http - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/textproto" - "strings" - - "github.com/cloudevents/sdk-go/pkg/cloudevents" - cecontext "github.com/cloudevents/sdk-go/pkg/cloudevents/context" - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" - "github.com/cloudevents/sdk-go/pkg/cloudevents/transport" - "github.com/cloudevents/sdk-go/pkg/cloudevents/types" -) - -// CodecV01 represents a http transport codec that uses CloudEvents spec v0.1 -type CodecV01 struct { - CodecStructured - - DefaultEncoding Encoding -} - -// Adheres to Codec -var _ transport.Codec = (*CodecV01)(nil) - -// Encode implements Codec.Encode -func (v CodecV01) Encode(ctx context.Context, e cloudevents.Event) (transport.Message, error) { - encoding := v.DefaultEncoding - strEnc := cecontext.EncodingFrom(ctx) - if strEnc != "" { - switch strEnc { - case Binary: - encoding = BinaryV01 - case Structured: - encoding = StructuredV01 - } - } - - _, r := observability.NewReporter(context.Background(), CodecObserved{o: reportEncode, c: encoding.Codec()}) - m, err := v.obsEncode(ctx, e, encoding) - if err != nil { - r.Error() - } else { - r.OK() - } - return m, err -} - -func (v CodecV01) obsEncode(ctx context.Context, e cloudevents.Event, encoding Encoding) (transport.Message, error) { - switch encoding { - case Default: - fallthrough - case BinaryV01: - return v.encodeBinary(ctx, e) - case StructuredV01: - return v.encodeStructured(ctx, e) - default: - return nil, fmt.Errorf("unknown encoding: %d", encoding) - } -} - -// Decode implements Codec.Decode -func (v CodecV01) Decode(ctx context.Context, msg transport.Message) (*cloudevents.Event, error) { - _, r := observability.NewReporter(ctx, CodecObserved{o: reportDecode, c: v.inspectEncoding(ctx, msg).Codec()}) // TODO: inspectEncoding is not free. - e, err := v.obsDecode(ctx, msg) - if err != nil { - r.Error() - } else { - r.OK() - } - return e, err -} - -func (v CodecV01) obsDecode(ctx context.Context, msg transport.Message) (*cloudevents.Event, error) { - switch v.inspectEncoding(ctx, msg) { - case BinaryV01: - return v.decodeBinary(ctx, msg) - case StructuredV01: - return v.decodeStructured(ctx, cloudevents.CloudEventsVersionV01, msg) - default: - return nil, transport.NewErrMessageEncodingUnknown("v01", TransportName) - } -} - -func (v CodecV01) encodeBinary(ctx context.Context, e cloudevents.Event) (transport.Message, error) { - header, err := v.toHeaders(e.Context.AsV01()) - if err != nil { - return nil, err - } - - body, err := e.DataBytes() - if err != nil { - panic("encode") - } - - msg := &Message{ - Header: header, - Body: body, - } - - return msg, nil -} - -func (v CodecV01) toHeaders(ec *cloudevents.EventContextV01) (http.Header, error) { - // Preserve case in v0.1, even though HTTP headers are case-insensitive. - h := http.Header{} - h["CE-CloudEventsVersion"] = []string{ec.CloudEventsVersion} - h["CE-EventID"] = []string{ec.EventID} - h["CE-EventType"] = []string{ec.EventType} - h["CE-Source"] = []string{ec.Source.String()} - if ec.EventTime != nil && !ec.EventTime.IsZero() { - h["CE-EventTime"] = []string{ec.EventTime.String()} - } - if ec.EventTypeVersion != nil { - h["CE-EventTypeVersion"] = []string{*ec.EventTypeVersion} - } - if ec.SchemaURL != nil { - h["CE-DataSchema"] = []string{ec.SchemaURL.String()} - } - if ec.ContentType != nil && *ec.ContentType != "" { - h.Set("Content-Type", *ec.ContentType) - } - - // Regarding Extensions, v0.1 Spec says the following: - // * Each map entry name MUST be prefixed with "CE-X-" - // * Each map entry name's first character MUST be capitalized - for k, v := range ec.Extensions { - encoded, err := json.Marshal(v) - if err != nil { - return nil, err - } - h["CE-X-"+strings.Title(k)] = []string{string(encoded)} - } - return h, nil -} - -func (v CodecV01) decodeBinary(ctx context.Context, msg transport.Message) (*cloudevents.Event, error) { - m, ok := msg.(*Message) - if !ok { - return nil, fmt.Errorf("failed to convert transport.Message to http.Message") - } - ca, err := v.fromHeaders(m.Header) - if err != nil { - return nil, err - } - var body interface{} - if len(m.Body) > 0 { - body = m.Body - } - return &cloudevents.Event{ - Context: &ca, - Data: body, - DataEncoded: body != nil, - }, nil -} - -func (v CodecV01) fromHeaders(h http.Header) (cloudevents.EventContextV01, error) { - // Normalize headers. - for k, v := range h { - ck := textproto.CanonicalMIMEHeaderKey(k) - if k != ck { - h[ck] = v - } - } - - ec := cloudevents.EventContextV01{} - ec.CloudEventsVersion = h.Get("CE-CloudEventsVersion") - h.Del("CE-CloudEventsVersion") - ec.EventID = h.Get("CE-EventID") - h.Del("CE-EventID") - ec.EventType = h.Get("CE-EventType") - h.Del("CE-EventType") - source := types.ParseURLRef(h.Get("CE-Source")) - h.Del("CE-Source") - if source != nil { - ec.Source = *source - } - var err error - ec.EventTime, err = types.ParseTimestamp(h.Get("CE-EventTime")) - if err != nil { - return ec, err - } - h.Del("CE-EventTime") - etv := h.Get("CE-EventTypeVersion") - h.Del("CE-EventTypeVersion") - if etv != "" { - ec.EventTypeVersion = &etv - } - ec.SchemaURL = types.ParseURLRef(h.Get("CE-DataSchema")) - h.Del("CE-DataSchema") - et := h.Get("Content-Type") - if et != "" { - ec.ContentType = &et - } - - extensions := make(map[string]interface{}) - for k, v := range h { - if len(k) > len("CE-X-") && strings.EqualFold(k[:len("CE-X-")], "CE-X-") { - key := k[len("CE-X-"):] - var tmp interface{} - if err := json.Unmarshal([]byte(v[0]), &tmp); err == nil { - extensions[key] = tmp - } else { - // If we can't unmarshal the data, treat it as a string. - extensions[key] = v[0] - } - h.Del(k) - } - } - if len(extensions) > 0 { - ec.Extensions = extensions - } - return ec, nil -} - -func (v CodecV01) inspectEncoding(ctx context.Context, msg transport.Message) Encoding { - version := msg.CloudEventsVersion() - if version != cloudevents.CloudEventsVersionV01 { - return Unknown - } - m, ok := msg.(*Message) - if !ok { - return Unknown - } - contentType := m.Header.Get("Content-Type") - if contentType == cloudevents.ApplicationCloudEventsJSON { - return StructuredV01 - } - return BinaryV01 -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec_v02.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec_v02.go deleted file mode 100644 index aeb67c0e8c0..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec_v02.go +++ /dev/null @@ -1,261 +0,0 @@ -package http - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/textproto" - "strings" - - "github.com/cloudevents/sdk-go/pkg/cloudevents" - cecontext "github.com/cloudevents/sdk-go/pkg/cloudevents/context" - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" - "github.com/cloudevents/sdk-go/pkg/cloudevents/transport" - "github.com/cloudevents/sdk-go/pkg/cloudevents/types" -) - -// CodecV02 represents a http transport codec that uses CloudEvents spec v0.2 -type CodecV02 struct { - CodecStructured - - DefaultEncoding Encoding -} - -// Adheres to Codec -var _ transport.Codec = (*CodecV02)(nil) - -// Encode implements Codec.Encode -func (v CodecV02) Encode(ctx context.Context, e cloudevents.Event) (transport.Message, error) { - encoding := v.DefaultEncoding - strEnc := cecontext.EncodingFrom(ctx) - if strEnc != "" { - switch strEnc { - case Binary: - encoding = BinaryV02 - case Structured: - encoding = StructuredV02 - } - } - - _, r := observability.NewReporter(ctx, CodecObserved{o: reportEncode, c: encoding.Codec()}) - m, err := v.obsEncode(ctx, e, encoding) - if err != nil { - r.Error() - } else { - r.OK() - } - return m, err -} - -func (v CodecV02) obsEncode(ctx context.Context, e cloudevents.Event, encoding Encoding) (transport.Message, error) { - switch encoding { - case Default: - fallthrough - case BinaryV02: - return v.encodeBinary(ctx, e) - case StructuredV02: - return v.encodeStructured(ctx, e) - default: - return nil, fmt.Errorf("unknown encoding: %d", encoding) - } -} - -// Decode implements Codec.Decode -func (v CodecV02) Decode(ctx context.Context, msg transport.Message) (*cloudevents.Event, error) { - _, r := observability.NewReporter(ctx, CodecObserved{o: reportDecode, c: v.inspectEncoding(ctx, msg).Codec()}) // TODO: inspectEncoding is not free. - e, err := v.obsDecode(ctx, msg) - if err != nil { - r.Error() - } else { - r.OK() - } - return e, err -} - -func (v CodecV02) obsDecode(ctx context.Context, msg transport.Message) (*cloudevents.Event, error) { - switch v.inspectEncoding(ctx, msg) { - case BinaryV02: - return v.decodeBinary(ctx, msg) - case StructuredV02: - return v.decodeStructured(ctx, cloudevents.CloudEventsVersionV02, msg) - default: - return nil, transport.NewErrMessageEncodingUnknown("v02", TransportName) - } -} - -func (v CodecV02) encodeBinary(ctx context.Context, e cloudevents.Event) (transport.Message, error) { - header, err := v.toHeaders(e.Context.AsV02()) - if err != nil { - return nil, err - } - body, err := e.DataBytes() - if err != nil { - return nil, err - } - - msg := &Message{ - Header: header, - Body: body, - } - - return msg, nil -} - -func (v CodecV02) toHeaders(ec *cloudevents.EventContextV02) (http.Header, error) { - h := http.Header{} - h.Set("ce-specversion", ec.SpecVersion) - h.Set("ce-type", ec.Type) - h.Set("ce-source", ec.Source.String()) - h.Set("ce-id", ec.ID) - if ec.Time != nil && !ec.Time.IsZero() { - h.Set("ce-time", ec.Time.String()) - } - if ec.SchemaURL != nil { - h.Set("ce-schemaurl", ec.SchemaURL.String()) - } - if ec.ContentType != nil && *ec.ContentType != "" { - h.Set("Content-Type", *ec.ContentType) - } - for k, v := range ec.Extensions { - // Per spec, map-valued extensions are converted to a list of headers as: - // CE-attrib-key - if mapVal, ok := v.(map[string]interface{}); ok { - for subkey, subval := range mapVal { - encoded, err := json.Marshal(subval) - if err != nil { - return nil, err - } - h.Set("ce-"+k+"-"+subkey, string(encoded)) - } - continue - } - encoded, err := json.Marshal(v) - if err != nil { - return nil, err - } - h.Set("ce-"+k, string(encoded)) - } - - return h, nil -} - -func (v CodecV02) decodeBinary(ctx context.Context, msg transport.Message) (*cloudevents.Event, error) { - m, ok := msg.(*Message) - if !ok { - return nil, fmt.Errorf("failed to convert transport.Message to http.Message") - } - ca, err := v.fromHeaders(m.Header) - if err != nil { - return nil, err - } - var body interface{} - if len(m.Body) > 0 { - body = m.Body - } - return &cloudevents.Event{ - Context: &ca, - Data: body, - DataEncoded: body != nil, - }, nil -} - -func (v CodecV02) fromHeaders(h http.Header) (cloudevents.EventContextV02, error) { - // Normalize headers. - for k, v := range h { - ck := textproto.CanonicalMIMEHeaderKey(k) - if k != ck { - delete(h, k) - h[ck] = v - } - } - - ec := cloudevents.EventContextV02{} - - ec.SpecVersion = h.Get("ce-specversion") - h.Del("ce-specversion") - - ec.ID = h.Get("ce-id") - h.Del("ce-id") - - ec.Type = h.Get("ce-type") - h.Del("ce-type") - - source := types.ParseURLRef(h.Get("ce-source")) - if source != nil { - ec.Source = *source - } - h.Del("ce-source") - - var err error - ec.Time, err = types.ParseTimestamp(h.Get("ce-time")) - if err != nil { - return ec, err - } - h.Del("ce-time") - - ec.SchemaURL = types.ParseURLRef(h.Get("ce-schemaurl")) - h.Del("ce-schemaurl") - - contentType := h.Get("Content-Type") - if contentType != "" { - ec.ContentType = &contentType - } - h.Del("Content-Type") - - // At this point, we have deleted all the known headers. - // Everything left is assumed to be an extension. - - extensions := make(map[string]interface{}) - for k, v := range h { - if len(k) > len("ce-") && strings.EqualFold(k[:len("ce-")], "ce-") { - ak := strings.ToLower(k[len("ce-"):]) - if i := strings.Index(ak, "-"); i > 0 { - // attrib-key - attrib := ak[:i] - key := ak[(i + 1):] - if xv, ok := extensions[attrib]; ok { - if m, ok := xv.(map[string]interface{}); ok { - m[key] = v - continue - } - // TODO: revisit how we want to bubble errors up. - return ec, fmt.Errorf("failed to process map type extension") - } else { - m := make(map[string]interface{}) - m[key] = v - extensions[attrib] = m - } - } else { - // key - var tmp interface{} - if err := json.Unmarshal([]byte(v[0]), &tmp); err == nil { - extensions[ak] = tmp - } else { - // If we can't unmarshal the data, treat it as a string. - extensions[ak] = v[0] - } - } - } - } - if len(extensions) > 0 { - ec.Extensions = extensions - } - return ec, nil -} - -func (v CodecV02) inspectEncoding(ctx context.Context, msg transport.Message) Encoding { - version := msg.CloudEventsVersion() - if version != cloudevents.CloudEventsVersionV02 { - return Unknown - } - m, ok := msg.(*Message) - if !ok { - return Unknown - } - contentType := m.Header.Get("Content-Type") - if contentType == cloudevents.ApplicationCloudEventsJSON { - return StructuredV02 - } - return BinaryV02 -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec_v03.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec_v03.go deleted file mode 100644 index b2b3c87ee9b..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec_v03.go +++ /dev/null @@ -1,302 +0,0 @@ -package http - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/textproto" - "strings" - - "github.com/cloudevents/sdk-go/pkg/cloudevents" - cecontext "github.com/cloudevents/sdk-go/pkg/cloudevents/context" - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" - "github.com/cloudevents/sdk-go/pkg/cloudevents/transport" - "github.com/cloudevents/sdk-go/pkg/cloudevents/types" -) - -// CodecV03 represents a http transport codec that uses CloudEvents spec v0.3 -type CodecV03 struct { - CodecStructured - - DefaultEncoding Encoding -} - -// Adheres to Codec -var _ transport.Codec = (*CodecV03)(nil) - -// Encode implements Codec.Encode -func (v CodecV03) Encode(ctx context.Context, e cloudevents.Event) (transport.Message, error) { - encoding := v.DefaultEncoding - strEnc := cecontext.EncodingFrom(ctx) - if strEnc != "" { - switch strEnc { - case Binary: - encoding = BinaryV03 - case Structured: - encoding = StructuredV03 - } - } - - _, r := observability.NewReporter(ctx, CodecObserved{o: reportEncode, c: encoding.Codec()}) - m, err := v.obsEncode(ctx, e, encoding) - if err != nil { - r.Error() - } else { - r.OK() - } - return m, err -} - -func (v CodecV03) obsEncode(ctx context.Context, e cloudevents.Event, encoding Encoding) (transport.Message, error) { - switch encoding { - case Default: - fallthrough - case BinaryV03: - return v.encodeBinary(ctx, e) - case StructuredV03: - return v.encodeStructured(ctx, e) - case BatchedV03: - return nil, fmt.Errorf("not implemented") - default: - return nil, fmt.Errorf("unknown encoding: %d", encoding) - } -} - -// Decode implements Codec.Decode -func (v CodecV03) Decode(ctx context.Context, msg transport.Message) (*cloudevents.Event, error) { - _, r := observability.NewReporter(ctx, CodecObserved{o: reportDecode, c: v.inspectEncoding(ctx, msg).Codec()}) // TODO: inspectEncoding is not free. - e, err := v.obsDecode(ctx, msg) - if err != nil { - r.Error() - } else { - r.OK() - } - return e, err -} - -func (v CodecV03) obsDecode(ctx context.Context, msg transport.Message) (*cloudevents.Event, error) { - switch v.inspectEncoding(ctx, msg) { - case BinaryV03: - return v.decodeBinary(ctx, msg) - case StructuredV03: - return v.decodeStructured(ctx, cloudevents.CloudEventsVersionV03, msg) - case BatchedV03: - return nil, fmt.Errorf("not implemented") - default: - return nil, transport.NewErrMessageEncodingUnknown("v03", TransportName) - } -} - -func (v CodecV03) encodeBinary(ctx context.Context, e cloudevents.Event) (transport.Message, error) { - header, err := v.toHeaders(e.Context.AsV03()) - if err != nil { - return nil, err - } - - body, err := e.DataBytes() - if err != nil { - return nil, err - } - - msg := &Message{ - Header: header, - Body: body, - } - - return msg, nil -} - -func (v CodecV03) toHeaders(ec *cloudevents.EventContextV03) (http.Header, error) { - h := http.Header{} - h.Set("ce-specversion", ec.SpecVersion) - h.Set("ce-type", ec.Type) - h.Set("ce-source", ec.Source.String()) - if ec.Subject != nil { - h.Set("ce-subject", *ec.Subject) - } - h.Set("ce-id", ec.ID) - if ec.Time != nil && !ec.Time.IsZero() { - h.Set("ce-time", ec.Time.String()) - } - if ec.SchemaURL != nil { - h.Set("ce-schemaurl", ec.SchemaURL.String()) - } - if ec.DataContentType != nil && *ec.DataContentType != "" { - h.Set("Content-Type", *ec.DataContentType) - } - if ec.DataContentEncoding != nil { - h.Set("ce-datacontentencoding", *ec.DataContentEncoding) - } - - for k, v := range ec.Extensions { - k = strings.ToLower(k) - // Per spec, map-valued extensions are converted to a list of headers as: - // CE-attrib-key - switch v.(type) { - case string: - h.Set("ce-"+k, v.(string)) - - case map[string]interface{}: - mapVal := v.(map[string]interface{}) - - for subkey, subval := range mapVal { - if subvalstr, ok := v.(string); ok { - h.Set("ce-"+k+"-"+subkey, subvalstr) - continue - } - - encoded, err := json.Marshal(subval) - if err != nil { - return nil, err - } - h.Set("ce-"+k+"-"+subkey, string(encoded)) - } - - default: - encoded, err := json.Marshal(v) - if err != nil { - return nil, err - } - h.Set("ce-"+k, string(encoded)) - } - } - - return h, nil -} - -func (v CodecV03) decodeBinary(ctx context.Context, msg transport.Message) (*cloudevents.Event, error) { - m, ok := msg.(*Message) - if !ok { - return nil, fmt.Errorf("failed to convert transport.Message to http.Message") - } - ca, err := v.fromHeaders(m.Header) - if err != nil { - return nil, err - } - var body interface{} - if len(m.Body) > 0 { - body = m.Body - } - return &cloudevents.Event{ - Context: &ca, - Data: body, - DataEncoded: body != nil, - }, nil -} - -func (v CodecV03) fromHeaders(h http.Header) (cloudevents.EventContextV03, error) { - // Normalize headers. - for k, v := range h { - ck := textproto.CanonicalMIMEHeaderKey(k) - if k != ck { - delete(h, k) - h[ck] = v - } - } - - ec := cloudevents.EventContextV03{} - - ec.SpecVersion = h.Get("ce-specversion") - h.Del("ce-specversion") - - ec.ID = h.Get("ce-id") - h.Del("ce-id") - - ec.Type = h.Get("ce-type") - h.Del("ce-type") - - source := types.ParseURLRef(h.Get("ce-source")) - if source != nil { - ec.Source = *source - } - h.Del("ce-source") - - subject := h.Get("ce-subject") - if subject != "" { - ec.Subject = &subject - } - h.Del("ce-subject") - - var err error - ec.Time, err = types.ParseTimestamp(h.Get("ce-time")) - if err != nil { - return ec, err - } - h.Del("ce-time") - - ec.SchemaURL = types.ParseURLRef(h.Get("ce-schemaurl")) - h.Del("ce-schemaurl") - - contentType := h.Get("Content-Type") - if contentType != "" { - ec.DataContentType = &contentType - } - h.Del("Content-Type") - - dataContentEncoding := h.Get("ce-datacontentencoding") - if dataContentEncoding != "" { - ec.DataContentEncoding = &dataContentEncoding - } - h.Del("ce-datacontentencoding") - - // At this point, we have deleted all the known headers. - // Everything left is assumed to be an extension. - - extensions := make(map[string]interface{}) - for k, v := range h { - k = strings.ToLower(k) - if len(k) > len("ce-") && strings.EqualFold(k[:len("ce-")], "ce-") { - ak := strings.ToLower(k[len("ce-"):]) - if i := strings.Index(ak, "-"); i > 0 { - // attrib-key - attrib := ak[:i] - key := ak[(i + 1):] - if xv, ok := extensions[attrib]; ok { - if m, ok := xv.(map[string]interface{}); ok { - m[key] = v - continue - } - // TODO: revisit how we want to bubble errors up. - return ec, fmt.Errorf("failed to process map type extension") - } else { - m := make(map[string]interface{}) - m[key] = v - extensions[attrib] = m - } - } else { - // key - var tmp interface{} - if err := json.Unmarshal([]byte(v[0]), &tmp); err == nil { - extensions[ak] = tmp - } else { - // If we can't unmarshal the data, treat it as a string. - extensions[ak] = v[0] - } - } - } - } - if len(extensions) > 0 { - ec.Extensions = extensions - } - return ec, nil -} - -func (v CodecV03) inspectEncoding(ctx context.Context, msg transport.Message) Encoding { - version := msg.CloudEventsVersion() - if version != cloudevents.CloudEventsVersionV03 { - return Unknown - } - m, ok := msg.(*Message) - if !ok { - return Unknown - } - contentType := m.Header.Get("Content-Type") - if contentType == cloudevents.ApplicationCloudEventsJSON { - return StructuredV03 - } - if contentType == cloudevents.ApplicationCloudEventsBatchJSON { - return BatchedV03 - } - return BinaryV03 -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec_v1.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec_v1.go deleted file mode 100644 index 4ebe7422b07..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/codec_v1.go +++ /dev/null @@ -1,245 +0,0 @@ -package http - -import ( - "context" - "fmt" - "net/http" - "net/textproto" - "strings" - - "github.com/cloudevents/sdk-go/pkg/cloudevents" - cecontext "github.com/cloudevents/sdk-go/pkg/cloudevents/context" - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" - "github.com/cloudevents/sdk-go/pkg/cloudevents/transport" - "github.com/cloudevents/sdk-go/pkg/cloudevents/types" -) - -// CodecV1 represents a http transport codec that uses CloudEvents spec v1.0 -type CodecV1 struct { - CodecStructured - - DefaultEncoding Encoding -} - -// Adheres to Codec -var _ transport.Codec = (*CodecV1)(nil) - -// Encode implements Codec.Encode -func (v CodecV1) Encode(ctx context.Context, e cloudevents.Event) (transport.Message, error) { - encoding := v.DefaultEncoding - strEnc := cecontext.EncodingFrom(ctx) - if strEnc != "" { - switch strEnc { - case Binary: - encoding = BinaryV1 - case Structured: - encoding = StructuredV1 - } - } - - _, r := observability.NewReporter(ctx, CodecObserved{o: reportEncode, c: encoding.Codec()}) - m, err := v.obsEncode(ctx, e, encoding) - if err != nil { - r.Error() - } else { - r.OK() - } - return m, err -} - -func (v CodecV1) obsEncode(ctx context.Context, e cloudevents.Event, encoding Encoding) (transport.Message, error) { - switch encoding { - case Default: - fallthrough - case BinaryV1: - return v.encodeBinary(ctx, e) - case StructuredV1: - return v.encodeStructured(ctx, e) - case BatchedV1: - return nil, fmt.Errorf("not implemented") - default: - return nil, fmt.Errorf("unknown encoding: %d", encoding) - } -} - -// Decode implements Codec.Decode -func (v CodecV1) Decode(ctx context.Context, msg transport.Message) (*cloudevents.Event, error) { - _, r := observability.NewReporter(ctx, CodecObserved{o: reportDecode, c: v.inspectEncoding(ctx, msg).Codec()}) // TODO: inspectEncoding is not free. - e, err := v.obsDecode(ctx, msg) - if err != nil { - r.Error() - } else { - r.OK() - } - return e, err -} - -func (v CodecV1) obsDecode(ctx context.Context, msg transport.Message) (*cloudevents.Event, error) { - switch v.inspectEncoding(ctx, msg) { - case BinaryV1: - return v.decodeBinary(ctx, msg) - case StructuredV1: - return v.decodeStructured(ctx, cloudevents.CloudEventsVersionV1, msg) - case BatchedV1: - return nil, fmt.Errorf("not implemented") - default: - return nil, transport.NewErrMessageEncodingUnknown("V1", TransportName) - } -} - -func (v CodecV1) encodeBinary(ctx context.Context, e cloudevents.Event) (transport.Message, error) { - header, err := v.toHeaders(e.Context.AsV1()) - if err != nil { - return nil, err - } - - body, err := e.DataBytes() - if err != nil { - return nil, err - } - - msg := &Message{ - Header: header, - Body: body, - } - - return msg, nil -} - -func (v CodecV1) toHeaders(ec *cloudevents.EventContextV1) (http.Header, error) { - h := http.Header{} - h.Set("ce-specversion", ec.SpecVersion) - h.Set("ce-type", ec.Type) - h.Set("ce-source", ec.Source.String()) - if ec.Subject != nil { - h.Set("ce-subject", *ec.Subject) - } - h.Set("ce-id", ec.ID) - if ec.Time != nil && !ec.Time.IsZero() { - h.Set("ce-time", ec.Time.String()) - } - if ec.DataSchema != nil { - h.Set("ce-dataschema", ec.DataSchema.String()) - } - if ec.DataContentType != nil && *ec.DataContentType != "" { - h.Set("Content-Type", *ec.DataContentType) - } - - for k, v := range ec.Extensions { - k = strings.ToLower(k) - // Per spec, extensions are strings and converted to a list of headers as: - // ce-key: value - cstr, err := types.Format(v) - if err != nil { - return h, err - } - h.Set("ce-"+k, cstr) - } - - return h, nil -} - -func (v CodecV1) decodeBinary(ctx context.Context, msg transport.Message) (*cloudevents.Event, error) { - m, ok := msg.(*Message) - if !ok { - return nil, fmt.Errorf("failed to convert transport.Message to http.Message") - } - ca, err := v.fromHeaders(m.Header) - if err != nil { - return nil, err - } - var body interface{} - if len(m.Body) > 0 { - body = m.Body - } - return &cloudevents.Event{ - Context: &ca, - Data: body, - DataEncoded: body != nil, - }, nil -} - -func (v CodecV1) fromHeaders(h http.Header) (cloudevents.EventContextV1, error) { - // Normalize headers. - for k, v := range h { - ck := textproto.CanonicalMIMEHeaderKey(k) - if k != ck { - delete(h, k) - h[ck] = v - } - } - - ec := cloudevents.EventContextV1{} - - ec.SpecVersion = h.Get("ce-specversion") - h.Del("ce-specversion") - - ec.ID = h.Get("ce-id") - h.Del("ce-id") - - ec.Type = h.Get("ce-type") - h.Del("ce-type") - - source := types.ParseURIRef(h.Get("ce-source")) - if source != nil { - ec.Source = *source - } - h.Del("ce-source") - - subject := h.Get("ce-subject") - if subject != "" { - ec.Subject = &subject - } - h.Del("ce-subject") - - var err error - ec.Time, err = types.ParseTimestamp(h.Get("ce-time")) - if err != nil { - return ec, err - } - h.Del("ce-time") - - ec.DataSchema = types.ParseURI(h.Get("ce-dataschema")) - h.Del("ce-dataschema") - - contentType := h.Get("Content-Type") - if contentType != "" { - ec.DataContentType = &contentType - } - h.Del("Content-Type") - - // At this point, we have deleted all the known headers. - // Everything left is assumed to be an extension. - - extensions := make(map[string]interface{}) - for k := range h { - k = strings.ToLower(k) - if len(k) > len("ce-") && strings.EqualFold(k[:len("ce-")], "ce-") { - ak := strings.ToLower(k[len("ce-"):]) - extensions[ak] = h.Get(k) - } - } - if len(extensions) > 0 { - ec.Extensions = extensions - } - return ec, nil -} - -func (v CodecV1) inspectEncoding(ctx context.Context, msg transport.Message) Encoding { - version := msg.CloudEventsVersion() - if version != cloudevents.CloudEventsVersionV1 { - return Unknown - } - m, ok := msg.(*Message) - if !ok { - return Unknown - } - contentType := m.Header.Get("Content-Type") - if contentType == cloudevents.ApplicationCloudEventsJSON { - return StructuredV1 - } - if contentType == cloudevents.ApplicationCloudEventsBatchJSON { - return BatchedV1 - } - return BinaryV1 -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/context.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/context.go deleted file mode 100644 index 8e3c7b44e11..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/context.go +++ /dev/null @@ -1,212 +0,0 @@ -package http - -import ( - "context" - "fmt" - "net/http" - "net/url" - "strconv" - "strings" -) - -// TransportContext allows a Receiver to understand the context of a request. -type TransportContext struct { - URI string - Host string - Method string - Header http.Header - StatusCode int - - // IgnoreHeaderPrefixes controls what comes back from AttendToHeaders. - // AttendToHeaders controls what is output for .String() - IgnoreHeaderPrefixes []string -} - -// NewTransportContext creates a new TransportContext from a http.Request. -func NewTransportContext(req *http.Request) TransportContext { - var tx *TransportContext - if req != nil { - tx = &TransportContext{ - URI: req.RequestURI, - Host: req.Host, - Method: req.Method, - Header: req.Header, - } - } else { - tx = &TransportContext{} - } - tx.AddIgnoreHeaderPrefix("accept-encoding", "user-agent", "connection", "content-type") - return *tx -} - -// NewTransportContextFromResponse creates a new TransportContext from a http.Response. -// If `res` is nil, it returns a context with a http.StatusInternalServerError status code. -func NewTransportContextFromResponse(res *http.Response) TransportContext { - var tx *TransportContext - if res != nil { - tx = &TransportContext{ - Header: res.Header, - StatusCode: res.StatusCode, - } - } else { - tx = &TransportContext{StatusCode: http.StatusInternalServerError} - } - tx.AddIgnoreHeaderPrefix("accept-encoding", "user-agent", "connection", "content-type") - return *tx -} - -// TransportResponseContext allows a Receiver response with http transport specific fields. -type TransportResponseContext struct { - // Header will be merged with the response headers. - Header http.Header -} - -// AttendToHeaders returns the list of headers that exist in the TransportContext that are not currently in -// tx.IgnoreHeaderPrefix. -func (tx TransportContext) AttendToHeaders() []string { - a := []string(nil) - if tx.Header != nil && len(tx.Header) > 0 { - for k := range tx.Header { - if tx.shouldIgnoreHeader(k) { - continue - } - a = append(a, k) - } - } - return a -} - -func (tx TransportContext) shouldIgnoreHeader(h string) bool { - for _, v := range tx.IgnoreHeaderPrefixes { - if strings.HasPrefix(strings.ToLower(h), strings.ToLower(v)) { - return true - } - } - return false -} - -// String generates a pretty-printed version of the resource as a string. -func (tx TransportContext) String() string { - b := strings.Builder{} - - b.WriteString("Transport Context,\n") - - empty := b.Len() - - if tx.URI != "" { - b.WriteString(" URI: " + tx.URI + "\n") - } - if tx.Host != "" { - b.WriteString(" Host: " + tx.Host + "\n") - } - - if tx.Method != "" { - b.WriteString(" Method: " + tx.Method + "\n") - } - - if tx.StatusCode != 0 { - b.WriteString(" StatusCode: " + strconv.Itoa(tx.StatusCode) + "\n") - } - - if tx.Header != nil && len(tx.Header) > 0 { - b.WriteString(" Header:\n") - for _, k := range tx.AttendToHeaders() { - b.WriteString(fmt.Sprintf(" %s: %s\n", k, tx.Header.Get(k))) - } - } - - if b.Len() == empty { - b.WriteString(" nil\n") - } - - return b.String() -} - -// AddIgnoreHeaderPrefix controls what header key is to be attended to and/or printed. -func (tx *TransportContext) AddIgnoreHeaderPrefix(prefix ...string) { - if tx.IgnoreHeaderPrefixes == nil { - tx.IgnoreHeaderPrefixes = []string(nil) - } - tx.IgnoreHeaderPrefixes = append(tx.IgnoreHeaderPrefixes, prefix...) -} - -// Opaque key type used to store TransportContext -type transportContextKeyType struct{} - -var transportContextKey = transportContextKeyType{} - -// WithTransportContext return a context with the given TransportContext into the provided context object. -func WithTransportContext(ctx context.Context, tcxt TransportContext) context.Context { - return context.WithValue(ctx, transportContextKey, tcxt) -} - -// TransportContextFrom pulls a TransportContext out of a context. Always -// returns a non-nil object. -func TransportContextFrom(ctx context.Context) TransportContext { - tctx := ctx.Value(transportContextKey) - if tctx != nil { - if tx, ok := tctx.(TransportContext); ok { - return tx - } - if tx, ok := tctx.(*TransportContext); ok { - return *tx - } - } - return TransportContext{} -} - -// Opaque key type used to store Headers -type headerKeyType struct{} - -var headerKey = headerKeyType{} - -// ContextWithHeader returns a context with a header added to the given context. -// Can be called multiple times to set multiple header key/value pairs. -func ContextWithHeader(ctx context.Context, key, value string) context.Context { - header := HeaderFrom(ctx) - header.Add(key, value) - return context.WithValue(ctx, headerKey, header) -} - -// HeaderFrom extracts the header object in the given context. Always returns a non-nil Header. -func HeaderFrom(ctx context.Context) http.Header { - ch := http.Header{} - header := ctx.Value(headerKey) - if header != nil { - if h, ok := header.(http.Header); ok { - copyHeaders(h, ch) - } - } - return ch -} - -// SetContextHeader sets the context's headers replacing any headers currently in context. -func SetContextHeaders(ctx context.Context, headers http.Header) context.Context { - return context.WithValue(ctx, headerKey, headers) -} - -// Opaque key type used to store long poll target. -type longPollTargetKeyType struct{} - -var longPollTargetKey = longPollTargetKeyType{} - -// WithLongPollTarget returns a new context with the given long poll target. -// `target` should be a full URL and will be injected into the long polling -// http request within StartReceiver. -func ContextWithLongPollTarget(ctx context.Context, target string) context.Context { - return context.WithValue(ctx, longPollTargetKey, target) -} - -// LongPollTargetFrom looks in the given context and returns `target` as a -// parsed url if found and valid, otherwise nil. -func LongPollTargetFrom(ctx context.Context) *url.URL { - c := ctx.Value(longPollTargetKey) - if c != nil { - if s, ok := c.(string); ok && s != "" { - if target, err := url.Parse(s); err == nil { - return target - } - } - } - return nil -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/doc.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/doc.go deleted file mode 100644 index 1a171e46e1e..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/doc.go +++ /dev/null @@ -1,4 +0,0 @@ -/* -Package http implements the CloudEvent transport implementation using HTTP. -*/ -package http diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/encoding.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/encoding.go deleted file mode 100644 index 60f3e3ea3e6..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/encoding.go +++ /dev/null @@ -1,205 +0,0 @@ -package http - -import ( - "context" - - "github.com/cloudevents/sdk-go/pkg/cloudevents" - cecontext "github.com/cloudevents/sdk-go/pkg/cloudevents/context" -) - -// Encoding to use for HTTP transport. -type Encoding int32 - -type EncodingSelector func(context.Context, cloudevents.Event) Encoding - -const ( - // Default - Default Encoding = iota - // BinaryV01 is Binary CloudEvents spec v0.1. - BinaryV01 - // StructuredV01 is Structured CloudEvents spec v0.1. - StructuredV01 - // BinaryV02 is Binary CloudEvents spec v0.2. - BinaryV02 - // StructuredV02 is Structured CloudEvents spec v0.2. - StructuredV02 - // BinaryV03 is Binary CloudEvents spec v0.3. - BinaryV03 - // StructuredV03 is Structured CloudEvents spec v0.3. - StructuredV03 - // BatchedV03 is Batched CloudEvents spec v0.3. - BatchedV03 - // BinaryV1 is Binary CloudEvents spec v1.0. - BinaryV1 - // StructuredV03 is Structured CloudEvents spec v1.0. - StructuredV1 - // BatchedV1 is Batched CloudEvents spec v1.0. - BatchedV1 - - // Unknown is unknown. - Unknown - - // Binary is used for Context Based Encoding Selections to use the - // DefaultBinaryEncodingSelectionStrategy - Binary = "binary" - - // Structured is used for Context Based Encoding Selections to use the - // DefaultStructuredEncodingSelectionStrategy - Structured = "structured" - - // Batched is used for Context Based Encoding Selections to use the - // DefaultStructuredEncodingSelectionStrategy - Batched = "batched" -) - -func ContextBasedEncodingSelectionStrategy(ctx context.Context, e cloudevents.Event) Encoding { - encoding := cecontext.EncodingFrom(ctx) - switch encoding { - case "", Binary: - return DefaultBinaryEncodingSelectionStrategy(ctx, e) - case Structured: - return DefaultStructuredEncodingSelectionStrategy(ctx, e) - } - return Default -} - -// DefaultBinaryEncodingSelectionStrategy implements a selection process for -// which binary encoding to use based on spec version of the event. -func DefaultBinaryEncodingSelectionStrategy(ctx context.Context, e cloudevents.Event) Encoding { - switch e.SpecVersion() { - case cloudevents.CloudEventsVersionV01: - return BinaryV01 - case cloudevents.CloudEventsVersionV02: - return BinaryV02 - case cloudevents.CloudEventsVersionV03: - return BinaryV03 - case cloudevents.CloudEventsVersionV1: - return BinaryV1 - } - // Unknown version, return Default. - return Default -} - -// DefaultStructuredEncodingSelectionStrategy implements a selection process -// for which structured encoding to use based on spec version of the event. -func DefaultStructuredEncodingSelectionStrategy(ctx context.Context, e cloudevents.Event) Encoding { - switch e.SpecVersion() { - case cloudevents.CloudEventsVersionV01: - return StructuredV01 - case cloudevents.CloudEventsVersionV02: - return StructuredV02 - case cloudevents.CloudEventsVersionV03: - return StructuredV03 - case cloudevents.CloudEventsVersionV1: - return StructuredV1 - } - // Unknown version, return Default. - return Default -} - -// String pretty-prints the encoding as a string. -func (e Encoding) String() string { - switch e { - case Default: - return "Default Encoding " + e.Version() - - // Binary - case BinaryV01, BinaryV02, BinaryV03, BinaryV1: - return "Binary Encoding " + e.Version() - - // Structured - case StructuredV01, StructuredV02, StructuredV03, StructuredV1: - return "Structured Encoding " + e.Version() - - // Batched - case BatchedV03, BatchedV1: - return "Batched Encoding " + e.Version() - - default: - return "Unknown Encoding" - } -} - -// Version pretty-prints the encoding version as a string. -func (e Encoding) Version() string { - switch e { - case Default: - return "Default" - - // Version 0.1 - case BinaryV01, StructuredV01: - return "v0.1" - - // Version 0.2 - case BinaryV02, StructuredV02: - return "v0.2" - - // Version 0.3 - case BinaryV03, StructuredV03, BatchedV03: - return "v0.3" - - // Version 1.0 - case BinaryV1, StructuredV1, BatchedV1: - return "v1.0" - - // Unknown - default: - return "Unknown" - } -} - -// Codec creates a structured string to represent the the codec version. -func (e Encoding) Codec() string { - switch e { - case Default: - return "default" - - // Version 0.1 - case BinaryV01: - return "binary/v0.1" - case StructuredV01: - return "structured/v0.1" - - // Version 0.2 - case BinaryV02: - return "binary/v0.2" - case StructuredV02: - return "structured/v0.2" - - // Version 0.3 - case BinaryV03: - return "binary/v0.3" - case StructuredV03: - return "structured/v0.3" - case BatchedV03: - return "batched/v0.3" - - // Version 1.0 - case BinaryV1: - return "binary/v1.0" - case StructuredV1: - return "structured/v1.0" - case BatchedV1: - return "batched/v1.0" - - // Unknown - default: - return "unknown" - } -} - -// Name creates a string to represent the the codec name. -func (e Encoding) Name() string { - switch e { - case Default: - return Binary - case BinaryV01, BinaryV02, BinaryV03, BinaryV1: - return Binary - case StructuredV01, StructuredV02, StructuredV03, StructuredV1: - return Structured - case BatchedV03, BatchedV1: - return Batched - default: - return Binary - } -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/message.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/message.go deleted file mode 100644 index a6cdbecb1c6..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/message.go +++ /dev/null @@ -1,148 +0,0 @@ -package http - -import ( - "bytes" - "encoding/json" - - "io" - "io/ioutil" - "net/http" - - "github.com/cloudevents/sdk-go/pkg/cloudevents/transport" -) - -// type check that this transport message impl matches the contract -var _ transport.Message = (*Message)(nil) - -// Message is an http transport message. -type Message struct { - Header http.Header - Body []byte -} - -// Response is an http transport response. -type Response struct { - StatusCode int - Message -} - -// CloudEventsVersion inspects a message and tries to discover and return the -// CloudEvents spec version. -func (m Message) CloudEventsVersion() string { - - // TODO: the impl of this method needs to move into the codec. - - if m.Header != nil { - // Try headers first. - // v0.1, cased from the spec - // Note: don't pass literal string direct to m.Header[] so that - // go vet won't complain about non-canonical case. - name := "CE-CloudEventsVersion" - if v := m.Header[name]; len(v) == 1 { - return v[0] - } - // v0.2, canonical casing - if ver := m.Header.Get("CE-CloudEventsVersion"); ver != "" { - return ver - } - - // v0.2, cased from the spec - name = "ce-specversion" - if v := m.Header[name]; len(v) == 1 { - return v[0] - } - // v0.2, canonical casing - name = "ce-specversion" - if ver := m.Header.Get(name); ver != "" { - return ver - } - } - - // Then try the data body. - // TODO: we need to use the correct decoding based on content type. - - raw := make(map[string]json.RawMessage) - if err := json.Unmarshal(m.Body, &raw); err != nil { - return "" - } - - // v0.1 - if v, ok := raw["cloudEventsVersion"]; ok { - var version string - if err := json.Unmarshal(v, &version); err != nil { - return "" - } - return version - } - - // v0.2 - if v, ok := raw["specversion"]; ok { - var version string - if err := json.Unmarshal(v, &version); err != nil { - return "" - } - return version - } - - return "" -} - -func readAllClose(r io.ReadCloser) ([]byte, error) { - if r != nil { - defer r.Close() - return ioutil.ReadAll(r) - } - return nil, nil -} - -// NewMessage creates a new message from the Header and Body of -// an http.Request or http.Response -func NewMessage(header http.Header, body io.ReadCloser) (*Message, error) { - var m Message - err := m.Init(header, body) - return &m, err -} - -// NewResponse creates a new response from the Header and Body of -// an http.Request or http.Response -func NewResponse(header http.Header, body io.ReadCloser, statusCode int) (*Response, error) { - resp := Response{StatusCode: statusCode} - err := resp.Init(header, body) - return &resp, err -} - -// Copy copies a new Body and Header into a message, replacing any previous data. -func (m *Message) Init(header http.Header, body io.ReadCloser) error { - m.Header = make(http.Header, len(header)) - copyHeadersEnsure(header, &m.Header) - var err error - m.Body, err = readAllClose(body) - return err -} - -func (m *Message) copyOut(header *http.Header, body *io.ReadCloser) { - copyHeadersEnsure(m.Header, header) - *body = nil - if m.Body != nil { - copy := append([]byte(nil), m.Body...) - *body = ioutil.NopCloser(bytes.NewBuffer(copy)) - } -} - -// ToRequest updates a http.Request from a Message. -// Replaces Body, ContentLength and Method, updates Headers. -// Panic if req is nil -func (m *Message) ToRequest(req *http.Request) { - m.copyOut(&req.Header, &req.Body) - req.ContentLength = int64(len(m.Body)) - req.Method = http.MethodPost -} - -// ToResponse updates a http.Response from a Response. -// Replaces Body, updates Headers. -// Panic if resp is nil -func (m *Response) ToResponse(resp *http.Response) { - m.copyOut(&resp.Header, &resp.Body) - resp.ContentLength = int64(len(m.Body)) - resp.StatusCode = m.StatusCode -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/observability.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/observability.go deleted file mode 100644 index 40171572013..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/observability.go +++ /dev/null @@ -1,86 +0,0 @@ -package http - -import ( - "fmt" - - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" -) - -var ( - // LatencyMs measures the latency in milliseconds for the http transport - // methods for CloudEvents. - LatencyMs = stats.Float64( - "cloudevents.io/sdk-go/transport/http/latency", - "The latency in milliseconds for the http transport methods for CloudEvents.", - "ms") -) - -var ( - // LatencyView is an OpenCensus view that shows http transport method latency. - LatencyView = &view.View{ - Name: "transport/http/latency", - Measure: LatencyMs, - Description: "The distribution of latency inside of http transport for CloudEvents.", - Aggregation: view.Distribution(0, .01, .1, 1, 10, 100, 1000, 10000), - TagKeys: observability.LatencyTags(), - } -) - -type observed int32 - -// Adheres to Observable -var _ observability.Observable = observed(0) - -const ( - reportSend observed = iota - reportReceive - reportServeHTTP - reportEncode - reportDecode -) - -// MethodName implements Observable.MethodName -func (o observed) MethodName() string { - switch o { - case reportSend: - return "send" - case reportReceive: - return "receive" - case reportServeHTTP: - return "servehttp" - case reportEncode: - return "encode" - case reportDecode: - return "decode" - default: - return "unknown" - } -} - -// LatencyMs implements Observable.LatencyMs -func (o observed) LatencyMs() *stats.Float64Measure { - return LatencyMs -} - -// CodecObserved is a wrapper to append version to observed. -type CodecObserved struct { - // Method - o observed - // Codec - c string -} - -// Adheres to Observable -var _ observability.Observable = (*CodecObserved)(nil) - -// MethodName implements Observable.MethodName -func (c CodecObserved) MethodName() string { - return fmt.Sprintf("%s/%s", c.o.MethodName(), c.c) -} - -// LatencyMs implements Observable.LatencyMs -func (c CodecObserved) LatencyMs() *stats.Float64Measure { - return c.o.LatencyMs() -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/options.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/options.go deleted file mode 100644 index fde7598b0ee..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/options.go +++ /dev/null @@ -1,274 +0,0 @@ -package http - -import ( - "fmt" - "net" - nethttp "net/http" - "net/url" - "strings" - "time" -) - -// Option is the function signature required to be considered an http.Option. -type Option func(*Transport) error - -// WithTarget sets the outbound recipient of cloudevents when using an HTTP -// request. -func WithTarget(targetUrl string) Option { - return func(t *Transport) error { - if t == nil { - return fmt.Errorf("http target option can not set nil transport") - } - targetUrl = strings.TrimSpace(targetUrl) - if targetUrl != "" { - var err error - var target *url.URL - target, err = url.Parse(targetUrl) - if err != nil { - return fmt.Errorf("http target option failed to parse target url: %s", err.Error()) - } - - if t.Req == nil { - t.Req = &nethttp.Request{ - Method: nethttp.MethodPost, - } - } - t.Req.URL = target - return nil - } - return fmt.Errorf("http target option was empty string") - } -} - -// WithMethod sets the HTTP verb (GET, POST, PUT, etc.) to use -// when using an HTTP request. -func WithMethod(method string) Option { - return func(t *Transport) error { - if t == nil { - return fmt.Errorf("http method option can not set nil transport") - } - method = strings.TrimSpace(method) - if method != "" { - if t.Req == nil { - t.Req = &nethttp.Request{} - } - t.Req.Method = method - return nil - } - return fmt.Errorf("http method option was empty string") - } -} - -// WithHeader sets an additional default outbound header for all cloudevents -// when using an HTTP request. -func WithHeader(key, value string) Option { - return func(t *Transport) error { - if t == nil { - return fmt.Errorf("http header option can not set nil transport") - } - key = strings.TrimSpace(key) - if key != "" { - if t.Req == nil { - t.Req = &nethttp.Request{} - } - if t.Req.Header == nil { - t.Req.Header = nethttp.Header{} - } - t.Req.Header.Add(key, value) - return nil - } - return fmt.Errorf("http header option was empty string") - } -} - -// WithShutdownTimeout sets the shutdown timeout when the http server is being shutdown. -func WithShutdownTimeout(timeout time.Duration) Option { - return func(t *Transport) error { - if t == nil { - return fmt.Errorf("http shutdown timeout option can not set nil transport") - } - t.ShutdownTimeout = &timeout - return nil - } -} - -// WithEncoding sets the encoding for clients with HTTP transports. -func WithEncoding(encoding Encoding) Option { - return func(t *Transport) error { - if t == nil { - return fmt.Errorf("http encoding option can not set nil transport") - } - t.Encoding = encoding - return nil - } -} - -// WithDefaultEncodingSelector sets the encoding selection strategy for -// default encoding selections based on Event. -func WithDefaultEncodingSelector(fn EncodingSelector) Option { - return func(t *Transport) error { - if t == nil { - return fmt.Errorf("http default encoding selector option can not set nil transport") - } - if fn != nil { - t.DefaultEncodingSelectionFn = fn - return nil - } - return fmt.Errorf("http fn for DefaultEncodingSelector was nil") - } -} - -// WithContextBasedEncoding sets the encoding selection strategy for -// default encoding selections based context and then on Event, the encoded -// event will be the given version in the encoding specified by the given -// context, or Binary if not set. -func WithContextBasedEncoding() Option { - return func(t *Transport) error { - if t == nil { - return fmt.Errorf("http context based encoding option can not set nil transport") - } - - t.DefaultEncodingSelectionFn = ContextBasedEncodingSelectionStrategy - return nil - } -} - -// WithBinaryEncoding sets the encoding selection strategy for -// default encoding selections based on Event, the encoded event will be the -// given version in Binary form. -func WithBinaryEncoding() Option { - return func(t *Transport) error { - if t == nil { - return fmt.Errorf("http binary encoding option can not set nil transport") - } - - t.DefaultEncodingSelectionFn = DefaultBinaryEncodingSelectionStrategy - return nil - } -} - -// WithStructuredEncoding sets the encoding selection strategy for -// default encoding selections based on Event, the encoded event will be the -// given version in Structured form. -func WithStructuredEncoding() Option { - return func(t *Transport) error { - if t == nil { - return fmt.Errorf("http structured encoding option can not set nil transport") - } - - t.DefaultEncodingSelectionFn = DefaultStructuredEncodingSelectionStrategy - return nil - } -} - -func checkListen(t *Transport, prefix string) error { - switch { - case t.Port != nil: - return fmt.Errorf("%v port already set", prefix) - case t.listener != nil: - return fmt.Errorf("%v listener already set", prefix) - } - return nil -} - -// WithPort sets the listening port for StartReceiver. -// Only one of WithListener or WithPort is allowed. -func WithPort(port int) Option { - return func(t *Transport) error { - if t == nil { - return fmt.Errorf("http port option can not set nil transport") - } - if port < 0 || port > 65535 { - return fmt.Errorf("http port option was given an invalid port: %d", port) - } - if err := checkListen(t, "http port option"); err != nil { - return err - } - t.setPort(port) - return nil - } -} - -// WithListener sets the listener for StartReceiver. -// Only one of WithListener or WithPort is allowed. -func WithListener(l net.Listener) Option { - return func(t *Transport) error { - if t == nil { - return fmt.Errorf("http listener option can not set nil transport") - } - if err := checkListen(t, "http port option"); err != nil { - return err - } - t.listener = l - _, err := t.listen() - return err - } -} - -// WithPath sets the path to receive cloudevents on for HTTP transports. -func WithPath(path string) Option { - return func(t *Transport) error { - if t == nil { - return fmt.Errorf("http path option can not set nil transport") - } - path = strings.TrimSpace(path) - if len(path) == 0 { - return fmt.Errorf("http path option was given an invalid path: %q", path) - } - t.Path = path - return nil - } -} - -// Middleware is a function that takes an existing http.Handler and wraps it in middleware, -// returning the wrapped http.Handler. -type Middleware func(next nethttp.Handler) nethttp.Handler - -// WithMiddleware adds an HTTP middleware to the transport. It may be specified multiple times. -// Middleware is applied to everything before it. For example -// `NewClient(WithMiddleware(foo), WithMiddleware(bar))` would result in `bar(foo(original))`. -func WithMiddleware(middleware Middleware) Option { - return func(t *Transport) error { - if t == nil { - return fmt.Errorf("http middleware option can not set nil transport") - } - t.middleware = append(t.middleware, middleware) - return nil - } -} - -// WithLongPollTarget sets the receivers URL to perform long polling after -// StartReceiver is called. -func WithLongPollTarget(targetUrl string) Option { - return func(t *Transport) error { - if t == nil { - return fmt.Errorf("http long poll target option can not set nil transport") - } - targetUrl = strings.TrimSpace(targetUrl) - if targetUrl != "" { - var err error - var target *url.URL - target, err = url.Parse(targetUrl) - if err != nil { - return fmt.Errorf("http long poll target option failed to parse target url: %s", err.Error()) - } - - if t.LongPollReq == nil { - t.LongPollReq = &nethttp.Request{ - Method: nethttp.MethodGet, - } - } - t.LongPollReq.URL = target - return nil - } - return fmt.Errorf("http long poll target option was empty string") - } -} - -// WithHTTPTransport sets the HTTP client transport. -func WithHTTPTransport(httpTransport nethttp.RoundTripper) Option { - return func(t *Transport) error { - t.transport = httpTransport - return nil - } -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/transport.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/transport.go deleted file mode 100644 index 2c79e567294..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http/transport.go +++ /dev/null @@ -1,711 +0,0 @@ -package http - -import ( - "context" - "errors" - "fmt" - "io/ioutil" - "net" - "net/http" - "net/url" - "strconv" - "strings" - "sync" - "time" - - "go.opencensus.io/plugin/ochttp" - "go.opencensus.io/plugin/ochttp/propagation/tracecontext" - "go.uber.org/zap" - - "github.com/cloudevents/sdk-go/pkg/cloudevents" - cecontext "github.com/cloudevents/sdk-go/pkg/cloudevents/context" - "github.com/cloudevents/sdk-go/pkg/cloudevents/observability" - "github.com/cloudevents/sdk-go/pkg/cloudevents/transport" -) - -// Transport adheres to transport.Transport. -var _ transport.Transport = (*Transport)(nil) - -const ( - // DefaultShutdownTimeout defines the default timeout given to the http.Server when calling Shutdown. - DefaultShutdownTimeout = time.Minute * 1 - - // TransportName is the name of this transport. - TransportName = "HTTP" -) - -// Transport acts as both a http client and a http handler. -type Transport struct { - // The encoding used to select the codec for outbound events. - Encoding Encoding - - // DefaultEncodingSelectionFn allows for other encoding selection strategies to be injected. - DefaultEncodingSelectionFn EncodingSelector - - // ShutdownTimeout defines the timeout given to the http.Server when calling Shutdown. - // If nil, DefaultShutdownTimeout is used. - ShutdownTimeout *time.Duration - - // Sending - - // Deprecated - setting http client will override use of the - // HTTP transport set with WithHTTPTransport. - Client *http.Client - - // Req is the base http request that is used for http.Do. - // Only .Method, .URL, .Close, and .Header is considered. - // If not set, Req.Method defaults to POST. - // Req.URL or context.WithTarget(url) are required for sending. - Req *http.Request - - // Receiving - - // Receiver is invoked target for incoming events. - Receiver transport.Receiver - // Converter is invoked if the incoming transport receives an undecodable - // message. - Converter transport.Converter - // Port is the port to bind the receiver to. Defaults to 8080. - Port *int - // Path is the path to bind the receiver to. Defaults to "/". - Path string - // Handler is the handler the http Server will use. Use this to reuse the - // http server. If nil, the Transport will create a one. - Handler *http.ServeMux - - // LongPollClient is the http client that will be used to long poll. - // If nil and LongPollReq is set, the Transport will create a one. - LongPollClient *http.Client - // LongPollReq is the base http request that is used for long poll. - // Only .Method, .URL, .Close, and .Header is considered. - // If not set, LongPollReq.Method defaults to GET. - // LongPollReq.URL or context.WithLongPollTarget(url) are required to long - // poll on StartReceiver. - LongPollReq *http.Request - - listener net.Listener - server *http.Server - handlerRegistered bool - codec transport.Codec - // Create Mutex - crMu sync.Mutex - // Receive Mutex - reMu sync.Mutex - - middleware []Middleware - - // transport is the http client transport that will be used to send requests. - // If nil, the default transport will be used. - transport http.RoundTripper -} - -func New(opts ...Option) (*Transport, error) { - t := &Transport{ - Req: &http.Request{ - Method: http.MethodPost, - }, - } - if err := t.applyOptions(opts...); err != nil { - return nil, err - } - t.transport = &ochttp.Transport{ - Base: t.transport, - Propagation: &tracecontext.HTTPFormat{}, - NewClientTrace: ochttp.NewSpanAnnotatingClientTrace, - FormatSpanName: formatSpanName, - } - return t, nil -} - -func (t *Transport) applyOptions(opts ...Option) error { - for _, fn := range opts { - if err := fn(t); err != nil { - return err - } - } - return nil -} - -func (t *Transport) loadCodec(ctx context.Context) bool { - if t.codec == nil { - t.crMu.Lock() - if t.DefaultEncodingSelectionFn != nil && t.Encoding != Default { - logger := cecontext.LoggerFrom(ctx) - logger.Warn("transport has a DefaultEncodingSelectionFn set but Encoding is not Default. DefaultEncodingSelectionFn will be ignored.") - - t.codec = &Codec{ - Encoding: t.Encoding, - } - } else { - t.codec = &Codec{ - Encoding: t.Encoding, - DefaultEncodingSelectionFn: t.DefaultEncodingSelectionFn, - } - } - t.crMu.Unlock() - } - return true -} - -func copyHeaders(from, to http.Header) { - if from == nil || to == nil { - return - } - for header, values := range from { - for _, value := range values { - to.Add(header, value) - } - } -} - -// Ensure to is a non-nil map before copying -func copyHeadersEnsure(from http.Header, to *http.Header) { - if len(from) > 0 { - if *to == nil { - *to = http.Header{} - } - copyHeaders(from, *to) - } -} - -// Send implements Transport.Send -func (t *Transport) Send(ctx context.Context, event cloudevents.Event) (context.Context, *cloudevents.Event, error) { - ctx, r := observability.NewReporter(ctx, reportSend) - rctx, resp, err := t.obsSend(ctx, event) - if err != nil { - r.Error() - } else { - r.OK() - } - return rctx, resp, err -} - -func (t *Transport) obsSend(ctx context.Context, event cloudevents.Event) (context.Context, *cloudevents.Event, error) { - req := http.Request{ - Header: HeaderFrom(ctx), - } - if t.Req != nil { - req.Method = t.Req.Method - req.URL = t.Req.URL - req.Close = t.Req.Close - req.Host = t.Req.Host - copyHeadersEnsure(t.Req.Header, &req.Header) - } - - // Override the default request with target from context. - if target := cecontext.TargetFrom(ctx); target != nil { - req.URL = target - } - - if ok := t.loadCodec(ctx); !ok { - return WithTransportContext(ctx, NewTransportContextFromResponse(nil)), nil, fmt.Errorf("unknown encoding set on transport: %d", t.Encoding) - } - - msg, err := t.codec.Encode(ctx, event) - if err != nil { - return WithTransportContext(ctx, NewTransportContextFromResponse(nil)), nil, err - } - - if m, ok := msg.(*Message); ok { - m.ToRequest(&req) - client := t.Client - if client == nil { - client = &http.Client{Transport: t.transport} - } - return httpDo(ctx, client, &req, func(resp *http.Response, err error) (context.Context, *cloudevents.Event, error) { - rctx := WithTransportContext(ctx, NewTransportContextFromResponse(resp)) - if err != nil { - return rctx, nil, err - } - defer resp.Body.Close() - - body, _ := ioutil.ReadAll(resp.Body) - respEvent, err := t.MessageToEvent(ctx, &Message{ - Header: resp.Header, - Body: body, - }) - if err != nil { - isErr := true - handled := false - if txerr, ok := err.(*transport.ErrTransportMessageConversion); ok { - if !txerr.IsFatal() { - isErr = false - } - if txerr.Handled() { - handled = true - } - } - if isErr { - return rctx, nil, err - } - if handled { - return rctx, nil, nil - } - } - if accepted(resp) { - return rctx, respEvent, nil - } - return rctx, respEvent, fmt.Errorf("error sending cloudevent: %s", resp.Status) - }) - } - return WithTransportContext(ctx, NewTransportContextFromResponse(nil)), nil, fmt.Errorf("failed to encode Event into a Message") -} - -func (t *Transport) MessageToEvent(ctx context.Context, msg *Message) (*cloudevents.Event, error) { - logger := cecontext.LoggerFrom(ctx) - var event *cloudevents.Event - var err error - - if msg.CloudEventsVersion() != "" { - // This is likely a cloudevents encoded message, try to decode it. - if ok := t.loadCodec(ctx); !ok { - err = transport.NewErrTransportMessageConversion("http", fmt.Sprintf("unknown encoding set on transport: %d", t.Encoding), false, true) - logger.Error("failed to load codec", zap.Error(err)) - } else { - event, err = t.codec.Decode(ctx, msg) - } - } else { - err = transport.NewErrTransportMessageConversion("http", "cloudevents version unknown", false, false) - } - - // If codec returns and error, or could not load the correct codec, try - // with the converter if it is set. - if err != nil && t.HasConverter() { - event, err = t.Converter.Convert(ctx, msg, err) - } - - // If err is still set, it means that there was no converter, or the - // converter failed to convert. - if err != nil { - logger.Debug("failed to decode message", zap.Error(err)) - } - - // If event and error are both nil, then there is nothing to do with this event, it was handled. - if err == nil && event == nil { - logger.Debug("convert function returned (nil, nil)") - err = transport.NewErrTransportMessageConversion("http", "convert function handled request", true, false) - } - - return event, err -} - -// SetReceiver implements Transport.SetReceiver -func (t *Transport) SetReceiver(r transport.Receiver) { - t.Receiver = r -} - -// SetConverter implements Transport.SetConverter -func (t *Transport) SetConverter(c transport.Converter) { - t.Converter = c -} - -// HasConverter implements Transport.HasConverter -func (t *Transport) HasConverter() bool { - return t.Converter != nil -} - -// StartReceiver implements Transport.StartReceiver -// NOTE: This is a blocking call. -func (t *Transport) StartReceiver(ctx context.Context) error { - t.reMu.Lock() - defer t.reMu.Unlock() - - if t.LongPollReq != nil { - go func() { _ = t.longPollStart(ctx) }() - } - - if t.Handler == nil { - t.Handler = http.NewServeMux() - } - if !t.handlerRegistered { - // handler.Handle might panic if the user tries to use the same path as the sdk. - t.Handler.Handle(t.GetPath(), t) - t.handlerRegistered = true - } - - addr, err := t.listen() - if err != nil { - return err - } - - t.server = &http.Server{ - Addr: addr.String(), - Handler: &ochttp.Handler{ - Propagation: &tracecontext.HTTPFormat{}, - Handler: attachMiddleware(t.Handler, t.middleware), - FormatSpanName: formatSpanName, - }, - } - - // Shutdown - defer func() { - t.server.Close() - t.server = nil - }() - - errChan := make(chan error, 1) - go func() { - errChan <- t.server.Serve(t.listener) - }() - - // wait for the server to return or ctx.Done(). - select { - case <-ctx.Done(): - // Try a gracefully shutdown. - timeout := DefaultShutdownTimeout - if t.ShutdownTimeout != nil { - timeout = *t.ShutdownTimeout - } - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - err := t.server.Shutdown(ctx) - <-errChan // Wait for server goroutine to exit - return err - case err := <-errChan: - return err - } -} - -// HasTracePropagation implements Transport.HasTracePropagation -func (t *Transport) HasTracePropagation() bool { - return true -} - -func (t *Transport) longPollStart(ctx context.Context) error { - logger := cecontext.LoggerFrom(ctx) - logger.Info("starting long poll receiver") - - if t.LongPollClient == nil { - t.crMu.Lock() - t.LongPollClient = &http.Client{} - t.crMu.Unlock() - } - req := &http.Request{ - // TODO: decide if it is ok to use HeaderFrom context here. - Header: HeaderFrom(ctx), - } - if t.LongPollReq != nil { - req.Method = t.LongPollReq.Method - req.URL = t.LongPollReq.URL - req.Close = t.LongPollReq.Close - copyHeaders(t.LongPollReq.Header, req.Header) - } - - // Override the default request with target from context. - if target := LongPollTargetFrom(ctx); target != nil { - req.URL = target - } - - if req.URL == nil { - return errors.New("no long poll target found") - } - - req = req.WithContext(ctx) - msgCh := make(chan Message) - defer close(msgCh) - isClosed := false - - go func(ch chan<- Message) { - for { - if isClosed { - return - } - - if resp, err := t.LongPollClient.Do(req); err != nil { - logger.Errorw("long poll request returned error", err) - uErr := err.(*url.Error) - if uErr.Temporary() || uErr.Timeout() { - continue - } - // TODO: if the transport is throwing errors, we might want to try again. Maybe with a back-off sleep. - // But this error also might be that there was a done on the context. - } else if resp.StatusCode == http.StatusNotModified { - // Keep polling. - continue - } else if resp.StatusCode == http.StatusOK { - body, _ := ioutil.ReadAll(resp.Body) - if err := resp.Body.Close(); err != nil { - logger.Warnw("error closing long poll response body", zap.Error(err)) - } - msg := Message{ - Header: resp.Header, - Body: body, - } - msgCh <- msg - } else { - // TODO: not sure what to do with upstream errors yet. - logger.Errorw("unhandled long poll response", zap.Any("resp", resp)) - } - } - }(msgCh) - - // Attach the long poll request context to the context. - ctx = WithTransportContext(ctx, TransportContext{ - URI: req.URL.RequestURI(), - Host: req.URL.Host, - Method: req.Method, - }) - - for { - select { - case <-ctx.Done(): - isClosed = true - return nil - case msg := <-msgCh: - logger.Debug("got a message", zap.Any("msg", msg)) - if event, err := t.MessageToEvent(ctx, &msg); err != nil { - logger.Errorw("could not convert http message to event", zap.Error(err)) - } else { - logger.Debugw("got an event", zap.Any("event", event)) - // TODO: deliver event. - if _, err := t.invokeReceiver(ctx, *event); err != nil { - logger.Errorw("could not invoke receiver event", zap.Error(err)) - } - } - } - } -} - -// attachMiddleware attaches the HTTP middleware to the specified handler. -func attachMiddleware(h http.Handler, middleware []Middleware) http.Handler { - for _, m := range middleware { - h = m(h) - } - return h -} - -func formatSpanName(r *http.Request) string { - return "cloudevents.http." + r.URL.Path -} - -type eventError struct { - ctx context.Context - event *cloudevents.Event - err error -} - -func httpDo(ctx context.Context, client *http.Client, req *http.Request, fn func(*http.Response, error) (context.Context, *cloudevents.Event, error)) (context.Context, *cloudevents.Event, error) { - // Run the HTTP request in a goroutine and pass the response to fn. - c := make(chan eventError, 1) - req = req.WithContext(ctx) - go func() { - rctx, event, err := fn(client.Do(req)) - c <- eventError{ctx: rctx, event: event, err: err} - }() - select { - case <-ctx.Done(): - return ctx, nil, ctx.Err() - case ee := <-c: - return ee.ctx, ee.event, ee.err - } -} - -// accepted is a helper method to understand if the response from the target -// accepted the CloudEvent. -func accepted(resp *http.Response) bool { - if resp.StatusCode >= 200 && resp.StatusCode < 300 { - return true - } - return false -} - -func (t *Transport) invokeReceiver(ctx context.Context, event cloudevents.Event) (*Response, error) { - ctx, r := observability.NewReporter(ctx, reportReceive) - resp, err := t.obsInvokeReceiver(ctx, event) - if err != nil { - r.Error() - } else { - r.OK() - } - return resp, err -} - -func (t *Transport) obsInvokeReceiver(ctx context.Context, event cloudevents.Event) (*Response, error) { - logger := cecontext.LoggerFrom(ctx) - if t.Receiver != nil { - // Note: http does not use eventResp.Reason - eventResp := cloudevents.EventResponse{} - resp := Response{} - - err := t.Receiver.Receive(ctx, event, &eventResp) - if err != nil { - logger.Warnw("got an error from receiver fn", zap.Error(err)) - resp.StatusCode = http.StatusInternalServerError - return &resp, err - } - - if eventResp.Event != nil { - if t.loadCodec(ctx) { - if m, err := t.codec.Encode(ctx, *eventResp.Event); err != nil { - logger.Errorw("failed to encode response from receiver fn", zap.Error(err)) - } else if msg, ok := m.(*Message); ok { - resp.Message = *msg - } - } else { - logger.Error("failed to load codec") - resp.StatusCode = http.StatusInternalServerError - return &resp, err - } - // Look for a transport response context - var trx *TransportResponseContext - if ptrTrx, ok := eventResp.Context.(*TransportResponseContext); ok { - // found a *TransportResponseContext, use it. - trx = ptrTrx - } else if realTrx, ok := eventResp.Context.(TransportResponseContext); ok { - // found a TransportResponseContext, make it a pointer. - trx = &realTrx - } - // If we found a TransportResponseContext, use it. - if trx != nil && trx.Header != nil && len(trx.Header) > 0 { - copyHeadersEnsure(trx.Header, &resp.Message.Header) - } - } - - if eventResp.Status != 0 { - resp.StatusCode = eventResp.Status - } else { - resp.StatusCode = http.StatusAccepted // default is 202 - Accepted - } - return &resp, err - } - return nil, nil -} - -// ServeHTTP implements http.Handler -func (t *Transport) ServeHTTP(w http.ResponseWriter, req *http.Request) { - ctx, r := observability.NewReporter(req.Context(), reportServeHTTP) - // Add the transport context to ctx. - ctx = WithTransportContext(ctx, NewTransportContext(req)) - logger := cecontext.LoggerFrom(ctx) - - body, err := ioutil.ReadAll(req.Body) - if err != nil { - logger.Errorw("failed to handle request", zap.Error(err)) - w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(`{"error":"Invalid request"}`)) - r.Error() - return - } - - event, err := t.MessageToEvent(ctx, &Message{ - Header: req.Header, - Body: body, - }) - if err != nil { - isFatal := true - handled := false - if txerr, ok := err.(*transport.ErrTransportMessageConversion); ok { - isFatal = txerr.IsFatal() - handled = txerr.Handled() - } - if isFatal { - logger.Errorw("failed to convert http message to event", zap.Error(err)) - w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(fmt.Sprintf(`{"error":%q}`, err.Error()))) - r.Error() - return - } - // if handled, do not pass to receiver. - if handled { - w.WriteHeader(http.StatusNoContent) - r.OK() - return - } - } - if event == nil { - logger.Error("failed to get non-nil event from MessageToEvent") - w.WriteHeader(http.StatusBadRequest) - r.Error() - return - } - - resp, err := t.invokeReceiver(ctx, *event) - if err != nil { - logger.Warnw("error returned from invokeReceiver", zap.Error(err)) - w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(fmt.Sprintf(`{"error":%q}`, err.Error()))) - r.Error() - return - } - - if resp != nil { - if t.Req != nil { - copyHeaders(t.Req.Header, w.Header()) - } - if len(resp.Message.Header) > 0 { - copyHeaders(resp.Message.Header, w.Header()) - } - - status := http.StatusAccepted - if resp.StatusCode >= 200 && resp.StatusCode < 600 { - status = resp.StatusCode - } - w.Header().Add("Content-Length", strconv.Itoa(len(resp.Message.Body))) - w.WriteHeader(status) - - if len(resp.Message.Body) > 0 { - if _, err := w.Write(resp.Message.Body); err != nil { - r.Error() - return - } - } - - r.OK() - return - } - - w.WriteHeader(http.StatusNoContent) - r.OK() -} - -// 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. -func (t *Transport) GetPort() int { - // Ensure we have a listener and therefore a port. - if _, err := t.listen(); err == nil || t.Port != nil { - return *t.Port - } - return -1 -} - -func (t *Transport) setPort(port int) { - if t.Port == nil { - t.Port = new(int) - } - *t.Port = port -} - -// listen if not already listening, update t.Port -func (t *Transport) listen() (net.Addr, error) { - if t.listener == nil { - port := 8080 - if t.Port != nil { - port = *t.Port - if port < 0 || port > 65535 { - return nil, fmt.Errorf("invalid port %d", port) - } - } - var err error - if t.listener, err = net.Listen("tcp", fmt.Sprintf(":%d", port)); err != nil { - return nil, err - } - } - addr := t.listener.Addr() - if tcpAddr, ok := addr.(*net.TCPAddr); ok { - t.setPort(tcpAddr.Port) - } - return addr, nil -} - -// GetPath returns the path the transport is hosted on. If the path is '/', -// the transport will handle requests on any URI. To discover the true path -// a request was received on, inspect the context from Receive(cxt, ...) with -// TransportContextFrom(ctx). -func (t *Transport) GetPath() string { - path := strings.TrimSpace(t.Path) - if len(path) > 0 { - return path - } - return "/" // default -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/message.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/message.go deleted file mode 100644 index e2ed55c970f..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/message.go +++ /dev/null @@ -1,9 +0,0 @@ -package transport - -// Message is the abstract transport message wrapper. -type Message interface { - // CloudEventsVersion returns the version of the CloudEvent. - CloudEventsVersion() string - - // TODO maybe get encoding -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/transport.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/transport.go deleted file mode 100644 index ba7979da67e..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/transport.go +++ /dev/null @@ -1,49 +0,0 @@ -package transport - -import ( - "context" - - "github.com/cloudevents/sdk-go/pkg/cloudevents" -) - -// Transport is the interface for transport sender to send the converted Message -// over the underlying transport. -type Transport interface { - Send(context.Context, cloudevents.Event) (context.Context, *cloudevents.Event, error) - - SetReceiver(Receiver) - StartReceiver(context.Context) error - - // SetConverter sets the delegate to use for converting messages that have - // failed to be decoded from known codecs for this transport. - SetConverter(Converter) - // HasConverter is true when a non-nil converter has been set. - HasConverter() bool - // HasTracePropagation is true when the transport implements - // in-band trace propagation. When false, the client receiver - // will propagate trace context from distributed tracing - // extension attributes when available. - HasTracePropagation() bool -} - -// Receiver is an interface to define how a transport will invoke a listener -// of incoming events. -type Receiver interface { - Receive(context.Context, cloudevents.Event, *cloudevents.EventResponse) error -} - -// ReceiveFunc wraps a function as a Receiver object. -type ReceiveFunc func(ctx context.Context, e cloudevents.Event, er *cloudevents.EventResponse) error - -// Receive implements Receiver.Receive -func (f ReceiveFunc) Receive(ctx context.Context, e cloudevents.Event, er *cloudevents.EventResponse) error { - return f(ctx, e, er) -} - -// Converter is an interface to define how a transport delegate to convert an -// non-understood transport message from the internal codecs. Providing a -// Converter allows incoming requests to be bridged to CloudEvents format if -// they have not been sent as an event in CloudEvents format. -type Converter interface { - Convert(context.Context, Message, error) (*cloudevents.Event, error) -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/allocate.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/allocate.go deleted file mode 100644 index c38f7117701..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/allocate.go +++ /dev/null @@ -1,36 +0,0 @@ -package types - -import "reflect" - -// Allocate allocates a new instance of type t and returns: -// asPtr is of type t if t is a pointer type and of type &t otherwise -// asValue is a Value of type t pointing to the same data as asPtr -func Allocate(obj interface{}) (asPtr interface{}, asValue reflect.Value) { - if obj == nil { - return nil, reflect.Value{} - } - - switch t := reflect.TypeOf(obj); t.Kind() { - case reflect.Ptr: - reflectPtr := reflect.New(t.Elem()) - asPtr = reflectPtr.Interface() - asValue = reflectPtr - case reflect.Map: - reflectPtr := reflect.MakeMap(t) - asPtr = reflectPtr.Interface() - asValue = reflectPtr - case reflect.String: - reflectPtr := reflect.New(t) - asPtr = "" - asValue = reflectPtr.Elem() - case reflect.Slice: - reflectPtr := reflect.MakeSlice(t, 0, 0) - asPtr = reflectPtr.Interface() - asValue = reflectPtr - default: - reflectPtr := reflect.New(t) - asPtr = reflectPtr.Interface() - asValue = reflectPtr.Elem() - } - return -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/doc.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/doc.go deleted file mode 100644 index b1d9c29da7f..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/doc.go +++ /dev/null @@ -1,41 +0,0 @@ -/* -Package types implements the CloudEvents type system. - -CloudEvents defines a set of abstract types for event context attributes. Each -type has a corresponding native Go type and a canonical string encoding. The -native Go types used to represent the CloudEvents types are: -bool, int32, string, []byte, *url.URL, time.Time - - +----------------+----------------+-----------------------------------+ - |CloudEvents Type|Native Type |Convertible From | - +================+================+===================================+ - |Bool |bool |bool | - +----------------+----------------+-----------------------------------+ - |Integer |int32 |Any numeric type with value in | - | | |range of int32 | - +----------------+----------------+-----------------------------------+ - |String |string |string | - +----------------+----------------+-----------------------------------+ - |Binary |[]byte |[]byte | - +----------------+----------------+-----------------------------------+ - |URI-Reference |*url.URL |url.URL, types.URIRef, types.URI | - +----------------+----------------+-----------------------------------+ - |URI |*url.URL |url.URL, types.URIRef, types.URI | - | | |Must be an absolute URI. | - +----------------+----------------+-----------------------------------+ - |Timestamp |time.Time |time.Time, types.Timestamp | - +----------------+----------------+-----------------------------------+ - -Extension attributes may be stored as a native type or a canonical string. The -To functions will convert to the desired from any convertible type -or from the canonical string form. - -The Parse and Format functions convert native types to/from -canonical strings. - -Note are no Parse or Format functions for URL or string. For URL use the -standard url.Parse() and url.URL.String(). The canonical string format of a -string is the string itself. - -*/ -package types diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/timestamp.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/timestamp.go deleted file mode 100644 index 3ae1c7def87..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/timestamp.go +++ /dev/null @@ -1,70 +0,0 @@ -package types - -import ( - "encoding/json" - "encoding/xml" - "fmt" - "time" -) - -// Timestamp wraps time.Time to normalize the time layout to RFC3339. It is -// intended to enforce compliance with the CloudEvents spec for their -// definition of Timestamp. Custom marshal methods are implemented to ensure -// the outbound Timestamp is a string in the RFC3339 layout. -type Timestamp struct { - time.Time -} - -// ParseTimestamp attempts to parse the given time assuming RFC3339 layout -func ParseTimestamp(s string) (*Timestamp, error) { - if s == "" { - return nil, nil - } - tt, err := ParseTime(s) - return &Timestamp{Time: tt}, err -} - -// MarshalJSON implements a custom json marshal method used when this type is -// marshaled using json.Marshal. -func (t *Timestamp) MarshalJSON() ([]byte, error) { - if t == nil || t.IsZero() { - return []byte(`""`), nil - } - return []byte(fmt.Sprintf("%q", t)), nil -} - -// UnmarshalJSON implements the json unmarshal method used when this type is -// unmarshaled using json.Unmarshal. -func (t *Timestamp) UnmarshalJSON(b []byte) error { - var timestamp string - if err := json.Unmarshal(b, ×tamp); err != nil { - return err - } - var err error - t.Time, err = ParseTime(timestamp) - return err -} - -// MarshalXML implements a custom xml marshal method used when this type is -// marshaled using xml.Marshal. -func (t *Timestamp) MarshalXML(e *xml.Encoder, start xml.StartElement) error { - if t == nil || t.IsZero() { - return e.EncodeElement(nil, start) - } - return e.EncodeElement(t.String(), start) -} - -// UnmarshalXML implements the xml unmarshal method used when this type is -// unmarshaled using xml.Unmarshal. -func (t *Timestamp) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { - var timestamp string - if err := d.DecodeElement(×tamp, &start); err != nil { - return err - } - var err error - t.Time, err = ParseTime(timestamp) - return err -} - -// String outputs the time using RFC3339 format. -func (t Timestamp) String() string { return FormatTime(t.Time) } diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/uri.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/uri.go deleted file mode 100644 index 97248a24dfd..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/uri.go +++ /dev/null @@ -1,77 +0,0 @@ -package types - -import ( - "encoding/json" - "encoding/xml" - "fmt" - "net/url" -) - -// URI is a wrapper to url.URL. It is intended to enforce compliance with -// the CloudEvents spec for their definition of URI. Custom -// marshal methods are implemented to ensure the outbound URI object -// is a flat string. -type URI struct { - url.URL -} - -// ParseURI attempts to parse the given string as a URI. -func ParseURI(u string) *URI { - if u == "" { - return nil - } - pu, err := url.Parse(u) - if err != nil { - return nil - } - return &URI{URL: *pu} -} - -// MarshalJSON implements a custom json marshal method used when this type is -// marshaled using json.Marshal. -func (u URI) MarshalJSON() ([]byte, error) { - b := fmt.Sprintf("%q", u.String()) - return []byte(b), nil -} - -// UnmarshalJSON implements the json unmarshal method used when this type is -// unmarshaled using json.Unmarshal. -func (u *URI) UnmarshalJSON(b []byte) error { - var ref string - if err := json.Unmarshal(b, &ref); err != nil { - return err - } - r := ParseURI(ref) - if r != nil { - *u = *r - } - return nil -} - -// MarshalXML implements a custom xml marshal method used when this type is -// marshaled using xml.Marshal. -func (u URI) MarshalXML(e *xml.Encoder, start xml.StartElement) error { - return e.EncodeElement(u.String(), start) -} - -// UnmarshalXML implements the xml unmarshal method used when this type is -// unmarshaled using xml.Unmarshal. -func (u *URI) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { - var ref string - if err := d.DecodeElement(&ref, &start); err != nil { - return err - } - r := ParseURI(ref) - if r != nil { - *u = *r - } - return nil -} - -// String returns the full string representation of the URI-Reference. -func (u *URI) String() string { - if u == nil { - return "" - } - return u.URL.String() -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/uriref.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/uriref.go deleted file mode 100644 index e19a1dbb71b..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/uriref.go +++ /dev/null @@ -1,77 +0,0 @@ -package types - -import ( - "encoding/json" - "encoding/xml" - "fmt" - "net/url" -) - -// URIRef is a wrapper to url.URL. It is intended to enforce compliance with -// the CloudEvents spec for their definition of URI-Reference. Custom -// marshal methods are implemented to ensure the outbound URIRef object is -// is a flat string. -type URIRef struct { - url.URL -} - -// ParseURIRef attempts to parse the given string as a URI-Reference. -func ParseURIRef(u string) *URIRef { - if u == "" { - return nil - } - pu, err := url.Parse(u) - if err != nil { - return nil - } - return &URIRef{URL: *pu} -} - -// MarshalJSON implements a custom json marshal method used when this type is -// marshaled using json.Marshal. -func (u URIRef) MarshalJSON() ([]byte, error) { - b := fmt.Sprintf("%q", u.String()) - return []byte(b), nil -} - -// UnmarshalJSON implements the json unmarshal method used when this type is -// unmarshaled using json.Unmarshal. -func (u *URIRef) UnmarshalJSON(b []byte) error { - var ref string - if err := json.Unmarshal(b, &ref); err != nil { - return err - } - r := ParseURIRef(ref) - if r != nil { - *u = *r - } - return nil -} - -// MarshalXML implements a custom xml marshal method used when this type is -// marshaled using xml.Marshal. -func (u URIRef) MarshalXML(e *xml.Encoder, start xml.StartElement) error { - return e.EncodeElement(u.String(), start) -} - -// UnmarshalXML implements the xml unmarshal method used when this type is -// unmarshaled using xml.Unmarshal. -func (u *URIRef) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { - var ref string - if err := d.DecodeElement(&ref, &start); err != nil { - return err - } - r := ParseURIRef(ref) - if r != nil { - *u = *r - } - return nil -} - -// String returns the full string representation of the URI-Reference. -func (u *URIRef) String() string { - if u == nil { - return "" - } - return u.URL.String() -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/urlref.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/urlref.go deleted file mode 100644 index 2578801cd83..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/urlref.go +++ /dev/null @@ -1,79 +0,0 @@ -package types - -import ( - "encoding/json" - "encoding/xml" - "fmt" - "net/url" -) - -// URLRef is a wrapper to url.URL. It is intended to enforce compliance with -// the CloudEvents spec for their definition of URI-Reference. Custom -// marshal methods are implemented to ensure the outbound URLRef object is -// is a flat string. -// -// deprecated: use URIRef. -type URLRef struct { - url.URL -} - -// ParseURLRef attempts to parse the given string as a URI-Reference. -func ParseURLRef(u string) *URLRef { - if u == "" { - return nil - } - pu, err := url.Parse(u) - if err != nil { - return nil - } - return &URLRef{URL: *pu} -} - -// MarshalJSON implements a custom json marshal method used when this type is -// marshaled using json.Marshal. -func (u URLRef) MarshalJSON() ([]byte, error) { - b := fmt.Sprintf("%q", u.String()) - return []byte(b), nil -} - -// UnmarshalJSON implements the json unmarshal method used when this type is -// unmarshaled using json.Unmarshal. -func (u *URLRef) UnmarshalJSON(b []byte) error { - var ref string - if err := json.Unmarshal(b, &ref); err != nil { - return err - } - r := ParseURLRef(ref) - if r != nil { - *u = *r - } - return nil -} - -// MarshalXML implements a custom xml marshal method used when this type is -// marshaled using xml.Marshal. -func (u URLRef) MarshalXML(e *xml.Encoder, start xml.StartElement) error { - return e.EncodeElement(u.String(), start) -} - -// UnmarshalXML implements the xml unmarshal method used when this type is -// unmarshaled using xml.Unmarshal. -func (u *URLRef) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { - var ref string - if err := d.DecodeElement(&ref, &start); err != nil { - return err - } - r := ParseURLRef(ref) - if r != nil { - *u = *r - } - return nil -} - -// String returns the full string representation of the URI-Reference. -func (u *URLRef) String() string { - if u == nil { - return "" - } - return u.URL.String() -} diff --git a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/value.go b/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/value.go deleted file mode 100644 index 4086808e66a..00000000000 --- a/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/types/value.go +++ /dev/null @@ -1,269 +0,0 @@ -package types - -import ( - "encoding/base64" - "fmt" - "math" - "net/url" - "reflect" - "strconv" - "time" -) - -// FormatBool returns canonical string format: "true" or "false" -func FormatBool(v bool) string { return strconv.FormatBool(v) } - -// FormatInteger returns canonical string format: decimal notation. -func FormatInteger(v int32) string { return strconv.Itoa(int(v)) } - -// FormatBinary returns canonical string format: standard base64 encoding -func FormatBinary(v []byte) string { return base64.StdEncoding.EncodeToString(v) } - -// FormatTime returns canonical string format: RFC3339 with nanoseconds -func FormatTime(v time.Time) string { return v.UTC().Format(time.RFC3339Nano) } - -// ParseBool parse canonical string format: "true" or "false" -func ParseBool(v string) (bool, error) { return strconv.ParseBool(v) } - -// ParseInteger parse canonical string format: decimal notation. -func ParseInteger(v string) (int32, error) { - // Accept floating-point but truncate to int32 as per CE spec. - f, err := strconv.ParseFloat(v, 64) - if err != nil { - return 0, err - } - if f > math.MaxInt32 || f < math.MinInt32 { - return 0, rangeErr(v) - } - return int32(f), nil -} - -// ParseBinary parse canonical string format: standard base64 encoding -func ParseBinary(v string) ([]byte, error) { return base64.StdEncoding.DecodeString(v) } - -// ParseTime parse canonical string format: RFC3339 with nanoseconds -func ParseTime(v string) (time.Time, error) { - t, err := time.Parse(time.RFC3339Nano, v) - if err != nil { - err := convertErr(time.Time{}, v) - err.extra = ": not in RFC3339 format" - return time.Time{}, err - } - return t, nil -} - -// Format returns the canonical string format of v, where v can be -// any type that is convertible to a CloudEvents type. -func Format(v interface{}) (string, error) { - v, err := Validate(v) - if err != nil { - return "", err - } - switch v := v.(type) { - case bool: - return FormatBool(v), nil - case int32: - return FormatInteger(v), nil - case string: - return v, nil - case []byte: - return FormatBinary(v), nil - case URI: - return v.String(), nil - case URIRef: - // url.URL is often passed by pointer so allow both - return v.String(), nil - case Timestamp: - return FormatTime(v.Time), nil - default: - return "", fmt.Errorf("%T is not a CloudEvents type", v) - } -} - -// Validate v is a valid CloudEvents attribute value, convert it to one of: -// bool, int32, string, []byte, types.URI, types.URIRef, types.Timestamp -func Validate(v interface{}) (interface{}, error) { - switch v := v.(type) { - case bool, int32, string, []byte: - return v, nil // Already a CloudEvents type, no validation needed. - - case uint, uintptr, uint8, uint16, uint32, uint64: - u := reflect.ValueOf(v).Uint() - if u > math.MaxInt32 { - return nil, rangeErr(v) - } - return int32(u), nil - case int, int8, int16, int64: - i := reflect.ValueOf(v).Int() - if i > math.MaxInt32 || i < math.MinInt32 { - return nil, rangeErr(v) - } - return int32(i), nil - case float32, float64: - f := reflect.ValueOf(v).Float() - if f > math.MaxInt32 || f < math.MinInt32 { - return nil, rangeErr(v) - } - return int32(f), nil - - case *url.URL: - if v == nil { - break - } - return URI{*v}, nil - case url.URL: - return URI{v}, nil - case URIRef: - return v, nil - case URI: - return v, nil - case URLRef: - // Convert old type to new one - return URIRef{v.URL}, nil - case time.Time: - return Timestamp{v}, nil - case *time.Time: - if v == nil { - break - } - return Timestamp{*v}, nil - case Timestamp: - return v, nil - } - rx := reflect.ValueOf(v) - if rx.Kind() == reflect.Ptr && !rx.IsNil() { - // Allow pointers-to convertible types - return Validate(rx.Elem().Interface()) - } - return nil, fmt.Errorf("invalid CloudEvents value: %#v", v) -} - -// ToBool accepts a bool value or canonical "true"/"false" string. -func ToBool(v interface{}) (bool, error) { - v, err := Validate(v) - if err != nil { - return false, err - } - switch v := v.(type) { - case bool: - return v, nil - case string: - return ParseBool(v) - default: - return false, convertErr(true, v) - } -} - -// ToInteger accepts any numeric value in int32 range, or canonical string. -func ToInteger(v interface{}) (int32, error) { - v, err := Validate(v) - if err != nil { - return 0, err - } - switch v := v.(type) { - case int32: - return v, nil - case string: - return ParseInteger(v) - default: - return 0, convertErr(int32(0), v) - } -} - -// ToString returns a string value unaltered. -// -// This function does not perform canonical string encoding, use one of the -// Format functions for that. -func ToString(v interface{}) (string, error) { - v, err := Validate(v) - if err != nil { - return "", err - } - switch v := v.(type) { - case string: - return v, nil - default: - return "", convertErr("", v) - } -} - -// ToBinary returns a []byte value, decoding from base64 string if necessary. -func ToBinary(v interface{}) ([]byte, error) { - v, err := Validate(v) - if err != nil { - return nil, err - } - switch v := v.(type) { - case []byte: - return v, nil - case string: - return base64.StdEncoding.DecodeString(v) - default: - return nil, convertErr([]byte(nil), v) - } -} - -// ToURL returns a *url.URL value, parsing from string if necessary. -func ToURL(v interface{}) (*url.URL, error) { - v, err := Validate(v) - if err != nil { - return nil, err - } - switch v := v.(type) { - case URI: - return &v.URL, nil - case URIRef: - return &v.URL, nil - case string: - u, err := url.Parse(v) - if err != nil { - return nil, err - } - return u, nil - default: - return nil, convertErr((*url.URL)(nil), v) - } -} - -// ToTime returns a time.Time value, parsing from RFC3339 string if necessary. -func ToTime(v interface{}) (time.Time, error) { - v, err := Validate(v) - if err != nil { - return time.Time{}, err - } - switch v := v.(type) { - case Timestamp: - return v.Time, nil - case string: - ts, err := time.Parse(time.RFC3339Nano, v) - if err != nil { - return time.Time{}, err - } - return ts, nil - default: - return time.Time{}, convertErr(time.Time{}, v) - } -} - -type ConvertErr struct { - // Value being converted - Value interface{} - // Type of attempted conversion - Type reflect.Type - - extra string -} - -func (e *ConvertErr) Error() string { - return fmt.Sprintf("cannot convert %#v to %s%s", e.Value, e.Type, e.extra) -} - -func convertErr(target, v interface{}) *ConvertErr { - return &ConvertErr{Value: v, Type: reflect.TypeOf(target)} -} - -func rangeErr(v interface{}) error { - e := convertErr(int32(0), v) - e.extra = ": out of range" - return e -} diff --git a/vendor/modules.txt b/vendor/modules.txt index e0fa4cec5c5..0bbc998db35 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -76,21 +76,6 @@ 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 v1.2.0 -## explicit -github.com/cloudevents/sdk-go -github.com/cloudevents/sdk-go/pkg/cloudevents -github.com/cloudevents/sdk-go/pkg/cloudevents/client -github.com/cloudevents/sdk-go/pkg/cloudevents/context -github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec -github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/json -github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/text -github.com/cloudevents/sdk-go/pkg/cloudevents/datacodec/xml -github.com/cloudevents/sdk-go/pkg/cloudevents/extensions -github.com/cloudevents/sdk-go/pkg/cloudevents/observability -github.com/cloudevents/sdk-go/pkg/cloudevents/transport -github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http -github.com/cloudevents/sdk-go/pkg/cloudevents/types # github.com/cloudevents/sdk-go/v2 v2.0.1-0.20200608152019-2ab697c8fc0b ## explicit github.com/cloudevents/sdk-go/v2