diff --git a/sdks/sandbox/go/Makefile b/sdks/sandbox/go/Makefile new file mode 100644 index 00000000..dc5f1d02 --- /dev/null +++ b/sdks/sandbox/go/Makefile @@ -0,0 +1,27 @@ +.PHONY: all build vet test lint generate + +all: build vet test + +generate: + cd opensandbox/api/lifecycle && oapi-codegen --config cfg.yaml ../specs/sandbox-lifecycle.yml + cd opensandbox/api/execd && oapi-codegen --config cfg.yaml ../specs/execd-api.yaml + cd opensandbox/api/egress && oapi-codegen --config cfg.yaml ../specs/egress-api.yaml + @echo "Generated all API clients from OpenAPI specs" + +build: + go build ./... + +vet: + go vet ./... + +test: + go test ./opensandbox/ -v + +test-integration: + go test -tags=integration ./opensandbox/ -v -timeout 3m + +test-staging: + go test -tags=staging ./opensandbox/ -v -timeout 3m + +lint: + @which staticcheck >/dev/null 2>&1 && staticcheck ./... || echo "staticcheck not installed — skipping lint" diff --git a/sdks/sandbox/go/README.md b/sdks/sandbox/go/README.md new file mode 100644 index 00000000..3e5af776 --- /dev/null +++ b/sdks/sandbox/go/README.md @@ -0,0 +1,238 @@ +# OpenSandbox Go SDK + +Go client library for the [OpenSandbox](https://github.com/alibaba/OpenSandbox) API. + +Covers all three OpenAPI specs: +- **Lifecycle** — Create, manage, and destroy sandbox instances +- **Execd** — Execute commands, manage files, monitor metrics inside sandboxes +- **Egress** — Inspect and mutate sandbox network policy at runtime + +## Installation + +```bash +go get github.com/alibaba/OpenSandbox/sdks/sandbox/go +``` + +## Quick Start + +### Create and manage a sandbox + +```go +package main + +import ( + "context" + "fmt" + "log" + + "github.com/alibaba/OpenSandbox/sdks/sandbox/go/opensandbox" +) + +func main() { + ctx := context.Background() + + // Create a lifecycle client + lc := opensandbox.NewLifecycleClient("http://localhost:8080/v1", "your-api-key") + + // Create a sandbox + sbx, err := lc.CreateSandbox(ctx, opensandbox.CreateSandboxRequest{ + Image: opensandbox.ImageSpec{URI: "python:3.12"}, + Entrypoint: []string{"/bin/sh"}, + ResourceLimits: opensandbox.ResourceLimits{ + "cpu": "500m", + "memory": "512Mi", + }, + }) + if err != nil { + log.Fatal(err) + } + fmt.Printf("Created sandbox: %s (state: %s)\n", sbx.ID, sbx.Status.State) + + // Get sandbox details + sbx, err = lc.GetSandbox(ctx, sbx.ID) + if err != nil { + log.Fatal(err) + } + + // List all running sandboxes + list, err := lc.ListSandboxes(ctx, opensandbox.ListOptions{ + States: []opensandbox.SandboxState{opensandbox.StateRunning}, + PageSize: 10, + }) + if err != nil { + log.Fatal(err) + } + fmt.Printf("Running sandboxes: %d\n", list.Pagination.TotalItems) + + // Pause and resume + _ = lc.PauseSandbox(ctx, sbx.ID) + _ = lc.ResumeSandbox(ctx, sbx.ID) + + // Clean up + _ = lc.DeleteSandbox(ctx, sbx.ID) +} +``` + +### Run a command with streaming output + +```go +exec := opensandbox.NewExecdClient("http://localhost:9090", "your-execd-token") + +err := exec.RunCommand(ctx, opensandbox.RunCommandRequest{ + Command: "echo 'Hello from sandbox!'", + Timeout: 30000, +}, func(event opensandbox.StreamEvent) error { + // event.Event is populated from the NDJSON "type" field automatically. + switch event.Event { + case "stdout": + fmt.Print(event.Data) + case "stderr": + fmt.Fprintf(os.Stderr, "%s", event.Data) + case "execution_complete": + fmt.Println("\n[done]") + } + return nil +}) +``` + +### Check egress policy + +```go +egress := opensandbox.NewEgressClient("http://localhost:18080", "your-egress-token") + +// Get current policy +policy, err := egress.GetPolicy(ctx) +fmt.Printf("Mode: %s, Default: %s\n", policy.Mode, policy.Policy.DefaultAction) + +// Add a rule +updated, err := egress.PatchPolicy(ctx, []opensandbox.NetworkRule{ + {Action: "allow", Target: "api.example.com"}, +}) +``` + +## API Reference + +### LifecycleClient + +Created with `NewLifecycleClient(baseURL, apiKey string, opts ...Option)`. + +| Method | Description | +|--------|-------------| +| `CreateSandbox(ctx, req)` | Create a new sandbox from a container image | +| `GetSandbox(ctx, id)` | Get sandbox details by ID | +| `ListSandboxes(ctx, opts)` | List sandboxes with filtering and pagination | +| `DeleteSandbox(ctx, id)` | Delete a sandbox | +| `PauseSandbox(ctx, id)` | Pause a running sandbox | +| `ResumeSandbox(ctx, id)` | Resume a paused sandbox | +| `RenewExpiration(ctx, id, expiresAt)` | Extend sandbox expiration time | +| `GetEndpoint(ctx, sandboxID, port, useServerProxy)` | Get public endpoint for a sandbox port | + +### ExecdClient + +Created with `NewExecdClient(baseURL, accessToken string, opts ...Option)`. + +**Health:** +| Method | Description | +|--------|-------------| +| `Ping(ctx)` | Check server health | + +**Code Execution:** +| Method | Description | +|--------|-------------| +| `ListContexts(ctx, language)` | List active code execution contexts | +| `CreateContext(ctx, req)` | Create a code execution context | +| `GetContext(ctx, contextID)` | Get context details | +| `DeleteContext(ctx, contextID)` | Delete a context | +| `DeleteContextsByLanguage(ctx, language)` | Delete all contexts for a language | +| `ExecuteCode(ctx, req, handler)` | Execute code with SSE streaming | +| `InterruptCode(ctx, sessionID)` | Interrupt running code | + +**Command Execution:** +| Method | Description | +|--------|-------------| +| `CreateSession(ctx)` | Create a bash session | +| `RunInSession(ctx, sessionID, req, handler)` | Run command in session with SSE | +| `DeleteSession(ctx, sessionID)` | Delete a bash session | +| `RunCommand(ctx, req, handler)` | Run a command with SSE streaming | +| `InterruptCommand(ctx, sessionID)` | Interrupt running command | +| `GetCommandStatus(ctx, commandID)` | Get command execution status | +| `GetCommandLogs(ctx, commandID, cursor)` | Get command stdout/stderr | + +**File Operations:** +| Method | Description | +|--------|-------------| +| `GetFileInfo(ctx, path)` | Get file metadata | +| `DeleteFiles(ctx, paths)` | Delete files | +| `SetPermissions(ctx, req)` | Change file permissions | +| `MoveFiles(ctx, req)` | Move/rename files | +| `SearchFiles(ctx, dir, pattern)` | Search files by glob pattern | +| `ReplaceInFiles(ctx, req)` | Text replacement in files | +| `UploadFile(ctx, localPath, remotePath)` | Upload a file to the sandbox | +| `DownloadFile(ctx, remotePath, rangeHeader)` | Download a file from the sandbox | + +**Directory Operations:** +| Method | Description | +|--------|-------------| +| `CreateDirectory(ctx, path, mode)` | Create a directory (mkdir -p) | +| `DeleteDirectory(ctx, path)` | Delete a directory recursively | + +**Metrics:** +| Method | Description | +|--------|-------------| +| `GetMetrics(ctx)` | Get system resource metrics | +| `WatchMetrics(ctx, handler)` | Stream metrics via SSE | + +### EgressClient + +Created with `NewEgressClient(baseURL, authToken string, opts ...Option)`. + +| Method | Description | +|--------|-------------| +| `GetPolicy(ctx)` | Get current egress policy | +| `PatchPolicy(ctx, rules)` | Merge rules into current policy | + +## SSE Streaming + +Methods that stream output (`RunCommand`, `ExecuteCode`, `RunInSession`, `WatchMetrics`) accept an `EventHandler` callback: + +```go +type EventHandler func(event StreamEvent) error +``` + +Each `StreamEvent` contains: +- `Event` — the event type (e.g. `"stdout"`, `"stderr"`, `"result"`, `"execution_complete"`). For NDJSON streams, this is extracted from the JSON `type` field automatically. +- `Data` — the raw event payload (JSON string for NDJSON streams). +- `ID` — optional event identifier + +Return a non-nil error from the handler to stop processing the stream early. + +## Client Options + +All client constructors accept optional `Option` functions: + +```go +// Use a custom http.Client +client := opensandbox.NewLifecycleClient(url, key, + opensandbox.WithHTTPClient(myHTTPClient), +) + +// Set a custom timeout +client := opensandbox.NewExecdClient(url, token, + opensandbox.WithTimeout(60 * time.Second), +) +``` + +## Error Handling + +Non-2xx responses are returned as `*opensandbox.APIError`: + +```go +_, err := lc.GetSandbox(ctx, "nonexistent") +if apiErr, ok := err.(*opensandbox.APIError); ok { + fmt.Printf("HTTP %d: %s — %s\n", apiErr.StatusCode, apiErr.Response.Code, apiErr.Response.Message) +} +``` + +## License + +Apache 2.0 diff --git a/sdks/sandbox/go/examples/agent_loop/main.go b/sdks/sandbox/go/examples/agent_loop/main.go new file mode 100644 index 00000000..2ba58fc2 --- /dev/null +++ b/sdks/sandbox/go/examples/agent_loop/main.go @@ -0,0 +1,134 @@ +// Example: Simple Agent Loop +// +// Demonstrates a basic AI agent that: +// 1. Gets a task from the user +// 2. Asks an LLM to write Python code +// 3. Executes the code in an OpenSandbox sandbox +// 4. Returns the result +// +// Usage: +// +// export OPEN_SANDBOX_DOMAIN=localhost:8080 +// export OPEN_SANDBOX_API_KEY=your-api-key +// export LLM_ENDPOINT=http://localhost:8080/v1 # OpenAI-compatible endpoint +// export LLM_MODEL=gpt-4o-mini # or azure/gpt-4o-mini for Bifrost +// go run main.go "Calculate the first 20 prime numbers" +package main + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "os" + "strings" + "time" + + "github.com/alibaba/OpenSandbox/sdks/sandbox/go/opensandbox" +) + +func main() { + task := "Calculate the first 10 Fibonacci numbers and print them" + if len(os.Args) > 1 { + task = strings.Join(os.Args[1:], " ") + } + + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) + defer cancel() + + // 1. Create sandbox + fmt.Println("Creating sandbox...") + config := opensandbox.ConnectionConfig{} + sb, err := opensandbox.CreateSandbox(ctx, config, opensandbox.SandboxCreateOptions{ + Image: "python:3.11-slim", + }) + if err != nil { + fmt.Fprintf(os.Stderr, "Failed to create sandbox: %v\n", err) + os.Exit(1) + } + defer sb.Kill(context.Background()) + fmt.Printf("Sandbox ready: %s\n", sb.ID()) + + // 2. Ask LLM for code + fmt.Printf("Task: %s\n", task) + code, err := askLLM(ctx, task) + if err != nil { + fmt.Fprintf(os.Stderr, "LLM error: %v\n", err) + os.Exit(1) + } + fmt.Printf("Generated code:\n%s\n\n", code) + + // 3. Execute in sandbox + fmt.Println("Executing in sandbox...") + sb.RunCommand(ctx, fmt.Sprintf("cat > /tmp/task.py << 'EOF'\n%s\nEOF", code), nil) + exec, err := sb.RunCommand(ctx, "python3 /tmp/task.py", nil) + if err != nil { + fmt.Fprintf(os.Stderr, "Execution error: %v\n", err) + os.Exit(1) + } + + // 4. Show result + fmt.Printf("Result:\n%s\n", exec.Text()) + if exec.ExitCode != nil { + fmt.Printf("Exit code: %d\n", *exec.ExitCode) + } +} + +func askLLM(ctx context.Context, task string) (string, error) { + endpoint := os.Getenv("LLM_ENDPOINT") + if endpoint == "" { + return "", fmt.Errorf("LLM_ENDPOINT not set") + } + model := os.Getenv("LLM_MODEL") + if model == "" { + model = "gpt-4o-mini" + } + + body, _ := json.Marshal(map[string]any{ + "model": model, + "messages": []map[string]string{ + {"role": "system", "content": "Respond ONLY with a Python code block. No explanation."}, + {"role": "user", "content": task}, + }, + "max_tokens": 1024, + }) + + req, _ := http.NewRequestWithContext(ctx, "POST", endpoint+"/chat/completions", bytes.NewReader(body)) + req.Header.Set("Content-Type", "application/json") + + resp, err := http.DefaultClient.Do(req) + if err != nil { + return "", err + } + defer resp.Body.Close() + data, _ := io.ReadAll(resp.Body) + + var result struct { + Choices []struct { + Message struct { + Content string `json:"content"` + } `json:"message"` + } `json:"choices"` + } + json.Unmarshal(data, &result) + if len(result.Choices) == 0 { + return "", fmt.Errorf("no response from LLM: %s", string(data)) + } + + text := result.Choices[0].Message.Content + // Extract code from markdown block + if start := strings.Index(text, "```python"); start != -1 { + text = text[start+9:] + if end := strings.Index(text, "```"); end != -1 { + text = text[:end] + } + } else if start := strings.Index(text, "```"); start != -1 { + text = text[start+3:] + if end := strings.Index(text, "```"); end != -1 { + text = text[:end] + } + } + return strings.TrimSpace(text), nil +} diff --git a/sdks/sandbox/go/examples/code_interpreter_agent/main.go b/sdks/sandbox/go/examples/code_interpreter_agent/main.go new file mode 100644 index 00000000..53b2f47a --- /dev/null +++ b/sdks/sandbox/go/examples/code_interpreter_agent/main.go @@ -0,0 +1,140 @@ +// Example: Multi-turn Code Interpreter Agent +// +// Demonstrates an AI agent that maintains persistent Python state across +// multiple conversation turns using OpenSandbox's code interpreter: +// +// Turn 1: LLM creates a dataset +// Turn 2: LLM analyzes it (variables persist from turn 1) +// Turn 3: LLM generates a summary +// +// Usage: +// +// export OPEN_SANDBOX_DOMAIN=localhost:8080 +// export OPEN_SANDBOX_API_KEY=your-api-key +// export LLM_ENDPOINT=http://localhost:8080/v1 +// export LLM_MODEL=gpt-4o-mini +// go run main.go +package main + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "os" + "strings" + "time" + + "github.com/alibaba/OpenSandbox/sdks/sandbox/go/opensandbox" +) + +func main() { + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) + defer cancel() + + // Create code interpreter sandbox + fmt.Println("Creating code interpreter...") + config := opensandbox.ConnectionConfig{} + ci, err := opensandbox.CreateCodeInterpreter(ctx, config, opensandbox.CodeInterpreterCreateOptions{ + ReadyTimeout: 60 * time.Second, + }) + if err != nil { + fmt.Fprintf(os.Stderr, "Failed: %v\n", err) + os.Exit(1) + } + defer ci.Kill(context.Background()) + fmt.Printf("Ready: %s\n\n", ci.ID()) + + // Create persistent Python context + codeCtx, err := ci.CreateContext(ctx, opensandbox.CreateContextRequest{Language: "python"}) + if err != nil { + fmt.Fprintf(os.Stderr, "CreateContext: %v\n", err) + os.Exit(1) + } + + conversation := []map[string]string{ + {"role": "system", "content": "You are a data analysis assistant. Respond ONLY with a Python code block. Use only stdlib. Always print results."}, + } + + // Multi-turn conversation + turns := []string{ + "Create a list called 'temps' with 12 monthly average temperatures (Celsius) for São Paulo: [22, 23, 22, 20, 18, 17, 16, 18, 19, 20, 21, 22]. Print it.", + "Using the 'temps' variable, find the coldest month (1-indexed), hottest month, and the average temperature. Print all three.", + "Using 'temps', classify each month as 'hot' (>20), 'warm' (18-20), or 'cool' (<18). Print the classification for each month.", + } + + for i, prompt := range turns { + fmt.Printf("--- Turn %d ---\n", i+1) + fmt.Printf("User: %s\n\n", prompt) + + conversation = append(conversation, map[string]string{"role": "user", "content": prompt}) + + code, err := chatLLM(ctx, conversation) + if err != nil { + fmt.Fprintf(os.Stderr, "LLM error: %v\n", err) + os.Exit(1) + } + fmt.Printf("Code:\n%s\n\n", code) + + exec, err := ci.ExecuteInContext(ctx, codeCtx.ID, "python", code, nil) + if err != nil { + fmt.Fprintf(os.Stderr, "Execute error: %v\n", err) + os.Exit(1) + } + fmt.Printf("Output:\n%s\n\n", exec.Text()) + + conversation = append(conversation, map[string]string{"role": "assistant", "content": "```python\n" + code + "\n```"}) + } + + ci.DeleteContext(ctx, codeCtx.ID) + fmt.Println("Done! All turns completed with persistent state.") +} + +func chatLLM(ctx context.Context, messages []map[string]string) (string, error) { + endpoint := os.Getenv("LLM_ENDPOINT") + if endpoint == "" { + return "", fmt.Errorf("LLM_ENDPOINT not set") + } + model := os.Getenv("LLM_MODEL") + if model == "" { + model = "gpt-4o-mini" + } + + body, _ := json.Marshal(map[string]any{ + "model": model, + "messages": messages, + "max_tokens": 1024, + }) + req, _ := http.NewRequestWithContext(ctx, "POST", endpoint+"/chat/completions", bytes.NewReader(body)) + req.Header.Set("Content-Type", "application/json") + + resp, err := http.DefaultClient.Do(req) + if err != nil { + return "", err + } + defer resp.Body.Close() + data, _ := io.ReadAll(resp.Body) + + var result struct { + Choices []struct { + Message struct { + Content string `json:"content"` + } `json:"message"` + } `json:"choices"` + } + json.Unmarshal(data, &result) + if len(result.Choices) == 0 { + return "", fmt.Errorf("no choices: %s", string(data)) + } + + text := result.Choices[0].Message.Content + if start := strings.Index(text, "```python"); start != -1 { + text = text[start+9:] + if end := strings.Index(text, "```"); end != -1 { + text = text[:end] + } + } + return strings.TrimSpace(text), nil +} diff --git a/sdks/sandbox/go/go.mod b/sdks/sandbox/go/go.mod new file mode 100644 index 00000000..787be601 --- /dev/null +++ b/sdks/sandbox/go/go.mod @@ -0,0 +1,9 @@ +module github.com/alibaba/OpenSandbox/sdks/sandbox/go + +go 1.24.0 + +require ( + github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/oapi-codegen/runtime v1.3.1 // indirect +) diff --git a/sdks/sandbox/go/go.sum b/sdks/sandbox/go/go.sum new file mode 100644 index 00000000..06982a0b --- /dev/null +++ b/sdks/sandbox/go/go.sum @@ -0,0 +1,14 @@ +github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk= +github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ= +github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk= +github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE= +github.com/oapi-codegen/runtime v1.3.1 h1:RgDY6J4OGQLbRXhG/Xpt3vSVqYpHQS7hN4m85+5xB9g= +github.com/oapi-codegen/runtime v1.3.1/go.mod h1:kOdeacKy7t40Rclb1je37ZLFboFxh+YLy0zaPCMibPY= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/sdks/sandbox/go/opensandbox/api/egress/cfg.yaml b/sdks/sandbox/go/opensandbox/api/egress/cfg.yaml new file mode 100644 index 00000000..09559fc1 --- /dev/null +++ b/sdks/sandbox/go/opensandbox/api/egress/cfg.yaml @@ -0,0 +1,7 @@ +package: egress +output: gen.go +generate: + models: true + client: true +output-options: + name-normalizer: ToCamelCaseWithInitialisms diff --git a/sdks/sandbox/go/opensandbox/api/egress/gen.go b/sdks/sandbox/go/opensandbox/api/egress/gen.go new file mode 100644 index 00000000..cc6b29e3 --- /dev/null +++ b/sdks/sandbox/go/opensandbox/api/egress/gen.go @@ -0,0 +1,463 @@ +// Package egress provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.6.0 DO NOT EDIT. +package egress + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" +) + +// Defines values for NetworkPolicyDefaultAction. +const ( + NetworkPolicyDefaultActionAllow NetworkPolicyDefaultAction = "allow" + NetworkPolicyDefaultActionDeny NetworkPolicyDefaultAction = "deny" +) + +// Valid indicates whether the value is a known member of the NetworkPolicyDefaultAction enum. +func (e NetworkPolicyDefaultAction) Valid() bool { + switch e { + case NetworkPolicyDefaultActionAllow: + return true + case NetworkPolicyDefaultActionDeny: + return true + default: + return false + } +} + +// Defines values for NetworkRuleAction. +const ( + NetworkRuleActionAllow NetworkRuleAction = "allow" + NetworkRuleActionDeny NetworkRuleAction = "deny" +) + +// Valid indicates whether the value is a known member of the NetworkRuleAction enum. +func (e NetworkRuleAction) Valid() bool { + switch e { + case NetworkRuleActionAllow: + return true + case NetworkRuleActionDeny: + return true + default: + return false + } +} + +// NetworkPolicy Egress network policy matching the sidecar `/policy` request body. +// If `defaultAction` is omitted, the sidecar defaults to "deny"; passing an empty +// object or null results in allow-all behavior at startup. +type NetworkPolicy struct { + // DefaultAction Default action when no egress rule matches. Defaults to "deny". + DefaultAction *NetworkPolicyDefaultAction `json:"defaultAction,omitempty"` + + // Egress List of egress rules evaluated in order. + Egress *[]NetworkRule `json:"egress,omitempty"` +} + +// NetworkPolicyDefaultAction Default action when no egress rule matches. Defaults to "deny". +type NetworkPolicyDefaultAction string + +// NetworkRule defines model for NetworkRule. +type NetworkRule struct { + // Action Whether to allow or deny matching targets. + Action NetworkRuleAction `json:"action"` + + // Target FQDN or wildcard domain (e.g., "example.com", "*.example.com"). + // IP/CIDR not yet supported in the egress MVP. + Target string `json:"target"` +} + +// NetworkRuleAction Whether to allow or deny matching targets. +type NetworkRuleAction string + +// PolicyStatusResponse defines model for PolicyStatusResponse. +type PolicyStatusResponse struct { + // EnforcementMode Egress sidecar enforcement backend mode. + EnforcementMode *string `json:"enforcementMode,omitempty"` + + // Mode Derived runtime mode for the current policy. + Mode *string `json:"mode,omitempty"` + + // Policy Egress network policy matching the sidecar `/policy` request body. + // If `defaultAction` is omitted, the sidecar defaults to "deny"; passing an empty + // object or null results in allow-all behavior at startup. + Policy *NetworkPolicy `json:"policy,omitempty"` + + // Reason Optional human-readable reason when the sidecar returns extra context. + Reason *string `json:"reason,omitempty"` + + // Status Operation status reported by the sidecar. + Status *string `json:"status,omitempty"` +} + +// PatchPolicyJSONBody defines parameters for PatchPolicy. +type PatchPolicyJSONBody = []NetworkRule + +// PatchPolicyJSONRequestBody defines body for PatchPolicy for application/json ContentType. +type PatchPolicyJSONRequestBody = PatchPolicyJSONBody + +// RequestEditorFn is the function signature for the RequestEditor callback function +type RequestEditorFn func(ctx context.Context, req *http.Request) error + +// Doer performs HTTP requests. +// +// The standard http.Client implements this interface. +type HttpRequestDoer interface { + Do(req *http.Request) (*http.Response, error) +} + +// Client which conforms to the OpenAPI3 specification for this service. +type Client struct { + // The endpoint of the server conforming to this interface, with scheme, + // https://api.deepmap.com for example. This can contain a path relative + // to the server, such as https://api.deepmap.com/dev-test, and all the + // paths in the swagger spec will be appended to the server. + Server string + + // Doer for performing requests, typically a *http.Client with any + // customized settings, such as certificate chains. + Client HttpRequestDoer + + // A list of callbacks for modifying requests which are generated before sending over + // the network. + RequestEditors []RequestEditorFn +} + +// ClientOption allows setting custom parameters during construction +type ClientOption func(*Client) error + +// Creates a new Client, with reasonable defaults +func NewClient(server string, opts ...ClientOption) (*Client, error) { + // create a client with sane default values + client := Client{ + Server: server, + } + // mutate client and add all optional params + for _, o := range opts { + if err := o(&client); err != nil { + return nil, err + } + } + // ensure the server URL always has a trailing slash + if !strings.HasSuffix(client.Server, "/") { + client.Server += "/" + } + // create httpClient, if not already present + if client.Client == nil { + client.Client = &http.Client{} + } + return &client, nil +} + +// WithHTTPClient allows overriding the default Doer, which is +// automatically created using http.Client. This is useful for tests. +func WithHTTPClient(doer HttpRequestDoer) ClientOption { + return func(c *Client) error { + c.Client = doer + return nil + } +} + +// WithRequestEditorFn allows setting up a callback function, which will be +// called right before sending the request. This can be used to mutate the request. +func WithRequestEditorFn(fn RequestEditorFn) ClientOption { + return func(c *Client) error { + c.RequestEditors = append(c.RequestEditors, fn) + return nil + } +} + +// The interface specification for the client above. +type ClientInterface interface { + // GetPolicy request + GetPolicy(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) + + // PatchPolicyWithBody request with any body + PatchPolicyWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + PatchPolicy(ctx context.Context, body PatchPolicyJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) +} + +func (c *Client) GetPolicy(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetPolicyRequest(c.Server) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PatchPolicyWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPatchPolicyRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PatchPolicy(ctx context.Context, body PatchPolicyJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPatchPolicyRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +// NewGetPolicyRequest generates requests for GetPolicy +func NewGetPolicyRequest(server string) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/policy") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewPatchPolicyRequest calls the generic PatchPolicy builder with application/json body +func NewPatchPolicyRequest(server string, body PatchPolicyJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewPatchPolicyRequestWithBody(server, "application/json", bodyReader) +} + +// NewPatchPolicyRequestWithBody generates requests for PatchPolicy with any type of body +func NewPatchPolicyRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/policy") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("PATCH", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { + for _, r := range c.RequestEditors { + if err := r(ctx, req); err != nil { + return err + } + } + for _, r := range additionalEditors { + if err := r(ctx, req); err != nil { + return err + } + } + return nil +} + +// ClientWithResponses builds on ClientInterface to offer response payloads +type ClientWithResponses struct { + ClientInterface +} + +// NewClientWithResponses creates a new ClientWithResponses, which wraps +// Client with return type handling +func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { + client, err := NewClient(server, opts...) + if err != nil { + return nil, err + } + return &ClientWithResponses{client}, nil +} + +// WithBaseURL overrides the baseURL. +func WithBaseURL(baseURL string) ClientOption { + return func(c *Client) error { + newBaseURL, err := url.Parse(baseURL) + if err != nil { + return err + } + c.Server = newBaseURL.String() + return nil + } +} + +// ClientWithResponsesInterface is the interface specification for the client with responses above. +type ClientWithResponsesInterface interface { + // GetPolicyWithResponse request + GetPolicyWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetPolicyResponse, error) + + // PatchPolicyWithBodyWithResponse request with any body + PatchPolicyWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PatchPolicyResponse, error) + + PatchPolicyWithResponse(ctx context.Context, body PatchPolicyJSONRequestBody, reqEditors ...RequestEditorFn) (*PatchPolicyResponse, error) +} + +type GetPolicyResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *PolicyStatusResponse +} + +// Status returns HTTPResponse.Status +func (r GetPolicyResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetPolicyResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type PatchPolicyResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *PolicyStatusResponse +} + +// Status returns HTTPResponse.Status +func (r PatchPolicyResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PatchPolicyResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// GetPolicyWithResponse request returning *GetPolicyResponse +func (c *ClientWithResponses) GetPolicyWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetPolicyResponse, error) { + rsp, err := c.GetPolicy(ctx, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetPolicyResponse(rsp) +} + +// PatchPolicyWithBodyWithResponse request with arbitrary body returning *PatchPolicyResponse +func (c *ClientWithResponses) PatchPolicyWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PatchPolicyResponse, error) { + rsp, err := c.PatchPolicyWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePatchPolicyResponse(rsp) +} + +func (c *ClientWithResponses) PatchPolicyWithResponse(ctx context.Context, body PatchPolicyJSONRequestBody, reqEditors ...RequestEditorFn) (*PatchPolicyResponse, error) { + rsp, err := c.PatchPolicy(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePatchPolicyResponse(rsp) +} + +// ParseGetPolicyResponse parses an HTTP response from a GetPolicyWithResponse call +func ParseGetPolicyResponse(rsp *http.Response) (*GetPolicyResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetPolicyResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest PolicyStatusResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + +// ParsePatchPolicyResponse parses an HTTP response from a PatchPolicyWithResponse call +func ParsePatchPolicyResponse(rsp *http.Response) (*PatchPolicyResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PatchPolicyResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest PolicyStatusResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} diff --git a/sdks/sandbox/go/opensandbox/api/egress/generate.go b/sdks/sandbox/go/opensandbox/api/egress/generate.go new file mode 100644 index 00000000..95e5c8d9 --- /dev/null +++ b/sdks/sandbox/go/opensandbox/api/egress/generate.go @@ -0,0 +1,3 @@ +package egress + +//go:generate oapi-codegen --config cfg.yaml ../specs/egress-api.yaml diff --git a/sdks/sandbox/go/opensandbox/api/execd/cfg.yaml b/sdks/sandbox/go/opensandbox/api/execd/cfg.yaml new file mode 100644 index 00000000..4240f143 --- /dev/null +++ b/sdks/sandbox/go/opensandbox/api/execd/cfg.yaml @@ -0,0 +1,7 @@ +package: execd +output: gen.go +generate: + models: true + client: true +output-options: + name-normalizer: ToCamelCaseWithInitialisms diff --git a/sdks/sandbox/go/opensandbox/api/execd/gen.go b/sdks/sandbox/go/opensandbox/api/execd/gen.go new file mode 100644 index 00000000..74c07c85 --- /dev/null +++ b/sdks/sandbox/go/opensandbox/api/execd/gen.go @@ -0,0 +1,4173 @@ +// Package execd provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.6.0 DO NOT EDIT. +package execd + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" + "time" + + "github.com/oapi-codegen/runtime" + openapi_types "github.com/oapi-codegen/runtime/types" +) + +const ( + AccessTokenScopes = "AccessToken.Scopes" +) + +// Defines values for ServerStreamEventType. +const ( + Error ServerStreamEventType = "error" + ExecutionComplete ServerStreamEventType = "execution_complete" + ExecutionCount ServerStreamEventType = "execution_count" + Init ServerStreamEventType = "init" + Ping ServerStreamEventType = "ping" + Result ServerStreamEventType = "result" + Status ServerStreamEventType = "status" + Stderr ServerStreamEventType = "stderr" + Stdout ServerStreamEventType = "stdout" +) + +// Valid indicates whether the value is a known member of the ServerStreamEventType enum. +func (e ServerStreamEventType) Valid() bool { + switch e { + case Error: + return true + case ExecutionComplete: + return true + case ExecutionCount: + return true + case Init: + return true + case Ping: + return true + case Result: + return true + case Status: + return true + case Stderr: + return true + case Stdout: + return true + default: + return false + } +} + +// CodeContext Code execution context with session identifier +type CodeContext struct { + // ID Unique session identifier returned by CreateContext + ID *string `json:"id,omitempty"` + + // Language Execution runtime + Language string `json:"language"` +} + +// CodeContextRequest Request to create a code execution context +type CodeContextRequest struct { + // Language Execution runtime (python, bash, java, etc.) + Language *string `json:"language,omitempty"` +} + +// CommandStatusResponse Command execution status (foreground or background) +type CommandStatusResponse struct { + // Content Original command content + Content *string `json:"content,omitempty"` + + // Error Error message if the command failed + Error *string `json:"error,omitempty"` + + // ExitCode Exit code if the command has finished + ExitCode *int32 `json:"exit_code,omitempty"` + + // FinishedAt Finish time in RFC3339 format (null if still running) + FinishedAt *time.Time `json:"finished_at,omitempty"` + + // ID Command ID returned by RunCommand + ID *string `json:"id,omitempty"` + + // Running Whether the command is still running + Running *bool `json:"running,omitempty"` + + // StartedAt Start time in RFC3339 format + StartedAt *time.Time `json:"started_at,omitempty"` +} + +// CreateSessionRequest Request to create a bash session (optional body; empty treated as defaults) +type CreateSessionRequest struct { + // Cwd Working directory for the session (optional) + Cwd *string `json:"cwd,omitempty"` +} + +// ErrorResponse Standard error response format +type ErrorResponse struct { + // Code Error code for programmatic handling + Code string `json:"code"` + + // Message Human-readable error message + Message string `json:"message"` +} + +// FileInfo File metadata including path and permissions +type FileInfo struct { + // CreatedAt File creation time + CreatedAt time.Time `json:"created_at"` + + // Group File group name + Group string `json:"group"` + + // Mode File permissions in octal format + Mode int `json:"mode"` + + // ModifiedAt Last modification time + ModifiedAt time.Time `json:"modified_at"` + + // Owner File owner username + Owner string `json:"owner"` + + // Path Absolute file path + Path string `json:"path"` + + // Size File size in bytes + Size int64 `json:"size"` +} + +// Metrics System resource usage metrics +type Metrics struct { + // CPUCount Number of CPU cores + CPUCount float32 `json:"cpu_count"` + + // CPUUsedPct CPU usage percentage + CPUUsedPct float32 `json:"cpu_used_pct"` + + // MemTotalMib Total memory in MiB + MemTotalMib float32 `json:"mem_total_mib"` + + // MemUsedMib Used memory in MiB + MemUsedMib float32 `json:"mem_used_mib"` + + // Timestamp Timestamp when metrics were collected (Unix milliseconds) + Timestamp int64 `json:"timestamp"` +} + +// Permission File ownership and mode settings +type Permission struct { + // Group Group name + Group *string `json:"group,omitempty"` + + // Mode Permission mode in octal format (e.g., 644, 755) + Mode int `json:"mode"` + + // Owner Owner username + Owner *string `json:"owner,omitempty"` +} + +// RenameFileItem File rename/move operation +type RenameFileItem struct { + // Dest Destination file path + Dest string `json:"dest"` + + // Src Source file path + Src string `json:"src"` +} + +// ReplaceFileContentItem Content replacement operation +type ReplaceFileContentItem struct { + // New Replacement string + New string `json:"new"` + + // Old String to be replaced + Old string `json:"old"` +} + +// RunCodeRequest Request to execute code in a context +type RunCodeRequest struct { + // Code Source code to execute + Code string `json:"code"` + + // Context Code execution context with session identifier + Context *CodeContext `json:"context,omitempty"` +} + +// RunCommandRequest Request to execute a shell command +type RunCommandRequest struct { + // Background Whether to run command in detached mode + Background *bool `json:"background,omitempty"` + + // Command Shell command to execute + Command string `json:"command"` + + // Cwd Working directory for command execution + Cwd *string `json:"cwd,omitempty"` + + // Envs Environment variables injected into the command process. + Envs *map[string]string `json:"envs,omitempty"` + + // GID Unix group ID used to run the command. Requires `uid` to be provided. + GID *int32 `json:"gid,omitempty"` + + // Timeout Maximum allowed execution time in milliseconds before the command is forcefully terminated by the server. If omitted, the server will not enforce any timeout. + Timeout *int64 `json:"timeout,omitempty"` + + // UID Unix user ID used to run the command. If `gid` is provided, `uid` is required. + UID *int32 `json:"uid,omitempty"` +} + +// RunInSessionRequest Request to run a command in an existing bash session +type RunInSessionRequest struct { + // Command Shell command to execute in the session + Command string `json:"command"` + + // Cwd Working directory override for this run (optional) + Cwd *string `json:"cwd,omitempty"` + + // Timeout Maximum execution time in milliseconds (optional; server may not enforce if omitted) + Timeout *int64 `json:"timeout,omitempty"` +} + +// ServerStreamEvent Server-sent event for streaming execution output +type ServerStreamEvent struct { + // Error Execution error details if an error occurred + Error *struct { + // Ename Error name/type + Ename *string `json:"ename,omitempty"` + + // Evalue Error value/message + Evalue *string `json:"evalue,omitempty"` + + // Traceback Stack trace lines + Traceback *[]string `json:"traceback,omitempty"` + } `json:"error,omitempty"` + + // ExecutionCount Cell execution number in the session + ExecutionCount *int `json:"execution_count,omitempty"` + + // ExecutionTime Execution duration in milliseconds + ExecutionTime *int64 `json:"execution_time,omitempty"` + + // Results Execution output in various MIME types (e.g., "text/plain", "text/html") + Results *map[string]interface{} `json:"results,omitempty"` + + // Text Textual data for status, init, and stream events + Text *string `json:"text,omitempty"` + + // Timestamp When the event was generated (Unix milliseconds) + Timestamp *int64 `json:"timestamp,omitempty"` + + // Type Event type for client-side handling + Type *ServerStreamEventType `json:"type,omitempty"` +} + +// ServerStreamEventType Event type for client-side handling +type ServerStreamEventType string + +// SessionCreated Response for create_session +type SessionCreated struct { + // SessionID Unique session ID for run_in_session and delete_session + SessionID string `json:"session_id"` +} + +// BadRequest Standard error response format +type BadRequest = ErrorResponse + +// InternalServerError Standard error response format +type InternalServerError = ErrorResponse + +// NotFound Standard error response format +type NotFound = ErrorResponse + +// InterruptCodeParams defines parameters for InterruptCode. +type InterruptCodeParams struct { + // ID Session ID of the execution context to interrupt + ID string `form:"id" json:"id"` +} + +// DeleteContextsByLanguageParams defines parameters for DeleteContextsByLanguage. +type DeleteContextsByLanguageParams struct { + // Language Target execution runtime whose contexts should be deleted + Language string `form:"language" json:"language"` +} + +// ListContextsParams defines parameters for ListContexts. +type ListContextsParams struct { + // Language Filter contexts by execution runtime (python, bash, java, etc.) + Language string `form:"language" json:"language"` +} + +// InterruptCommandParams defines parameters for InterruptCommand. +type InterruptCommandParams struct { + // ID Session ID of the execution context to interrupt + ID string `form:"id" json:"id"` +} + +// GetBackgroundCommandLogsParams defines parameters for GetBackgroundCommandLogs. +type GetBackgroundCommandLogsParams struct { + // Cursor Optional 0-based line cursor (behaves like a file seek). When provided, only + // stdout/stderr lines after this line are returned. The response includes the + // latest line index (`cursor`) so the client can request incremental output + // on subsequent calls. If omitted, the full log is returned. + Cursor *int64 `form:"cursor,omitempty" json:"cursor,omitempty"` +} + +// RemoveDirsParams defines parameters for RemoveDirs. +type RemoveDirsParams struct { + // Path Directory path(s) to delete (can be specified multiple times) + Path []string `form:"path" json:"path"` +} + +// MakeDirsJSONBody defines parameters for MakeDirs. +type MakeDirsJSONBody map[string]Permission + +// RemoveFilesParams defines parameters for RemoveFiles. +type RemoveFilesParams struct { + // Path File path(s) to delete (can be specified multiple times) + Path []string `form:"path" json:"path"` +} + +// DownloadFileParams defines parameters for DownloadFile. +type DownloadFileParams struct { + // Path Absolute or relative path of the file to download + Path string `form:"path" json:"path"` + + // Range HTTP Range header for partial content requests + Range *string `json:"Range,omitempty"` +} + +// GetFilesInfoParams defines parameters for GetFilesInfo. +type GetFilesInfoParams struct { + // Path File path(s) to get info for (can be specified multiple times) + Path []string `form:"path" json:"path"` +} + +// RenameFilesJSONBody defines parameters for RenameFiles. +type RenameFilesJSONBody = []RenameFileItem + +// ChmodFilesJSONBody defines parameters for ChmodFiles. +type ChmodFilesJSONBody map[string]Permission + +// ReplaceContentJSONBody defines parameters for ReplaceContent. +type ReplaceContentJSONBody map[string]ReplaceFileContentItem + +// SearchFilesParams defines parameters for SearchFiles. +type SearchFilesParams struct { + // Path Root directory path to search in + Path string `form:"path" json:"path"` + + // Pattern Glob pattern to match files (default is **) + Pattern *string `form:"pattern,omitempty" json:"pattern,omitempty"` +} + +// UploadFileMultipartBody defines parameters for UploadFile. +type UploadFileMultipartBody struct { + // File File to upload + File *openapi_types.File `json:"file,omitempty"` + + // Metadata JSON-encoded file metadata (FileMetadata object) + Metadata *string `json:"metadata,omitempty"` +} + +// RunCodeJSONRequestBody defines body for RunCode for application/json ContentType. +type RunCodeJSONRequestBody = RunCodeRequest + +// CreateCodeContextJSONRequestBody defines body for CreateCodeContext for application/json ContentType. +type CreateCodeContextJSONRequestBody = CodeContextRequest + +// RunCommandJSONRequestBody defines body for RunCommand for application/json ContentType. +type RunCommandJSONRequestBody = RunCommandRequest + +// MakeDirsJSONRequestBody defines body for MakeDirs for application/json ContentType. +type MakeDirsJSONRequestBody MakeDirsJSONBody + +// RenameFilesJSONRequestBody defines body for RenameFiles for application/json ContentType. +type RenameFilesJSONRequestBody = RenameFilesJSONBody + +// ChmodFilesJSONRequestBody defines body for ChmodFiles for application/json ContentType. +type ChmodFilesJSONRequestBody ChmodFilesJSONBody + +// ReplaceContentJSONRequestBody defines body for ReplaceContent for application/json ContentType. +type ReplaceContentJSONRequestBody ReplaceContentJSONBody + +// UploadFileMultipartRequestBody defines body for UploadFile for multipart/form-data ContentType. +type UploadFileMultipartRequestBody UploadFileMultipartBody + +// CreateSessionJSONRequestBody defines body for CreateSession for application/json ContentType. +type CreateSessionJSONRequestBody = CreateSessionRequest + +// RunInSessionJSONRequestBody defines body for RunInSession for application/json ContentType. +type RunInSessionJSONRequestBody = RunInSessionRequest + +// RequestEditorFn is the function signature for the RequestEditor callback function +type RequestEditorFn func(ctx context.Context, req *http.Request) error + +// Doer performs HTTP requests. +// +// The standard http.Client implements this interface. +type HttpRequestDoer interface { + Do(req *http.Request) (*http.Response, error) +} + +// Client which conforms to the OpenAPI3 specification for this service. +type Client struct { + // The endpoint of the server conforming to this interface, with scheme, + // https://api.deepmap.com for example. This can contain a path relative + // to the server, such as https://api.deepmap.com/dev-test, and all the + // paths in the swagger spec will be appended to the server. + Server string + + // Doer for performing requests, typically a *http.Client with any + // customized settings, such as certificate chains. + Client HttpRequestDoer + + // A list of callbacks for modifying requests which are generated before sending over + // the network. + RequestEditors []RequestEditorFn +} + +// ClientOption allows setting custom parameters during construction +type ClientOption func(*Client) error + +// Creates a new Client, with reasonable defaults +func NewClient(server string, opts ...ClientOption) (*Client, error) { + // create a client with sane default values + client := Client{ + Server: server, + } + // mutate client and add all optional params + for _, o := range opts { + if err := o(&client); err != nil { + return nil, err + } + } + // ensure the server URL always has a trailing slash + if !strings.HasSuffix(client.Server, "/") { + client.Server += "/" + } + // create httpClient, if not already present + if client.Client == nil { + client.Client = &http.Client{} + } + return &client, nil +} + +// WithHTTPClient allows overriding the default Doer, which is +// automatically created using http.Client. This is useful for tests. +func WithHTTPClient(doer HttpRequestDoer) ClientOption { + return func(c *Client) error { + c.Client = doer + return nil + } +} + +// WithRequestEditorFn allows setting up a callback function, which will be +// called right before sending the request. This can be used to mutate the request. +func WithRequestEditorFn(fn RequestEditorFn) ClientOption { + return func(c *Client) error { + c.RequestEditors = append(c.RequestEditors, fn) + return nil + } +} + +// The interface specification for the client above. +type ClientInterface interface { + // InterruptCode request + InterruptCode(ctx context.Context, params *InterruptCodeParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // RunCodeWithBody request with any body + RunCodeWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + RunCode(ctx context.Context, body RunCodeJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // CreateCodeContextWithBody request with any body + CreateCodeContextWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + CreateCodeContext(ctx context.Context, body CreateCodeContextJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // DeleteContextsByLanguage request + DeleteContextsByLanguage(ctx context.Context, params *DeleteContextsByLanguageParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // ListContexts request + ListContexts(ctx context.Context, params *ListContextsParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // DeleteContext request + DeleteContext(ctx context.Context, contextID string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetContext request + GetContext(ctx context.Context, contextID string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // InterruptCommand request + InterruptCommand(ctx context.Context, params *InterruptCommandParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // RunCommandWithBody request with any body + RunCommandWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + RunCommand(ctx context.Context, body RunCommandJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetCommandStatus request + GetCommandStatus(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetBackgroundCommandLogs request + GetBackgroundCommandLogs(ctx context.Context, id string, params *GetBackgroundCommandLogsParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // RemoveDirs request + RemoveDirs(ctx context.Context, params *RemoveDirsParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // MakeDirsWithBody request with any body + MakeDirsWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + MakeDirs(ctx context.Context, body MakeDirsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // RemoveFiles request + RemoveFiles(ctx context.Context, params *RemoveFilesParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // DownloadFile request + DownloadFile(ctx context.Context, params *DownloadFileParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetFilesInfo request + GetFilesInfo(ctx context.Context, params *GetFilesInfoParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // RenameFilesWithBody request with any body + RenameFilesWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + RenameFiles(ctx context.Context, body RenameFilesJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // ChmodFilesWithBody request with any body + ChmodFilesWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + ChmodFiles(ctx context.Context, body ChmodFilesJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // ReplaceContentWithBody request with any body + ReplaceContentWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + ReplaceContent(ctx context.Context, body ReplaceContentJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // SearchFiles request + SearchFiles(ctx context.Context, params *SearchFilesParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // UploadFileWithBody request with any body + UploadFileWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetMetrics request + GetMetrics(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) + + // WatchMetrics request + WatchMetrics(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) + + // Ping request + Ping(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) + + // CreateSessionWithBody request with any body + CreateSessionWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + CreateSession(ctx context.Context, body CreateSessionJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // DeleteSession request + DeleteSession(ctx context.Context, sessionID string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // RunInSessionWithBody request with any body + RunInSessionWithBody(ctx context.Context, sessionID string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + RunInSession(ctx context.Context, sessionID string, body RunInSessionJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) +} + +func (c *Client) InterruptCode(ctx context.Context, params *InterruptCodeParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewInterruptCodeRequest(c.Server, params) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) RunCodeWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewRunCodeRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) RunCode(ctx context.Context, body RunCodeJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewRunCodeRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CreateCodeContextWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateCodeContextRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CreateCodeContext(ctx context.Context, body CreateCodeContextJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateCodeContextRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) DeleteContextsByLanguage(ctx context.Context, params *DeleteContextsByLanguageParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDeleteContextsByLanguageRequest(c.Server, params) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) ListContexts(ctx context.Context, params *ListContextsParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewListContextsRequest(c.Server, params) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) DeleteContext(ctx context.Context, contextID string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDeleteContextRequest(c.Server, contextID) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetContext(ctx context.Context, contextID string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetContextRequest(c.Server, contextID) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) InterruptCommand(ctx context.Context, params *InterruptCommandParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewInterruptCommandRequest(c.Server, params) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) RunCommandWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewRunCommandRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) RunCommand(ctx context.Context, body RunCommandJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewRunCommandRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetCommandStatus(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetCommandStatusRequest(c.Server, id) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetBackgroundCommandLogs(ctx context.Context, id string, params *GetBackgroundCommandLogsParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetBackgroundCommandLogsRequest(c.Server, id, params) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) RemoveDirs(ctx context.Context, params *RemoveDirsParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewRemoveDirsRequest(c.Server, params) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) MakeDirsWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewMakeDirsRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) MakeDirs(ctx context.Context, body MakeDirsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewMakeDirsRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) RemoveFiles(ctx context.Context, params *RemoveFilesParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewRemoveFilesRequest(c.Server, params) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) DownloadFile(ctx context.Context, params *DownloadFileParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDownloadFileRequest(c.Server, params) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetFilesInfo(ctx context.Context, params *GetFilesInfoParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetFilesInfoRequest(c.Server, params) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) RenameFilesWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewRenameFilesRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) RenameFiles(ctx context.Context, body RenameFilesJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewRenameFilesRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) ChmodFilesWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewChmodFilesRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) ChmodFiles(ctx context.Context, body ChmodFilesJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewChmodFilesRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) ReplaceContentWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewReplaceContentRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) ReplaceContent(ctx context.Context, body ReplaceContentJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewReplaceContentRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) SearchFiles(ctx context.Context, params *SearchFilesParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewSearchFilesRequest(c.Server, params) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) UploadFileWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewUploadFileRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetMetrics(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetMetricsRequest(c.Server) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) WatchMetrics(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewWatchMetricsRequest(c.Server) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) Ping(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPingRequest(c.Server) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CreateSessionWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateSessionRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CreateSession(ctx context.Context, body CreateSessionJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateSessionRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) DeleteSession(ctx context.Context, sessionID string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDeleteSessionRequest(c.Server, sessionID) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) RunInSessionWithBody(ctx context.Context, sessionID string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewRunInSessionRequestWithBody(c.Server, sessionID, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) RunInSession(ctx context.Context, sessionID string, body RunInSessionJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewRunInSessionRequest(c.Server, sessionID, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +// NewInterruptCodeRequest generates requests for InterruptCode +func NewInterruptCodeRequest(server string, params *InterruptCodeParams) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/code") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + queryValues := queryURL.Query() + + if queryFrag, err := runtime.StyleParamWithOptions("form", true, "id", params.ID, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "string", Format: ""}); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + queryURL.RawQuery = queryValues.Encode() + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewRunCodeRequest calls the generic RunCode builder with application/json body +func NewRunCodeRequest(server string, body RunCodeJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewRunCodeRequestWithBody(server, "application/json", bodyReader) +} + +// NewRunCodeRequestWithBody generates requests for RunCode with any type of body +func NewRunCodeRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/code") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewCreateCodeContextRequest calls the generic CreateCodeContext builder with application/json body +func NewCreateCodeContextRequest(server string, body CreateCodeContextJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewCreateCodeContextRequestWithBody(server, "application/json", bodyReader) +} + +// NewCreateCodeContextRequestWithBody generates requests for CreateCodeContext with any type of body +func NewCreateCodeContextRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/code/context") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewDeleteContextsByLanguageRequest generates requests for DeleteContextsByLanguage +func NewDeleteContextsByLanguageRequest(server string, params *DeleteContextsByLanguageParams) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/code/contexts") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + queryValues := queryURL.Query() + + if queryFrag, err := runtime.StyleParamWithOptions("form", true, "language", params.Language, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "string", Format: ""}); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + queryURL.RawQuery = queryValues.Encode() + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewListContextsRequest generates requests for ListContexts +func NewListContextsRequest(server string, params *ListContextsParams) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/code/contexts") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + queryValues := queryURL.Query() + + if queryFrag, err := runtime.StyleParamWithOptions("form", true, "language", params.Language, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "string", Format: ""}); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + queryURL.RawQuery = queryValues.Encode() + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewDeleteContextRequest generates requests for DeleteContext +func NewDeleteContextRequest(server string, contextID string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "context_id", contextID, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/code/contexts/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetContextRequest generates requests for GetContext +func NewGetContextRequest(server string, contextID string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "context_id", contextID, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/code/contexts/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewInterruptCommandRequest generates requests for InterruptCommand +func NewInterruptCommandRequest(server string, params *InterruptCommandParams) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/command") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + queryValues := queryURL.Query() + + if queryFrag, err := runtime.StyleParamWithOptions("form", true, "id", params.ID, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "string", Format: ""}); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + queryURL.RawQuery = queryValues.Encode() + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewRunCommandRequest calls the generic RunCommand builder with application/json body +func NewRunCommandRequest(server string, body RunCommandJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewRunCommandRequestWithBody(server, "application/json", bodyReader) +} + +// NewRunCommandRequestWithBody generates requests for RunCommand with any type of body +func NewRunCommandRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/command") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewGetCommandStatusRequest generates requests for GetCommandStatus +func NewGetCommandStatusRequest(server string, id string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/command/status/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetBackgroundCommandLogsRequest generates requests for GetBackgroundCommandLogs +func NewGetBackgroundCommandLogsRequest(server string, id string, params *GetBackgroundCommandLogsParams) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/command/%s/logs", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + queryValues := queryURL.Query() + + if params.Cursor != nil { + + if queryFrag, err := runtime.StyleParamWithOptions("form", true, "cursor", *params.Cursor, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "integer", Format: "int64"}); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + queryURL.RawQuery = queryValues.Encode() + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewRemoveDirsRequest generates requests for RemoveDirs +func NewRemoveDirsRequest(server string, params *RemoveDirsParams) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/directories") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + queryValues := queryURL.Query() + + if params.Path != nil { + + if queryFrag, err := runtime.StyleParamWithOptions("form", true, "path", params.Path, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "array", Format: ""}); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + queryURL.RawQuery = queryValues.Encode() + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewMakeDirsRequest calls the generic MakeDirs builder with application/json body +func NewMakeDirsRequest(server string, body MakeDirsJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewMakeDirsRequestWithBody(server, "application/json", bodyReader) +} + +// NewMakeDirsRequestWithBody generates requests for MakeDirs with any type of body +func NewMakeDirsRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/directories") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewRemoveFilesRequest generates requests for RemoveFiles +func NewRemoveFilesRequest(server string, params *RemoveFilesParams) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/files") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + queryValues := queryURL.Query() + + if params.Path != nil { + + if queryFrag, err := runtime.StyleParamWithOptions("form", true, "path", params.Path, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "array", Format: ""}); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + queryURL.RawQuery = queryValues.Encode() + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewDownloadFileRequest generates requests for DownloadFile +func NewDownloadFileRequest(server string, params *DownloadFileParams) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/files/download") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + queryValues := queryURL.Query() + + if queryFrag, err := runtime.StyleParamWithOptions("form", true, "path", params.Path, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "string", Format: ""}); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + queryURL.RawQuery = queryValues.Encode() + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + if params != nil { + + if params.Range != nil { + var headerParam0 string + + headerParam0, err = runtime.StyleParamWithOptions("simple", false, "Range", *params.Range, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationHeader, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + req.Header.Set("Range", headerParam0) + } + + } + + return req, nil +} + +// NewGetFilesInfoRequest generates requests for GetFilesInfo +func NewGetFilesInfoRequest(server string, params *GetFilesInfoParams) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/files/info") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + queryValues := queryURL.Query() + + if params.Path != nil { + + if queryFrag, err := runtime.StyleParamWithOptions("form", true, "path", params.Path, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "array", Format: ""}); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + queryURL.RawQuery = queryValues.Encode() + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewRenameFilesRequest calls the generic RenameFiles builder with application/json body +func NewRenameFilesRequest(server string, body RenameFilesJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewRenameFilesRequestWithBody(server, "application/json", bodyReader) +} + +// NewRenameFilesRequestWithBody generates requests for RenameFiles with any type of body +func NewRenameFilesRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/files/mv") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewChmodFilesRequest calls the generic ChmodFiles builder with application/json body +func NewChmodFilesRequest(server string, body ChmodFilesJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewChmodFilesRequestWithBody(server, "application/json", bodyReader) +} + +// NewChmodFilesRequestWithBody generates requests for ChmodFiles with any type of body +func NewChmodFilesRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/files/permissions") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewReplaceContentRequest calls the generic ReplaceContent builder with application/json body +func NewReplaceContentRequest(server string, body ReplaceContentJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewReplaceContentRequestWithBody(server, "application/json", bodyReader) +} + +// NewReplaceContentRequestWithBody generates requests for ReplaceContent with any type of body +func NewReplaceContentRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/files/replace") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewSearchFilesRequest generates requests for SearchFiles +func NewSearchFilesRequest(server string, params *SearchFilesParams) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/files/search") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + queryValues := queryURL.Query() + + if queryFrag, err := runtime.StyleParamWithOptions("form", true, "path", params.Path, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "string", Format: ""}); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + if params.Pattern != nil { + + if queryFrag, err := runtime.StyleParamWithOptions("form", true, "pattern", *params.Pattern, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "string", Format: ""}); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + queryURL.RawQuery = queryValues.Encode() + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewUploadFileRequestWithBody generates requests for UploadFile with any type of body +func NewUploadFileRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/files/upload") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewGetMetricsRequest generates requests for GetMetrics +func NewGetMetricsRequest(server string) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/metrics") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewWatchMetricsRequest generates requests for WatchMetrics +func NewWatchMetricsRequest(server string) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/metrics/watch") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewPingRequest generates requests for Ping +func NewPingRequest(server string) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/ping") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewCreateSessionRequest calls the generic CreateSession builder with application/json body +func NewCreateSessionRequest(server string, body CreateSessionJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewCreateSessionRequestWithBody(server, "application/json", bodyReader) +} + +// NewCreateSessionRequestWithBody generates requests for CreateSession with any type of body +func NewCreateSessionRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/session") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewDeleteSessionRequest generates requests for DeleteSession +func NewDeleteSessionRequest(server string, sessionID string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "sessionId", sessionID, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/session/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewRunInSessionRequest calls the generic RunInSession builder with application/json body +func NewRunInSessionRequest(server string, sessionID string, body RunInSessionJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewRunInSessionRequestWithBody(server, sessionID, "application/json", bodyReader) +} + +// NewRunInSessionRequestWithBody generates requests for RunInSession with any type of body +func NewRunInSessionRequestWithBody(server string, sessionID string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "sessionId", sessionID, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/session/%s/run", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { + for _, r := range c.RequestEditors { + if err := r(ctx, req); err != nil { + return err + } + } + for _, r := range additionalEditors { + if err := r(ctx, req); err != nil { + return err + } + } + return nil +} + +// ClientWithResponses builds on ClientInterface to offer response payloads +type ClientWithResponses struct { + ClientInterface +} + +// NewClientWithResponses creates a new ClientWithResponses, which wraps +// Client with return type handling +func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { + client, err := NewClient(server, opts...) + if err != nil { + return nil, err + } + return &ClientWithResponses{client}, nil +} + +// WithBaseURL overrides the baseURL. +func WithBaseURL(baseURL string) ClientOption { + return func(c *Client) error { + newBaseURL, err := url.Parse(baseURL) + if err != nil { + return err + } + c.Server = newBaseURL.String() + return nil + } +} + +// ClientWithResponsesInterface is the interface specification for the client with responses above. +type ClientWithResponsesInterface interface { + // InterruptCodeWithResponse request + InterruptCodeWithResponse(ctx context.Context, params *InterruptCodeParams, reqEditors ...RequestEditorFn) (*InterruptCodeResponse, error) + + // RunCodeWithBodyWithResponse request with any body + RunCodeWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RunCodeResponse, error) + + RunCodeWithResponse(ctx context.Context, body RunCodeJSONRequestBody, reqEditors ...RequestEditorFn) (*RunCodeResponse, error) + + // CreateCodeContextWithBodyWithResponse request with any body + CreateCodeContextWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateCodeContextResponse, error) + + CreateCodeContextWithResponse(ctx context.Context, body CreateCodeContextJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateCodeContextResponse, error) + + // DeleteContextsByLanguageWithResponse request + DeleteContextsByLanguageWithResponse(ctx context.Context, params *DeleteContextsByLanguageParams, reqEditors ...RequestEditorFn) (*DeleteContextsByLanguageResponse, error) + + // ListContextsWithResponse request + ListContextsWithResponse(ctx context.Context, params *ListContextsParams, reqEditors ...RequestEditorFn) (*ListContextsResponse, error) + + // DeleteContextWithResponse request + DeleteContextWithResponse(ctx context.Context, contextID string, reqEditors ...RequestEditorFn) (*DeleteContextResponse, error) + + // GetContextWithResponse request + GetContextWithResponse(ctx context.Context, contextID string, reqEditors ...RequestEditorFn) (*GetContextResponse, error) + + // InterruptCommandWithResponse request + InterruptCommandWithResponse(ctx context.Context, params *InterruptCommandParams, reqEditors ...RequestEditorFn) (*InterruptCommandResponse, error) + + // RunCommandWithBodyWithResponse request with any body + RunCommandWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RunCommandResponse, error) + + RunCommandWithResponse(ctx context.Context, body RunCommandJSONRequestBody, reqEditors ...RequestEditorFn) (*RunCommandResponse, error) + + // GetCommandStatusWithResponse request + GetCommandStatusWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetCommandStatusResponse, error) + + // GetBackgroundCommandLogsWithResponse request + GetBackgroundCommandLogsWithResponse(ctx context.Context, id string, params *GetBackgroundCommandLogsParams, reqEditors ...RequestEditorFn) (*GetBackgroundCommandLogsResponse, error) + + // RemoveDirsWithResponse request + RemoveDirsWithResponse(ctx context.Context, params *RemoveDirsParams, reqEditors ...RequestEditorFn) (*RemoveDirsResponse, error) + + // MakeDirsWithBodyWithResponse request with any body + MakeDirsWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*MakeDirsResponse, error) + + MakeDirsWithResponse(ctx context.Context, body MakeDirsJSONRequestBody, reqEditors ...RequestEditorFn) (*MakeDirsResponse, error) + + // RemoveFilesWithResponse request + RemoveFilesWithResponse(ctx context.Context, params *RemoveFilesParams, reqEditors ...RequestEditorFn) (*RemoveFilesResponse, error) + + // DownloadFileWithResponse request + DownloadFileWithResponse(ctx context.Context, params *DownloadFileParams, reqEditors ...RequestEditorFn) (*DownloadFileResponse, error) + + // GetFilesInfoWithResponse request + GetFilesInfoWithResponse(ctx context.Context, params *GetFilesInfoParams, reqEditors ...RequestEditorFn) (*GetFilesInfoResponse, error) + + // RenameFilesWithBodyWithResponse request with any body + RenameFilesWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RenameFilesResponse, error) + + RenameFilesWithResponse(ctx context.Context, body RenameFilesJSONRequestBody, reqEditors ...RequestEditorFn) (*RenameFilesResponse, error) + + // ChmodFilesWithBodyWithResponse request with any body + ChmodFilesWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ChmodFilesResponse, error) + + ChmodFilesWithResponse(ctx context.Context, body ChmodFilesJSONRequestBody, reqEditors ...RequestEditorFn) (*ChmodFilesResponse, error) + + // ReplaceContentWithBodyWithResponse request with any body + ReplaceContentWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ReplaceContentResponse, error) + + ReplaceContentWithResponse(ctx context.Context, body ReplaceContentJSONRequestBody, reqEditors ...RequestEditorFn) (*ReplaceContentResponse, error) + + // SearchFilesWithResponse request + SearchFilesWithResponse(ctx context.Context, params *SearchFilesParams, reqEditors ...RequestEditorFn) (*SearchFilesResponse, error) + + // UploadFileWithBodyWithResponse request with any body + UploadFileWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UploadFileResponse, error) + + // GetMetricsWithResponse request + GetMetricsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetMetricsResponse, error) + + // WatchMetricsWithResponse request + WatchMetricsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*WatchMetricsResponse, error) + + // PingWithResponse request + PingWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PingResponse, error) + + // CreateSessionWithBodyWithResponse request with any body + CreateSessionWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateSessionResponse, error) + + CreateSessionWithResponse(ctx context.Context, body CreateSessionJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateSessionResponse, error) + + // DeleteSessionWithResponse request + DeleteSessionWithResponse(ctx context.Context, sessionID string, reqEditors ...RequestEditorFn) (*DeleteSessionResponse, error) + + // RunInSessionWithBodyWithResponse request with any body + RunInSessionWithBodyWithResponse(ctx context.Context, sessionID string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RunInSessionResponse, error) + + RunInSessionWithResponse(ctx context.Context, sessionID string, body RunInSessionJSONRequestBody, reqEditors ...RequestEditorFn) (*RunInSessionResponse, error) +} + +type InterruptCodeResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r InterruptCodeResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r InterruptCodeResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type RunCodeResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r RunCodeResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r RunCodeResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type CreateCodeContextResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *CodeContext + JSON400 *BadRequest + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r CreateCodeContextResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CreateCodeContextResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type DeleteContextsByLanguageResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r DeleteContextsByLanguageResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r DeleteContextsByLanguageResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type ListContextsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *[]CodeContext + JSON400 *BadRequest + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r ListContextsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ListContextsResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type DeleteContextResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON404 *NotFound + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r DeleteContextResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r DeleteContextResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetContextResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *CodeContext + JSON404 *NotFound + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r GetContextResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetContextResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type InterruptCommandResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r InterruptCommandResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r InterruptCommandResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type RunCommandResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r RunCommandResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r RunCommandResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetCommandStatusResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *CommandStatusResponse + JSON400 *BadRequest + JSON404 *NotFound + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r GetCommandStatusResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetCommandStatusResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetBackgroundCommandLogsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON404 *NotFound + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r GetBackgroundCommandLogsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetBackgroundCommandLogsResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type RemoveDirsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r RemoveDirsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r RemoveDirsResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type MakeDirsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r MakeDirsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r MakeDirsResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type RemoveFilesResponse struct { + Body []byte + HTTPResponse *http.Response + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r RemoveFilesResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r RemoveFilesResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type DownloadFileResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON404 *NotFound + JSON416 *ErrorResponse + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r DownloadFileResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r DownloadFileResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetFilesInfoResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]FileInfo + JSON404 *NotFound + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r GetFilesInfoResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetFilesInfoResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type RenameFilesResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON404 *NotFound + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r RenameFilesResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r RenameFilesResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type ChmodFilesResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r ChmodFilesResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ChmodFilesResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type ReplaceContentResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r ReplaceContentResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ReplaceContentResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type SearchFilesResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *[]FileInfo + JSON400 *BadRequest + JSON404 *NotFound + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r SearchFilesResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r SearchFilesResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type UploadFileResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r UploadFileResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r UploadFileResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetMetricsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Metrics + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r GetMetricsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetMetricsResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type WatchMetricsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r WatchMetricsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r WatchMetricsResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type PingResponse struct { + Body []byte + HTTPResponse *http.Response +} + +// Status returns HTTPResponse.Status +func (r PingResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PingResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type CreateSessionResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *SessionCreated + JSON400 *BadRequest + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r CreateSessionResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CreateSessionResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type DeleteSessionResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON404 *NotFound + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r DeleteSessionResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r DeleteSessionResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type RunInSessionResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON500 *InternalServerError +} + +// Status returns HTTPResponse.Status +func (r RunInSessionResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r RunInSessionResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// InterruptCodeWithResponse request returning *InterruptCodeResponse +func (c *ClientWithResponses) InterruptCodeWithResponse(ctx context.Context, params *InterruptCodeParams, reqEditors ...RequestEditorFn) (*InterruptCodeResponse, error) { + rsp, err := c.InterruptCode(ctx, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseInterruptCodeResponse(rsp) +} + +// RunCodeWithBodyWithResponse request with arbitrary body returning *RunCodeResponse +func (c *ClientWithResponses) RunCodeWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RunCodeResponse, error) { + rsp, err := c.RunCodeWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseRunCodeResponse(rsp) +} + +func (c *ClientWithResponses) RunCodeWithResponse(ctx context.Context, body RunCodeJSONRequestBody, reqEditors ...RequestEditorFn) (*RunCodeResponse, error) { + rsp, err := c.RunCode(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseRunCodeResponse(rsp) +} + +// CreateCodeContextWithBodyWithResponse request with arbitrary body returning *CreateCodeContextResponse +func (c *ClientWithResponses) CreateCodeContextWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateCodeContextResponse, error) { + rsp, err := c.CreateCodeContextWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateCodeContextResponse(rsp) +} + +func (c *ClientWithResponses) CreateCodeContextWithResponse(ctx context.Context, body CreateCodeContextJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateCodeContextResponse, error) { + rsp, err := c.CreateCodeContext(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateCodeContextResponse(rsp) +} + +// DeleteContextsByLanguageWithResponse request returning *DeleteContextsByLanguageResponse +func (c *ClientWithResponses) DeleteContextsByLanguageWithResponse(ctx context.Context, params *DeleteContextsByLanguageParams, reqEditors ...RequestEditorFn) (*DeleteContextsByLanguageResponse, error) { + rsp, err := c.DeleteContextsByLanguage(ctx, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseDeleteContextsByLanguageResponse(rsp) +} + +// ListContextsWithResponse request returning *ListContextsResponse +func (c *ClientWithResponses) ListContextsWithResponse(ctx context.Context, params *ListContextsParams, reqEditors ...RequestEditorFn) (*ListContextsResponse, error) { + rsp, err := c.ListContexts(ctx, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseListContextsResponse(rsp) +} + +// DeleteContextWithResponse request returning *DeleteContextResponse +func (c *ClientWithResponses) DeleteContextWithResponse(ctx context.Context, contextID string, reqEditors ...RequestEditorFn) (*DeleteContextResponse, error) { + rsp, err := c.DeleteContext(ctx, contextID, reqEditors...) + if err != nil { + return nil, err + } + return ParseDeleteContextResponse(rsp) +} + +// GetContextWithResponse request returning *GetContextResponse +func (c *ClientWithResponses) GetContextWithResponse(ctx context.Context, contextID string, reqEditors ...RequestEditorFn) (*GetContextResponse, error) { + rsp, err := c.GetContext(ctx, contextID, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetContextResponse(rsp) +} + +// InterruptCommandWithResponse request returning *InterruptCommandResponse +func (c *ClientWithResponses) InterruptCommandWithResponse(ctx context.Context, params *InterruptCommandParams, reqEditors ...RequestEditorFn) (*InterruptCommandResponse, error) { + rsp, err := c.InterruptCommand(ctx, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseInterruptCommandResponse(rsp) +} + +// RunCommandWithBodyWithResponse request with arbitrary body returning *RunCommandResponse +func (c *ClientWithResponses) RunCommandWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RunCommandResponse, error) { + rsp, err := c.RunCommandWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseRunCommandResponse(rsp) +} + +func (c *ClientWithResponses) RunCommandWithResponse(ctx context.Context, body RunCommandJSONRequestBody, reqEditors ...RequestEditorFn) (*RunCommandResponse, error) { + rsp, err := c.RunCommand(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseRunCommandResponse(rsp) +} + +// GetCommandStatusWithResponse request returning *GetCommandStatusResponse +func (c *ClientWithResponses) GetCommandStatusWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetCommandStatusResponse, error) { + rsp, err := c.GetCommandStatus(ctx, id, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetCommandStatusResponse(rsp) +} + +// GetBackgroundCommandLogsWithResponse request returning *GetBackgroundCommandLogsResponse +func (c *ClientWithResponses) GetBackgroundCommandLogsWithResponse(ctx context.Context, id string, params *GetBackgroundCommandLogsParams, reqEditors ...RequestEditorFn) (*GetBackgroundCommandLogsResponse, error) { + rsp, err := c.GetBackgroundCommandLogs(ctx, id, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetBackgroundCommandLogsResponse(rsp) +} + +// RemoveDirsWithResponse request returning *RemoveDirsResponse +func (c *ClientWithResponses) RemoveDirsWithResponse(ctx context.Context, params *RemoveDirsParams, reqEditors ...RequestEditorFn) (*RemoveDirsResponse, error) { + rsp, err := c.RemoveDirs(ctx, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseRemoveDirsResponse(rsp) +} + +// MakeDirsWithBodyWithResponse request with arbitrary body returning *MakeDirsResponse +func (c *ClientWithResponses) MakeDirsWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*MakeDirsResponse, error) { + rsp, err := c.MakeDirsWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseMakeDirsResponse(rsp) +} + +func (c *ClientWithResponses) MakeDirsWithResponse(ctx context.Context, body MakeDirsJSONRequestBody, reqEditors ...RequestEditorFn) (*MakeDirsResponse, error) { + rsp, err := c.MakeDirs(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseMakeDirsResponse(rsp) +} + +// RemoveFilesWithResponse request returning *RemoveFilesResponse +func (c *ClientWithResponses) RemoveFilesWithResponse(ctx context.Context, params *RemoveFilesParams, reqEditors ...RequestEditorFn) (*RemoveFilesResponse, error) { + rsp, err := c.RemoveFiles(ctx, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseRemoveFilesResponse(rsp) +} + +// DownloadFileWithResponse request returning *DownloadFileResponse +func (c *ClientWithResponses) DownloadFileWithResponse(ctx context.Context, params *DownloadFileParams, reqEditors ...RequestEditorFn) (*DownloadFileResponse, error) { + rsp, err := c.DownloadFile(ctx, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseDownloadFileResponse(rsp) +} + +// GetFilesInfoWithResponse request returning *GetFilesInfoResponse +func (c *ClientWithResponses) GetFilesInfoWithResponse(ctx context.Context, params *GetFilesInfoParams, reqEditors ...RequestEditorFn) (*GetFilesInfoResponse, error) { + rsp, err := c.GetFilesInfo(ctx, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetFilesInfoResponse(rsp) +} + +// RenameFilesWithBodyWithResponse request with arbitrary body returning *RenameFilesResponse +func (c *ClientWithResponses) RenameFilesWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RenameFilesResponse, error) { + rsp, err := c.RenameFilesWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseRenameFilesResponse(rsp) +} + +func (c *ClientWithResponses) RenameFilesWithResponse(ctx context.Context, body RenameFilesJSONRequestBody, reqEditors ...RequestEditorFn) (*RenameFilesResponse, error) { + rsp, err := c.RenameFiles(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseRenameFilesResponse(rsp) +} + +// ChmodFilesWithBodyWithResponse request with arbitrary body returning *ChmodFilesResponse +func (c *ClientWithResponses) ChmodFilesWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ChmodFilesResponse, error) { + rsp, err := c.ChmodFilesWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseChmodFilesResponse(rsp) +} + +func (c *ClientWithResponses) ChmodFilesWithResponse(ctx context.Context, body ChmodFilesJSONRequestBody, reqEditors ...RequestEditorFn) (*ChmodFilesResponse, error) { + rsp, err := c.ChmodFiles(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseChmodFilesResponse(rsp) +} + +// ReplaceContentWithBodyWithResponse request with arbitrary body returning *ReplaceContentResponse +func (c *ClientWithResponses) ReplaceContentWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ReplaceContentResponse, error) { + rsp, err := c.ReplaceContentWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseReplaceContentResponse(rsp) +} + +func (c *ClientWithResponses) ReplaceContentWithResponse(ctx context.Context, body ReplaceContentJSONRequestBody, reqEditors ...RequestEditorFn) (*ReplaceContentResponse, error) { + rsp, err := c.ReplaceContent(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseReplaceContentResponse(rsp) +} + +// SearchFilesWithResponse request returning *SearchFilesResponse +func (c *ClientWithResponses) SearchFilesWithResponse(ctx context.Context, params *SearchFilesParams, reqEditors ...RequestEditorFn) (*SearchFilesResponse, error) { + rsp, err := c.SearchFiles(ctx, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseSearchFilesResponse(rsp) +} + +// UploadFileWithBodyWithResponse request with arbitrary body returning *UploadFileResponse +func (c *ClientWithResponses) UploadFileWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UploadFileResponse, error) { + rsp, err := c.UploadFileWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseUploadFileResponse(rsp) +} + +// GetMetricsWithResponse request returning *GetMetricsResponse +func (c *ClientWithResponses) GetMetricsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetMetricsResponse, error) { + rsp, err := c.GetMetrics(ctx, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetMetricsResponse(rsp) +} + +// WatchMetricsWithResponse request returning *WatchMetricsResponse +func (c *ClientWithResponses) WatchMetricsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*WatchMetricsResponse, error) { + rsp, err := c.WatchMetrics(ctx, reqEditors...) + if err != nil { + return nil, err + } + return ParseWatchMetricsResponse(rsp) +} + +// PingWithResponse request returning *PingResponse +func (c *ClientWithResponses) PingWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PingResponse, error) { + rsp, err := c.Ping(ctx, reqEditors...) + if err != nil { + return nil, err + } + return ParsePingResponse(rsp) +} + +// CreateSessionWithBodyWithResponse request with arbitrary body returning *CreateSessionResponse +func (c *ClientWithResponses) CreateSessionWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateSessionResponse, error) { + rsp, err := c.CreateSessionWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateSessionResponse(rsp) +} + +func (c *ClientWithResponses) CreateSessionWithResponse(ctx context.Context, body CreateSessionJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateSessionResponse, error) { + rsp, err := c.CreateSession(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateSessionResponse(rsp) +} + +// DeleteSessionWithResponse request returning *DeleteSessionResponse +func (c *ClientWithResponses) DeleteSessionWithResponse(ctx context.Context, sessionID string, reqEditors ...RequestEditorFn) (*DeleteSessionResponse, error) { + rsp, err := c.DeleteSession(ctx, sessionID, reqEditors...) + if err != nil { + return nil, err + } + return ParseDeleteSessionResponse(rsp) +} + +// RunInSessionWithBodyWithResponse request with arbitrary body returning *RunInSessionResponse +func (c *ClientWithResponses) RunInSessionWithBodyWithResponse(ctx context.Context, sessionID string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RunInSessionResponse, error) { + rsp, err := c.RunInSessionWithBody(ctx, sessionID, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseRunInSessionResponse(rsp) +} + +func (c *ClientWithResponses) RunInSessionWithResponse(ctx context.Context, sessionID string, body RunInSessionJSONRequestBody, reqEditors ...RequestEditorFn) (*RunInSessionResponse, error) { + rsp, err := c.RunInSession(ctx, sessionID, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseRunInSessionResponse(rsp) +} + +// ParseInterruptCodeResponse parses an HTTP response from a InterruptCodeWithResponse call +func ParseInterruptCodeResponse(rsp *http.Response) (*InterruptCodeResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &InterruptCodeResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseRunCodeResponse parses an HTTP response from a RunCodeWithResponse call +func ParseRunCodeResponse(rsp *http.Response) (*RunCodeResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &RunCodeResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseCreateCodeContextResponse parses an HTTP response from a CreateCodeContextWithResponse call +func ParseCreateCodeContextResponse(rsp *http.Response) (*CreateCodeContextResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CreateCodeContextResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest CodeContext + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseDeleteContextsByLanguageResponse parses an HTTP response from a DeleteContextsByLanguageWithResponse call +func ParseDeleteContextsByLanguageResponse(rsp *http.Response) (*DeleteContextsByLanguageResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DeleteContextsByLanguageResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseListContextsResponse parses an HTTP response from a ListContextsWithResponse call +func ParseListContextsResponse(rsp *http.Response) (*ListContextsResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ListContextsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest []CodeContext + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseDeleteContextResponse parses an HTTP response from a DeleteContextWithResponse call +func ParseDeleteContextResponse(rsp *http.Response) (*DeleteContextResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DeleteContextResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest NotFound + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseGetContextResponse parses an HTTP response from a GetContextWithResponse call +func ParseGetContextResponse(rsp *http.Response) (*GetContextResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetContextResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest CodeContext + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest NotFound + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseInterruptCommandResponse parses an HTTP response from a InterruptCommandWithResponse call +func ParseInterruptCommandResponse(rsp *http.Response) (*InterruptCommandResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &InterruptCommandResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseRunCommandResponse parses an HTTP response from a RunCommandWithResponse call +func ParseRunCommandResponse(rsp *http.Response) (*RunCommandResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &RunCommandResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseGetCommandStatusResponse parses an HTTP response from a GetCommandStatusWithResponse call +func ParseGetCommandStatusResponse(rsp *http.Response) (*GetCommandStatusResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetCommandStatusResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest CommandStatusResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest NotFound + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseGetBackgroundCommandLogsResponse parses an HTTP response from a GetBackgroundCommandLogsWithResponse call +func ParseGetBackgroundCommandLogsResponse(rsp *http.Response) (*GetBackgroundCommandLogsResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetBackgroundCommandLogsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest NotFound + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseRemoveDirsResponse parses an HTTP response from a RemoveDirsWithResponse call +func ParseRemoveDirsResponse(rsp *http.Response) (*RemoveDirsResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &RemoveDirsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseMakeDirsResponse parses an HTTP response from a MakeDirsWithResponse call +func ParseMakeDirsResponse(rsp *http.Response) (*MakeDirsResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &MakeDirsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseRemoveFilesResponse parses an HTTP response from a RemoveFilesWithResponse call +func ParseRemoveFilesResponse(rsp *http.Response) (*RemoveFilesResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &RemoveFilesResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseDownloadFileResponse parses an HTTP response from a DownloadFileWithResponse call +func ParseDownloadFileResponse(rsp *http.Response) (*DownloadFileResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DownloadFileResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest NotFound + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 416: + var dest ErrorResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON416 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseGetFilesInfoResponse parses an HTTP response from a GetFilesInfoWithResponse call +func ParseGetFilesInfoResponse(rsp *http.Response) (*GetFilesInfoResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetFilesInfoResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]FileInfo + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest NotFound + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseRenameFilesResponse parses an HTTP response from a RenameFilesWithResponse call +func ParseRenameFilesResponse(rsp *http.Response) (*RenameFilesResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &RenameFilesResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest NotFound + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseChmodFilesResponse parses an HTTP response from a ChmodFilesWithResponse call +func ParseChmodFilesResponse(rsp *http.Response) (*ChmodFilesResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ChmodFilesResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseReplaceContentResponse parses an HTTP response from a ReplaceContentWithResponse call +func ParseReplaceContentResponse(rsp *http.Response) (*ReplaceContentResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ReplaceContentResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseSearchFilesResponse parses an HTTP response from a SearchFilesWithResponse call +func ParseSearchFilesResponse(rsp *http.Response) (*SearchFilesResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &SearchFilesResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest []FileInfo + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest NotFound + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseUploadFileResponse parses an HTTP response from a UploadFileWithResponse call +func ParseUploadFileResponse(rsp *http.Response) (*UploadFileResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &UploadFileResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseGetMetricsResponse parses an HTTP response from a GetMetricsWithResponse call +func ParseGetMetricsResponse(rsp *http.Response) (*GetMetricsResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetMetricsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Metrics + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseWatchMetricsResponse parses an HTTP response from a WatchMetricsWithResponse call +func ParseWatchMetricsResponse(rsp *http.Response) (*WatchMetricsResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &WatchMetricsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParsePingResponse parses an HTTP response from a PingWithResponse call +func ParsePingResponse(rsp *http.Response) (*PingResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PingResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + return response, nil +} + +// ParseCreateSessionResponse parses an HTTP response from a CreateSessionWithResponse call +func ParseCreateSessionResponse(rsp *http.Response) (*CreateSessionResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CreateSessionResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest SessionCreated + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseDeleteSessionResponse parses an HTTP response from a DeleteSessionWithResponse call +func ParseDeleteSessionResponse(rsp *http.Response) (*DeleteSessionResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DeleteSessionResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest NotFound + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseRunInSessionResponse parses an HTTP response from a RunInSessionWithResponse call +func ParseRunInSessionResponse(rsp *http.Response) (*RunInSessionResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &RunInSessionResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest BadRequest + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest InternalServerError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} diff --git a/sdks/sandbox/go/opensandbox/api/execd/generate.go b/sdks/sandbox/go/opensandbox/api/execd/generate.go new file mode 100644 index 00000000..cdd8c691 --- /dev/null +++ b/sdks/sandbox/go/opensandbox/api/execd/generate.go @@ -0,0 +1,3 @@ +package execd + +//go:generate oapi-codegen --config cfg.yaml ../specs/execd-api.yaml diff --git a/sdks/sandbox/go/opensandbox/api/lifecycle/cfg.yaml b/sdks/sandbox/go/opensandbox/api/lifecycle/cfg.yaml new file mode 100644 index 00000000..e6c26b89 --- /dev/null +++ b/sdks/sandbox/go/opensandbox/api/lifecycle/cfg.yaml @@ -0,0 +1,7 @@ +package: lifecycle +output: gen.go +generate: + models: true + client: true +output-options: + name-normalizer: ToCamelCaseWithInitialisms diff --git a/sdks/sandbox/go/opensandbox/api/lifecycle/gen.go b/sdks/sandbox/go/opensandbox/api/lifecycle/gen.go new file mode 100644 index 00000000..f61d0c98 --- /dev/null +++ b/sdks/sandbox/go/opensandbox/api/lifecycle/gen.go @@ -0,0 +1,1954 @@ +// Package lifecycle provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.6.0 DO NOT EDIT. +package lifecycle + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" + "time" + + "github.com/oapi-codegen/runtime" +) + +const ( + ApiKeyAuthScopes = "apiKeyAuth.Scopes" +) + +// Defines values for NetworkPolicyDefaultAction. +const ( + NetworkPolicyDefaultActionAllow NetworkPolicyDefaultAction = "allow" + NetworkPolicyDefaultActionDeny NetworkPolicyDefaultAction = "deny" +) + +// Valid indicates whether the value is a known member of the NetworkPolicyDefaultAction enum. +func (e NetworkPolicyDefaultAction) Valid() bool { + switch e { + case NetworkPolicyDefaultActionAllow: + return true + case NetworkPolicyDefaultActionDeny: + return true + default: + return false + } +} + +// Defines values for NetworkRuleAction. +const ( + NetworkRuleActionAllow NetworkRuleAction = "allow" + NetworkRuleActionDeny NetworkRuleAction = "deny" +) + +// Valid indicates whether the value is a known member of the NetworkRuleAction enum. +func (e NetworkRuleAction) Valid() bool { + switch e { + case NetworkRuleActionAllow: + return true + case NetworkRuleActionDeny: + return true + default: + return false + } +} + +// Defines values for OSSFSVersion. +const ( + N10 OSSFSVersion = "1.0" + N20 OSSFSVersion = "2.0" +) + +// Valid indicates whether the value is a known member of the OSSFSVersion enum. +func (e OSSFSVersion) Valid() bool { + switch e { + case N10: + return true + case N20: + return true + default: + return false + } +} + +// CreateSandboxRequest Request to create a new sandbox from a container image. +// +// **Note**: API Key authentication is required via the `OPEN-SANDBOX-API-KEY` header. +type CreateSandboxRequest struct { + // Entrypoint The command to execute as the sandbox's entry process (required). + // + // Explicitly specifies the user's expected main process, allowing the sandbox management + // service to reliably inject control processes before executing this command. + // + // Format: [executable, arg1, arg2, ...] + // + // Examples: + // - ["python", "/app/main.py"] + // - ["/bin/bash"] + // - ["java", "-jar", "/app/app.jar"] + // - ["node", "server.js"] + Entrypoint []string `json:"entrypoint"` + + // Env Environment variables to inject into the sandbox runtime. + Env *map[string]string `json:"env,omitempty"` + + // Extensions Opaque container for provider-specific or transient parameters not supported by the core API. + // + // **Note**: This field is reserved for internal features, experimental flags, or temporary behaviors. Standard parameters should be proposed as core API fields. + // + // **Best Practices**: + // - **Namespacing**: Use prefixed keys (e.g., `storage.id`) to prevent collisions. + // - **Pass-through**: SDKs and middleware must treat this object as opaque and pass it through transparently. + // + // **Well-known keys**: + // - `access.renew.extend.seconds` (optional): Decimal integer string from **300** to **86400** (5 minutes to 24 hours inclusive). Opts the sandbox into OSEP-0009 renew-on-access and sets per-renewal extension seconds. Omit to disable. Invalid values are rejected at creation with HTTP 400 (validated on the lifecycle create endpoint via `validate_extensions` in server `src/extensions/validation.py`). + Extensions *map[string]string `json:"extensions,omitempty"` + + // Image Container image specification for sandbox provisioning. + // + // Supports public registry images and private registry images with authentication. + Image ImageSpec `json:"image"` + + // Metadata Custom key-value metadata for management, filtering, and tagging. + // Use "name" key for a human-readable identifier. + Metadata *map[string]string `json:"metadata,omitempty"` + + // NetworkPolicy Egress network policy matching the sidecar `/policy` request body. + // If `defaultAction` is omitted, the sidecar defaults to "deny"; passing an empty + // object or null results in allow-all behavior at startup. + NetworkPolicy *NetworkPolicy `json:"networkPolicy,omitempty"` + + // ResourceLimits Runtime resource constraints as key-value pairs. Similar to Kubernetes resource specifications, + // allows flexible definition of resource limits. Common resource types include: + // - `cpu`: CPU allocation in millicores (e.g., "250m" for 0.25 CPU cores) + // - `memory`: Memory allocation in bytes or human-readable format (e.g., "512Mi", "1Gi") + // - `gpu`: Number of GPU devices (e.g., "1") + // + // New resource types can be added without API changes. + ResourceLimits ResourceLimits `json:"resourceLimits"` + + // Timeout Sandbox timeout in seconds. The sandbox will automatically terminate after this duration. + // The maximum is controlled by the server configuration (`server.max_sandbox_timeout_seconds`). + // Omit this field or set it to null to disable automatic expiration and require explicit cleanup. + // Note: manual cleanup support is runtime-dependent; Kubernetes providers may reject + // omitted or null timeout when the underlying workload provider does not support non-expiring sandboxes. + Timeout *int `json:"timeout,omitempty"` + + // Volumes Storage mounts for the sandbox. Each volume entry specifies a named backend-specific + // storage source and common mount settings. Exactly one backend type must be specified + // per volume entry. + Volumes *[]Volume `json:"volumes,omitempty"` +} + +// CreateSandboxResponse Response from creating a new sandbox. Contains essential information without image and updatedAt. +type CreateSandboxResponse struct { + // CreatedAt Sandbox creation timestamp + CreatedAt time.Time `json:"createdAt"` + + // Entrypoint Entry process specification from creation request + Entrypoint []string `json:"entrypoint"` + + // ExpiresAt Timestamp when sandbox will auto-terminate. Omitted when manual cleanup is enabled. + ExpiresAt *time.Time `json:"expiresAt,omitempty"` + + // ID Unique sandbox identifier + ID string `json:"id"` + + // Metadata Custom metadata from creation request + Metadata *map[string]string `json:"metadata,omitempty"` + + // Status Detailed status information with lifecycle state and transition details + Status SandboxStatus `json:"status"` +} + +// Endpoint Endpoint for accessing a service running in the sandbox. +// The service must be listening on the specified port inside the sandbox for the endpoint to be available. +type Endpoint struct { + // Endpoint Public URL to access the service from outside the sandbox. + // Format: {endpoint-host}/sandboxes/{sandboxId}/port/{port} + // Example: endpoint.opensandbox.io/sandboxes/abc123/port/8080 + Endpoint string `json:"endpoint"` + + // Headers Requests targeting the sandbox must include the corresponding header(s). + Headers *map[string]string `json:"headers,omitempty"` +} + +// ErrorResponse Standard error response for all non-2xx HTTP responses. +// HTTP status code indicates the error category; code and message provide details. +type ErrorResponse struct { + // Code Machine-readable error code (e.g., INVALID_REQUEST, NOT_FOUND, INTERNAL_ERROR). + // Use this for programmatic error handling. + Code string `json:"code"` + + // Message Human-readable error message describing what went wrong and how to fix it. + Message string `json:"message"` +} + +// Host Host path bind mount backend. Maps a directory on the host filesystem +// into the container. Only available when the runtime supports host mounts. +// +// Security note: Host paths are restricted by server-side allowlist. +// Users must specify paths under permitted prefixes. +type Host struct { + // Path Absolute path on the host filesystem to mount. + // Must start with '/' and be under an allowed prefix. + Path string `json:"path"` +} + +// ImageSpec Container image specification for sandbox provisioning. +// +// Supports public registry images and private registry images with authentication. +type ImageSpec struct { + // Auth Registry authentication credentials (required for private registries) + Auth *struct { + // Password Registry password or authentication token + Password *string `json:"password,omitempty"` + + // Username Registry username or service account + Username *string `json:"username,omitempty"` + } `json:"auth,omitempty"` + + // URI Container image URI in standard format. + // + // Examples: + // - "python:3.11" (Docker Hub) + // - "ubuntu:22.04" + // - "gcr.io/my-project/model-server:v1.0" + // - "private-registry.company.com:5000/app:latest" + URI string `json:"uri"` +} + +// ListSandboxesResponse defines model for ListSandboxesResponse. +type ListSandboxesResponse struct { + Items []Sandbox `json:"items"` + + // Pagination Pagination metadata for list responses + Pagination PaginationInfo `json:"pagination"` +} + +// NetworkPolicy Egress network policy matching the sidecar `/policy` request body. +// If `defaultAction` is omitted, the sidecar defaults to "deny"; passing an empty +// object or null results in allow-all behavior at startup. +type NetworkPolicy struct { + // DefaultAction Default action when no egress rule matches. Defaults to "deny". + DefaultAction *NetworkPolicyDefaultAction `json:"defaultAction,omitempty"` + + // Egress List of egress rules evaluated in order. + Egress *[]NetworkRule `json:"egress,omitempty"` +} + +// NetworkPolicyDefaultAction Default action when no egress rule matches. Defaults to "deny". +type NetworkPolicyDefaultAction string + +// NetworkRule defines model for NetworkRule. +type NetworkRule struct { + // Action Whether to allow or deny matching targets. + Action NetworkRuleAction `json:"action"` + + // Target FQDN or wildcard domain (e.g., "example.com", "*.example.com"). + // IP/CIDR not yet supported in the egress MVP. + Target string `json:"target"` +} + +// NetworkRuleAction Whether to allow or deny matching targets. +type NetworkRuleAction string + +// OSSFS Alibaba Cloud OSS mount backend via ossfs. +// +// The runtime mounts a host-side OSS path under `storage.ossfs_mount_root` +// and bind-mounts the resolved path into the sandbox container. +// Prefix selection is expressed via `Volume.subPath`. +// In Docker runtime, OSSFS backend requires OpenSandbox Server to run on a Linux host with FUSE support. +type OSSFS struct { + // AccessKeyID OSS access key ID for inline credentials mode. + AccessKeyID string `json:"accessKeyId"` + + // AccessKeySecret OSS access key secret for inline credentials mode. + AccessKeySecret string `json:"accessKeySecret"` + + // Bucket OSS bucket name. + Bucket string `json:"bucket"` + + // Endpoint OSS endpoint (e.g., `oss-cn-hangzhou.aliyuncs.com`). + Endpoint string `json:"endpoint"` + + // Options Additional ossfs mount options. + // Runtime encodes options by `version`: + // - `1.0`: mounts with `ossfs ... -o