File: hmacauth.go

package info (click to toggle)
deck 1.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,080 kB
  • sloc: makefile: 17; sh: 3
file content (84 lines) | stat: -rw-r--r-- 2,102 bytes parent folder | download | duplicates (2)
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

// HMACAuthsCollection stores and indexes hmac-auth credentials.
type HMACAuthsCollection struct {
	credentialsCollection
}

func newHMACAuthsCollection(common collection) *HMACAuthsCollection {
	return &HMACAuthsCollection{
		credentialsCollection: credentialsCollection{
			collection: common,
			CredType:   "hmac-auth",
		},
	}
}

// Add adds a hmac-auth credential to HMACAuthsCollection
func (k *HMACAuthsCollection) Add(hmacAuth HMACAuth) error {
	cred := (entity)(&hmacAuth)
	return k.credentialsCollection.Add(cred)
}

// Get gets a hmac-auth credential by key or ID.
func (k *HMACAuthsCollection) Get(keyOrID string) (*HMACAuth, error) {
	cred, err := k.credentialsCollection.Get(keyOrID)
	if err != nil {
		return nil, err
	}

	hmacAuth, ok := cred.(*HMACAuth)
	if !ok {
		panic(unexpectedType)
	}
	return &HMACAuth{HMACAuth: *hmacAuth.DeepCopy()}, nil
}

// GetAllByConsumerID returns all hmac-auth credentials
// belong to a Consumer with id.
func (k *HMACAuthsCollection) GetAllByConsumerID(id string) ([]*HMACAuth,
	error) {
	creds, err := k.credentialsCollection.GetAllByConsumerID(id)
	if err != nil {
		return nil, err
	}

	var res []*HMACAuth
	for _, cred := range creds {
		r, ok := cred.(*HMACAuth)
		if !ok {
			panic(unexpectedType)
		}
		res = append(res, &HMACAuth{HMACAuth: *r.DeepCopy()})
	}
	return res, nil
}

// Update updates an existing hmac-auth credential.
func (k *HMACAuthsCollection) Update(hmacAuth HMACAuth) error {
	cred := (entity)(&hmacAuth)
	return k.credentialsCollection.Update(cred)
}

// Delete deletes a hmac-auth credential by key or ID.
func (k *HMACAuthsCollection) Delete(keyOrID string) error {
	return k.credentialsCollection.Delete(keyOrID)
}

// GetAll gets all hmac-auth credentials.
func (k *HMACAuthsCollection) GetAll() ([]*HMACAuth, error) {
	creds, err := k.credentialsCollection.GetAll()
	if err != nil {
		return nil, err
	}

	var res []*HMACAuth
	for _, cred := range creds {
		r, ok := cred.(*HMACAuth)
		if !ok {
			panic(unexpectedType)
		}
		res = append(res, &HMACAuth{HMACAuth: *r.DeepCopy()})
	}
	return res, nil
}