-
Notifications
You must be signed in to change notification settings - Fork 240
/
reset_password.go
63 lines (47 loc) · 1.22 KB
/
reset_password.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package redis
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/gql"
"github.com/superfly/flyctl/iostreams"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
)
func newReset() (cmd *cobra.Command) {
const (
long = `Reset the password for an Upstash Redis database`
short = long
usage = "reset <name>"
)
cmd = command.New(usage, short, long, runReset, command.RequireSession)
flag.Add(cmd)
cmd.Args = cobra.ExactArgs(1)
return cmd
}
func runReset(ctx context.Context) (err error) {
var (
io = iostreams.FromContext(ctx)
client = client.FromContext(ctx).API().GenqClient
colorize = io.ColorScheme()
out = io.Out
)
name := flag.FirstArg(ctx)
_ = `# @genqlient
mutation ResetAddOnPassword($name: String!) {
resetAddOnPassword(input: {name: $name}) {
addOn {
publicUrl
}
}
}
`
response, err := gql.ResetAddOnPassword(ctx, client, name)
if err != nil {
return
}
fmt.Fprintf(out, "The password for your Redis database %s was reset.\n", name)
fmt.Fprintf(out, "Your new Redis connection URL is %s\n", colorize.Green(response.ResetAddOnPassword.AddOn.PublicUrl))
return
}