-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathapi_keys.go
More file actions
117 lines (104 loc) · 4.56 KB
/
Copy pathapi_keys.go
File metadata and controls
117 lines (104 loc) · 4.56 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Code generated by oagen. DO NOT EDIT.
package workos
import (
"context"
"encoding/json"
"fmt"
"net/url"
)
// APIKeyService handles ApiKeys operations.
type APIKeyService struct {
client *Client
}
// APIKeysListOrganizationAPIKeysParams contains the parameters for ListOrganizationAPIKeys.
type APIKeysListOrganizationAPIKeysParams struct {
PaginationParams
}
// ListOrganizationAPIKeys list API keys for an organization
// Get a list of all API keys for an organization.
func (s *APIKeyService) ListOrganizationAPIKeys(ctx context.Context, organizationID string, params *APIKeysListOrganizationAPIKeysParams, opts ...RequestOption) *Iterator[OrganizationAPIKey] {
return newIterator[OrganizationAPIKey](ctx, s.client, "GET", fmt.Sprintf("/organizations/%s/api_keys", url.PathEscape(organizationID)), params, "after", "data", opts, map[string]string{"limit": "10", "order": "desc"})
}
// APIKeysCreateOrganizationAPIKeyParams contains the parameters for CreateOrganizationAPIKey.
type APIKeysCreateOrganizationAPIKeyParams struct {
// Name is the name for the API key.
Name string `json:"name" url:"-"`
// Permissions is the permission slugs to assign to the API key.
Permissions []string `json:"permissions,omitempty" url:"-"`
// ExpiresAt is the timestamp when the API key should expire. Must be a future timestamp. If omitted, the key does not expire.
ExpiresAt *string `json:"expires_at,omitempty" url:"-"`
}
// CreateOrganizationAPIKey create an API key for an organization
// Create a new API key for an organization.
func (s *APIKeyService) CreateOrganizationAPIKey(ctx context.Context, organizationID string, params *APIKeysCreateOrganizationAPIKeyParams, opts ...RequestOption) (*OrganizationAPIKeyWithValue, error) {
var result OrganizationAPIKeyWithValue
_, err := s.client.request(ctx, "POST", fmt.Sprintf("/organizations/%s/api_keys", url.PathEscape(organizationID)), nil, params, &result, opts)
if err != nil {
return nil, err
}
return &result, nil
}
// APIKeysCreateValidationParams contains the parameters for CreateValidation.
type APIKeysCreateValidationParams struct {
// Value is the value for an API key.
Value string `json:"value" url:"-"`
}
// CreateValidation validate API key
// Validate an API key value and return the API key object if valid.
func (s *APIKeyService) CreateValidation(ctx context.Context, params *APIKeysCreateValidationParams, opts ...RequestOption) (*APIKeyValidationResponse, error) {
var result APIKeyValidationResponse
_, err := s.client.request(ctx, "POST", "/api_keys/validations", nil, params, &result, opts)
if err != nil {
return nil, err
}
return &result, nil
}
// Delete an API key
// Permanently deletes an API key. This action cannot be undone. Once deleted, any requests using this API key will fail authentication.
func (s *APIKeyService) Delete(ctx context.Context, id string, opts ...RequestOption) error {
_, err := s.client.request(ctx, "DELETE", fmt.Sprintf("/api_keys/%s", url.PathEscape(id)), nil, nil, nil, opts)
return err
}
// APIKeysCreateExpireParams contains the parameters for CreateExpire.
type APIKeysCreateExpireParams struct {
// ExpiresAt is when the API key should expire. If omitted or in the past, the key expires immediately. Use null to clear a scheduled future expiration.
ExpiresAt *string `json:"expires_at,omitempty" url:"-"`
// NullFields lists JSON field names to send as an explicit null,
// clearing the corresponding value (e.g. []string{"external_id"}).
NullFields []string `json:"-" url:"-"`
}
// MarshalJSON implements json.Marshaler for APIKeysCreateExpireParams.
func (p APIKeysCreateExpireParams) MarshalJSON() ([]byte, error) {
type Alias APIKeysCreateExpireParams
data, err := json.Marshal(Alias(p))
if err != nil {
return nil, err
}
if len(p.NullFields) == 0 {
return data, nil
}
var m map[string]any
if err := json.Unmarshal(data, &m); err != nil {
return nil, err
}
nullable := map[string]bool{
"expires_at": true,
}
for _, f := range p.NullFields {
if !nullable[f] {
return nil, fmt.Errorf("APIKeysCreateExpireParams: %q is not a nullable field", f)
}
m[f] = nil
}
return json.Marshal(m)
}
// CreateExpire expire an API key
// Expire an API key immediately, schedule a future expiration, or clear a scheduled future expiration.
func (s *APIKeyService) CreateExpire(ctx context.Context, id string, params *APIKeysCreateExpireParams, opts ...RequestOption) (*APIKey, error) {
var result APIKey
_, err := s.client.request(ctx, "POST", fmt.Sprintf("/api_keys/%s/expire", url.PathEscape(id)), nil, params, &result, opts)
if err != nil {
return nil, err
}
return &result, nil
}