-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.go
58 lines (45 loc) · 1 KB
/
index.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
package test
import (
"fmt"
"github.com/charmbracelet/lipgloss"
"github.com/spf13/cobra"
tokencli "github.com/simiancreative/simiango/simian-go/app/token"
"github.com/simiancreative/simiango/token"
)
var key string
var tokenStr string
var cmd = &cobra.Command{
Use: "test",
Short: "test a jwt token",
RunE: func(cmd *cobra.Command, args []string) error {
return run()
},
}
func init() {
cmd.Flags().StringVarP(&key, "key", "k", "", "the jwt secret key")
cmd.Flags().StringVarP(&tokenStr, "token", "t", "", "the jwt token")
tokencli.Cmd.AddCommand(cmd)
}
func run() error {
if len(key) == 0 {
return fmt.Errorf("secret required")
}
err := token.TestWithSecret(
tokenStr,
[]byte(key),
)
if err != nil {
return err
}
var style = lipgloss.NewStyle().
Foreground(lipgloss.Color("#FFF")).
Background(lipgloss.Color("#158978")).
Bold(true).
MarginTop(1).
PaddingTop(1).
PaddingRight(4).
PaddingBottom(1).
PaddingLeft(4)
fmt.Println(style.Render("valid 👍"))
return nil
}