Class: Babl::ModuleResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/babl/module_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ModuleResponse

Returns a new instance of ModuleResponse.



5
6
7
8
9
10
11
12
13
# File 'lib/babl/module_response.rb', line 5

def initialize response
  @stdout_raw = response["Stdout"]
  @stderr_raw = response["Stderr"]
  @exitcode = response["Exitcode"].to_i

  if !response["PayloadUrl"].nil? and response["PayloadUrl"] != ""
    @payload_url = response["PayloadUrl"]
  end
end

Instance Attribute Details

#exitcodeObject (readonly)

Returns the value of attribute exitcode.



3
4
5
# File 'lib/babl/module_response.rb', line 3

def exitcode
  @exitcode
end

#payload_urlObject (readonly)

Returns the value of attribute payload_url.



3
4
5
# File 'lib/babl/module_response.rb', line 3

def payload_url
  @payload_url
end

Instance Method Details

#fetch_payloadObject



35
36
37
38
39
# File 'lib/babl/module_response.rb', line 35

def fetch_payload
  if payload_url
    Net::HTTP.get URI(payload_url)
  end
end

#raise_exception_when_unsuccessful!Object



41
42
43
44
45
# File 'lib/babl/module_response.rb', line 41

def raise_exception_when_unsuccessful!
  if exitcode != 0
    raise ModuleError.new(stdout: stdout(false), stderr: stderr, exitcode: exitcode, payload_url: payload_url)
  end
end

#stderrObject



27
28
29
30
31
32
33
# File 'lib/babl/module_response.rb', line 27

def stderr
  @stderr ||= begin
    o = Base64.decode64(@stderr_raw)
    @stderr_raw = nil
    o
  end
end

#stdout(allow_fetch = true) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/babl/module_response.rb', line 15

def stdout allow_fetch = true
  @stdout ||= begin
    if payload_url
      fetch_payload if allow_fetch
    else
      o = Base64.decode64(@stdout_raw)
      @stdout_raw = nil
      o
    end
  end
end