Class: OpenSandbox::Execd

Inherits:
Object
  • Object
show all
Defined in:
lib/open_sandbox/execd.rb,
lib/open_sandbox/execd/files.rb,
lib/open_sandbox/execd/commands.rb,
lib/open_sandbox/execd/code_interpreter.rb

Defined Under Namespace

Classes: CodeInterpreter, Commands, Files

Constant Summary collapse

EXECD_PORT =
44772

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sandbox_id:, client: OpenSandbox.client) ⇒ Execd

Returns a new instance of Execd.



13
14
15
16
# File 'lib/open_sandbox/execd.rb', line 13

def initialize(sandbox_id:, client: OpenSandbox.client)
  @sandbox_id = sandbox_id
  @client = client
end

Instance Attribute Details

#sandbox_idObject (readonly)

Returns the value of attribute sandbox_id.



11
12
13
# File 'lib/open_sandbox/execd.rb', line 11

def sandbox_id
  @sandbox_id
end

Instance Method Details

#code_interpreterObject



26
27
28
# File 'lib/open_sandbox/execd.rb', line 26

def code_interpreter
  @code_interpreter ||= Execd::CodeInterpreter.new(self)
end

#commandsObject



18
19
20
# File 'lib/open_sandbox/execd.rb', line 18

def commands
  @commands ||= Execd::Commands.new(self)
end

#filesObject



22
23
24
# File 'lib/open_sandbox/execd.rb', line 22

def files
  @files ||= Execd::Files.new(self)
end

#pingObject



56
57
58
59
60
61
# File 'lib/open_sandbox/execd.rb', line 56

def ping
  response = proxy(method: :get, path: "/ping")
  response.code == 200
rescue OpenSandbox::Error
  false
end

#proxy(method:, path:, body: nil, headers: {}, raw_body: nil) ⇒ Object

Low-level proxy helper — routes HTTP requests through the OpenSandbox server proxy



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/open_sandbox/execd.rb', line 31

def proxy(method:, path:, body: nil, headers: {}, raw_body: nil)
  @client.sandboxes.proxy(
    @sandbox_id,
    port: EXECD_PORT,
    method: method,
    path: path,
    body: body,
    headers: headers,
    raw_body: raw_body
  )
end

#proxy_stream(method:, path:, body: nil, headers: {}, raw_body: nil, &block) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/open_sandbox/execd.rb', line 43

def proxy_stream(method:, path:, body: nil, headers: {}, raw_body: nil, &block)
  @client.sandboxes.proxy_stream(
    @sandbox_id,
    port: EXECD_PORT,
    method: method,
    path: path,
    body: body,
    headers: headers,
    raw_body: raw_body,
    &block
  )
end