Module: Fog::Radosgw::Utils
- Included in:
- Provisioning::Mock, Provisioning::Real
- Defined in:
- lib/fog/radosgw/utils.rb
Instance Method Summary collapse
- #configure_uri_options(options = {}) ⇒ Object
- #escape(string) ⇒ Object
- #radosgw_uri ⇒ Object
- #signature(params, expires) ⇒ Object
- #signed_headers(params) ⇒ Object
Instance Method Details
#configure_uri_options(options = {}) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/fog/radosgw/utils.rb', line 4 def ( = {}) @host = [:host] || 'localhost' @persistent = [:persistent] || true @port = [:port] || 8080 @scheme = [:scheme] || 'http' end |
#escape(string) ⇒ Object
15 16 17 18 19 |
# File 'lib/fog/radosgw/utils.rb', line 15 def escape(string) string.gsub(/([^a-zA-Z0-9_.\-~]+)/) { "%" + $1.unpack("H2" * $1.bytesize).join("%").upcase } end |
#radosgw_uri ⇒ Object
11 12 13 |
# File 'lib/fog/radosgw/utils.rb', line 11 def radosgw_uri "#{@scheme}://#{@host}:#{@port}" end |
#signature(params, expires) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fog/radosgw/utils.rb', line 21 def signature(params, expires) headers = params[:headers] || {} string_to_sign = [ params[:method].to_s.upcase, headers['Content-MD5'], headers['Content-Type'], expires].map(&:to_s).join("\n") + "\n" amz_headers, canonical_amz_headers = {}, '' for key, value in headers if key[0..5] == 'x-amz-' amz_headers[key] = value end end amz_headers = amz_headers.sort {|x, y| x[0] <=> y[0]} for key, value in amz_headers canonical_amz_headers << "#{key}:#{value}\n" end string_to_sign << canonical_amz_headers query_string = '' if params[:query] query_args = [] for key in params[:query].keys.sort if VALID_QUERY_KEYS.include?(key) value = params[:query][key] if value query_args << "#{key}=#{value}" else query_args << key end end end if query_args.any? query_string = '?' + query_args.join('&') end end canonical_path = (params[:path] || object_to_path(params[:object_name])).to_s canonical_path = '/' + canonical_path if canonical_path[0..0] != '/' if params[:bucket_name] canonical_resource = "/#{params[:bucket_name]}#{canonical_path}" else canonical_resource = canonical_path end canonical_resource << query_string string_to_sign << canonical_resource hmac = Fog::HMAC.new('sha1', @radosgw_secret_access_key) signed_string = hmac.sign(string_to_sign) Base64.encode64(signed_string).chomp! end |
#signed_headers(params) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/fog/radosgw/utils.rb', line 76 def signed_headers(params) expires = Fog::Time.now.to_date_header auth = signature(params,expires) awskey = @radosgw_access_key_id headers = { 'Date' => expires, 'Authorization' => "AWS #{awskey}:#{auth}" } end |