-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtoken.go
More file actions
40 lines (35 loc) · 1.27 KB
/
token.go
File metadata and controls
40 lines (35 loc) · 1.27 KB
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
package nimbusec
// Token represents the credentials of an API or agent for the nimbusec API.
type Token struct {
Id int `json:"id"` // unique identification of a token
Name string `json:"name"` // given name for a token
Key string `json:"key"` // oauth key
Secret string `json:"secret"` // oauth secret
LastCall int `json:"lastCall"` // last timestamp (in ms) an agent used the token
Version int `json:"version"` // last agent version that was seen for this key
}
// CreateToken issues the nimbusec API to create a new agent token.
func (a *API) CreateToken(token *Token) (*Token, error) {
dst := new(Token)
url := a.BuildURL("/v2/agent/token")
err := a.Post(url, Params{}, token, dst)
return dst, err
}
// GetToken fetches a token by its ID.
func (a *API) GetToken(token int) (*Token, error) {
dst := new(Token)
url := a.BuildURL("/v2/agent/token/%d", token)
err := a.Get(url, Params{}, dst)
return dst, err
}
// FindTOkens searches for tokens that match the given filter criteria.
func (a *API) FindTokens(filter string) ([]Token, error) {
params := Params{}
if filter != EmptyFilter {
params["q"] = filter
}
dst := make([]Token, 0)
url := a.BuildURL("/v2/agent/token")
err := a.Get(url, params, &dst)
return dst, err
}