Skip to content

Commit e0dc9c0

Browse files
feat(api): deployments
1 parent f2ddf2c commit e0dc9c0

6 files changed

Lines changed: 112 additions & 24 deletions

File tree

.stats.yml

Lines changed: 3 additions & 3 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
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
44
config_hash: 00ec9df250b9dc077f8d3b93a442d252

api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ Response Types:
1414
- <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>
1515
- <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>
1616
- <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>
1718
- <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>
1819

1920
Methods:
2021

2122
- <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>
2223
- <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>
2325
- <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>
2426

2527
# 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: 74 additions & 0 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],
@@ -414,6 +474,20 @@ const (
414474
DeploymentNewParamsRegionAwsUsEast1a DeploymentNewParamsRegion = "aws.us-east-1a"
415475
)
416476

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+
417491
type DeploymentFollowParams struct {
418492
// Show logs since the given time (RFC timestamps or durations like 5m).
419493
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+
}

0 commit comments

Comments
 (0)