Skip to content

Commit 3ecd0c4

Browse files
feat(api): manual updates
1 parent 77f5109 commit 3ecd0c4

File tree

7 files changed

+360
-7
lines changed

7 files changed

+360
-7
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 115
1+
configured_endpoints: 116
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/gitpod%2Fgitpod-d854bc81e0a99171716893e6790a87ba350bb6fc778f8e3244abdd47d5c252c3.yml
33
openapi_spec_hash: 5189220e4712a7b0cdd35beba2ebb47d
4-
config_hash: 981e43e8b1e3ddabd435d350aeeed417
4+
config_hash: 60929489bdc1eaf979e7ef74fdd17b94

api.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,16 @@ Methods:
557557
- <code title="post /gitpod.v1.SecretService/GetSecretValue">client.Secrets.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#SecretService.GetValue">GetValue</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#SecretGetValueParams">SecretGetValueParams</a>) (<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#SecretGetValueResponse">SecretGetValueResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
558558
- <code title="post /gitpod.v1.SecretService/UpdateSecretValue">client.Secrets.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#SecretService.UpdateValue">UpdateValue</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#SecretUpdateValueParams">SecretUpdateValueParams</a>) (<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#SecretUpdateValueResponse">SecretUpdateValueResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
559559

560+
# Usage
561+
562+
Response Types:
563+
564+
- <a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#EnvironmentSession">EnvironmentSession</a>
565+
566+
Methods:
567+
568+
- <code title="post /gitpod.v1.UsageService/ListEnvironmentSessions">client.Usage.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#UsageService.ListEnvironmentSessions">ListEnvironmentSessions</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, params <a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#UsageListEnvironmentSessionsParams">UsageListEnvironmentSessionsParams</a>) (<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go/packages/pagination#SessionsPage">SessionsPage</a>[<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go">gitpod</a>.<a href="https://pkg.go.dev/github.com/gitpod-io/gitpod-sdk-go#EnvironmentSession">EnvironmentSession</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
569+
560570
# Users
561571

562572
Response Types:

client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Client struct {
2626
Projects *ProjectService
2727
Runners *RunnerService
2828
Secrets *SecretService
29+
Usage *UsageService
2930
Users *UserService
3031
}
3132

