|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +package kernel |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "net/http" |
| 8 | + "slices" |
| 9 | + |
| 10 | + "github.com/kernel/kernel-go-sdk/internal/apijson" |
| 11 | + shimjson "github.com/kernel/kernel-go-sdk/internal/encoding/json" |
| 12 | + "github.com/kernel/kernel-go-sdk/internal/requestconfig" |
| 13 | + "github.com/kernel/kernel-go-sdk/option" |
| 14 | + "github.com/kernel/kernel-go-sdk/packages/param" |
| 15 | + "github.com/kernel/kernel-go-sdk/packages/respjson" |
| 16 | +) |
| 17 | + |
| 18 | +// Read and manage organization-level limits. |
| 19 | +// |
| 20 | +// OrganizationLimitService contains methods and other services that help with |
| 21 | +// interacting with the kernel API. |
| 22 | +// |
| 23 | +// Note, unlike clients, this service does not read variables from the environment |
| 24 | +// automatically. You should not instantiate this service directly, and instead use |
| 25 | +// the [NewOrganizationLimitService] method instead. |
| 26 | +type OrganizationLimitService struct { |
| 27 | + Options []option.RequestOption |
| 28 | +} |
| 29 | + |
| 30 | +// NewOrganizationLimitService generates a new service that applies the given |
| 31 | +// options to each request. These options are applied after the parent client's |
| 32 | +// options (if there is one), and before any request-specific options. |
| 33 | +func NewOrganizationLimitService(opts ...option.RequestOption) (r OrganizationLimitService) { |
| 34 | + r = OrganizationLimitService{} |
| 35 | + r.Options = opts |
| 36 | + return |
| 37 | +} |
| 38 | + |
| 39 | +// Get the organization's concurrent session ceiling and the default per-project |
| 40 | +// concurrency cap applied to projects without an explicit override. |
| 41 | +func (r *OrganizationLimitService) Get(ctx context.Context, opts ...option.RequestOption) (res *OrgLimits, err error) { |
| 42 | + opts = slices.Concat(r.Options, opts) |
| 43 | + path := "org/limits" |
| 44 | + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) |
| 45 | + return res, err |
| 46 | +} |
| 47 | + |
| 48 | +// Set the default per-project concurrency cap applied to projects without an |
| 49 | +// explicit override. Set the value to 0 to remove the default; omit to leave it |
| 50 | +// unchanged. The default cannot exceed the organization's concurrent session |
| 51 | +// ceiling. |
| 52 | +func (r *OrganizationLimitService) Update(ctx context.Context, body OrganizationLimitUpdateParams, opts ...option.RequestOption) (res *OrgLimits, err error) { |
| 53 | + opts = slices.Concat(r.Options, opts) |
| 54 | + path := "org/limits" |
| 55 | + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...) |
| 56 | + return res, err |
| 57 | +} |
| 58 | + |
| 59 | +type OrgLimits struct { |
| 60 | + // Default maximum concurrent browser sessions applied to every project that has no |
| 61 | + // explicit per-project override. Null means no org-level default, so such projects |
| 62 | + // are uncapped (only the org-wide limit applies). Applies to existing and newly |
| 63 | + // created projects. |
| 64 | + DefaultProjectMaxConcurrentSessions int64 `json:"default_project_max_concurrent_sessions" api:"nullable"` |
| 65 | + // The organization's effective concurrent browser session ceiling, from its plan |
| 66 | + // or an override. Read-only and shared across all projects in the org; a |
| 67 | + // per-project default cannot exceed it. |
| 68 | + MaxConcurrentSessions int64 `json:"max_concurrent_sessions"` |
| 69 | + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. |
| 70 | + JSON struct { |
| 71 | + DefaultProjectMaxConcurrentSessions respjson.Field |
| 72 | + MaxConcurrentSessions respjson.Field |
| 73 | + ExtraFields map[string]respjson.Field |
| 74 | + raw string |
| 75 | + } `json:"-"` |
| 76 | +} |
| 77 | + |
| 78 | +// Returns the unmodified JSON received from the API |
| 79 | +func (r OrgLimits) RawJSON() string { return r.JSON.raw } |
| 80 | +func (r *OrgLimits) UnmarshalJSON(data []byte) error { |
| 81 | + return apijson.UnmarshalRoot(data, r) |
| 82 | +} |
| 83 | + |
| 84 | +type UpdateOrgLimitsRequestParam struct { |
| 85 | + // Default maximum concurrent browser sessions for projects without an explicit |
| 86 | + // override. Set to 0 to remove the default; omit to leave unchanged. Cannot exceed |
| 87 | + // the organization's concurrent session ceiling. |
| 88 | + DefaultProjectMaxConcurrentSessions param.Opt[int64] `json:"default_project_max_concurrent_sessions,omitzero"` |
| 89 | + paramObj |
| 90 | +} |
| 91 | + |
| 92 | +func (r UpdateOrgLimitsRequestParam) MarshalJSON() (data []byte, err error) { |
| 93 | + type shadow UpdateOrgLimitsRequestParam |
| 94 | + return param.MarshalObject(r, (*shadow)(&r)) |
| 95 | +} |
| 96 | +func (r *UpdateOrgLimitsRequestParam) UnmarshalJSON(data []byte) error { |
| 97 | + return apijson.UnmarshalRoot(data, r) |
| 98 | +} |
| 99 | + |
| 100 | +type OrganizationLimitUpdateParams struct { |
| 101 | + UpdateOrgLimitsRequest UpdateOrgLimitsRequestParam |
| 102 | + paramObj |
| 103 | +} |
| 104 | + |
| 105 | +func (r OrganizationLimitUpdateParams) MarshalJSON() (data []byte, err error) { |
| 106 | + return shimjson.Marshal(r.UpdateOrgLimitsRequest) |
| 107 | +} |
| 108 | +func (r *OrganizationLimitUpdateParams) UnmarshalJSON(data []byte) error { |
| 109 | + return apijson.UnmarshalRoot(data, r) |
| 110 | +} |
0 commit comments