Skip to content

Commit

Permalink
Add webhookdb integration roll-key command
Browse files Browse the repository at this point in the history
Supports replacing the the webhookdb api key for an integration.
  • Loading branch information
rgalanakis committed Jan 15, 2024
1 parent 00fd6be commit f29f6aa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions client/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"-"`
Expand Down
22 changes: 22 additions & 0 deletions cmd/cmd_integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.",
Expand Down

0 comments on commit f29f6aa

Please sign in to comment.