-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_keys.go
More file actions
60 lines (48 loc) · 1.61 KB
/
api_keys.go
File metadata and controls
60 lines (48 loc) · 1.61 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package linkvite
import "context"
// APIKeysService handles API key operations.
type APIKeysService struct {
client *Client
}
// CreateAPIKeyInput represents input for creating an API key.
type CreateAPIKeyInput struct {
Name string `json:"name"`
Scopes []string `json:"scopes,omitempty"`
}
// EditAPIKeyInput represents input for editing an API key.
type EditAPIKeyInput struct {
Name string `json:"name,omitempty"`
Scopes []string `json:"scopes,omitempty"`
}
// CreateAPIKeyResult represents the result when creating an API key.
// The Key field contains the full API key and is only returned once.
type CreateAPIKeyResult struct {
APIKey
Key string `json:"key"`
}
// List retrieves all API keys for the current user.
func (s *APIKeysService) List(ctx context.Context) ([]*APIKey, error) {
var result []*APIKey
if err := s.client.get(ctx, "/api-keys", &result); err != nil {
return nil, err
}
return result, nil
}
// Create creates a new API key.
// The returned CreateAPIKeyResult contains the full API key in the Key field.
// This is the only time the full key is available.
func (s *APIKeysService) Create(ctx context.Context, input *CreateAPIKeyInput) (*CreateAPIKeyResult, error) {
var result CreateAPIKeyResult
if err := s.client.post(ctx, "/api-keys", input, &result); err != nil {
return nil, err
}
return &result, nil
}
// Edit updates an API key.
func (s *APIKeysService) Edit(ctx context.Context, id string, input *EditAPIKeyInput) (*APIKey, error) {
var result APIKey
if err := s.client.patch(ctx, "/api-keys/"+id, input, &result); err != nil {
return nil, err
}
return &result, nil
}