-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkspaceapikey.go
More file actions
94 lines (82 loc) · 3.11 KB
/
workspaceapikey.go
File metadata and controls
94 lines (82 loc) · 3.11 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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package openlayer
import (
"context"
"errors"
"fmt"
"net/http"
"slices"
"time"
"github.com/openlayer-ai/openlayer-go/internal/apijson"
"github.com/openlayer-ai/openlayer-go/internal/param"
"github.com/openlayer-ai/openlayer-go/internal/requestconfig"
"github.com/openlayer-ai/openlayer-go/option"
)
// WorkspaceAPIKeyService contains methods and other services that help with
// interacting with the openlayer API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewWorkspaceAPIKeyService] method instead.
type WorkspaceAPIKeyService struct {
Options []option.RequestOption
}
// NewWorkspaceAPIKeyService generates a new service that applies the given options
// to each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewWorkspaceAPIKeyService(opts ...option.RequestOption) (r *WorkspaceAPIKeyService) {
r = &WorkspaceAPIKeyService{}
r.Options = opts
return
}
// Create a new API key in a workspace.
func (r *WorkspaceAPIKeyService) New(ctx context.Context, workspaceID string, body WorkspaceAPIKeyNewParams, opts ...option.RequestOption) (res *WorkspaceAPIKeyNewResponse, err error) {
opts = slices.Concat(r.Options, opts)
if workspaceID == "" {
err = errors.New("missing required workspaceId parameter")
return nil, err
}
path := fmt.Sprintf("workspaces/%s/api-keys", workspaceID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
type WorkspaceAPIKeyNewResponse struct {
// The API key id.
ID string `json:"id" api:"required" format:"uuid"`
// The API key creation date.
DateCreated time.Time `json:"dateCreated" api:"required" format:"date-time"`
// The API key last use date.
DateLastUsed time.Time `json:"dateLastUsed" api:"required,nullable" format:"date-time"`
// The API key last update date.
DateUpdated time.Time `json:"dateUpdated" api:"required" format:"date-time"`
// The API key value.
SecureKey string `json:"secureKey" api:"required"`
// The API key name.
Name string `json:"name" api:"nullable"`
JSON workspaceAPIKeyNewResponseJSON `json:"-"`
}
// workspaceAPIKeyNewResponseJSON contains the JSON metadata for the struct
// [WorkspaceAPIKeyNewResponse]
type workspaceAPIKeyNewResponseJSON struct {
ID apijson.Field
DateCreated apijson.Field
DateLastUsed apijson.Field
DateUpdated apijson.Field
SecureKey apijson.Field
Name apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *WorkspaceAPIKeyNewResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r workspaceAPIKeyNewResponseJSON) RawJSON() string {
return r.raw
}
type WorkspaceAPIKeyNewParams struct {
// The API key name.
Name param.Field[string] `json:"name"`
}
func (r WorkspaceAPIKeyNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}