Skip to content

Commit e2c8f14

Browse files
feat(api): add GET deployments endpoint
1 parent 4a9818a commit e2c8f14

8 files changed

Lines changed: 139 additions & 45 deletions

File tree

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 16
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-ff8ccba8b5409eaa1128df9027582cb63f66e8accd75e511f70b7c27ef26c9ae.yml
3-
openapi_spec_hash: 1dbacc339695a7c78718f90f791d3f01
4-
config_hash: b8e1fff080fbaa22656ab0a57b591777
1+
configured_endpoints: 17
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-2eeb61205775c5997abf8154cd6f6fe81a1e83870eff10050b17ed415aa7860b.yml
3+
openapi_spec_hash: 63405add4a3f53718f8183cbb8c1a22f
4+
config_hash: 00ec9df250b9dc077f8d3b93a442d252

aliases.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ type paramObj = param.APIObject
1616

1717
type Error = apierror.Error
1818

19+
// An action available on the app
20+
//
21+
// This is an alias to an internal type.
22+
type AppAction = shared.AppAction
23+
1924
// This is an alias to an internal type.
2025
type ErrorDetail = shared.ErrorDetail
2126

api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Shared Response Types
22

3+
- <a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk/shared">shared</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk/shared#AppAction">AppAction</a>
34
- <a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk/shared">shared</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk/shared#ErrorDetail">ErrorDetail</a>
45
- <a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk/shared">shared</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk/shared#ErrorEvent">ErrorEvent</a>
56
- <a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk/shared">shared</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk/shared#ErrorModel">ErrorModel</a>
@@ -13,12 +14,14 @@ Response Types:
1314
- <a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#DeploymentStateEvent">DeploymentStateEvent</a>
1415
- <a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#DeploymentNewResponse">DeploymentNewResponse</a>
1516
- <a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#DeploymentGetResponse">DeploymentGetResponse</a>
17+
- <a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#DeploymentListResponse">DeploymentListResponse</a>
1618
- <a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#DeploymentFollowResponseUnion">DeploymentFollowResponseUnion</a>
1719

1820
Methods:
1921

2022
- <code title="post /deployments">client.Deployments.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#DeploymentService.New">New</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/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#DeploymentNewParams">DeploymentNewParams</a>) (<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#DeploymentNewResponse">DeploymentNewResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
2123
- <code title="get /deployments/{id}">client.Deployments.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#DeploymentService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#DeploymentGetResponse">DeploymentGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
24+
- <code title="get /deployments">client.Deployments.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#DeploymentService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, query <a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#DeploymentListParams">DeploymentListParams</a>) ([]<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#DeploymentListResponse">DeploymentListResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
2225
- <code title="get /deployments/{id}/events">client.Deployments.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#DeploymentService.Follow">Follow</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>, query <a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#DeploymentFollowParams">DeploymentFollowParams</a>) (<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#DeploymentFollowResponseUnion">DeploymentFollowResponseUnion</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
2326

2427
# Apps

app.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/onkernel/kernel-go-sdk/option"
1414
"github.com/onkernel/kernel-go-sdk/packages/param"
1515
"github.com/onkernel/kernel-go-sdk/packages/respjson"
16+
"github.com/onkernel/kernel-go-sdk/shared"
1617
"github.com/onkernel/kernel-go-sdk/shared/constant"
1718
)
1819

