withruntime 0.28.0 → 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 -775
  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
@@ -1,292 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "fileutils"
4
- require "stringio"
5
- require "tmpdir"
6
- require "zlib"
7
-
8
- module WithRuntime
9
- # A small ustar writer and reader for directory uploads, downloads and build contexts.
10
- module Tar
11
- module_function
12
-
13
- def header(name, size, mode, type, mtime = 0)
14
- bytes = name.b
15
- prefix = "".b
16
- if bytes.bytesize > 100
17
- split = name.rindex("/", 155)
18
- raise ArgumentError, "Path too long for a tar archive: #{name}" if split.nil? || split <= 0 || name[(split + 1)..].bytesize > 100
19
-
20
- prefix = name[0, split].b
21
- bytes = name[(split + 1)..].b
22
- end
23
- block = "\0".b * 512
24
- put = ->(offset, value, length) { block[offset, [length, value.bytesize].min] = value.b[0, length] }
25
- octal = ->(value, length) { "#{value.to_s(8).rjust(length - 1, "0")}\0" }
26
- put.call(0, bytes, 100)
27
- put.call(100, octal.call(mode & 0o7777, 8), 8)
28
- put.call(108, octal.call(0, 8), 8)
29
- put.call(116, octal.call(0, 8), 8)
30
- put.call(124, octal.call(size, 12), 12)
31
- put.call(136, octal.call(mtime, 12), 12)
32
- put.call(148, " " * 8, 8)
33
- put.call(156, type, 1)
34
- put.call(257, "ustar\u000000", 8)
35
- put.call(345, prefix, 155)
36
- put.call(148, "#{block.sum(64).to_s(8).rjust(6, "0")}\0 ", 8)
37
- block
38
- end
39
-
40
- def pad(size) = "\0".b * ((512 - (size % 512)) % 512)
41
-
42
- def gzip(data)
43
- out = StringIO.new("".b)
44
- writer = Zlib::GzipWriter.new(out, 6)
45
- writer.mtime = 0
46
- writer.write(data)
47
- writer.close
48
- out.string
49
- end
50
-
51
- # A directory as a gzipped tar: directories and regular files; links stay behind.
52
- def pack_directory(root)
53
- tar = "".b
54
- base = File.expand_path(root)
55
- Dir.glob("**/*", File::FNM_DOTMATCH, base: base).sort.each do |relative|
56
- next if relative.split("/").any? { |part| [".", ".."].include?(part) }
57
-
58
- full = File.join(base, relative)
59
- stat = File.lstat(full)
60
- if stat.directory?
61
- tar << header("#{relative}/", 0, stat.mode, "5", stat.mtime.to_i)
62
- elsif stat.file?
63
- data = File.binread(full)
64
- tar << header(relative, data.bytesize, stat.mode, "0", stat.mtime.to_i) << data << pad(data.bytesize)
65
- end
66
- end
67
- gzip(tar << ("\0".b * 1024))
68
- end
69
-
70
- # A folder that did not arrive whole: tar in the sandbox stopped part way
71
- # (a file it may not read, one that changed as it was read), which ends
72
- # the gzip stream short, or the connection was lost.
73
- def cut_short
74
- Error.new("The folder's archive arrived cut short: tar in the sandbox stopped part way, or the " \
75
- "connection was lost. Nothing was written.",
76
- code: "download_incomplete",
77
- hint: "Try again. If it fails the same way, a file in the folder cannot be read by the " \
78
- "sandbox user or changes as it is read.")
79
- end
80
-
81
- # Unpacks a whole gzipped tar held in memory into target, by Unpacker's rules.
82
- def unpack(archive, target)
83
- unpacker = Unpacker.new(target)
84
- begin
85
- unpacker.feed(archive)
86
- unpacker.finish
87
- ensure
88
- unpacker.discard
89
- end
90
- end
91
-
92
- # Unpacks a gzipped tar fed to it a chunk at a time into a target folder,
93
- # holding no more than a chunk. Entries land only inside the target, and
94
- # symbolic links are not made; a hard link lands as the file it names. It unpacks into a folder beside the target and moves
95
- # it into place only once the whole archive arrived (+finish+), so an
96
- # archive cut short leaves nothing behind that could pass for the folder.
97
- # A target that exists is merged into, files of the same name replaced,
98
- # never through a link in it. +discard+ removes what was unpacked if
99
- # +finish+ was never reached.
100
- class Unpacker
101
- def initialize(target)
102
- @final = File.expand_path(target)
103
- FileUtils.mkdir_p(File.dirname(@final))
104
- @staging = Dir.mktmpdir("#{File.basename(@final)}.runtime-partial-", File.dirname(@final))
105
- @root = File.realpath(@staging)
106
- @inflate = Zlib::Inflate.new(Zlib::MAX_WBITS + 16)
107
- @held = "".b
108
- @entry = nil
109
- @left = 0
110
- @padding = 0
111
- @long = nil
112
- @long_link = nil
113
- @ended = false
114
- end
115
-
116
- def feed(data)
117
- begin
118
- @held << @inflate.inflate(data)
119
- rescue Zlib::Error
120
- raise Tar.cut_short
121
- end
122
- nil while step
123
- end
124
-
125
- # Checks the archive arrived whole, then puts it in place.
126
- def finish
127
- raise Tar.cut_short unless @inflate.finished? && @ended
128
-
129
- if File.exist?(@final) || File.symlink?(@final)
130
- final = File.realpath(@final)
131
- merge(@root, final, final)
132
- else
133
- File.rename(@staging, @final)
134
- end
135
- end
136
-
137
- def discard
138
- @entry[:file]&.close if @entry.is_a?(Hash)
139
- FileUtils.rm_rf(@staging)
140
- end
141
-
142
- private
143
-
144
- def step
145
- if @ended
146
- @held.clear
147
- return false
148
- end
149
- if @entry.nil?
150
- return false if @held.bytesize < 512
151
-
152
- header = @held.slice!(0, 512)
153
- if header.count("\0") == 512
154
- @ended = true
155
- else
156
- begin_entry(header)
157
- end
158
- return true
159
- end
160
- if @left.positive?
161
- return false if @held.empty?
162
-
163
- part = @held.slice!(0, @left)
164
- @left -= part.bytesize
165
- @entry[:file]&.write(part)
166
- @entry[:long]&.<<(part)
167
- return false if @left.positive?
168
-
169
- end_body
170
- return true
171
- end
172
- if @padding.positive?
173
- return false if @held.empty?
174
-
175
- @padding -= @held.slice!(0, @padding).bytesize
176
- return false if @padding.positive?
177
- end
178
- @entry = nil
179
- true
180
- end
181
-
182
- def field(header, start, length) = header[start, length].split("\0", 2).first.to_s.force_encoding("UTF-8")
183
-
184
- def begin_entry(header)
185
- size = if header.getbyte(124) & 0x80 != 0
186
- header[125, 11].bytes.inject(0) { |sum, byte| (sum << 8) | byte }
187
- else
188
- field(header, 124, 12).strip.then { |text| text.empty? ? 0 : text.to_i(8) }
189
- end
190
- type = header[156]
191
- prefix = field(header, 345, 155)
192
- name = @long || (prefix.empty? ? field(header, 0, 100) : "#{prefix}/#{field(header, 0, 100)}")
193
- link = @long_link || field(header, 157, 100)
194
- @long = nil
195
- @long_link = nil
196
- @long_link = nil
197
- mode = field(header, 100, 8).strip.then { |text| text.empty? ? 0o644 : text.to_i(8) }
198
- @left = size
199
- @padding = -size % 512
200
- @entry = {}
201
- if %w[L K x].include?(type)
202
- @entry = { long: "".b, type: type }
203
- else
204
- name = name.delete_prefix("./")
205
- unless name.empty? || name == "." || name == "./"
206
- destination = File.expand_path(name, @root)
207
- raise IOError, "Refusing an archive entry outside the target: #{name}" unless destination.start_with?("#{@root}/")
208
-
209
- case type
210
- when "5" then FileUtils.mkdir_p(destination)
211
- when "1" then hard_link(destination, link, name)
212
- when "0", "\0", "7"
213
- FileUtils.mkdir_p(File.dirname(destination))
214
- # A name already unpacked may share its file with a hard link;
215
- # writing through it would change the link's copy too.
216
- File.unlink(destination) if File.exist?(destination) || File.symlink?(destination)
217
- @entry = { file: File.open(destination, "wb"), path: destination, mode: mode }
218
- end
219
- end
220
- end
221
- end_body if @left.zero?
222
- end
223
-
224
- def end_body
225
- if @entry[:file]
226
- @entry[:file].close
227
- File.chmod(@entry[:mode] & 0o777, @entry[:path])
228
- elsif @entry[:long]
229
- body = @entry[:long]
230
- case @entry[:type]
231
- when "L" then @long = body.split("\0", 2).first.force_encoding("UTF-8")
232
- when "K" then @long_link = body.split("\0", 2).first.force_encoding("UTF-8")
233
- else @long = pax_path(body)
234
- end
235
- end
236
- @entry = {}
237
- end
238
-
239
- # A second name for a file the archive already carried: tar writes the
240
- # first name as a file and every other as a hard link to it. The link
241
- # names a plain file unpacked earlier in this archive, or the unpack
242
- # fails; it never reaches outside or ahead.
243
- def hard_link(destination, link, name)
244
- source = File.expand_path(link.delete_prefix("./"), @root)
245
- unless source.start_with?("#{@root}/") && !link.start_with?("/")
246
- raise IOError, "Refusing an archive hard link that leads outside the target: #{name} -> #{link}"
247
- end
248
- unless File.file?(source) && !File.symlink?(source)
249
- raise IOError, "Refusing an archive hard link to a file it does not carry: #{name} -> #{link}"
250
- end
251
- return if source == destination
252
-
253
- FileUtils.mkdir_p(File.dirname(destination))
254
- File.unlink(destination) if File.exist?(destination) || File.symlink?(destination)
255
- begin
256
- File.link(source, destination)
257
- rescue SystemCallError
258
- FileUtils.cp(source, destination, preserve: true)
259
- end
260
- end
261
-
262
- # A pax header's path record, if it has one.
263
- def pax_path(body)
264
- until body.empty?
265
- length = body[/\A\d+/].to_i
266
- key, value = body[0, length].split(" ", 2).last.chomp.split("=", 2)
267
- return value.force_encoding("UTF-8") if key == "path"
268
-
269
- body = body[length..]
270
- end
271
- nil
272
- end
273
-
274
- def merge(from, to, root)
275
- Dir.children(from).each do |name|
276
- source = File.join(from, name)
277
- destination = File.join(to, name)
278
- through = destination.delete_prefix("#{root}/").split("/").each_with_object([root]) { |part, way| way << File.join(way.last, part) }
279
- if through.drop(1).any? { |path| File.symlink?(path) }
280
- raise IOError, "Refusing an archive entry that passes through a link: #{destination.delete_prefix("#{root}/")}"
281
- end
282
-
283
- if File.directory?(source) && File.directory?(destination)
284
- merge(source, destination, root)
285
- else
286
- File.rename(source, destination)
287
- end
288
- end
289
- end
290
- end
291
- end
292
- end