Sha256: cf7753e28931750243dcdd448b5c97e92b4db739527c03853aefb0aa904a0625
Contents?: true
Size: 1.62 KB
Versions: 1
Compression:
Stored size: 1.62 KB
Contents
module Fog module Radosgw class Usage module Utils def sanitize_and_convert_time(time) fmt = '%Y-%m-%d %H:%M:%S' Fog::AWS.escape(time.strftime(fmt)) end end class Real include Utils def get_usage(access_key_id, options = {}) path = "admin/usage" t_now = Fog::Time.now start_time = sanitize_and_convert_time(options[:start_time] || t_now - 86400) end_time = sanitize_and_convert_time(options[:end_time] || t_now) query = "?format=json&start=#{start_time}&end=#{end_time}" params = { :method => 'GET', :path => path, } begin response = Excon.get("#{@scheme}://#{@host}/#{path}#{query}", :headers => signed_headers(params)) if !response.body.empty? case response.headers['Content-Type'] when 'application/json' response.body = Fog::JSON.decode(response.body) end end response rescue Excon::Errors::BadRequest => e raise Fog::Radosgw::Provisioning::ServiceUnavailable.new end end end class Mock include Utils def get_usage(access_key, options = {}) Excon::Response.new.tap do |response| response.status = 200 response.headers['Content-Type'] = 'application/json' response.body = { 'entries' => [], 'summary' => [] } end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fog-radosgw-0.0.1 | lib/fog/radosgw/requests/usage/get_usage.rb |