Skip to content

Commit f29f6aa

Browse files
committed
Add webhookdb integration roll-key command
Supports replacing the the webhookdb api key for an integration.
1 parent 00fd6be commit f29f6aa

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

client/integrations.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ func IntegrationsReset(c context.Context, auth Auth, input IntegrationsResetInpu
7171
return makeStepRequestWithResponse(c, auth, nil, "/v1/organizations/%v/service_integrations/%v/reset", input.OrgIdentifier, input.IntegrationIdentifier)
7272
}
7373

74+
type IntegrationsRollKeyInput struct {
75+
IntegrationIdentifier string `json:"-"`
76+
OrgIdentifier types.OrgIdentifier `json:"-"`
77+
}
78+
79+
func IntegrationsRollKey(c context.Context, auth Auth, input IntegrationsRollKeyInput) (out IntegrationsRollKeyOutput, err error) {
80+
err = makeRequest(c, POST, auth, nil, &out, "/v1/organizations/%v/service_integrations/%v/roll_api_key", input.OrgIdentifier, input.IntegrationIdentifier)
81+
return
82+
}
83+
84+
type IntegrationsRollKeyOutput struct {
85+
WebhookdbApiKey string `json:"webhookdb_api_key"`
86+
}
87+
7488
type IntegrationsStatsInput struct {
7589
IntegrationIdentifier string `json:"-"`
7690
OrgIdentifier types.OrgIdentifier `json:"-"`

cmd/cmd_integrations.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"context"
5+
"fmt"
56
"github.com/urfave/cli/v2"
67
"github.com/webhookdb/webhookdb-cli/appcontext"
78
"github.com/webhookdb/webhookdb-cli/client"
@@ -140,6 +141,27 @@ var integrationsCmd = &cli.Command{
140141
return stateMachineResponseRunner(ctx, ac.Auth)(client.IntegrationsReset(ctx, ac.Auth, input))
141142
}),
142143
},
144+
{
145+
Name: "roll-key",
146+
Usage: "Roll the API key used to access this integration. Only relevant for certain integrations.",
147+
Flags: []cli.Flag{
148+
orgFlag(),
149+
integrationFlag(),
150+
},
151+
Action: cliAction(func(c *cli.Context, ac appcontext.AppContext, ctx context.Context) error {
152+
// This get some more work if it becomes more widely needed, but for now, it should be very rare.
153+
input := client.IntegrationsRollKeyInput{
154+
IntegrationIdentifier: getIntegrationFlagOrArg(c),
155+
OrgIdentifier: getOrgFlag(c, ac.Prefs),
156+
}
157+
out, err := client.IntegrationsRollKey(ctx, ac.Auth, input)
158+
if err != nil {
159+
return err
160+
}
161+
fmt.Fprint(c.App.Writer, out.WebhookdbApiKey)
162+
return nil
163+
}),
164+
},
143165
{
144166
Name: "stats",
145167
Usage: "Get statistics about webhooks for this integration.",

0 commit comments

Comments
 (0)