withruntime 0.27.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/lib/withruntime/generated/apps.rb +192 -0
  3. data/lib/withruntime/generated/audit.rb +78 -0
  4. data/lib/withruntime/generated/browsers.rb +192 -0
  5. data/lib/withruntime/generated/builds.rb +192 -0
  6. data/lib/withruntime/generated/ci.rb +192 -0
  7. data/lib/withruntime/generated/containers.rb +192 -0
  8. data/lib/withruntime/generated/desktops.rb +192 -0
  9. data/lib/withruntime/generated/domains.rb +152 -0
  10. data/lib/withruntime/generated/egress_ips.rb +81 -0
  11. data/lib/withruntime/generated/events.rb +60 -0
  12. data/lib/withruntime/generated/feedback.rb +96 -0
  13. data/lib/withruntime/generated/functions.rb +192 -0
  14. data/lib/withruntime/generated/identities.rb +68 -0
  15. data/lib/withruntime/generated/images.rb +391 -0
  16. data/lib/withruntime/generated/job_runs.rb +110 -0
  17. data/lib/withruntime/generated/jobs.rb +333 -0
  18. data/lib/withruntime/generated/keys.rb +261 -0
  19. data/lib/withruntime/generated/kit.rb +111 -0
  20. data/lib/withruntime/generated/me.rb +69 -0
  21. data/lib/withruntime/generated/networks.rb +72 -0
  22. data/lib/withruntime/generated/notebooks.rb +192 -0
  23. data/lib/withruntime/generated/otel.rb +94 -0
  24. data/lib/withruntime/generated/ports.rb +118 -0
  25. data/lib/withruntime/generated/previews.rb +124 -0
  26. data/lib/withruntime/generated/projects.rb +108 -0
  27. data/lib/withruntime/generated/roles.rb +68 -0
  28. data/lib/withruntime/generated/routes.rb +11 -0
  29. data/lib/withruntime/generated/runtime.rb +188 -0
  30. data/lib/withruntime/generated/sandboxes.rb +1835 -0
  31. data/lib/withruntime/generated/secrets.rb +294 -0
  32. data/lib/withruntime/generated/sessions.rb +143 -0
  33. data/lib/withruntime/generated/sites.rb +192 -0
  34. data/lib/withruntime/generated/snapshots.rb +32 -0
  35. data/lib/withruntime/generated/tunnels.rb +165 -0
  36. data/lib/withruntime/generated/usage.rb +287 -0
  37. data/lib/withruntime/generated/volumes.rb +61 -0
  38. data/lib/withruntime/generated/webhooks.rb +91 -0
  39. data/lib/withruntime/generated/workspaces.rb +192 -0
  40. data/lib/withruntime/signing.rb +162 -0
  41. data/lib/withruntime/version.rb +2 -2
  42. data/lib/withruntime.rb +5 -43
  43. metadata +45 -35
  44. data/lib/withruntime/agents.rb +0 -877
  45. data/lib/withruntime/api_defaults.rb +0 -17
  46. data/lib/withruntime/apps.rb +0 -377
  47. data/lib/withruntime/browsers.rb +0 -104
  48. data/lib/withruntime/builds.rb +0 -218
  49. data/lib/withruntime/ci.rb +0 -164
  50. data/lib/withruntime/client.rb +0 -140
  51. data/lib/withruntime/containers.rb +0 -39
  52. data/lib/withruntime/credentials.rb +0 -111
  53. data/lib/withruntime/fields.rb +0 -40
  54. data/lib/withruntime/file_watch.rb +0 -73
  55. data/lib/withruntime/images.rb +0 -258
  56. data/lib/withruntime/network_products.rb +0 -49
  57. data/lib/withruntime/parity_products.rb +0 -51
  58. data/lib/withruntime/products.rb +0 -560
  59. data/lib/withruntime/record.rb +0 -99
  60. data/lib/withruntime/reservations.rb +0 -76
  61. data/lib/withruntime/sandbox.rb +0 -770
  62. data/lib/withruntime/tar.rb +0 -292
  63. data/lib/withruntime/transport.rb +0 -575
  64. data/lib/withruntime/tunnel.rb +0 -275
  65. data/lib/withruntime/wallet.rb +0 -68
  66. data/lib/withruntime/websocket.rb +0 -384
