module GCEMetadata::HttpClient

Constants

DEFAULT_OPEN_TIMEOUT
DEFAULT_READ_TIMEOUT

Attributes

open_timeout_sec[RW]
read_timeout_sec[RW]

Public Class Methods

extended(obj) click to toggle source
# File lib/gce_metadata/http_client.rb, line 5
def self.extended(obj)
  obj.open_timeout_sec ||= DEFAULT_OPEN_TIMEOUT
  obj.read_timeout_sec ||= DEFAULT_READ_TIMEOUT
end

Public Instance Methods

get(path) click to toggle source
# File lib/gce_metadata/http_client.rb, line 16
def get(path)
  logging("GCEMetadata.get(#{path.inspect})") do
    http = Net::HTTP.new(DEFAULT_HOST)
    http.open_timeout = self.open_timeout_sec
    http.read_timeout = self.read_timeout_sec
    http.start do |http|
      res = http.get(path, 'Metadata-Flavor' => 'Google')
      res.is_a?(Net::HTTPSuccess) ? res.body : nil
    end
  end
end