diff --git a/cmd/application.go b/cmd/application.go index ea9dfc9..ee6a331 100644 --- a/cmd/application.go +++ b/cmd/application.go @@ -16,7 +16,6 @@ type applicationCmd struct { } func newApplicationCmd() *applicationCmd { - ac := &applicationCmd{} ac.cmd = &cobra.Command{ Use: "application", @@ -31,7 +30,7 @@ func newApplicationCmd() *applicationCmd { Run: func(cmd *cobra.Command, args []string) { printer := pretty.NewPrinter(getPrinterOptions(cmd)) svixClient := getSvixClientOrExit() - l, err := svixClient.Application.List(getApplicationListOptions(cmd)) + l, err := svixClient.Application.List(cmd.Context(), getApplicationListOptions(cmd)) printer.CheckErr(err) printer.Print(l) @@ -95,7 +94,7 @@ Example Schema: } svixClient := getSvixClientOrExit() - out, err := svixClient.Application.Create(&app) + out, err := svixClient.Application.Create(cmd.Context(), &app) printer.CheckErr(err) printer.Print(out) @@ -117,7 +116,7 @@ Example Schema: appID := args[0] svixClient := getSvixClientOrExit() - out, err := svixClient.Application.Get(appID) + out, err := svixClient.Application.Get(cmd.Context(), appID) printer.CheckErr(err) printer.Print(out) @@ -175,7 +174,7 @@ Example Schema: } svixClient := getSvixClientOrExit() - out, err := svixClient.Application.Update(appID, &app) + out, err := svixClient.Application.Update(cmd.Context(), appID, &app) printer.CheckErr(err) printer.Print(out) @@ -200,7 +199,7 @@ Example Schema: utils.Confirm(fmt.Sprintf("Are you sure you want to delete the app with id: %s", appID)) - err := svixClient.Application.Delete(appID) + err := svixClient.Application.Delete(cmd.Context(), appID) printer.CheckErr(err) fmt.Printf("Application \"%s\" Deleted!\n", appID) diff --git a/cmd/authentication.go b/cmd/authentication.go index d25b773..6635ffa 100644 --- a/cmd/authentication.go +++ b/cmd/authentication.go @@ -34,7 +34,7 @@ func newAuthenticationCmd() *authenticationCmd { printer := pretty.NewPrinter(getPrinterOptions(cmd)) svixClient := getSvixClientOrExit() - da, err := svixClient.Authentication.DashboardAccess(appID) + da, err := svixClient.Authentication.DashboardAccess(cmd.Context(), appID) printer.CheckErr(err) printer.Print(da) @@ -52,7 +52,7 @@ func newAuthenticationCmd() *authenticationCmd { printer := pretty.NewPrinter(getPrinterOptions(cmd)) svixClient := svix.New(authToken, getSvixClientOptsOrExit()) - err := svixClient.Authentication.Logout() + err := svixClient.Authentication.Logout(cmd.Context()) printer.CheckErr(err) }, } @@ -84,7 +84,7 @@ func newAuthenticationCmd() *authenticationCmd { } svixClient := getSvixClientOrExit() - out, err := svixClient.Authentication.AppPortalAccess(appID, &appPortalAccessIn) + out, err := svixClient.Authentication.AppPortalAccess(cmd.Context(), appID, &appPortalAccessIn) printer.CheckErr(err) printer.Print(out) diff --git a/cmd/endpoint.go b/cmd/endpoint.go index f1bdba2..3369711 100644 --- a/cmd/endpoint.go +++ b/cmd/endpoint.go @@ -33,7 +33,7 @@ func newEndpointCmd() *endpointCmd { appID := args[0] svixClient := getSvixClientOrExit() - l, err := svixClient.Endpoint.List(appID, getEndpointListOptions(cmd)) + l, err := svixClient.Endpoint.List(cmd.Context(), appID, getEndpointListOptions(cmd)) printer.CheckErr(err) printer.Print(l) @@ -56,7 +56,7 @@ func newEndpointCmd() *endpointCmd { Example Schema: { "url": "string", - "version": 0, + "version": 1, "description": "", "filterTypes": [ "string" @@ -90,11 +90,6 @@ Example Schema: printer.CheckErr(err) ep.Url = urlFlag } - if cmd.Flags().Changed(versionFlagName) { - versionFlag, err := cmd.Flags().GetInt32(versionFlagName) - printer.CheckErr(err) - ep.Version = versionFlag - } if cmd.Flags().Changed(filterTypesFlagName) { filterTypesFlag, err := cmd.Flags().GetStringArray(filterTypesFlagName) printer.CheckErr(err) @@ -110,16 +105,19 @@ Example Schema: printer.CheckErr(err) ep.Disabled = &disabledFlag } + versionFlag, err := cmd.Flags().GetInt32(versionFlagName) + printer.CheckErr(err) + ep.Version = versionFlag svixClient := getSvixClientOrExit() - out, err := svixClient.Endpoint.Create(appID, &ep) + out, err := svixClient.Endpoint.Create(cmd.Context(), appID, &ep) printer.CheckErr(err) printer.Print(out) }, } create.Flags().String(urlFlagName, "", "") - create.Flags().Int32(versionFlagName, 0, "") + create.Flags().Int32(versionFlagName, 1, "") create.Flags().StringArray(filterTypesFlagName, []string{}, "") create.Flags().Int32(rateLimitFlagName, 0, "Rate Limit of the endpoint (optional)") create.Flags().Bool(disabledFlagName, false, "") @@ -137,7 +135,7 @@ Example Schema: endpointID := args[1] svixClient := getSvixClientOrExit() - out, err := svixClient.Endpoint.Get(appID, endpointID) + out, err := svixClient.Endpoint.Get(cmd.Context(), appID, endpointID) printer.CheckErr(err) printer.Print(out) @@ -153,7 +151,7 @@ Example Schema: Example Schema: { "url": "string", - "version": 0, + "version": 1, "description": "", "filterTypes": [ "string" @@ -210,14 +208,14 @@ Example Schema: } svixClient := getSvixClientOrExit() - out, err := svixClient.Endpoint.Update(appID, endpointID, &ep) + out, err := svixClient.Endpoint.Update(cmd.Context(), appID, endpointID, &ep) printer.CheckErr(err) printer.Print(out) }, } update.Flags().String(urlFlagName, "", "") - update.Flags().Int32(versionFlagName, 0, "") + update.Flags().Int32(versionFlagName, 1, "") update.Flags().StringArray(filterTypesFlagName, []string{}, "") update.Flags().Int32(rateLimitFlagName, 0, "Rate Limit of the endpoint (optional)") update.Flags().Bool(disabledFlagName, false, "") @@ -237,7 +235,7 @@ Example Schema: utils.Confirm(fmt.Sprintf("Are you sure you want to delete the the endpoint with id: %s", endpointID)) svixClient := getSvixClientOrExit() - err := svixClient.Endpoint.Delete(appID, endpointID) + err := svixClient.Endpoint.Delete(cmd.Context(), appID, endpointID) printer.CheckErr(err) fmt.Printf("Endpoint \"%s\" Deleted!\n", endpointID) @@ -257,7 +255,7 @@ Example Schema: endpointID := args[1] svixClient := getSvixClientOrExit() - out, err := svixClient.Endpoint.GetSecret(appID, endpointID) + out, err := svixClient.Endpoint.GetSecret(cmd.Context(), appID, endpointID) printer.CheckErr(err) printer.Print(out) @@ -277,7 +275,7 @@ Example Schema: endpointID := args[1] svixClient := getSvixClientOrExit() - out, err := svixClient.Endpoint.GetHeaders(appID, endpointID) + out, err := svixClient.Endpoint.GetHeaders(cmd.Context(), appID, endpointID) printer.CheckErr(err) printer.Print(out) @@ -311,7 +309,7 @@ Example Schema: } svixClient := getSvixClientOrExit() - err := svixClient.Endpoint.UpdateHeaders(appID, endpointID, &headersIn) + err := svixClient.Endpoint.UpdateHeaders(cmd.Context(), appID, endpointID, &headersIn) printer.CheckErr(err) }, } @@ -343,7 +341,7 @@ Example Schema: } svixClient := getSvixClientOrExit() - err := svixClient.Endpoint.PatchHeaders(appID, endpointID, &headersIn) + err := svixClient.Endpoint.PatchHeaders(cmd.Context(), appID, endpointID, &headersIn) printer.CheckErr(err) }, } diff --git a/cmd/event.go b/cmd/event.go index 8bd3a4b..2e39aa4 100644 --- a/cmd/event.go +++ b/cmd/event.go @@ -30,7 +30,7 @@ func newEventTypeCmd() *eventTypeCmd { printer := pretty.NewPrinter(getPrinterOptions(cmd)) svixClient := getSvixClientOrExit() - l, err := svixClient.EventType.List(getEventListOptions(cmd)) + l, err := svixClient.EventType.List(cmd.Context(), getEventListOptions(cmd)) printer.CheckErr(err) printer.Print(l) @@ -84,7 +84,7 @@ Example Schema: } svixClient := getSvixClientOrExit() - out, err := svixClient.EventType.Create(&et) + out, err := svixClient.EventType.Create(cmd.Context(), &et) printer.CheckErr(err) printer.Print(out) @@ -133,7 +133,7 @@ Example Schema: } svixClient := getSvixClientOrExit() - out, err := svixClient.EventType.Update(eventName, &et) + out, err := svixClient.EventType.Update(cmd.Context(), eventName, &et) printer.CheckErr(err) printer.Print(out) @@ -155,7 +155,7 @@ Example Schema: utils.Confirm(fmt.Sprintf("Are you sure you want to delete the the event with id: %s", eventID)) svixClient := getSvixClientOrExit() - err := svixClient.EventType.Delete(eventID) + err := svixClient.EventType.Delete(cmd.Context(), eventID) printer.CheckErr(err) fmt.Printf("Event Type \"%s\" Deleted!\n", eventID) diff --git a/cmd/export.go b/cmd/export.go index 1eb1cb2..f483b5b 100644 --- a/cmd/export.go +++ b/cmd/export.go @@ -1,6 +1,7 @@ package cmd import ( + "context" "encoding/json" "flag" "io" @@ -40,7 +41,7 @@ Json Format: printer := pretty.NewPrinter(getPrinterOptions(cmd)) svixClient := getSvixClientOrExit() - eventTypes, err := inout.GetAllEventTypes(svixClient) + eventTypes, err := inout.GetAllEventTypes(context.Background(), svixClient) printer.CheckErr(err) var outStream io.Writer = printer diff --git a/cmd/import.go b/cmd/import.go index 8dde40c..8e8f018 100644 --- a/cmd/import.go +++ b/cmd/import.go @@ -1,6 +1,7 @@ package cmd import ( + "context" "flag" "fmt" "io" @@ -67,10 +68,10 @@ Json Format: fileType := getOrInferFileType(fileName) switch fileType { case "csv": - err := inout.ImportEventTypesCsv(svixClient, reader, force) + err := inout.ImportEventTypesCsv(context.Background(), svixClient, reader, force) printer.CheckErr(err) default: - err := inout.ImportEventTypesJson(svixClient, reader, force) + err := inout.ImportEventTypesJson(context.Background(), svixClient, reader, force) printer.CheckErr(err) } }, diff --git a/cmd/integration.go b/cmd/integration.go index 6156a49..604a779 100644 --- a/cmd/integration.go +++ b/cmd/integration.go @@ -34,7 +34,7 @@ func newIntegrationCmd() *integrationCmd { appID := args[0] - l, err := svixClient.Integration.List(appID, getIntegrationListOptions(cmd)) + l, err := svixClient.Integration.List(cmd.Context(), appID, getIntegrationListOptions(cmd)) printer.CheckErr(err) printer.Print(l) @@ -89,7 +89,7 @@ Example Schema: } svixClient := getSvixClientOrExit() - out, err := svixClient.Integration.Create(appID, &integration) + out, err := svixClient.Integration.Create(cmd.Context(), appID, &integration) printer.CheckErr(err) printer.Print(out) @@ -110,7 +110,7 @@ Example Schema: appID := args[0] integrationID := args[1] - l, err := svixClient.Integration.Get(appID, integrationID) + l, err := svixClient.Integration.Get(cmd.Context(), appID, integrationID) printer.CheckErr(err) printer.Print(l) @@ -164,7 +164,7 @@ Example Schema: } svixClient := getSvixClientOrExit() - out, err := svixClient.Integration.Update(appID, integrationID, &integration) + out, err := svixClient.Integration.Update(cmd.Context(), appID, integrationID, &integration) printer.CheckErr(err) printer.Print(out) @@ -185,7 +185,7 @@ Example Schema: appID := args[0] integrationID := args[1] - err := svixClient.Integration.Delete(appID, integrationID) + err := svixClient.Integration.Delete(cmd.Context(), appID, integrationID) printer.CheckErr(err) }, } @@ -203,7 +203,7 @@ Example Schema: appID := args[0] integrationID := args[1] - l, err := svixClient.Integration.GetKey(appID, integrationID) + l, err := svixClient.Integration.GetKey(cmd.Context(), appID, integrationID) printer.CheckErr(err) printer.Print(l) @@ -223,7 +223,7 @@ Example Schema: appID := args[0] integrationID := args[1] - l, err := svixClient.Integration.RotateKey(appID, integrationID) + l, err := svixClient.Integration.RotateKey(cmd.Context(), appID, integrationID) printer.CheckErr(err) printer.Print(l) diff --git a/cmd/message.go b/cmd/message.go index 93d2c87..c425d55 100644 --- a/cmd/message.go +++ b/cmd/message.go @@ -37,7 +37,7 @@ func newMessageCmd() *messageCmd { opts, err := getMessageFilterFlags(cmd) printer.CheckErr(err) - l, err := svixClient.Message.List(appID, opts) + l, err := svixClient.Message.List(cmd.Context(), appID, opts) printer.CheckErr(err) printer.Print(l) @@ -109,7 +109,7 @@ Example Schema: } svixClient := getSvixClientOrExit() - out, err := svixClient.Message.Create(appID, &msg) + out, err := svixClient.Message.Create(cmd.Context(), appID, &msg) printer.CheckErr(err) printer.Print(out) @@ -131,7 +131,7 @@ Example Schema: msgID := args[1] svixClient := getSvixClientOrExit() - out, err := svixClient.Message.Get(appID, msgID) + out, err := svixClient.Message.Get(cmd.Context(), appID, msgID) printer.CheckErr(err) printer.Print(out) diff --git a/cmd/messageattempt.go b/cmd/messageattempt.go index b4e68ad..f160848 100644 --- a/cmd/messageattempt.go +++ b/cmd/messageattempt.go @@ -36,7 +36,7 @@ func newMessageAttemptCmd() *messageAttemptCmd { opts, err := getMessageAttemptListOptions(cmd) printer.CheckErr(err) - l, err := svixClient.MessageAttempt.ListByMsg(appID, msgID, opts) + l, err := svixClient.MessageAttempt.ListByMsg(cmd.Context(), appID, msgID, opts) printer.CheckErr(err) printer.Print(l) @@ -59,7 +59,7 @@ func newMessageAttemptCmd() *messageAttemptCmd { svixClient := getSvixClientOrExit() opts, err := getMessageAttemptListOptions(cmd) printer.CheckErr(err) - l, err := svixClient.MessageAttempt.ListAttemptedDestinations(appID, msgID, opts) + l, err := svixClient.MessageAttempt.ListAttemptedDestinations(cmd.Context(), appID, msgID, opts) printer.CheckErr(err) printer.Print(l) @@ -86,7 +86,7 @@ func newMessageAttemptCmd() *messageAttemptCmd { opts, err := getMessageAttemptListOptions(cmd) printer.CheckErr(err) - l, err := svixClient.MessageAttempt.ListAttemptsForEndpoint(appID, msgID, endpointID, opts) + l, err := svixClient.MessageAttempt.ListAttemptsForEndpoint(cmd.Context(), appID, msgID, endpointID, opts) printer.CheckErr(err) printer.Print(l) @@ -111,7 +111,7 @@ func newMessageAttemptCmd() *messageAttemptCmd { opts, err := getMessageAttemptListOptions(cmd) printer.CheckErr(err) - l, err := svixClient.MessageAttempt.ListAttemptedMessages(appID, endpointID, opts) + l, err := svixClient.MessageAttempt.ListAttemptedMessages(cmd.Context(), appID, endpointID, opts) printer.CheckErr(err) printer.Print(l) @@ -134,7 +134,7 @@ func newMessageAttemptCmd() *messageAttemptCmd { attemptID := args[2] svixClient := getSvixClientOrExit() - out, err := svixClient.MessageAttempt.Get(appID, msgID, attemptID) + out, err := svixClient.MessageAttempt.Get(cmd.Context(), appID, msgID, attemptID) printer.CheckErr(err) printer.Print(out) @@ -156,7 +156,7 @@ func newMessageAttemptCmd() *messageAttemptCmd { endpointID := args[2] svixClient := getSvixClientOrExit() - err := svixClient.MessageAttempt.Resend(appID, msgID, endpointID) + err := svixClient.MessageAttempt.Resend(cmd.Context(), appID, msgID, endpointID) printer.CheckErr(err) }, } diff --git a/cmd/root.go b/cmd/root.go index 261c1ad..3eb936c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,11 +1,13 @@ package cmd import ( + "context" "flag" "fmt" "net/url" "os" "path/filepath" + "time" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -25,10 +27,14 @@ var rootCmd = &cobra.Command{ Version: version.Version, } +const commandTimeout = 15 * time.Second + // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { - cobra.CheckErr(rootCmd.Execute()) + ctx, cancel := context.WithTimeout(context.Background(), commandTimeout) + defer cancel() + cobra.CheckErr(rootCmd.ExecuteContext(ctx)) } func init() { diff --git a/go.mod b/go.mod index 2f3a2c9..f13d29c 100644 --- a/go.mod +++ b/go.mod @@ -6,12 +6,14 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de github.com/fatih/color v1.13.0 + github.com/fsnotify/fsnotify v1.5.1 // indirect github.com/gorilla/websocket v1.4.2 github.com/manifoldco/promptui v0.8.0 github.com/mitchellh/go-homedir v1.1.0 github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 + github.com/spf13/afero v1.6.0 // indirect github.com/spf13/cobra v1.3.0 github.com/spf13/viper v1.10.0 - github.com/svix/svix-webhooks v0.75.0 + github.com/svix/svix-webhooks v1.7.0 github.com/tidwall/pretty v1.1.1 ) diff --git a/go.sum b/go.sum index 2af4925..120384f 100644 --- a/go.sum +++ b/go.sum @@ -360,6 +360,8 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/svix/svix-webhooks v0.75.0 h1:GH8myVTh6EDlVIHbyEXqs6bA8a/zSBH3JmZKRdD10WQ= github.com/svix/svix-webhooks v0.75.0/go.mod h1:vWwH7D6zMhF9pCLfgLlogcXGDmnGqIJeIT9AXorZTAQ= +github.com/svix/svix-webhooks v1.7.0 h1:rfJ9yGc1h9odbdoNW8+dkO4ZdgajPYXvTdLqJsLBcIo= +github.com/svix/svix-webhooks v1.7.0/go.mod h1:q3Z9c8NXqDRPZviI+zLMToAja+bjhTw929cMVhJirOI= github.com/tidwall/pretty v1.1.1 h1:nt6/Ot5LtZnJCWwEFlelOixPo0xhPFsuZlKyOL3Xfnc= github.com/tidwall/pretty v1.1.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= @@ -368,6 +370,7 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.1/go.mod h1:pMEacxZW7o8pg4CrFE7pquyCJJzZvkvdD2RibOCCCGs= @@ -392,6 +395,7 @@ golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -428,6 +432,7 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= 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-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -470,6 +475,9 @@ golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d h1:LO7XpTYMwTqxjLcGWPijK3vRXg1aWdlNOVOHRq45d7c= golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= 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/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -499,6 +507,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 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= @@ -566,7 +575,13 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d h1:FjkYO/PPp4Wi0EAUOVLxePm7qVW4r4ctbWpURyuOD0E= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 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= @@ -577,6 +592,8 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -634,6 +651,7 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/inout/eventtypes.go b/inout/eventtypes.go index 06429ae..855d597 100644 --- a/inout/eventtypes.go +++ b/inout/eventtypes.go @@ -1,6 +1,7 @@ package inout import ( + "context" "encoding/csv" "encoding/json" "fmt" @@ -9,7 +10,7 @@ import ( svix "github.com/svix/svix-webhooks/go" ) -func ImportEventTypesJson(sc *svix.Svix, reader io.Reader, update bool) error { +func ImportEventTypesJson(ctx context.Context, sc *svix.Svix, reader io.Reader, update bool) error { dec := json.NewDecoder(reader) var eventTypes []*svix.EventTypeIn err := dec.Decode(&eventTypes) @@ -17,7 +18,7 @@ func ImportEventTypesJson(sc *svix.Svix, reader io.Reader, update bool) error { return err } for _, et := range eventTypes { - err = createOrUpdateEventType(sc, et, update) + err = createOrUpdateEventType(ctx, sc, et, update) if err != nil { return err } @@ -25,7 +26,7 @@ func ImportEventTypesJson(sc *svix.Svix, reader io.Reader, update bool) error { return nil } -func ImportEventTypesCsv(sc *svix.Svix, reader io.Reader, update bool) error { +func ImportEventTypesCsv(ctx context.Context, sc *svix.Svix, reader io.Reader, update bool) error { csvReader := csv.NewReader(reader) for { record, err := csvReader.Read() @@ -42,7 +43,7 @@ func ImportEventTypesCsv(sc *svix.Svix, reader io.Reader, update bool) error { Name: record[0], Description: record[1], } - err = createOrUpdateEventType(sc, et, update) + err = createOrUpdateEventType(ctx, sc, et, update) if err != nil { return err } @@ -50,13 +51,13 @@ func ImportEventTypesCsv(sc *svix.Svix, reader io.Reader, update bool) error { return nil } -func createOrUpdateEventType(sc *svix.Svix, et *svix.EventTypeIn, update bool) error { - _, err := sc.EventType.Create(et) +func createOrUpdateEventType(ctx context.Context, sc *svix.Svix, et *svix.EventTypeIn, update bool) error { + _, err := sc.EventType.Create(ctx, et) if err != nil { if sErr, ok := err.(*svix.Error); ok { if sErr.Status() == 409 { if update { - _, err := sc.EventType.Update(et.Name, &svix.EventTypeUpdate{Description: et.Description}) + _, err := sc.EventType.Update(ctx, et.Name, &svix.EventTypeUpdate{Description: et.Description}) if err != nil { return err } @@ -69,12 +70,12 @@ func createOrUpdateEventType(sc *svix.Svix, et *svix.EventTypeIn, update bool) e return nil } -func GetAllEventTypes(sc *svix.Svix) ([]svix.EventTypeOut, error) { +func GetAllEventTypes(ctx context.Context, sc *svix.Svix) ([]svix.EventTypeOut, error) { var eventTypes []svix.EventTypeOut done := false var iterator *string for !done { - out, err := sc.EventType.List(&svix.EventTypeListOptions{ + out, err := sc.EventType.List(ctx, &svix.EventTypeListOptions{ Iterator: iterator, }) if err != nil {