-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
handler_jwk.go
86 lines (72 loc) · 1.86 KB
/
handler_jwk.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
package cli
import (
"encoding/json"
"fmt"
"github.com/ory-am/hydra/config"
"github.com/ory-am/hydra/jwk"
"github.com/ory-am/hydra/pkg"
"github.com/spf13/cobra"
)
type JWKHandler struct {
Config *config.Config
M *jwk.HTTPManager
}
func newJWKHandler(c *config.Config) *JWKHandler {
return &JWKHandler{
Config: c,
M: &jwk.HTTPManager{},
}
}
func (h *JWKHandler) CreateKeys(cmd *cobra.Command, args []string) {
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Endpoint = h.Config.Resolve("/keys")
h.M.Client = h.Config.OAuth2Client(cmd)
if len(args) == 0 {
fmt.Println(cmd.UsageString())
return
}
alg, _ := cmd.Flags().GetString("alg")
keys, err := h.M.CreateKeys(args[0], alg)
if h.M.Dry {
fmt.Printf("%s\n", err)
return
}
pkg.Must(err, "Could not generate keys: %s", err)
out, err := json.MarshalIndent(keys, "", "\t")
pkg.Must(err, "Could not marshall keys: %s", err)
fmt.Printf("%s\n", out)
}
func (h *JWKHandler) GetKeys(cmd *cobra.Command, args []string) {
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Endpoint = h.Config.Resolve("/keys")
h.M.Client = h.Config.OAuth2Client(cmd)
if len(args) == 0 {
fmt.Println(cmd.UsageString())
return
}
keys, err := h.M.GetKeySet(args[0])
if h.M.Dry {
fmt.Printf("%s\n", err)
return
}
pkg.Must(err, "Could not generate keys: %s", err)
out, err := json.MarshalIndent(keys, "", "\t")
pkg.Must(err, "Could not marshall keys: %s", err)
fmt.Printf("%s\n", out)
}
func (h *JWKHandler) DeleteKeys(cmd *cobra.Command, args []string) {
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Endpoint = h.Config.Resolve("/keys")
h.M.Client = h.Config.OAuth2Client(cmd)
if len(args) == 0 {
fmt.Println(cmd.UsageString())
return
}
err := h.M.DeleteKeySet(args[0])
if h.M.Dry {
fmt.Printf("%s\n", err)
return
}
pkg.Must(err, "Could not generate keys: %s", err)
fmt.Println("Key set deleted.")
}