diff --git a/client/integrations.go b/client/integrations.go index 7832cb6..9986838 100644 --- a/client/integrations.go +++ b/client/integrations.go @@ -71,6 +71,20 @@ func IntegrationsReset(c context.Context, auth Auth, input IntegrationsResetInpu return makeStepRequestWithResponse(c, auth, nil, "/v1/organizations/%v/service_integrations/%v/reset", input.OrgIdentifier, input.IntegrationIdentifier) } +type IntegrationsRollKeyInput struct { + IntegrationIdentifier string `json:"-"` + OrgIdentifier types.OrgIdentifier `json:"-"` +} + +func IntegrationsRollKey(c context.Context, auth Auth, input IntegrationsRollKeyInput) (out IntegrationsRollKeyOutput, err error) { + err = makeRequest(c, POST, auth, nil, &out, "/v1/organizations/%v/service_integrations/%v/roll_api_key", input.OrgIdentifier, input.IntegrationIdentifier) + return +} + +type IntegrationsRollKeyOutput struct { + WebhookdbApiKey string `json:"webhookdb_api_key"` +} + type IntegrationsStatsInput struct { IntegrationIdentifier string `json:"-"` OrgIdentifier types.OrgIdentifier `json:"-"` diff --git a/cmd/cmd_integrations.go b/cmd/cmd_integrations.go index a80cea0..af27b76 100644 --- a/cmd/cmd_integrations.go +++ b/cmd/cmd_integrations.go @@ -2,6 +2,7 @@ package cmd import ( "context" + "fmt" "github.com/urfave/cli/v2" "github.com/webhookdb/webhookdb-cli/appcontext" "github.com/webhookdb/webhookdb-cli/client" @@ -140,6 +141,27 @@ var integrationsCmd = &cli.Command{ return stateMachineResponseRunner(ctx, ac.Auth)(client.IntegrationsReset(ctx, ac.Auth, input)) }), }, + { + Name: "roll-key", + Usage: "Roll the API key used to access this integration. Only relevant for certain integrations.", + Flags: []cli.Flag{ + orgFlag(), + integrationFlag(), + }, + Action: cliAction(func(c *cli.Context, ac appcontext.AppContext, ctx context.Context) error { + // This get some more work if it becomes more widely needed, but for now, it should be very rare. + input := client.IntegrationsRollKeyInput{ + IntegrationIdentifier: getIntegrationFlagOrArg(c), + OrgIdentifier: getOrgFlag(c, ac.Prefs), + } + out, err := client.IntegrationsRollKey(ctx, ac.Auth, input) + if err != nil { + return err + } + fmt.Fprint(c.App.Writer, out.WebhookdbApiKey) + return nil + }), + }, { Name: "stats", Usage: "Get statistics about webhooks for this integration.",