@@ -61,6 +62,7 @@ func NewClient(opts ...option.RequestOption) (r *Client) {
6162
r.Projects = NewProjectService(opts...)
6263
r.Runners = NewRunnerService(opts...)
6364
r.Secrets = NewSecretService(opts...)
65+
r.Usage = NewUsageService(opts...)
6466
r.Users = NewUserService(opts...)
6567

6668
return

packages/pagination/pagination.go

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,127 @@ func (r *ServicesPageAutoPager[T]) Index() int {
18311831
return r.run
18321832
}
18331833

1834+
type SessionsPagePagination struct {
1835+
NextToken string `json:"nextToken"`
1836+
JSON sessionsPagePaginationJSON `json:"-"`
1837+
}
1838+
1839+
// sessionsPagePaginationJSON contains the JSON metadata for the struct
1840+
// [SessionsPagePagination]
1841+
type sessionsPagePaginationJSON struct {
1842+
NextToken apijson.Field
1843+
raw string
1844+
ExtraFields map[string]apijson.Field
1845+
}
1846+
1847+
func (r *SessionsPagePagination) UnmarshalJSON(data []byte) (err error) {
1848+
return apijson.UnmarshalRoot(data, r)
1849+
}
1850+
1851+
func (r sessionsPagePaginationJSON) RawJSON() string {
1852+
return r.raw
1853+
}
1854+
1855+
type SessionsPage[T any] struct {
1856+
Pagination SessionsPagePagination `json:"pagination"`
1857+
Sessions []T `json:"sessions"`
1858+
JSON sessionsPageJSON `json:"-"`
1859+
cfg *requestconfig.RequestConfig
1860+
res *http.Response
1861+
}
1862+
1863+
// sessionsPageJSON contains the JSON metadata for the struct [SessionsPage[T]]
1864+
type sessionsPageJSON struct {
1865+
Pagination apijson.Field
1866+
Sessions apijson.Field
1867+
raw string
1868+
ExtraFields map[string]apijson.Field
1869+
}
1870+
1871+
func (r *SessionsPage[T]) UnmarshalJSON(data []byte) (err error) {
1872+
return apijson.UnmarshalRoot(data, r)
1873+
}
1874+
1875+
func (r sessionsPageJSON) RawJSON() string {
1876+
return r.raw
1877+
}
1878+
1879+
// GetNextPage returns the next page as defined by this pagination style. When
1880+
// there is no next page, this function will return a 'nil' for the page value, but
1881+
// will not return an error
1882+
func (r *SessionsPage[T]) GetNextPage() (res *SessionsPage[T], err error) {
1883+
next := r.Pagination.NextToken
1884+
if len(next) == 0 {
1885+
return nil, nil
1886+
}
1887+
cfg := r.cfg.Clone(r.cfg.Context)
1888+
err = cfg.Apply(option.WithQuery("token", next))
1889+
if err != nil {
1890+
return nil, err
1891+
}
1892+
var raw *http.Response
1893+
cfg.ResponseInto = &raw
1894+
cfg.ResponseBodyInto = &res
1895+
err = cfg.Execute()
1896+
if err != nil {
1897+
return nil, err
1898+
}
1899+
res.SetPageConfig(cfg, raw)
1900+
return res, nil
1901+
}
1902+
1903+
func (r *SessionsPage[T]) SetPageConfig(cfg *requestconfig.RequestConfig, res *http.Response) {
1904+
if r == nil {
1905+
r = &SessionsPage[T]{}
1906+
}
1907+
r.cfg = cfg
1908+
r.res = res
1909+
}
1910+
1911+
type SessionsPageAutoPager[T any] struct {
1912+
page *SessionsPage[T]
1913+
cur T
1914+
idx int
1915+
run int
1916+
err error
1917+
}
1918+
1919+
func NewSessionsPageAutoPager[T any](page *SessionsPage[T], err error) *SessionsPageAutoPager[T] {
1920+
return &SessionsPageAutoPager[T]{
1921+
page: page,
1922+
err: err,
1923+
}
1924+
}
1925+
1926+
func (r *SessionsPageAutoPager[T]) Next() bool {
1927+
if r.page == nil || len(r.page.Sessions) == 0 {
1928+
return false
1929+
}
1930+
if r.idx >= len(r.page.Sessions) {
1931+
r.idx = 0
1932+
r.page, r.err = r.page.GetNextPage()
1933+
if r.err != nil || r.page == nil || len(r.page.Sessions) == 0 {
1934+
return false
1935+
}
1936+
}
1937+
r.cur = r.page.Sessions[r.idx]
1938+
r.run += 1
1939+
r.idx += 1
1940+
return true
1941+
}
1942+
1943+
func (r *SessionsPageAutoPager[T]) Current() T {
1944+
return r.cur
1945+
}
1946+
1947+
func (r *SessionsPageAutoPager[T]) Err() error {
1948+
return r.err
1949+
}
1950+
1951+
func (r *SessionsPageAutoPager[T]) Index() int {
1952+
return r.run
1953+
}
1954+
18341955
type SSOConfigurationsPagePagination struct {
18351956
NextToken string `json:"nextToken"`
18361957
JSON ssoConfigurationsPagePaginationJSON `json:"-"`

usage.go

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package gitpod
4+
5+
import (
6+
"context"
7+
"net/http"
8+
"net/url"
9+
"time"
10+
11+
"github.com/gitpod-io/gitpod-sdk-go/internal/apijson"
12+
"github.com/gitpod-io/gitpod-sdk-go/internal/apiquery"
13+
"github.com/gitpod-io/gitpod-sdk-go/internal/param"
14+
"github.com/gitpod-io/gitpod-sdk-go/internal/requestconfig"
15+
"github.com/gitpod-io/gitpod-sdk-go/option"
16+
"github.com/gitpod-io/gitpod-sdk-go/packages/pagination"
17+
)
18+
19+
// UsageService contains methods and other services that help with interacting with
20+
// the gitpod API.
21+
//
22+
// Note, unlike clients, this service does not read variables from the environment
23+
// automatically. You should not instantiate this service directly, and instead use
24+
// the [NewUsageService] method instead.
25+
type UsageService struct {
26+
Options []option.RequestOption
27+
}
28+
29+
// NewUsageService generates a new service that applies the given options to each
30+
// request. These options are applied after the parent client's options (if there
31+
// is one), and before any request-specific options.
32+
func NewUsageService(opts ...option.RequestOption) (r *UsageService) {
33+
r = &UsageService{}
34+
r.Options = opts
35+
return
36+
}
37+
38+
// Lists environment sessions within a specified date range.
39+
//
40+
// Returns a list of environment sessions that were active within the specified
41+
// date range.
42+
func (r *UsageService) ListEnvironmentSessions(ctx context.Context, params UsageListEnvironmentSessionsParams, opts ...option.RequestOption) (res *pagination.SessionsPage[EnvironmentSession], err error) {
43+
var raw *http.Response
44+
opts = append(r.Options[:], opts...)
45+
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
46+
path := "gitpod.v1.UsageService/ListEnvironmentSessions"
47+
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodPost, path, params, &res, opts...)
48+
if err != nil {
49+
return nil, err
50+
}
51+
err = cfg.Execute()
52+
if err != nil {
53+
return nil, err
54+
}
55+
res.SetPageConfig(cfg, raw)
56+
return res, nil
57+
}
58+
59+
// Lists environment sessions within a specified date range.
60+
//
61+
// Returns a list of environment sessions that were active within the specified
62+
// date range.
63+
func (r *UsageService) ListEnvironmentSessionsAutoPaging(ctx context.Context, params UsageListEnvironmentSessionsParams, opts ...option.RequestOption) *pagination.SessionsPageAutoPager[EnvironmentSession] {
64+
return pagination.NewSessionsPageAutoPager(r.ListEnvironmentSessions(ctx, params, opts...))
65+
}
66+
67+
type EnvironmentSession struct {
68+
// Environment session ID.
69+
ID string `json:"id"`
70+
// Time when the session was created.
71+
CreatedAt time.Time `json:"createdAt" format:"date-time"`
72+
// Environment class ID associated with the session.
73+
EnvironmentClassID string `json:"environmentClassId"`
74+
// Environment ID associated with the session.
75+
EnvironmentID string `json:"environmentId"`
76+
// Project ID associated with the session.
77+
ProjectID string `json:"projectId"`
78+
// Runner ID associated with the session.
79+
RunnerID string `json:"runnerId"`
80+
// Time when the session was stopped.
81+
StoppedAt time.Time `json:"stoppedAt" format:"date-time"`
82+
// User ID who created the session.
83+
UserID string `json:"userId"`
84+
JSON environmentSessionJSON `json:"-"`
85+
}
86+
87+
// environmentSessionJSON contains the JSON metadata for the struct
88+
// [EnvironmentSession]
89+
type environmentSessionJSON struct {
90+
ID apijson.Field
91+
CreatedAt apijson.Field
92+
EnvironmentClassID apijson.Field
93+
EnvironmentID apijson.Field
94+
ProjectID apijson.Field
95+
RunnerID apijson.Field
96+
StoppedAt apijson.Field
97+
UserID apijson.Field
98+
raw string
99+
ExtraFields map[string]apijson.Field
100+
}
101+
102+
func (r *EnvironmentSession) UnmarshalJSON(data []byte) (err error) {
103+
return apijson.UnmarshalRoot(data, r)
104+
}
105+
106+
func (r environmentSessionJSON) RawJSON() string {
107+
return r.raw
108+
}
109+
110+
type UsageListEnvironmentSessionsParams struct {
111+
Token param.Field[string] `query:"token"`
112+
PageSize param.Field[int64] `query:"pageSize"`
113+
// Filter options.
114+
Filter param.Field[UsageListEnvironmentSessionsParamsFilter] `json:"filter"`
115+
// Pagination options.
116+
Pagination param.Field[UsageListEnvironmentSessionsParamsPagination] `json:"pagination"`
117+
}
118+
119+
func (r UsageListEnvironmentSessionsParams) MarshalJSON() (data []byte, err error) {
120+
return apijson.MarshalRoot(r)
121+
}
122+
123+
// URLQuery serializes [UsageListEnvironmentSessionsParams]'s query parameters as
124+
// `url.Values`.
125+
func (r UsageListEnvironmentSessionsParams) URLQuery() (v url.Values) {
126+
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
127+
ArrayFormat: apiquery.ArrayQueryFormatComma,
128+
NestedFormat: apiquery.NestedQueryFormatBrackets,
129+
})
130+
}
131+
132+
// Filter options.
133+
type UsageListEnvironmentSessionsParamsFilter struct {
134+
// Date range to query sessions within.
135+
DateRange param.Field[UsageListEnvironmentSessionsParamsFilterDateRange] `json:"dateRange,required"`
136+
// Optional project ID to filter sessions by.
137+
ProjectID param.Field[string] `json:"projectId"`
138+
}
139+
140+
func (r UsageListEnvironmentSessionsParamsFilter) MarshalJSON() (data []byte, err error) {
141+
return apijson.MarshalRoot(r)
142+
}
143+
144+
// Date range to query sessions within.
145+
type UsageListEnvironmentSessionsParamsFilterDateRange struct {
146+
// End time of the date range (exclusive).
147+
EndTime param.Field[time.Time] `json:"endTime,required" format:"date-time"`
148+
// Start time of the date range (inclusive).
149+
StartTime param.Field[time.Time] `json:"startTime,required" format:"date-time"`
150+
}
151+
152+
func (r UsageListEnvironmentSessionsParamsFilterDateRange) MarshalJSON() (data []byte, err error) {
153+
return apijson.MarshalRoot(r)
154+
}
155+
156+
// Pagination options.
157+
type UsageListEnvironmentSessionsParamsPagination struct {
158+
// Token for the next set of results that was returned as next_token of a
159+
// PaginationResponse
160+
Token param.Field[string] `json:"token"`
161+
// Page size is the maximum number of results to retrieve per page. Defaults to 25.
162+
// Maximum 100.
163+
PageSize param.Field[int64] `json:"pageSize"`
164+
}
165+
166+
func (r UsageListEnvironmentSessionsParamsPagination) MarshalJSON() (data []byte, err error) {
167+
return apijson.MarshalRoot(r)
168+
}

usage1_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package gitpod_test
4+
5+
import (
6+
"context"
7+
"os"
8+
"testing"
9+
10+
"github.com/gitpod-io/gitpod-sdk-go"
11+
"github.com/gitpod-io/gitpod-sdk-go/internal/testutil"
12+
"github.com/gitpod-io/gitpod-sdk-go/option"
13+
)
14+
15+
func TestUsage(t *testing.T) {
16+
baseURL := "http://localhost:4010"
17+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
18+
baseURL = envURL
19+
}
20+
if !testutil.CheckTestServer(t, baseURL) {
21+
return
22+
}
23+
client := gitpod.NewClient(
24+
option.WithBaseURL(baseURL),
25+
option.WithBearerToken("My Bearer Token"),
26+
)
27+
response, err := client.Identity.GetAuthenticatedIdentity(context.TODO(), gitpod.IdentityGetAuthenticatedIdentityParams{})
28+
if err != nil {
29+
t.Error(err)
30+
return
31+
}
32+
t.Logf("%+v\n", response.OrganizationID)
33+
}

0 commit comments

Comments
 (0)