Skip to content

Commit

Permalink
Upgrade svix libs and fix default endpoint version in 'create endpoin…
Browse files Browse the repository at this point in the history
…t' command (#98)

* Upgrade svix lib and set endpoint version to 1 when it is not specified

* Add command context with timeout

* Use correct patterns

* a bit more refactoring
  • Loading branch information
svix-lucho authored Aug 3, 2023
1 parent 8ae69bc commit a91eae1
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 61 deletions.
11 changes: 5 additions & 6 deletions cmd/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type applicationCmd struct {
}

func newApplicationCmd() *applicationCmd {

ac := &applicationCmd{}
ac.cmd = &cobra.Command{
Use: "application",
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions cmd/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
},
}
Expand Down Expand Up @@ -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)
Expand Down
34 changes: 16 additions & 18 deletions cmd/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -56,7 +56,7 @@ func newEndpointCmd() *endpointCmd {
Example Schema:
{
"url": "string",
"version": 0,
"version": 1,
"description": "",
"filterTypes": [
"string"
Expand Down Expand Up @@ -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)
Expand All @@ -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, "")
Expand All @@ -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)
Expand All @@ -153,7 +151,7 @@ Example Schema:
Example Schema:
{
"url": "string",
"version": 0,
"version": 1,
"description": "",
"filterTypes": [
"string"
Expand Down Expand Up @@ -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, "")
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
},
}
Expand Down Expand Up @@ -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)
},
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion cmd/export.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"encoding/json"
"flag"
"io"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions cmd/import.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"flag"
"fmt"
"io"
Expand Down Expand Up @@ -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)
}
},
Expand Down
14 changes: 7 additions & 7 deletions cmd/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
},
}
Expand All @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions cmd/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Loading

0 comments on commit a91eae1

Please sign in to comment.