Class: TrustedSandbox::Response
- Inherits:
-
Object
- Object
- TrustedSandbox::Response
- Defined in:
- lib/trusted_sandbox/response.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#error_to_raise ⇒ Object
readonly
Returns the value of attribute error_to_raise.
-
#host_code_dir_path ⇒ Object
readonly
Returns the value of attribute host_code_dir_path.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#output_file_name ⇒ Object
readonly
Returns the value of attribute output_file_name.
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Class Method Summary collapse
-
.timeout_error(err, logs) ⇒ Response
Object initialized with timeout error details.
Instance Method Summary collapse
-
#initialize(stdout = nil, stderr = nil, host_code_dir_path = nil, output_file_name = nil) ⇒ Response
constructor
A new instance of Response.
-
#output! ⇒ Object
The output returned by the container.
-
#parse! ⇒ nil
Parses the output file and stores the values in the appropriate ivars.
- #valid? ⇒ Boolean
Constructor Details
#initialize(stdout = nil, stderr = nil, host_code_dir_path = nil, output_file_name = nil) ⇒ Response
Returns a new instance of Response.
11 12 13 14 15 16 |
# File 'lib/trusted_sandbox/response.rb', line 11 def initialize(stdout = nil, stderr = nil, host_code_dir_path = nil, output_file_name = nil) @stdout = stdout @stderr = stderr @host_code_dir_path = host_code_dir_path @output_file_name = output_file_name end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
4 5 6 |
# File 'lib/trusted_sandbox/response.rb', line 4 def error @error end |
#error_to_raise ⇒ Object (readonly)
Returns the value of attribute error_to_raise.
4 5 6 |
# File 'lib/trusted_sandbox/response.rb', line 4 def error_to_raise @error_to_raise end |
#host_code_dir_path ⇒ Object (readonly)
Returns the value of attribute host_code_dir_path.
4 5 6 |
# File 'lib/trusted_sandbox/response.rb', line 4 def host_code_dir_path @host_code_dir_path end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
4 5 6 |
# File 'lib/trusted_sandbox/response.rb', line 4 def output @output end |
#output_file_name ⇒ Object (readonly)
Returns the value of attribute output_file_name.
4 5 6 |
# File 'lib/trusted_sandbox/response.rb', line 4 def output_file_name @output_file_name end |
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
4 5 6 |
# File 'lib/trusted_sandbox/response.rb', line 4 def raw_response @raw_response end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
4 5 6 |
# File 'lib/trusted_sandbox/response.rb', line 4 def status @status end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
4 5 6 |
# File 'lib/trusted_sandbox/response.rb', line 4 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
4 5 6 |
# File 'lib/trusted_sandbox/response.rb', line 4 def stdout @stdout end |
Class Method Details
.timeout_error(err, logs) ⇒ Response
Returns object initialized with timeout error details.
19 20 21 22 23 24 25 26 27 |
# File 'lib/trusted_sandbox/response.rb', line 19 def self.timeout_error(err, logs) obj = new(logs) obj.instance_eval do @status = 'error' @error = err @error_to_raise = TrustedSandbox::ExecutionTimeoutError.new(err) end obj end |
Instance Method Details
#output! ⇒ Object
Returns the output returned by the container. Raises errors if encountered.
37 38 39 40 |
# File 'lib/trusted_sandbox/response.rb', line 37 def output! propagate_errors! output end |
#parse! ⇒ nil
Parses the output file and stores the values in the appropriate ivars
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/trusted_sandbox/response.rb', line 44 def parse! unless File.exists? output_file_path @status = 'error' @error = ContainerError.new('User code did not finish properly') @error_to_raise = @error return end begin data = File.binread output_file_path @raw_response = Marshal.load(data) rescue => e @status = 'error' @error = e @error_to_raise = ContainerError.new(e) return end unless ['success', 'error'].include? @raw_response[:status] @status = 'error' @error = InternalError.new('Output file has invalid format') @error_to_raise = @error return end @status = @raw_response[:status] @output = @raw_response[:output] @error = @raw_response[:error] @error_to_raise = UserCodeError.new(@error) if @error nil end |
#valid? ⇒ Boolean
30 31 32 |
# File 'lib/trusted_sandbox/response.rb', line 30 def valid? status == 'success' end |