/
mtlsauth.go
84 lines (73 loc) · 2.02 KB
/
mtlsauth.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
package state
// MTLSAuthsCollection stores and indexes mtls-auth credentials.
type MTLSAuthsCollection struct {
credentialsCollection
}
func newMTLSAuthsCollection(common collection) *MTLSAuthsCollection {
return &MTLSAuthsCollection{
credentialsCollection: credentialsCollection{
collection: common,
CredType: "mtls-auth",
},
}
}
// Add adds a mtls-auth credential to MTLSAuthsCollection
func (k *MTLSAuthsCollection) Add(mtlsAuth MTLSAuth) error {
cred := (entity)(&mtlsAuth)
return k.credentialsCollection.Add(cred)
}
// Get gets a mtls-auth credential by ID.
func (k *MTLSAuthsCollection) Get(ID string) (*MTLSAuth, error) {
cred, err := k.credentialsCollection.Get(ID)
if err != nil {
return nil, err
}
mtlsAuth, ok := cred.(*MTLSAuth)
if !ok {
panic(unexpectedType)
}
return &MTLSAuth{MTLSAuth: *mtlsAuth.DeepCopy()}, nil
}
// GetAllByConsumerID returns all mtls-auth credentials
// belong to a Consumer with id.
func (k *MTLSAuthsCollection) GetAllByConsumerID(id string) ([]*MTLSAuth,
error) {
creds, err := k.credentialsCollection.GetAllByConsumerID(id)
if err != nil {
return nil, err
}
var res []*MTLSAuth
for _, cred := range creds {
r, ok := cred.(*MTLSAuth)
if !ok {
panic(unexpectedType)
}
res = append(res, &MTLSAuth{MTLSAuth: *r.DeepCopy()})
}
return res, nil
}
// Update updates an existing mtls-auth credential.
func (k *MTLSAuthsCollection) Update(mtlsAuth MTLSAuth) error {
cred := (entity)(&mtlsAuth)
return k.credentialsCollection.Update(cred)
}
// Delete deletes a mtls-auth credential by ID.
func (k *MTLSAuthsCollection) Delete(ID string) error {
return k.credentialsCollection.Delete(ID)
}
// GetAll gets all mtls-auth credentials.
func (k *MTLSAuthsCollection) GetAll() ([]*MTLSAuth, error) {
creds, err := k.credentialsCollection.GetAll()
if err != nil {
return nil, err
}
var res []*MTLSAuth
for _, cred := range creds {
r, ok := cred.(*MTLSAuth)
if !ok {
panic(unexpectedType)
}
res = append(res, &MTLSAuth{MTLSAuth: *r.DeepCopy()})
}
return res, nil
}