-
Notifications
You must be signed in to change notification settings - Fork 221
/
token.go
46 lines (36 loc) · 978 Bytes
/
token.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
package auth
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/iostreams"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/config"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/internal/render"
)
func newToken() *cobra.Command {
const (
long = `Shows the authentication token that is currently in use.
This can be used as an authentication token with API services,
independent of flyctl.
`
short = "Show the current auth token"
)
cmd := command.New("token", short, long, runAuthToken,
command.ExcludeFromMetrics,
command.RequireSession,
)
flag.Add(cmd, flag.JSONOutput())
return cmd
}
func runAuthToken(ctx context.Context) error {
cfg := config.FromContext(ctx)
token := cfg.AccessToken
if io := iostreams.FromContext(ctx); cfg.JSONOutput {
render.JSON(io.Out, map[string]string{"token": token})
} else {
fmt.Fprintln(io.Out, token)
}
return nil
}