Module: GCEMetadata::HttpClient
- Included in:
- GCEMetadata
- Defined in:
- lib/gce_metadata/http_client.rb
Constant Summary collapse
- DEFAULT_OPEN_TIMEOUT =
5
- DEFAULT_READ_TIMEOUT =
10
Instance Attribute Summary collapse
-
#open_timeout_sec ⇒ Object
Returns the value of attribute open_timeout_sec.
-
#read_timeout_sec ⇒ Object
Returns the value of attribute read_timeout_sec.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#open_timeout_sec ⇒ Object
Returns the value of attribute open_timeout_sec.
13 14 15 |
# File 'lib/gce_metadata/http_client.rb', line 13 def open_timeout_sec @open_timeout_sec end |
#read_timeout_sec ⇒ Object
Returns the value of attribute read_timeout_sec.
14 15 16 |
# File 'lib/gce_metadata/http_client.rb', line 14 def read_timeout_sec @read_timeout_sec end |
Class Method Details
.extended(obj) ⇒ Object
5 6 7 8 |
# 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 |
Instance Method Details
#get(path) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# 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 |