This repository has been archived by the owner on Apr 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
api_keys.go
79 lines (65 loc) · 2.11 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
67
68
69
70
71
72
73
74
75
76
77
78
79
package stormpath
import "net/url"
//APIKey represents an Account key id/secret pair resource
//
//See: https://docs.stormpath.com/rest/product-guide/latest/reference.html#account-api-keys
type APIKey struct {
resource
ID string `json:"id"`
Secret string `json:"secret"`
Status string `json:"status"`
Account *Account `json:"account"`
Tenant *Tenant `json:"tenant"`
}
//APIKeys represents a collection of APIKey resources
type APIKeys struct {
collectionResource
Items []APIKey `json:"items,omitempty"`
}
//APIKeyCriteria represents the criteria type for the APIKey resource
type APIKeyCriteria struct {
baseCriteria
}
//MakeAPIKeyCriteria creates a default APIKeyCriteria for a single APIKey resource
func MakeAPIKeyCriteria() APIKeyCriteria {
return APIKeyCriteria{baseCriteria{filter: url.Values{}}}
}
//MakeAPIKeysCriteria creates a default APIKeyCriteria for a APIKeys collection resource
func MakeAPIKeysCriteria() APIKeyCriteria {
return APIKeyCriteria{baseCriteria{limit: 25, filter: url.Values{}}}
}
//GetAPIKey retrives an APIKey resource by href and optional criteria
func GetAPIKey(href string, criteria APIKeyCriteria) (*APIKey, error) {
apiKey := &APIKey{}
err := client.get(
buildAbsoluteURL(href, criteria.toQueryString()),
apiKey,
)
if err != nil {
return nil, err
}
return apiKey, nil
}
//Delete deletes a given APIKey
func (k *APIKey) Delete() error {
return client.delete(k.Href)
}
//Update updates the given APIKey against Stormpath
func (k *APIKey) Update() error {
return client.post(k.Href, map[string]string{"status": k.Status}, k)
}
//WithAccount adds the account expansion to the given APIKeyCriteria
func (c APIKeyCriteria) WithAccount() APIKeyCriteria {
c.expandedAttributes = append(c.expandedAttributes, "account")
return c
}
//WithTenant adds the tenant expansion to the given APIKeyCriteria
func (c APIKeyCriteria) WithTenant() APIKeyCriteria {
c.expandedAttributes = append(c.expandedAttributes, "tenant")
return c
}
//IDEq adds the id filter to the given APIKeyCriteria
func (c APIKeyCriteria) IDEq(id string) APIKeyCriteria {
c.filter.Add("id", id)
return c
}