@@ -41,6 +41,15 @@ func (r *CommandService) Exec(ctx context.Context, body CommandExecParams, opts
41
41
return
42
42
}
43
43
44
+ // Run a function in a secure, isolated environment. Define a function named
45
+ // `execute`. The function will be passed `input` as an object.
46
+ func (r * CommandService ) ExecFunc (ctx context.Context , body CommandExecFuncParams , opts ... option.RequestOption ) (res * CommandExecFuncResponse , err error ) {
47
+ opts = append (r .Options [:], opts ... )
48
+ path := "v1/execute-function"
49
+ err = requestconfig .ExecuteNewRequest (ctx , http .MethodPost , path , body , & res , opts ... )
50
+ return
51
+ }
52
+
44
53
type CommandExecResponse struct {
45
54
// The exit code returned by the script. Will often be '0' on success and non-zero
46
55
// on failure.
@@ -70,6 +79,84 @@ func (r commandExecResponseJSON) RawJSON() string {
70
79
return r .raw
71
80
}
72
81
82
+ type CommandExecFuncResponse struct {
83
+ Execution CommandExecFuncResponseExecution `json:"execution"`
84
+ Output interface {} `json:"output"`
85
+ // The status of the output. "valid" means your function executed successfully and
86
+ // returned a valid JSON-serializable object, or void. "json_serialization_error"
87
+ // means your function executed successfully, but returned a nonserializable
88
+ // object. "error" means your function failed to execute.
89
+ OutputStatus CommandExecFuncResponseOutputStatus `json:"output_status"`
90
+ JSON commandExecFuncResponseJSON `json:"-"`
91
+ }
92
+
93
+ // commandExecFuncResponseJSON contains the JSON metadata for the struct
94
+ // [CommandExecFuncResponse]
95
+ type commandExecFuncResponseJSON struct {
96
+ Execution apijson.Field
97
+ Output apijson.Field
98
+ OutputStatus apijson.Field
99
+ raw string
100
+ ExtraFields map [string ]apijson.Field
101
+ }
102
+
103
+ func (r * CommandExecFuncResponse ) UnmarshalJSON (data []byte ) (err error ) {
104
+ return apijson .UnmarshalRoot (data , r )
105
+ }
106
+
107
+ func (r commandExecFuncResponseJSON ) RawJSON () string {
108
+ return r .raw
109
+ }
110
+
111
+ type CommandExecFuncResponseExecution struct {
112
+ // The exit code returned by the script. Will often be '0' on success and non-zero
113
+ // on failure.
114
+ ExitCode int64 `json:"exit_code"`
115
+ // The contents of 'stderr' after executing the script.
116
+ Stderr string `json:"stderr"`
117
+ // The contents of 'stdout' after executing the script.
118
+ Stdout string `json:"stdout"`
119
+ JSON commandExecFuncResponseExecutionJSON `json:"-"`
120
+ }
121
+
122
+ // commandExecFuncResponseExecutionJSON contains the JSON metadata for the struct
123
+ // [CommandExecFuncResponseExecution]
124
+ type commandExecFuncResponseExecutionJSON struct {
125
+ ExitCode apijson.Field
126
+ Stderr apijson.Field
127
+ Stdout apijson.Field
128
+ raw string
129
+ ExtraFields map [string ]apijson.Field
130
+ }
131
+
132
+ func (r * CommandExecFuncResponseExecution ) UnmarshalJSON (data []byte ) (err error ) {
133
+ return apijson .UnmarshalRoot (data , r )
134
+ }
135
+
136
+ func (r commandExecFuncResponseExecutionJSON ) RawJSON () string {
137
+ return r .raw
138
+ }
139
+
140
+ // The status of the output. "valid" means your function executed successfully and
141
+ // returned a valid JSON-serializable object, or void. "json_serialization_error"
142
+ // means your function executed successfully, but returned a nonserializable
143
+ // object. "error" means your function failed to execute.
144
+ type CommandExecFuncResponseOutputStatus string
145
+
146
+ const (
147
+ CommandExecFuncResponseOutputStatusError CommandExecFuncResponseOutputStatus = "error"
148
+ CommandExecFuncResponseOutputStatusJsonSerializationError CommandExecFuncResponseOutputStatus = "json_serialization_error"
149
+ CommandExecFuncResponseOutputStatusValid CommandExecFuncResponseOutputStatus = "valid"
150
+ )
151
+
152
+ func (r CommandExecFuncResponseOutputStatus ) IsKnown () bool {
153
+ switch r {
154
+ case CommandExecFuncResponseOutputStatusError , CommandExecFuncResponseOutputStatusJsonSerializationError , CommandExecFuncResponseOutputStatusValid :
155
+ return true
156
+ }
157
+ return false
158
+ }
159
+
73
160
type CommandExecParams struct {
74
161
// The code to execute.
75
162
Code param.Field [string ] `json:"code,required"`
@@ -210,3 +297,140 @@ type CommandExecParamsLimits struct {
210
297
func (r CommandExecParamsLimits ) MarshalJSON () (data []byte , err error ) {
211
298
return apijson .MarshalRoot (r )
212
299
}
300
+
301
+ type CommandExecFuncParams struct {
302
+ // The function to execute. Your code must define a function named 'execute' and
303
+ // return a JSON-serializable value.
304
+ Code param.Field [string ] `json:"code,required"`
305
+ // The interpreter to use when executing code.
306
+ Language param.Field [CommandExecFuncParamsLanguage ] `json:"language,required"`
307
+ // Set of key-value pairs to add to the script's execution environment.
308
+ Env param.Field [map [string ]string ] `json:"env"`
309
+ // List of input files.
310
+ Files param.Field [[]CommandExecFuncParamsFile ] `json:"files"`
311
+ // Configuration for HTTP requests and authentication.
312
+ HTTP param.Field [CommandExecFuncParamsHTTP ] `json:"http"`
313
+ Input param.Field [interface {}] `json:"input"`
314
+ // Configuration for execution environment limits.
315
+ Limits param.Field [CommandExecFuncParamsLimits ] `json:"limits"`
316
+ // The ID of the runtime revision to use when executing code.
317
+ RuntimeRevisionID param.Field [string ] `json:"runtime_revision_id"`
318
+ }
319
+
320
+ func (r CommandExecFuncParams ) MarshalJSON () (data []byte , err error ) {
321
+ return apijson .MarshalRoot (r )
322
+ }
323
+
324
+ // The interpreter to use when executing code.
325
+ type CommandExecFuncParamsLanguage string
326
+
327
+ const (
328
+ CommandExecFuncParamsLanguagePython CommandExecFuncParamsLanguage = "python"
329
+ CommandExecFuncParamsLanguageJavascript CommandExecFuncParamsLanguage = "javascript"
330
+ CommandExecFuncParamsLanguageTypescript CommandExecFuncParamsLanguage = "typescript"
331
+ CommandExecFuncParamsLanguageRuby CommandExecFuncParamsLanguage = "ruby"
332
+ CommandExecFuncParamsLanguagePhp CommandExecFuncParamsLanguage = "php"
333
+ )
334
+
335
+ func (r CommandExecFuncParamsLanguage ) IsKnown () bool {
336
+ switch r {
337
+ case CommandExecFuncParamsLanguagePython , CommandExecFuncParamsLanguageJavascript , CommandExecFuncParamsLanguageTypescript , CommandExecFuncParamsLanguageRuby , CommandExecFuncParamsLanguagePhp :
338
+ return true
339
+ }
340
+ return false
341
+ }
342
+
343
+ type CommandExecFuncParamsFile struct {
344
+ // The contents of the file.
345
+ Contents param.Field [string ] `json:"contents"`
346
+ // The relative path of the file.
347
+ Path param.Field [string ] `json:"path"`
348
+ }
349
+
350
+ func (r CommandExecFuncParamsFile ) MarshalJSON () (data []byte , err error ) {
351
+ return apijson .MarshalRoot (r )
352
+ }
353
+
354
+ // Configuration for HTTP requests and authentication.
355
+ type CommandExecFuncParamsHTTP struct {
356
+ // List of allowed HTTP hosts and associated authentication.
357
+ Allow param.Field [[]CommandExecFuncParamsHTTPAllow ] `json:"allow"`
358
+ }
359
+
360
+ func (r CommandExecFuncParamsHTTP ) MarshalJSON () (data []byte , err error ) {
361
+ return apijson .MarshalRoot (r )
362
+ }
363
+
364
+ // List of allowed HTTP hosts and associated authentication.
365
+ type CommandExecFuncParamsHTTPAllow struct {
366
+ // Authentication configuration for outbound requests to this host.
367
+ Auth param.Field [CommandExecFuncParamsHTTPAllowAuth ] `json:"auth"`
368
+ // The hostname to allow.
369
+ Host param.Field [string ] `json:"host"`
370
+ }
371
+
372
+ func (r CommandExecFuncParamsHTTPAllow ) MarshalJSON () (data []byte , err error ) {
373
+ return apijson .MarshalRoot (r )
374
+ }
375
+
376
+ // Authentication configuration for outbound requests to this host.
377
+ type CommandExecFuncParamsHTTPAllowAuth struct {
378
+ Basic param.Field [CommandExecFuncParamsHTTPAllowAuthBasic ] `json:"basic"`
379
+ // Configuration to add an 'Authorization' header using the 'Bearer' scheme.
380
+ Bearer param.Field [CommandExecFuncParamsHTTPAllowAuthBearer ] `json:"bearer"`
381
+ Header param.Field [CommandExecFuncParamsHTTPAllowAuthHeader ] `json:"header"`
382
+ Query param.Field [CommandExecFuncParamsHTTPAllowAuthQuery ] `json:"query"`
383
+ }
384
+
385
+ func (r CommandExecFuncParamsHTTPAllowAuth ) MarshalJSON () (data []byte , err error ) {
386
+ return apijson .MarshalRoot (r )
387
+ }
388
+
389
+ type CommandExecFuncParamsHTTPAllowAuthBasic struct {
390
+ Password param.Field [string ] `json:"password"`
391
+ UserID param.Field [string ] `json:"user_id"`
392
+ }
393
+
394
+ func (r CommandExecFuncParamsHTTPAllowAuthBasic ) MarshalJSON () (data []byte , err error ) {
395
+ return apijson .MarshalRoot (r )
396
+ }
397
+
398
+ // Configuration to add an 'Authorization' header using the 'Bearer' scheme.
399
+ type CommandExecFuncParamsHTTPAllowAuthBearer struct {
400
+ // The token to set, e.g. 'Authorization: Bearer <token>'.
401
+ Token param.Field [string ] `json:"token"`
402
+ }
403
+
404
+ func (r CommandExecFuncParamsHTTPAllowAuthBearer ) MarshalJSON () (data []byte , err error ) {
405
+ return apijson .MarshalRoot (r )
406
+ }
407
+
408
+ type CommandExecFuncParamsHTTPAllowAuthHeader struct {
409
+ Name param.Field [string ] `json:"name"`
410
+ Value param.Field [string ] `json:"value"`
411
+ }
412
+
413
+ func (r CommandExecFuncParamsHTTPAllowAuthHeader ) MarshalJSON () (data []byte , err error ) {
414
+ return apijson .MarshalRoot (r )
415
+ }
416
+
417
+ type CommandExecFuncParamsHTTPAllowAuthQuery struct {
418
+ Key param.Field [string ] `json:"key"`
419
+ Value param.Field [string ] `json:"value"`
420
+ }
421
+
422
+ func (r CommandExecFuncParamsHTTPAllowAuthQuery ) MarshalJSON () (data []byte , err error ) {
423
+ return apijson .MarshalRoot (r )
424
+ }
425
+
426
+ // Configuration for execution environment limits.
427
+ type CommandExecFuncParamsLimits struct {
428
+ // The maximum time allowed for execution (in seconds). Default is 30.
429
+ ExecutionTimeout param.Field [int64 ] `json:"execution_timeout"`
430
+ // The maximum memory allowed for execution (in MiB). Default is 128.
431
+ MemorySize param.Field [int64 ] `json:"memory_size"`
432
+ }
433
+
434
+ func (r CommandExecFuncParamsLimits ) MarshalJSON () (data []byte , err error ) {
435
+ return apijson .MarshalRoot (r )
436
+ }
0 commit comments