Class: Marty::Aws::Request

Inherits:
Base
  • Object
show all
Defined in:
lib/marty/aws/request.rb

Direct Known Subclasses

Diagnostic::Aws::Ec2Instance

Instance Method Summary collapse

Instance Method Details

#ensure_resp(path, obj) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/marty/aws/request.rb', line 33

def ensure_resp path, obj
  if path == []
    obj.is_a?(Array) ? obj : [obj]
  elsif obj.is_a?(Hash)
    key = path.shift
    raise "Unexpected AWS Response: #{key} missing" unless
      (obj.is_a?(Hash) && obj[key])

    ensure_resp(path, obj[key])
  else
    obj.map { |s| ensure_resp(path.clone, s) }.flatten(1)
  end
end

#request(info, params = {}) ⇒ Object

this class is used to make aws api requests for specific services currently only used for diagnostics



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/marty/aws/request.rb', line 5

def request info, params = {}
  action   = info[:action]
  endpoint = info[:endpoint]
  method   = info[:method] || :get

  default = action ? { 'Action' => action, 'Version' => @version } : {}

  host = "#{@service}.#{@doc[:region]}.amazonaws.com"

  url = "https://#{host}/"
  url += endpoint if endpoint
  url += '?' + (default + params).map { |a, v| "#{a}=#{v}" }.join('&') unless
    params.empty?

  sig = ::Aws::Sigv4::Signer.new(
    service: @service,
    region: @doc[:region],
    access_key_id: @creds[:access_key_id],
    secret_access_key: @creds[:secret_access_key],
    session_token: @creds[:token]
  )
  signed_url = sig.presign_url(http_method: 'GET', url: url)

  http = Net::HTTP.new(host, 443)
  http.use_ssl = true
  Net::HTTP.send(method, signed_url)
end