-
Notifications
You must be signed in to change notification settings - Fork 1
/
tokensDelete.go
59 lines (45 loc) · 1.17 KB
/
tokensDelete.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
package tokens
import (
"context"
"fmt"
"github.com/clintjedwards/gofer/internal/cli/cl"
proto "github.com/clintjedwards/gofer/proto/go"
"github.com/spf13/cobra"
"google.golang.org/grpc/metadata"
)
var cmdTokensDelete = &cobra.Command{
Use: "delete",
Short: "Delete specific token",
RunE: tokensDelete,
}
func init() {
CmdTokens.AddCommand(cmdTokensDelete)
}
func tokensDelete(_ *cobra.Command, _ []string) error {
cl.State.Fmt.Print("Deleting token")
cl.State.Fmt.Finish()
var input string
fmt.Print("Please paste the token to delete: ")
fmt.Scanln(&input)
cl.State.NewFormatter()
conn, err := cl.State.Connect()
if err != nil {
cl.State.Fmt.PrintErr(err)
cl.State.Fmt.Finish()
return err
}
client := proto.NewGoferClient(conn)
md := metadata.Pairs("Authorization", "Bearer "+cl.State.Config.Token)
ctx := metadata.NewOutgoingContext(context.Background(), md)
_, err = client.DeleteToken(ctx, &proto.DeleteTokenRequest{
Token: input,
})
if err != nil {
cl.State.Fmt.PrintErr(fmt.Sprintf("could not delete token: %v", err))
cl.State.Fmt.Finish()
return err
}
cl.State.Fmt.PrintSuccess("Token Deleted")
cl.State.Fmt.Finish()
return nil
}