-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager_http.go
95 lines (81 loc) · 2.29 KB
/
manager_http.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
package jwk
import (
"net/http"
"net/url"
"github.com/ory/hydra/pkg"
"github.com/square/go-jose"
)
type HTTPManager struct {
Client *http.Client
Endpoint *url.URL
Dry bool
FakeTLSTermination bool
}
func (m *HTTPManager) CreateKeys(set, algorithm string) (*jose.JSONWebKeySet, error) {
var c = struct {
Algorithm string `json:"alg"`
Keys []jose.JSONWebKey `json:"keys"`
}{
Algorithm: algorithm,
}
var r = pkg.NewSuperAgent(pkg.JoinURL(m.Endpoint, set).String())
r.Client = m.Client
r.Dry = m.Dry
r.FakeTLSTermination = m.FakeTLSTermination
if err := r.Create(&c); err != nil {
return nil, err
}
return &jose.JSONWebKeySet{
Keys: c.Keys,
}, nil
}
func (m *HTTPManager) AddKey(set string, key *jose.JSONWebKey) error {
var r = pkg.NewSuperAgent(pkg.JoinURL(m.Endpoint, set, key.KeyID).String())
r.Client = m.Client
r.Dry = m.Dry
r.FakeTLSTermination = m.FakeTLSTermination
return r.Update(key)
}
func (m *HTTPManager) AddKeySet(set string, keys *jose.JSONWebKeySet) error {
var r = pkg.NewSuperAgent(pkg.JoinURL(m.Endpoint, set).String())
r.Client = m.Client
r.Dry = m.Dry
r.FakeTLSTermination = m.FakeTLSTermination
return r.Update(keys)
}
func (m *HTTPManager) GetKey(set, kid string) (*jose.JSONWebKeySet, error) {
var c jose.JSONWebKeySet
var r = pkg.NewSuperAgent(pkg.JoinURL(m.Endpoint, set, kid).String())
r.Client = m.Client
r.Dry = m.Dry
r.FakeTLSTermination = m.FakeTLSTermination
if err := r.Get(&c); err != nil {
return nil, err
}
return &c, nil
}
func (m *HTTPManager) GetKeySet(set string) (*jose.JSONWebKeySet, error) {
var c jose.JSONWebKeySet
var r = pkg.NewSuperAgent(pkg.JoinURL(m.Endpoint, set).String())
r.Client = m.Client
r.Dry = m.Dry
r.FakeTLSTermination = m.FakeTLSTermination
if err := r.Get(&c); err != nil {
return nil, err
}
return &c, nil
}
func (m *HTTPManager) DeleteKey(set, kid string) error {
var r = pkg.NewSuperAgent(pkg.JoinURL(m.Endpoint, set, kid).String())
r.Client = m.Client
r.Dry = m.Dry
r.FakeTLSTermination = m.FakeTLSTermination
return r.Delete()
}
func (m *HTTPManager) DeleteKeySet(set string) error {
var r = pkg.NewSuperAgent(pkg.JoinURL(m.Endpoint, set).String())
r.Client = m.Client
r.Dry = m.Dry
r.FakeTLSTermination = m.FakeTLSTermination
return r.Delete()
}