-
Notifications
You must be signed in to change notification settings - Fork 3
/
agent_pool_token.go
62 lines (49 loc) · 1.7 KB
/
agent_pool_token.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
package scalr
import (
"context"
"fmt"
"net/url"
)
// Compile-time proof of interface implementation.
var _ AgentPoolTokens = (*agentPoolTokens)(nil)
// AgentPoolTokens describes all the access token related methods that the
// Scalr IACP API supports.
type AgentPoolTokens interface {
List(ctx context.Context, agentPoolID string, options AccessTokenListOptions) (*AccessTokenList, error)
Create(ctx context.Context, agentPoolID string, options AccessTokenCreateOptions) (*AccessToken, error)
}
// agentPoolTokens implements AgentPoolTokens.
type agentPoolTokens struct {
client *Client
}
// List all the agent pool's tokens.
func (s *agentPoolTokens) List(ctx context.Context, agentPoolID string, options AccessTokenListOptions) (*AccessTokenList, error) {
req, err := s.client.newRequest("GET", fmt.Sprintf("agent-pools/%s/access-tokens", url.QueryEscape(agentPoolID)), &options)
if err != nil {
return nil, err
}
tl := &AccessTokenList{}
err = s.client.do(ctx, req, tl)
if err != nil {
return nil, err
}
return tl, nil
}
// Create is used to create a new AccessToken for AgentPool.
func (s *agentPoolTokens) Create(ctx context.Context, agentPoolID string, options AccessTokenCreateOptions) (*AccessToken, error) {
// Make sure we don't send a user provided ID.
options.ID = ""
if !validStringID(&agentPoolID) {
return nil, fmt.Errorf("invalid value for agent pool ID: '%s'", agentPoolID)
}
req, err := s.client.newRequest("POST", fmt.Sprintf("agent-pools/%s/access-tokens", url.QueryEscape(agentPoolID)), &options)
if err != nil {
return nil, err
}
agentPoolToken := &AccessToken{}
err = s.client.do(ctx, req, agentPoolToken)
if err != nil {
return nil, err
}
return agentPoolToken, nil
}