-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprojectlimit.go
More file actions
132 lines (119 loc) · 5.15 KB
/
projectlimit.go
File metadata and controls
132 lines (119 loc) · 5.15 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package kernel
import (
"context"
"errors"
"fmt"
"net/http"
"slices"
"github.com/kernel/kernel-go-sdk/internal/apijson"
shimjson "github.com/kernel/kernel-go-sdk/internal/encoding/json"
"github.com/kernel/kernel-go-sdk/internal/requestconfig"
"github.com/kernel/kernel-go-sdk/option"
"github.com/kernel/kernel-go-sdk/packages/param"
"github.com/kernel/kernel-go-sdk/packages/respjson"
)
// Create and manage projects for resource isolation within an organization.
//
// ProjectLimitService contains methods and other services that help with
// interacting with the kernel 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 [NewProjectLimitService] method instead.
type ProjectLimitService struct {
Options []option.RequestOption
}
// NewProjectLimitService 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 NewProjectLimitService(opts ...option.RequestOption) (r ProjectLimitService) {
r = ProjectLimitService{}
r.Options = opts
return
}
// Get the resource limit overrides for a project. Null values mean no
// project-level cap (org limit applies).
func (r *ProjectLimitService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *ProjectLimits, err error) {
opts = slices.Concat(r.Options, opts)
if id == "" {
err = errors.New("missing required id parameter")
return nil, err
}
path := fmt.Sprintf("projects/%s/limits", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// Update resource limit overrides for a project. Only fields present in the
// request are modified. Set a field to 0 to remove that limit cap; omit a field to
// leave it unchanged.
func (r *ProjectLimitService) Update(ctx context.Context, id string, body ProjectLimitUpdateParams, opts ...option.RequestOption) (res *ProjectLimits, err error) {
opts = slices.Concat(r.Options, opts)
if id == "" {
err = errors.New("missing required id parameter")
return nil, err
}
path := fmt.Sprintf("projects/%s/limits", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...)
return res, err
}
type ProjectLimits struct {
// Maximum concurrent app invocations for this project. Null means no project-level
// cap.
MaxConcurrentInvocations int64 `json:"max_concurrent_invocations" api:"nullable"`
// Maximum concurrent browser sessions for this project. Null means no
// project-level cap.
MaxConcurrentSessions int64 `json:"max_concurrent_sessions" api:"nullable"`
// Maximum persistent browser sessions for this project. Null means no
// project-level cap.
MaxPersistentSessions int64 `json:"max_persistent_sessions" api:"nullable"`
// Maximum pooled sessions capacity for this project. Null means no project-level
// cap.
MaxPooledSessions int64 `json:"max_pooled_sessions" api:"nullable"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
MaxConcurrentInvocations respjson.Field
MaxConcurrentSessions respjson.Field
MaxPersistentSessions respjson.Field
MaxPooledSessions respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ProjectLimits) RawJSON() string { return r.JSON.raw }
func (r *ProjectLimits) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type UpdateProjectLimitsRequestParam struct {
// Maximum concurrent app invocations for this project. Set to 0 to remove the cap;
// omit to leave unchanged.
MaxConcurrentInvocations param.Opt[int64] `json:"max_concurrent_invocations,omitzero"`
// Maximum concurrent browser sessions for this project. Set to 0 to remove the
// cap; omit to leave unchanged.
MaxConcurrentSessions param.Opt[int64] `json:"max_concurrent_sessions,omitzero"`
// Maximum persistent browser sessions for this project. Set to 0 to remove the
// cap; omit to leave unchanged.
MaxPersistentSessions param.Opt[int64] `json:"max_persistent_sessions,omitzero"`
// Maximum pooled sessions capacity for this project. Set to 0 to remove the cap;
// omit to leave unchanged.
MaxPooledSessions param.Opt[int64] `json:"max_pooled_sessions,omitzero"`
paramObj
}
func (r UpdateProjectLimitsRequestParam) MarshalJSON() (data []byte, err error) {
type shadow UpdateProjectLimitsRequestParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *UpdateProjectLimitsRequestParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type ProjectLimitUpdateParams struct {
UpdateProjectLimitsRequest UpdateProjectLimitsRequestParam
paramObj
}
func (r ProjectLimitUpdateParams) MarshalJSON() (data []byte, err error) {
return shimjson.Marshal(r.UpdateProjectLimitsRequest)
}
func (r *ProjectLimitUpdateParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}