@@ -49,24 +50,27 @@ func (r *AppService) List(ctx context.Context, query AppListParams, opts ...opti
4950
type AppListResponse struct {
5051
// Unique identifier for the app version
5152
ID string `json:"id,required"`
53+
// List of actions available on the app
54+
Actions []shared.AppAction `json:"actions,required"`
5255
// Name of the application
5356
AppName string `json:"app_name,required"`
5457
// Deployment ID
5558
Deployment string `json:"deployment,required"`
59+
// Environment variables configured for this app version
60+
EnvVars map[string]string `json:"env_vars,required"`
5661
// Deployment region code
5762
Region constant.AwsUsEast1a `json:"region,required"`
5863
// Version label for the application
5964
Version string `json:"version,required"`
60-
// Environment variables configured for this app version
61-
EnvVars map[string]string `json:"env_vars"`
6265
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
6366
JSON struct {
6467
ID respjson.Field
68+
Actions respjson.Field
6569
AppName respjson.Field
6670
Deployment respjson.Field
71+
EnvVars respjson.Field
6772
Region respjson.Field
6873
Version respjson.Field
69-
EnvVars respjson.Field
7074
ExtraFields map[string]respjson.Field
7175
raw string
7276
} `json:"-"`

appdeployment.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ type AppDeploymentNewResponseApp struct {
9999
// ID for the app version deployed
100100
ID string `json:"id,required"`
101101
// List of actions available on the app
102-
Actions []AppDeploymentNewResponseAppAction `json:"actions,required"`
102+
Actions []shared.AppAction `json:"actions,required"`
103103
// Name of the app
104104
Name string `json:"name,required"`
105105
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
@@ -118,23 +118,6 @@ func (r *AppDeploymentNewResponseApp) UnmarshalJSON(data []byte) error {
118118
return apijson.UnmarshalRoot(data, r)
119119
}
120120

121-
type AppDeploymentNewResponseAppAction struct {
122-
// Name of the action
123-
Name string `json:"name,required"`
124-
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
125-
JSON struct {
126-
Name respjson.Field
127-
ExtraFields map[string]respjson.Field
128-
raw string
129-
} `json:"-"`
130-
}
131-
132-
// Returns the unmodified JSON received from the API
133-
func (r AppDeploymentNewResponseAppAction) RawJSON() string { return r.JSON.raw }
134-
func (r *AppDeploymentNewResponseAppAction) UnmarshalJSON(data []byte) error {
135-
return apijson.UnmarshalRoot(data, r)
136-
}
137-
138121
// Current status of the deployment
139122
type AppDeploymentNewResponseStatus string
140123

deployment.go

Lines changed: 76 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ func (r *DeploymentService) Get(ctx context.Context, id string, opts ...option.R
6565
return
6666
}
6767

68+
// List deployments. Optionally filter by application name.
69+
func (r *DeploymentService) List(ctx context.Context, query DeploymentListParams, opts ...option.RequestOption) (res *[]DeploymentListResponse, err error) {
70+
opts = append(r.Options[:], opts...)
71+
path := "deployments"
72+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
73+
return
74+
}
75+
6876
// Establishes a Server-Sent Events (SSE) stream that delivers real-time logs and
6977
// status updates for a deployment. The stream terminates automatically once the
7078
// deployment reaches a terminal state.
@@ -253,6 +261,58 @@ const (
253261
DeploymentGetResponseStatusStopped DeploymentGetResponseStatus = "stopped"
254262
)
255263

264+
// Deployment record information.
265+
type DeploymentListResponse struct {
266+
// Unique identifier for the deployment
267+
ID string `json:"id,required"`
268+
// Timestamp when the deployment was created
269+
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
270+
// Deployment region code
271+
Region constant.AwsUsEast1a `json:"region,required"`
272+
// Current status of the deployment
273+
//
274+
// Any of "queued", "in_progress", "running", "failed", "stopped".
275+
Status DeploymentListResponseStatus `json:"status,required"`
276+
// Relative path to the application entrypoint
277+
EntrypointRelPath string `json:"entrypoint_rel_path"`
278+
// Environment variables configured for this deployment
279+
EnvVars map[string]string `json:"env_vars"`
280+
// Status reason
281+
StatusReason string `json:"status_reason"`
282+
// Timestamp when the deployment was last updated
283+
UpdatedAt time.Time `json:"updated_at,nullable" format:"date-time"`
284+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
285+
JSON struct {
286+
ID respjson.Field
287+
CreatedAt respjson.Field
288+
Region respjson.Field
289+
Status respjson.Field
290+
EntrypointRelPath respjson.Field
291+
EnvVars respjson.Field
292+
StatusReason respjson.Field
293+
UpdatedAt respjson.Field
294+
ExtraFields map[string]respjson.Field
295+
raw string
296+
} `json:"-"`
297+
}
298+
299+
// Returns the unmodified JSON received from the API
300+
func (r DeploymentListResponse) RawJSON() string { return r.JSON.raw }
301+
func (r *DeploymentListResponse) UnmarshalJSON(data []byte) error {
302+
return apijson.UnmarshalRoot(data, r)
303+
}
304+
305+
// Current status of the deployment
306+
type DeploymentListResponseStatus string
307+
308+
const (
309+
DeploymentListResponseStatusQueued DeploymentListResponseStatus = "queued"
310+
DeploymentListResponseStatusInProgress DeploymentListResponseStatus = "in_progress"
311+
DeploymentListResponseStatusRunning DeploymentListResponseStatus = "running"
312+
DeploymentListResponseStatusFailed DeploymentListResponseStatus = "failed"
313+
DeploymentListResponseStatusStopped DeploymentListResponseStatus = "stopped"
314+
)
315+
256316
// DeploymentFollowResponseUnion contains all possible properties and values from
257317
// [shared.LogEvent], [DeploymentStateEvent],
258318
// [DeploymentFollowResponseAppVersionSummaryEvent], [shared.ErrorEvent],
@@ -272,7 +332,7 @@ type DeploymentFollowResponseUnion struct {
272332
// This field is from variant [DeploymentFollowResponseAppVersionSummaryEvent].
273333
ID string `json:"id"`
274334
// This field is from variant [DeploymentFollowResponseAppVersionSummaryEvent].
275-
Actions []DeploymentFollowResponseAppVersionSummaryEventAction `json:"actions"`
335+
Actions []shared.AppAction `json:"actions"`
276336
// This field is from variant [DeploymentFollowResponseAppVersionSummaryEvent].
277337
AppName string `json:"app_name"`
278338
// This field is from variant [DeploymentFollowResponseAppVersionSummaryEvent].
@@ -336,7 +396,7 @@ type DeploymentFollowResponseAppVersionSummaryEvent struct {
336396
// Unique identifier for the app version
337397
ID string `json:"id,required"`
338398
// List of actions available on the app
339-
Actions []DeploymentFollowResponseAppVersionSummaryEventAction `json:"actions,required"`
399+
Actions []shared.AppAction `json:"actions,required"`
340400
// Name of the application
341401
AppName string `json:"app_name,required"`
342402
// Event type identifier (always "app_version_summary").
@@ -370,24 +430,6 @@ func (r *DeploymentFollowResponseAppVersionSummaryEvent) UnmarshalJSON(data []by
370430
return apijson.UnmarshalRoot(data, r)
371431
}
372432

373-
// An action available on the app
374-
type DeploymentFollowResponseAppVersionSummaryEventAction struct {
375-
// Name of the action
376-
Name string `json:"name,required"`
377-
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
378-
JSON struct {
379-
Name respjson.Field
380-
ExtraFields map[string]respjson.Field
381-
raw string
382-
} `json:"-"`
383-
}
384-
385-
// Returns the unmodified JSON received from the API
386-
func (r DeploymentFollowResponseAppVersionSummaryEventAction) RawJSON() string { return r.JSON.raw }
387-
func (r *DeploymentFollowResponseAppVersionSummaryEventAction) UnmarshalJSON(data []byte) error {
388-
return apijson.UnmarshalRoot(data, r)
389-
}
390-
391433
type DeploymentNewParams struct {
392434
// Relative path to the entrypoint of the application
393435
EntrypointRelPath string `json:"entrypoint_rel_path,required"`
@@ -432,6 +474,20 @@ const (
432474
DeploymentNewParamsRegionAwsUsEast1a DeploymentNewParamsRegion = "aws.us-east-1a"
433475
)
434476

477+
type DeploymentListParams struct {
478+
// Filter results by application name.
479+
AppName param.Opt[string] `query:"app_name,omitzero" json:"-"`
480+
paramObj
481+
}
482+
483+
// URLQuery serializes [DeploymentListParams]'s query parameters as `url.Values`.
484+
func (r DeploymentListParams) URLQuery() (v url.Values, err error) {
485+
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
486+
ArrayFormat: apiquery.ArrayQueryFormatComma,
487+
NestedFormat: apiquery.NestedQueryFormatBrackets,
488+
})
489+
}
490+
435491
type DeploymentFollowParams struct {
436492
// Show logs since the given time (RFC timestamps or durations like 5m).
437493
Since param.Opt[string] `query:"since,omitzero" json:"-"`

deployment_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,28 @@ func TestDeploymentGet(t *testing.T) {
6969
t.Fatalf("err should be nil: %s", err.Error())
7070
}
7171
}
72+
73+
func TestDeploymentListWithOptionalParams(t *testing.T) {
74+
t.Skip("skipped: tests are disabled for the time being")
75+
baseURL := "http://localhost:4010"
76+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
77+
baseURL = envURL
78+
}
79+
if !testutil.CheckTestServer(t, baseURL) {
80+
return
81+
}
82+
client := kernel.NewClient(
83+
option.WithBaseURL(baseURL),
84+
option.WithAPIKey("My API Key"),
85+
)
86+
_, err := client.Deployments.List(context.TODO(), kernel.DeploymentListParams{
87+
AppName: kernel.String("app_name"),
88+
})
89+
if err != nil {
90+
var apierr *kernel.Error
91+
if errors.As(err, &apierr) {
92+
t.Log(string(apierr.DumpRequest(true)))
93+
}
94+
t.Fatalf("err should be nil: %s", err.Error())
95+
}
96+
}

shared/shared.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ type paramUnion = param.APIUnion
1717
// aliased to make [param.APIObject] private when embedding
1818
type paramObj = param.APIObject
1919

20+
// An action available on the app
21+
type AppAction struct {
22+
// Name of the action
23+
Name string `json:"name,required"`
24+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
25+
JSON struct {
26+
Name respjson.Field
27+
ExtraFields map[string]respjson.Field
28+
raw string
29+
} `json:"-"`
30+
}
31+
32+
// Returns the unmodified JSON received from the API
33+
func (r AppAction) RawJSON() string { return r.JSON.raw }
34+
func (r *AppAction) UnmarshalJSON(data []byte) error {
35+
return apijson.UnmarshalRoot(data, r)
36+
}
37+
2038
type ErrorDetail struct {
2139
// Lower-level error code providing more specific detail
2240
Code string `json:"code"`

0 commit comments

Comments
 (0)