-
Notifications
You must be signed in to change notification settings - Fork 0
/
password.go
96 lines (80 loc) · 2.05 KB
/
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/jlewi/bsctl/pkg"
"os"
comatproto "github.com/bluesky-social/indigo/api/atproto"
"github.com/urfave/cli/v2"
)
func doListAppPasswords(cCtx *cli.Context) error {
if cCtx.Args().Present() {
return cli.ShowSubcommandHelp(cCtx)
}
xrpcc, err := pkg.MakeXRPCC(cCtx)
if err != nil {
return fmt.Errorf("cannot create client: %w", err)
}
arg := cCtx.String("handle")
if arg == "" {
arg = xrpcc.Auth.Handle
}
passwords, err := comatproto.ServerListAppPasswords(context.TODO(), xrpcc)
if err != nil {
return fmt.Errorf("cannot get profile: %w", err)
}
if cCtx.Bool("json") {
for _, password := range passwords.Passwords {
json.NewEncoder(os.Stdout).Encode(password)
}
return nil
}
for _, password := range passwords.Passwords {
fmt.Printf("%s (%s)\n", password.Name, password.CreatedAt)
}
return nil
}
func doAddAppPassword(cCtx *cli.Context) error {
if !cCtx.Args().Present() {
return cli.ShowSubcommandHelp(cCtx)
}
xrpcc, err := pkg.MakeXRPCC(cCtx)
if err != nil {
return fmt.Errorf("cannot create client: %w", err)
}
for _, arg := range cCtx.Args().Slice() {
input := &comatproto.ServerCreateAppPassword_Input{
Name: arg,
}
password, err := comatproto.ServerCreateAppPassword(context.TODO(), xrpcc, input)
if err != nil {
return fmt.Errorf("cannot create app-password: %w", err)
}
if cCtx.Bool("json") {
json.NewEncoder(os.Stdout).Encode(password)
} else {
fmt.Printf("%s: %s\n", password.Name, password.Password)
}
}
return nil
}
func doRevokeAppPassword(cCtx *cli.Context) error {
if !cCtx.Args().Present() {
return cli.ShowSubcommandHelp(cCtx)
}
xrpcc, err := pkg.MakeXRPCC(cCtx)
if err != nil {
return fmt.Errorf("cannot create client: %w", err)
}
for _, arg := range cCtx.Args().Slice() {
input := &comatproto.ServerRevokeAppPassword_Input{
Name: arg,
}
err := comatproto.ServerRevokeAppPassword(context.TODO(), xrpcc, input)
if err != nil {
return fmt.Errorf("cannot create app-password: %w", err)
}
}
return nil
}