@@ -0,0 +1,294 @@
1
+ # Generated by spec-gen from engines/front/crates/spec. Do not edit:
2
+ # change the spec and run `cargo run -p runtime-front-spec-gen -- write`.
3
+
4
+ require "uri"
5
+ require_relative "runtime"
6
+
7
+ module Withruntime
8
+ module Generated
9
+ # Which machines may use a secret.
10
+ # - +labels_any+: Machines with every label of any one of these sets.
11
+ SecretScope = Struct.new(:labels_any, keyword_init: true) do
12
+ def self.from(h)
13
+ return nil if h.nil?
14
+
15
+ new(
16
+ labels_any: h["labelsAny"],
17
+ )
18
+ end
19
+
20
+ def to_wire
21
+ {
22
+ "labelsAny" => self.labels_any,
23
+ }.compact
24
+ end
25
+ end
26
+
27
+ # Which requests to a secret's hosts may carry it.
28
+ # - +methods+: Only these methods (`POST`); every method when omitted.
29
+ # - +paths+: Only these paths: exact (`/v1/chat/completions`), or a prefix ending in `/*`.
30
+ SecretRule = Struct.new(:methods, :paths, keyword_init: true) do
31
+ def self.from(h)
32
+ return nil if h.nil?
33
+
34
+ new(
35
+ methods: h["methods"],
36
+ paths: h["paths"],
37
+ )
38
+ end
39
+
40
+ def to_wire
41
+ {
42
+ "methods" => self.methods,
43
+ "paths" => self.paths,
44
+ }.compact
45
+ end
46
+ end
47
+
48
+ # What a git push carrying a secret may update.
49
+ # - +push+: The branches a push may update: 1 to 16 patterns of 12 to 256 characters, `refs/heads/` then a branch name, `*` only at the end, and `{label.<key>}` for the machine's own label right below a fixed first segment (`refs/heads/task/{label.task}`). A tag, a delete or any other ref is refused, and so is every API write that moves a ref. Opening or editing a pull request, reviewing it, and commenting on a pull request or an issue go under any rule that allows the path. Any other API write goes only when a rule names its exact path, with no `*`. A secret with no rules makes no API write.
50
+ SecretGit = Struct.new(:push, keyword_init: true) do
51
+ def self.from(h)
52
+ return nil if h.nil?
53
+
54
+ new(
55
+ push: h["push"],
56
+ )
57
+ end
58
+
59
+ def to_wire
60
+ {
61
+ "push" => self.push,
62
+ }.compact
63
+ end
64
+ end
65
+
66
+ # The GraphQL mutations a request carrying a secret may make.
67
+ # - +path+: The GraphQL endpoint's path; `/graphql` when omitted.
68
+ # - +mutations+: Only these mutations, by name (at most 64); a request making any other is refused.
69
+ SecretGraphql = Struct.new(:path, :mutations, keyword_init: true) do
70
+ def self.from(h)
71
+ return nil if h.nil?
72
+
73
+ new(
74
+ path: h["path"],
75
+ mutations: h["mutations"],
76
+ )
77
+ end
78
+
79
+ def to_wire
80
+ {
81
+ "path" => self.path,
82
+ "mutations" => self.mutations,
83
+ }.compact
84
+ end
85
+ end
86
+
87
+ # What API calls carrying a secret may do.
88
+ # - +graphql+: Its GraphQL mutations.
89
+ SecretApi = Struct.new(:graphql, keyword_init: true) do
90
+ def self.from(h)
91
+ return nil if h.nil?
92
+
93
+ new(
94
+ graphql: SecretGraphql.from(h["graphql"]),
95
+ )
96
+ end
97
+
98
+ def to_wire
99
+ {
100
+ "graphql" => self.graphql&.to_wire,
101
+ }.compact
102
+ end
103
+ end
104
+
105
+ # How a secret may be used, beyond its hosts: a request carries it only when every policy it holds allows it.
106
+ # - +rules+: Only requests one of these rules allows carry it; every request to its hosts when omitted. A set with its value and without rules removes them; one without its value keeps them, or narrows them to these.
107
+ # - +git+: Its git pushes' branches. Kept when a set leaves it out; only a set with the value changes it.
108
+ # - +api+: Its API calls' limits. Kept when a set leaves it out; only a set with the value changes it.
109
+ SecretPolicies = Struct.new(:rules, :git, :api, keyword_init: true) do
110
+ def self.from(h)
111
+ return nil if h.nil?
112
+
113
+ new(
114
+ rules: h["rules"]&.map { |i| SecretRule.from(i) },
115
+ git: SecretGit.from(h["git"]),
116
+ api: SecretApi.from(h["api"]),
117
+ )
118
+ end
119
+
120
+ def to_wire
121
+ {
122
+ "rules" => self.rules&.map { |i| i&.to_wire },
123
+ "git" => self.git&.to_wire,
124
+ "api" => self.api&.to_wire,
125
+ }.compact
126
+ end
127
+ end
128
+
129
+ # A secret's settings: what it keeps beside its sealed value.
130
+ # - +visible+: The machine holds the value itself, in its environment variable from its start and in the file `/run/secrets/<envName>` (mode 0400, owned by root), which is rewritten within a second of each change and removed within a second of a delete or a scope that leaves the machine out. For values the proxy cannot put in, such as a database password or an SSH key. Changed only by a set with the value; false when omitted.
131
+ # - +hosts+: The hosts its value goes to on HTTPS: a name, or `*.` and a name for every name under it. Required unless visible; refused when visible.
132
+ # - +header+: The header it is set in on every request to its hosts; when omitted, its placeholder is replaced in the credential headers (Authorization, x-api-key and the like). Hidden secrets only.
133
+ # - +format+: The header's value, `{value}` replaced by the secret; `{value}` when omitted. Hidden secrets only.
134
+ # - +env_name+: The environment variable that holds its placeholder (or, when visible, its value) in each machine it reaches; its name when omitted. When two secrets that reach one machine name the same variable, it holds the one first by name.
135
+ # - +scope+: The machines that may use it; every machine of the organization when omitted.
136
+ # - +policies+: How it may be used. Hidden secrets only.
137
+ SecretSettings = Struct.new(:visible, :hosts, :header, :format, :env_name, :scope, :policies, keyword_init: true) do
138
+ def self.from(h)
139
+ return nil if h.nil?
140
+
141
+ new(
142
+ visible: h["visible"],
143
+ hosts: h["hosts"],
144
+ header: h["header"],
145
+ format: h["format"],
146
+ env_name: h["envName"],
147
+ scope: SecretScope.from(h["scope"]),
148
+ policies: SecretPolicies.from(h["policies"]),
149
+ )
150
+ end
151
+
152
+ def to_wire
153
+ {
154
+ "visible" => self.visible,
155
+ "hosts" => self.hosts,
156
+ "header" => self.header,
157
+ "format" => self.format,
158
+ "envName" => self.env_name,
159
+ "scope" => self.scope&.to_wire,
160
+ "policies" => self.policies&.to_wire,
161
+ }.compact
162
+ end
163
+ end
164
+
165
+ # A secret, without its value.
166
+ # - +visible+: The machine holds the value itself, in its environment variable from its start and in the file `/run/secrets/<envName>` (mode 0400, owned by root), which is rewritten within a second of each change and removed within a second of a delete or a scope that leaves the machine out. For values the proxy cannot put in, such as a database password or an SSH key. Changed only by a set with the value; false when omitted.
167
+ # - +hosts+: The hosts its value goes to on HTTPS: a name, or `*.` and a name for every name under it. Required unless visible; refused when visible.
168
+ # - +header+: The header it is set in on every request to its hosts; when omitted, its placeholder is replaced in the credential headers (Authorization, x-api-key and the like). Hidden secrets only.
169
+ # - +format+: The header's value, `{value}` replaced by the secret; `{value}` when omitted. Hidden secrets only.
170
+ # - +env_name+: The environment variable that holds its placeholder (or, when visible, its value) in each machine it reaches; its name when omitted. When two secrets that reach one machine name the same variable, it holds the one first by name.
171
+ # - +scope+: The machines that may use it; every machine of the organization when omitted.
172
+ # - +policies+: How it may be used. Hidden secrets only.
173
+ # - +name+: Its name.
174
+ # - +object+: Always `secret`.
175
+ # - +state+: `active` while requests carry it; `deleted` once deleted: a delete's answer.
176
+ # - +placeholder+: What a machine holds in the value's place; none when visible.
177
+ # - +version+: Raised by each change.
178
+ # - +value_bytes+: Its value's length in bytes.
179
+ # - +updated_at+: When it was last changed.
180
+ # - +deleted_at+: When it was deleted: a delete's answer, its state `deleted`.
181
+ Secret = Struct.new(:visible, :hosts, :header, :format, :env_name, :scope, :policies, :name, :object, :state, :placeholder, :version, :value_bytes, :updated_at, :deleted_at, keyword_init: true) do
182
+ def self.from(h)
183
+ return nil if h.nil?
184
+
185
+ new(
186
+ visible: h["visible"],
187
+ hosts: h["hosts"],
188
+ header: h["header"],
189
+ format: h["format"],
190
+ env_name: h["envName"],
191
+ scope: SecretScope.from(h["scope"]),
192
+ policies: SecretPolicies.from(h["policies"]),
193
+ name: h["name"],
194
+ object: h["object"],
195
+ state: h["state"],
196
+ placeholder: h["placeholder"],
197
+ version: h["version"],
198
+ value_bytes: h["valueBytes"],
199
+ updated_at: h["updatedAt"],
200
+ deleted_at: h["deletedAt"],
201
+ )
202
+ end
203
+
204
+ def to_wire
205
+ {
206
+ "visible" => self.visible,
207
+ "hosts" => self.hosts,
208
+ "header" => self.header,
209
+ "format" => self.format,
210
+ "envName" => self.env_name,
211
+ "scope" => self.scope&.to_wire,
212
+ "policies" => self.policies&.to_wire,
213
+ "name" => self.name,
214
+ "object" => self.object,
215
+ "state" => self.state,
216
+ "placeholder" => self.placeholder,
217
+ "version" => self.version,
218
+ "valueBytes" => self.value_bytes,
219
+ "updatedAt" => self.updated_at,
220
+ "deletedAt" => self.deleted_at,
221
+ }.compact
222
+ end
223
+ end
224
+
225
+ # A secret to store or replace, or, without its value, to change.
226
+ # - +visible+: The machine holds the value itself, in its environment variable from its start and in the file `/run/secrets/<envName>` (mode 0400, owned by root), which is rewritten within a second of each change and removed within a second of a delete or a scope that leaves the machine out. For values the proxy cannot put in, such as a database password or an SSH key. Changed only by a set with the value; false when omitted.
227
+ # - +hosts+: The hosts its value goes to on HTTPS: a name, or `*.` and a name for every name under it. Required unless visible; refused when visible.
228
+ # - +header+: The header it is set in on every request to its hosts; when omitted, its placeholder is replaced in the credential headers (Authorization, x-api-key and the like). Hidden secrets only.
229
+ # - +format+: The header's value, `{value}` replaced by the secret; `{value}` when omitted. Hidden secrets only.
230
+ # - +env_name+: The environment variable that holds its placeholder (or, when visible, its value) in each machine it reaches; its name when omitted. When two secrets that reach one machine name the same variable, it holds the one first by name.
231
+ # - +scope+: The machines that may use it; every machine of the organization when omitted.
232
+ # - +policies+: How it may be used. Hidden secrets only.
233
+ # - +value+: Its value, never answered. Hidden: 1 to 8192 visible ASCII characters and spaces, one line, since it goes into an HTTP header. Visible: 1 byte to 64 KiB of UTF-8 text with no NUL, newlines included (a PEM file, an SSH key, a service account's JSON). With it, the set stores the secret whole, as its fields say. Without it, the set changes only the hosts, `policies.rules` and scope it names, and keeps the rest: hosts and rules only narrow, since widening needs the value, and so does a visible secret's scope, whose machines hold its value; any other field is refused 400.
234
+ # - +expected_version+: Replaced only from this version; 409 otherwise.
235
+ SecretSet = Struct.new(:visible, :hosts, :header, :format, :env_name, :scope, :policies, :value, :expected_version, keyword_init: true) do
236
+ def self.from(h)
237
+ return nil if h.nil?
238
+
239
+ new(
240
+ visible: h["visible"],
241
+ hosts: h["hosts"],
242
+ header: h["header"],
243
+ format: h["format"],
244
+ env_name: h["envName"],
245
+ scope: SecretScope.from(h["scope"]),
246
+ policies: SecretPolicies.from(h["policies"]),
247
+ value: h["value"],
248
+ expected_version: h["expectedVersion"],
249
+ )
250
+ end
251
+
252
+ def to_wire
253
+ {
254
+ "visible" => self.visible,
255
+ "hosts" => self.hosts,
256
+ "header" => self.header,
257
+ "format" => self.format,
258
+ "envName" => self.env_name,
259
+ "scope" => self.scope&.to_wire,
260
+ "policies" => self.policies&.to_wire,
261
+ "value" => self.value,
262
+ "expectedVersion" => self.expected_version,
263
+ }.compact
264
+ end
265
+ end
266
+
267
+ # A value a machine uses, sealed at rest and never answered. Hidden (the default): the machine sees a placeholder, and the egress proxy puts the value in its place, only on HTTPS to the secret's hosts. Visible: the machine holds the value, in its environment variable and in /run/secrets/<envName>.
268
+ class Secrets
269
+ def initialize(transport)
270
+ @transport = transport
271
+ end
272
+
273
+ # Lists the organization's secrets by name, without their values.
274
+ def list(cursor: nil, limit: nil)
275
+ Generated.page(@transport.request("GET", "/v2/secrets", query: { "cursor" => cursor, "limit" => limit }, idempotent: true)) { |i| Secret.from(i) }
276
+ end
277
+
278
+ # Returns a secret, without its value.
279
+ def get(name)
280
+ Secret.from(@transport.request("GET", "/v2/secrets/#{URI.encode_www_form_component(name)}", idempotent: true))
281
+ end
282
+
283
+ # Stores or replaces a secret with its value, or changes one without it. Replacing it keeps its placeholder and raises its version; machines' new requests carry the new value within a second, and a visible secret's file holds it within a second. A running machine's processes keep the environment they started with; new commands get the new one. Asked again with the same Idempotency-Key and body, it returns the secret as that request left it. A deleted secret's name stored again is a new secret with a new placeholder, and so is a visible secret stored hidden. Without its value, it changes only the hosts, rules (`policies.rules`) and scope it names and keeps every other setting: hosts and rules only narrow, refused 400 when wider, since widening needs the value; a visible secret's scope only narrows, since its machines hold its value, and its file is removed within a second from each machine the scope leaves out. A secret not stored yet needs its value (404).
284
+ def set(name, visible: nil, hosts: nil, header: nil, format: nil, env_name: nil, scope: nil, policies: nil, value: nil, expected_version: nil, idempotency_key: nil)
285
+ Secret.from(@transport.request("PUT", "/v2/secrets/#{URI.encode_www_form_component(name)}", body: { "visible" => visible, "hosts" => hosts, "header" => header, "format" => format, "envName" => env_name, "scope" => scope, "policies" => policies, "value" => value, "expectedVersion" => expected_version }.compact, idempotency_key: idempotency_key, idempotent: true))
286
+ end
287
+
288
+ # Deletes a secret and its value: no request carries it from then on, open connections' included, and a visible secret's file is removed from every machine within a second. Deleted again, it returns the same deleted secret.
289
+ def delete(name, idempotency_key: nil)
290
+ Secret.from(@transport.request("DELETE", "/v2/secrets/#{URI.encode_www_form_component(name)}", idempotency_key: idempotency_key, idempotent: true))
291
+ end
292
+ end
293
+ end
294
+ end
@@ -0,0 +1,143 @@
1
+ # Generated by spec-gen from engines/front/crates/spec. Do not edit:
2
+ # change the spec and run `cargo run -p runtime-front-spec-gen -- write`.
3
+
4
+ require "uri"
5
+ require_relative "runtime"
6
+
7
+ module Withruntime
8
+ module Generated
9
+ # A session to make.
10
+ # - +machine_id+: The machine it reaches (a sandbox, an app, a desktop, any machine), by its ID.
11
+ # - +expires_in_seconds+: Seconds until it stops working, 60 to 86400; 3600 when omitted. Never past the key that makes it. At least 60. At most 86400.
12
+ # - +name+: Its name: your own handle for it, such as the user it is for. At least 1 character. At most 64 characters.
13
+ SessionCreate = Struct.new(:machine_id, :expires_in_seconds, :name, keyword_init: true) do
14
+ def self.from(h)
15
+ return nil if h.nil?
16
+
17
+ new(
18
+ machine_id: h["machineId"],
19
+ expires_in_seconds: h["expiresInSeconds"],
20
+ name: h["name"],
21
+ )
22
+ end
23
+
24
+ def to_wire
25
+ {
26
+ "machineId" => self.machine_id,
27
+ "expiresInSeconds" => self.expires_in_seconds,
28
+ "name" => self.name,
29
+ }.compact
30
+ end
31
+ end
32
+
33
+ # A session: a token for one machine, for a frontend.
34
+ # - +id+: Its ID.
35
+ # - +object+: Always `session`.
36
+ # - +machine_id+: The machine it reaches, alone.
37
+ # - +name+: Its name, as its maker gave it.
38
+ # - +account_id+: The person it acts as or for.
39
+ # - +agent_id+: The agent or CI pipeline it acts as.
40
+ # - +state+: `active` while it works; `deleted` once ended: a delete's answer.
41
+ # - +created_at+: When it was made.
42
+ # - +expires_at+: When it stops working: its own end, or the end of the key that made it, the sooner.
43
+ # - +deleted_at+: When a delete ended it, or a revoke of the key that made it: a delete's answer, and a create's sent again once it ended. Omitted for one that ended at `expiresAt`.
44
+ Session = Struct.new(:id, :object, :machine_id, :name, :account_id, :agent_id, :state, :created_at, :expires_at, :deleted_at, keyword_init: true) do
45
+ def self.from(h)
46
+ return nil if h.nil?
47
+
48
+ new(
49
+ id: h["id"],
50
+ object: h["object"],
51
+ machine_id: h["machineId"],
52
+ name: h["name"],
53
+ account_id: h["accountId"],
54
+ agent_id: h["agentId"],
55
+ state: h["state"],
56
+ created_at: h["createdAt"],
57
+ expires_at: h["expiresAt"],
58
+ deleted_at: h["deletedAt"],
59
+ )
60
+ end
61
+
62
+ def to_wire
63
+ {
64
+ "id" => self.id,
65
+ "object" => self.object,
66
+ "machineId" => self.machine_id,
67
+ "name" => self.name,
68
+ "accountId" => self.account_id,
69
+ "agentId" => self.agent_id,
70
+ "state" => self.state,
71
+ "createdAt" => self.created_at,
72
+ "expiresAt" => self.expires_at,
73
+ "deletedAt" => self.deleted_at,
74
+ }.compact
75
+ end
76
+ end
77
+
78
+ # A session just made, with its token: shown this once, never again.
79
+ # - +id+: Its ID.
80
+ # - +object+: Always `session`.
81
+ # - +machine_id+: The machine it reaches, alone.
82
+ # - +name+: Its name, as its maker gave it.
83
+ # - +account_id+: The person it acts as or for.
84
+ # - +agent_id+: The agent or CI pipeline it acts as.
85
+ # - +state+: `active` while it works; `deleted` once ended: a delete's answer.
86
+ # - +created_at+: When it was made.
87
+ # - +expires_at+: When it stops working: its own end, or the end of the key that made it, the sooner.
88
+ # - +deleted_at+: When a delete ended it, or a revoke of the key that made it: a delete's answer, and a create's sent again once it ended. Omitted for one that ended at `expiresAt`.
89
+ # - +token+: The token, to send as `Authorization: Bearer <token>` from the frontend.
90
+ SessionCreated = Struct.new(:id, :object, :machine_id, :name, :account_id, :agent_id, :state, :created_at, :expires_at, :deleted_at, :token, keyword_init: true) do
91
+ def self.from(h)
92
+ return nil if h.nil?
93
+
94
+ new(
95
+ id: h["id"],
96
+ object: h["object"],
97
+ machine_id: h["machineId"],
98
+ name: h["name"],
99
+ account_id: h["accountId"],
100
+ agent_id: h["agentId"],
101
+ state: h["state"],
102
+ created_at: h["createdAt"],
103
+ expires_at: h["expiresAt"],
104
+ deleted_at: h["deletedAt"],
105
+ token: h["token"],
106
+ )
107
+ end
108
+
109
+ def to_wire
110
+ {
111
+ "id" => self.id,
112
+ "object" => self.object,
113
+ "machineId" => self.machine_id,
114
+ "name" => self.name,
115
+ "accountId" => self.account_id,
116
+ "agentId" => self.agent_id,
117
+ "state" => self.state,
118
+ "createdAt" => self.created_at,
119
+ "expiresAt" => self.expires_at,
120
+ "deletedAt" => self.deleted_at,
121
+ "token" => self.token,
122
+ }.compact
123
+ end
124
+ end
125
+
126
+ # A short-lived token a frontend holds to reach one machine directly: it reads the machine, runs its commands and processes, reads and writes its files, and signs its previews' links, and does nothing else. It acts as the key that made it and ends with that key.
127
+ class Sessions
128
+ def initialize(transport)
129
+ @transport = transport
130
+ end
131
+
132
+ # Makes a session for one machine the caller reaches and returns its token this once. The token reads the machine, runs its commands and processes, reads and writes its files and signs its previews' links, and nothing else; it acts as the caller, lives `expiresInSeconds` (an hour unless asked, a day at most), never past the caller's key, and ends when that key is revoked. The API answers CORS for its calls, so a web page can make them. Sent again with the same Idempotency-Key and body, it makes none and returns 409 `conflict` with the session it made in `details.made`, without its token; with another body, 409 `idempotency_key_reused`.
133
+ def create(machine_id:, expires_in_seconds: nil, name: nil, idempotency_key: nil)
134
+ SessionCreated.from(@transport.request("POST", "/v2/sessions", body: { "machineId" => machine_id, "expiresInSeconds" => expires_in_seconds, "name" => name }.compact, idempotency_key: idempotency_key, idempotent: true))
135
+ end
136
+
137
+ # Ends a session now: its next call is refused. Its maker ends its own; an owner or an admin, any of the organization's. Ended already, it returns 404.
138
+ def delete(id, idempotency_key: nil)
139
+ Session.from(@transport.request("DELETE", "/v2/sessions/#{URI.encode_www_form_component(id)}", idempotency_key: idempotency_key, idempotent: true))
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,192 @@
1
+ # Generated by spec-gen from engines/front/crates/spec. Do not edit:
2
+ # change the spec and run `cargo run -p runtime-front-spec-gen -- write`.
3
+
4
+ require "uri"
5
+ require_relative "runtime"
6
+ require_relative "sandboxes"
7
+
8
+ module Withruntime
9
+ module Generated
10
+ # A machine that serves the static files in /site on port 8080 (as Netlify and Vercel serve a build's output), reached at its preview. It pauses after 60 seconds with nothing happening, its memory kept, and a visit resumes it.
11
+ class Sites
12
+ def initialize(transport)
13
+ @transport = transport
14
+ end
15
+
16
+ # Creates a site. Asked again with the same Idempotency-Key, it returns the same site.
17
+ def create(vcpu: nil, memory_gb: nil, disk_gb: nil, image: nil, secrets: nil, start: nil, user: nil, volumes: nil, run: nil, name: nil, labels: nil, get_or_create: nil, max_cost: nil, idle_pause_seconds: nil, snapshot: nil, network: nil, env: nil, idempotency_key: nil)
18
+ Sandbox.from(@transport.request("POST", "/v2/sites", body: { "vcpu" => vcpu, "memoryGB" => memory_gb, "diskGB" => disk_gb, "image" => image, "secrets" => secrets, "start" => start, "user" => user, "volumes" => volumes, "run" => run, "name" => name, "labels" => labels, "getOrCreate" => get_or_create, "maxCost" => max_cost, "idlePauseSeconds" => idle_pause_seconds, "snapshot" => snapshot, "network" => network, "env" => env }.compact, idempotency_key: idempotency_key, idempotent: true))
19
+ end
20
+
21
+ # Returns a site.
22
+ def get(id, wait: nil, if_state: nil)
23
+ Sandbox.from(@transport.request("GET", "/v2/sites/#{URI.encode_www_form_component(id)}", query: { "wait" => wait, "ifState" => if_state }, idempotent: true))
24
+ end
25
+
26
+ # Lists the project's sites, newest first.
27
+ def list(state: nil, name: nil, label: nil, cursor: nil, limit: nil)
28
+ Generated.page(@transport.request("GET", "/v2/sites", query: { "state" => state, "name" => name, "label" => label, "cursor" => cursor, "limit" => limit }, idempotent: true)) { |i| Sandbox.from(i) }
29
+ end
30
+
31
+ # Deletes a site, its memory and its disk.
32
+ def delete(id, idempotency_key: nil)
33
+ Sandbox.from(@transport.request("DELETE", "/v2/sites/#{URI.encode_www_form_component(id)}", idempotency_key: idempotency_key))
34
+ end
35
+
36
+ # Pauses a site with its memory and disk kept. A call to it resumes it.
37
+ def pause(id, idempotency_key: nil)
38
+ Sandbox.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}:pause", idempotency_key: idempotency_key))
39
+ end
40
+
41
+ # Resumes a paused site where it was, its memory and processes as they were.
42
+ def resume(id, idempotency_key: nil)
43
+ Sandbox.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}:resume", idempotency_key: idempotency_key))
44
+ end
45
+
46
+ # Runs a command as a process and returns it once it ended, with its output; with wait false, at once, while it runs. A paused site is resumed first. Asked again with the same Idempotency-Key, it runs nothing more: it returns the first run's process, waiting for its end while it runs.
47
+ def exec(id, cmd:, cwd: nil, env: nil, stdin: nil, timeout_seconds: nil, stream: nil, wait: nil, stdin_open: nil, output_encoding: nil, pty: nil, user: nil, idempotency_key: nil)
48
+ Process.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}:exec", body: { "cmd" => cmd, "cwd" => cwd, "env" => env, "stdin" => stdin, "timeoutSeconds" => timeout_seconds, "stream" => stream, "wait" => wait, "stdinOpen" => stdin_open, "outputEncoding" => output_encoding, "pty" => pty, "user" => user }.compact, idempotency_key: idempotency_key, idempotent: true, runs: true, runs_seconds: timeout_seconds))
49
+ end
50
+
51
+ # Returns a file's bytes.
52
+ def read(id, path:)
53
+ @transport.request("GET", "/v2/sites/#{URI.encode_www_form_component(id)}/files", query: { "path" => path }, raw: true, idempotent: true)
54
+ end
55
+
56
+ # Writes the request's bytes to a file as they come, of any size (Content-Length required), its folders made: the file whole when they all came, or as it was. With offset, they are written into it in place.
57
+ def write(id, data, path:, mode: nil, offset: nil, sha256: nil, idempotency_key: nil)
58
+ FileWritten.from(@transport.request("PUT", "/v2/sites/#{URI.encode_www_form_component(id)}/files", query: { "path" => path, "mode" => mode, "offset" => offset, "sha256" => sha256 }, data: data, idempotency_key: idempotency_key))
59
+ end
60
+
61
+ # Returns a process's output after a cursor, and the cursor to read on from. The latest 1 MiB is kept; truncated says when the cursor fell behind.
62
+ def process_output(id, process, cursor: nil, wait_seconds: nil, max_bytes: nil, follow: nil)
63
+ ProcessOutput.from(@transport.request("GET", "/v2/sites/#{URI.encode_www_form_component(id)}/processes/#{URI.encode_www_form_component(process)}/output", query: { "cursor" => cursor, "waitSeconds" => wait_seconds, "maxBytes" => max_bytes, "follow" => follow }, idempotent: true))
64
+ end
65
+
66
+ # Sends input to a process started with stdinOpen or a pty, and returns how much of its input it has taken.
67
+ def write_process(id, process, data: nil, offset: nil, eof: nil, idempotency_key: nil)
68
+ ProcessWritten.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}/processes/#{URI.encode_www_form_component(process)}:write", body: { "data" => data, "offset" => offset, "eof" => eof }.compact, idempotency_key: idempotency_key))
69
+ end
70
+
71
+ # Sends a signal to a process and its group; a process that ended is not signalled, so a retry is safe.
72
+ def signal_process(id, process, signal: nil, idempotency_key: nil)
73
+ Process.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}/processes/#{URI.encode_www_form_component(process)}:signal", body: { "signal" => signal }.compact, idempotency_key: idempotency_key, idempotent: true))
74
+ end
75
+
76
+ # Lists a site's processes, newest first: those running and those that ended lately.
77
+ def list_processes(id)
78
+ ProcessList.from(@transport.request("GET", "/v2/sites/#{URI.encode_www_form_component(id)}/processes", idempotent: true))
79
+ end
80
+
81
+ # Removes a file, a link or a directory (recursive for one with contents). One missing is success, removed false.
82
+ def remove(id, path:, recursive: nil, idempotency_key: nil)
83
+ FileRemoved.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}/files:remove", body: { "path" => path, "recursive" => recursive }.compact, idempotency_key: idempotency_key))
84
+ end
85
+
86
+ # Returns what is at a path: a file, a directory or a link, or nothing (exists false). With sha256=true, a file's SHA-256 too.
87
+ def stat(id, path:, sha256: nil)
88
+ FileInfo.from(@transport.request("GET", "/v2/sites/#{URI.encode_www_form_component(id)}/files/stat", query: { "path" => path, "sha256" => sha256 }, idempotent: true))
89
+ end
90
+
91
+ # Lists a directory's entries in path order, to a depth.
92
+ def list_files(id, path: nil, depth: nil, limit: nil, hidden: nil, glob: nil)
93
+ FileList.from(@transport.request("GET", "/v2/sites/#{URI.encode_www_form_component(id)}/files/list", query: { "path" => path, "depth" => depth, "limit" => limit, "hidden" => hidden, "glob" => glob }, idempotent: true))
94
+ end
95
+
96
+ # Returns a folder as a tar archive (`application/x-tar`, or `application/gzip` with gzip), packed by tar in the site as it streams, of any size; its entries are relative to the folder (`./a.txt`). A folder that fails part way (a file it may not read, or one that changes as it is read) ends as an archive every tar reader refuses, never as a short one that reads whole. At most 4 at once in a site. A paused site is woken first.
97
+ def download_folder(id, path:, gzip: nil, user: nil, exclude: nil)
98
+ @transport.request("GET", "/v2/sites/#{URI.encode_www_form_component(id)}/files/archive", query: { "path" => path, "gzip" => gzip, "user" => user, "exclude" => exclude }, raw: true, idempotent: true)
99
+ end
100
+
101
+ # Unpacks the request's tar archive (gzip-compressed or not, told by its first bytes) into a folder, made with its parents, by tar in the site as the bytes arrive, of any size, nothing of it kept on disk but what tar writes; returns once tar has ended, or 400 `invalid_archive` with what tar said. A paused site is woken first.
102
+ def upload_folder(id, data, path:, user: nil, idempotency_key: nil)
103
+ FolderUnpacked.from(@transport.request("PUT", "/v2/sites/#{URI.encode_www_form_component(id)}/files/archive", query: { "path" => path, "user" => user }, data: data, idempotency_key: idempotency_key, idempotent: true))
104
+ end
105
+
106
+ # Begins a folder's upload in parts: tar starts in the site, unpacking into the folder each part as it arrives. Send the parts in order by offset (writeFolderUpload), then commitFolderUpload; an upload no call names for 10 minutes is ended. A paused site is woken first.
107
+ def begin_folder_upload(id, path:, gzip: nil, user: nil, idempotency_key: nil)
108
+ FolderUpload.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}/files/archive/uploads", body: { "path" => path, "gzip" => gzip, "user" => user }.compact, idempotency_key: idempotency_key))
109
+ end
110
+
111
+ # Sends the request's bytes, a part of the archive at its offset, into tar's input as they arrive, of any size, and returns the bytes received in all once tar took them. A part past them is refused 409 `upload_incomplete`, naming them: send the parts in order.
112
+ def write_folder_upload(id, upload, data, offset: nil, idempotency_key: nil)
113
+ FolderUploadReceived.from(@transport.request("PUT", "/v2/sites/#{URI.encode_www_form_component(id)}/files/archive/uploads/#{URI.encode_www_form_component(upload)}", query: { "offset" => offset }, data: data, idempotency_key: idempotency_key, idempotent: true))
114
+ end
115
+
116
+ # Ends a folder upload's input and returns once tar has ended, as an exec returns once its command has: the folder, or 400 `invalid_archive` with what tar said. A front that restarts meanwhile returns 503 `run_goes_on`; sent again, it returns how tar ended. An upload no call has named for 10 minutes since its last part or commit is ended.
117
+ def commit_folder_upload(id, upload, idempotency_key: nil)
118
+ FolderUnpacked.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}/files/archive/uploads/#{URI.encode_www_form_component(upload)}:commit", idempotency_key: idempotency_key, idempotent: true))
119
+ end
120
+
121
+ # Stops a folder upload's tar; what it unpacked so far stays.
122
+ def abort_folder_upload(id, upload, idempotency_key: nil)
123
+ FolderUploadAborted.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}/files/archive/uploads/#{URI.encode_www_form_component(upload)}:abort", idempotency_key: idempotency_key, idempotent: true))
124
+ end
125
+
126
+ # Makes a directory, and its parents unless parents is false. One there already is success, created false.
127
+ def mkdir(id, path:, parents: nil, idempotency_key: nil)
128
+ FileMade.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}/files:mkdir", body: { "path" => path, "parents" => parents }.compact, idempotency_key: idempotency_key, idempotent: true))
129
+ end
130
+
131
+ # Moves a file, a link or a directory; refused 409 when something is at its new path, unless overwrite. With sha256 or size, a file written in parts is put in place once whole: its writes ended, then only a file of that size with every byte written and whose bytes hash to it moves; refused 409 `upload_incomplete` or `checksum_mismatch`, nothing moved. With sha256, it is safe to send again: once moved, it returns the same answer while `from` is gone and `to` holds those bytes.
132
+ def rename(id, from:, to:, overwrite: nil, sha256: nil, size: nil, idempotency_key: nil)
133
+ FileRenamed.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}/files:rename", body: { "from" => from, "to" => to, "overwrite" => overwrite, "sha256" => sha256, "size" => size }.compact, idempotency_key: idempotency_key))
134
+ end
135
+
136
+ # Makes an expiring address for one file that anyone may open with no API key, from a browser, curl or another service: GET downloads it (Range works, so videos play and downloads resume; archive: true downloads a folder as .tar.gz), PUT with the raw body uploads it (up to maxBytes, written whole; Content-Length required). The link acts as the key that made it: an upload link needs write, and the link ends with its key, with revokeLinks or with its site. A paused site is woken for it unless wake is false.
137
+ def link(id, path:, method: nil, expires_in_seconds: nil, filename: nil, max_bytes: nil, wake: nil, archive: nil, idempotency_key: nil)
138
+ FileLink.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}/files:link", body: { "path" => path, "method" => method, "expiresInSeconds" => expires_in_seconds, "filename" => filename, "maxBytes" => max_bytes, "wake" => wake, "archive" => archive }.compact, idempotency_key: idempotency_key))
139
+ end
140
+
141
+ # Ends every file link made for a site so far; links made after work.
142
+ def revoke_links(id, idempotency_key: nil)
143
+ FileLinksRevoked.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}/files:revokeLinks", idempotency_key: idempotency_key))
144
+ end
145
+
146
+ # Returns where a site may connect out.
147
+ def get_network(id)
148
+ SandboxNetwork.from(@transport.request("GET", "/v2/sites/#{URI.encode_www_form_component(id)}/network", idempotent: true))
149
+ end
150
+
151
+ # Returns a site's CPU, memory, disks and pressure, as its host reads them from the site's own cgroup over a fifth of a second: never a call into the site, so it does not wake a paused one nor keep one from its idle pause. One that is not running has no reading.
152
+ def metrics(id, range: nil)
153
+ SandboxMetrics.from(@transport.request("GET", "/v2/sites/#{URI.encode_www_form_component(id)}/metrics", query: { "range" => range }, idempotent: true))
154
+ end
155
+
156
+ # Replaces where a site may connect out, for its next connection and within a second for its open ones: those the new rules refuse are cut.
157
+ def set_network(id, allow_outbound: nil, deny_outbound: nil, idempotency_key: nil)
158
+ SandboxNetwork.from(@transport.request("PUT", "/v2/sites/#{URI.encode_www_form_component(id)}/network", body: { "allowOutbound" => allow_outbound, "denyOutbound" => deny_outbound }.compact, idempotency_key: idempotency_key))
159
+ end
160
+
161
+ # Copies a site as it is now, memory and disk, into `count` copies of its own, each running on its host. Asked again with the same Idempotency-Key, it returns the same copies.
162
+ def fork(id, count: nil, name: nil, labels: nil, secrets: nil, max_cost: nil, idle_pause_seconds: nil, idempotency_key: nil)
163
+ Forked.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}:fork", body: { "count" => count, "name" => name, "labels" => labels, "secrets" => secrets, "maxCost" => max_cost, "idlePauseSeconds" => idle_pause_seconds }.compact, idempotency_key: idempotency_key, idempotent: true))
164
+ end
165
+
166
+ # Keeps a site's memory and disk as they are now, a snapshot to start sites from; with `image`, its disk alone as that image's next version. The site runs on. Asked again with the same Idempotency-Key, it returns the same snapshot.
167
+ def snapshot(id, name: nil, labels: nil, image: nil, start: nil, idempotency_key: nil)
168
+ Stored.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}:snapshot", body: { "name" => name, "labels" => labels, "image" => image, "start" => start }.compact, idempotency_key: idempotency_key, idempotent: true))
169
+ end
170
+
171
+ # Changes its name, labels, idle pause, maxCost, environment or sizes; each field left out stays as it is. A running one holds a changed environment before this answers (a paused one's at its wake): each process it starts after the answer has it, and its running processes keep the one they started with. Its vCPUs, memory and disk grow while it runs, its commands running on; a smaller size, or a sandbox that is not running, is refused 409 naming why, and nothing is changed. With If-Match, made only while its revision is that one, else 412.
172
+ def update(id, name: nil, labels: nil, idle_pause_seconds: nil, vcpu: nil, memory_gb: nil, disk_gb: nil, user: nil, env: nil, remove_env: nil, max_cost: nil, idempotency_key: nil)
173
+ Sandbox.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}:update", body: { "name" => name, "labels" => labels, "idlePauseSeconds" => idle_pause_seconds, "vcpu" => vcpu, "memoryGB" => memory_gb, "diskGB" => disk_gb, "user" => user, "env" => env, "removeEnv" => remove_env, "maxCost" => max_cost }.compact, idempotency_key: idempotency_key))
174
+ end
175
+
176
+ # Returns what a site's screen shows now, as `image/png` (or `image/jpeg`): its X display `:1`, whole. Refused 409 `display_not_running` when no display runs. A paused site is resumed first.
177
+ def screenshot(id, format: nil, quality: nil)
178
+ @transport.request("GET", "/v2/sites/#{URI.encode_www_form_component(id)}/screenshot", query: { "format" => format, "quality" => quality }, raw: true, idempotent: true)
179
+ end
180
+
181
+ # Moves, clicks, drags and scrolls the mouse and types on the keyboard of a site's screen (its X display `:1`), each step in turn as one command, and returns where the mouse is then. It stops at the first step that fails, refused 409 `act_failed` naming it; refused 409 `display_not_running` when no display runs. A paused site is resumed first.
182
+ def act(id, actions:, idempotency_key: nil)
183
+ Acted.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}:act", body: { "actions" => actions }.compact, idempotency_key: idempotency_key))
184
+ end
185
+
186
+ # Runs a cell of Python in a site as a notebook does, in a Jupyter kernel it keeps running for the cell's `context`: variables, imports and functions stay for the next cell. Returns what it printed, its values and displays (text, HTML, images such as charts), and its exception with its traceback. The context's kernel starts on its first cell. A cell past `timeoutSeconds` is interrupted and its context kept. Refused 409 `kernel_not_installed` when the image has no ipykernel. A paused site is resumed first.
187
+ def run_code(id, code:, language: nil, context: nil, timeout_seconds: nil, idempotency_key: nil)
188
+ CodeRun.from(@transport.request("POST", "/v2/sites/#{URI.encode_www_form_component(id)}:runCode", body: { "code" => code, "language" => language, "context" => context, "timeoutSeconds" => timeout_seconds }.compact, idempotency_key: idempotency_key))
189
+ end
190
+ end
191
+ end
192
+ end