forked from jarias/stormpath-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_keys.go
66 lines (52 loc) · 1.32 KB
/
api_keys.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
package stormpath
import "net/url"
type APIKey struct {
resource
ID string `json:"id"`
Secret string `json:"secret"`
Status string `json:"status"`
Account *Account `json:"account"`
Tenant *Tenant `json:"tenant"`
}
type APIKeys struct {
collectionResource
Items []APIKey `json:"items,omitempty"`
}
type APIKeyCriteria struct {
baseCriteria
}
func MakeAPIKeyCriteria() APIKeyCriteria {
return APIKeyCriteria{baseCriteria{filter: url.Values{}}}
}
func MakeAPIKeysCriteria() APIKeyCriteria {
return APIKeyCriteria{baseCriteria{limit: 25, filter: url.Values{}}}
}
func GetAPIKey(href string, criteria Criteria) (*APIKey, error) {
apiKey := &APIKey{}
err := client.get(
buildAbsoluteURL(href, criteria.ToQueryString()),
apiKey,
)
if err != nil {
return nil, err
}
return apiKey, nil
}
func (k *APIKey) Delete() error {
return client.delete(k.Href)
}
func (k *APIKey) Update() error {
return client.post(k.Href, map[string]string{"status": k.Status}, k)
}
func (c APIKeyCriteria) WithAccount() APIKeyCriteria {
c.expandedAttributes = append(c.expandedAttributes, "account")
return c
}
func (c APIKeyCriteria) WithTenant() APIKeyCriteria {
c.expandedAttributes = append(c.expandedAttributes, "tenant")
return c
}
func (c APIKeyCriteria) idEq(id string) APIKeyCriteria {
c.filter.Add("id", id)
return c
}