-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokens.go
42 lines (31 loc) · 1.23 KB
/
tokens.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
package client
import (
"context"
"time"
"github.com/canonical/lxd/shared/api"
"github.com/masnax/microclustertest/internal/rest/types"
)
// RequestToken requests a join token with the given name.
func (c *Client) RequestToken(ctx context.Context, name string) (string, error) {
queryCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
var token string
tokenRecord := types.TokenRecord{Name: name}
err := c.QueryStruct(queryCtx, "POST", PublicEndpoint, api.NewURL().Path("tokens"), tokenRecord, &token)
return token, err
}
// DeleteTokenRecord deletes the toekn record.
func (c *Client) DeleteTokenRecord(ctx context.Context, name string) error {
queryCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
err := c.QueryStruct(queryCtx, "DELETE", InternalEndpoint, api.NewURL().Path("tokens", name), nil, nil)
return err
}
// GetTokenRecords returns the token records.
func (c *Client) GetTokenRecords(ctx context.Context) ([]types.TokenRecord, error) {
queryCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
tokenRecords := []types.TokenRecord{}
err := c.QueryStruct(queryCtx, "GET", PublicEndpoint, api.NewURL().Path("tokens"), nil, &tokenRecords)
return tokenRecords, err
}