Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added get_url for Files class

  • Loading branch information...
commit 7aead998112a8dbcefe6aabbc8d825efafdc3410 1 parent 3630815
shadysayed authored September 17, 2012
14  lib/fog/azure/models/storage/files.rb
@@ -54,12 +54,24 @@ def get(key, options = {})
54 54
         rescue Excon::Errors::NotFound => error
55 55
         end
56 56
         
57  
-        def get_url(key)
  57
+        def get_url(key, expires = nil, options={})
58 58
           requires :directory
  59
+          # if self.directory.public_url
  60
+          #   ::File.join(self.directory.public_url, key)
  61
+          # end
  62
+          connection.get_blob_http_url(directory.key, key, expires, options)
59 63
         end
60 64
         
61 65
         def head(key, options = {})
62 66
           requires :directory
  67
+          data = connection.head_blob(directory.key, key)
  68
+          file_data = data.headers.merge({
  69
+            :key => key
  70
+          })
  71
+          normalize_headers(file_attributes)
  72
+          new(file_data)
  73
+        rescue Excon::Errors::NotFound => error
  74
+          nil
63 75
         end
64 76
         
65 77
         alias :each_file_this_page :each
2  lib/fog/azure/requests/storage/get_blob.rb
@@ -27,6 +27,8 @@ def get_blob(container, path, options = {}, &block)
27 27
         end
28 28
       end
29 29
       class Mock
  30
+        def get_blob(container, path, options = {}, &block)
  31
+        end
30 32
       end
31 33
     end
32 34
   end
40  lib/fog/azure/requests/storage/get_blob_http_url.rb
... ...
@@ -0,0 +1,40 @@
  1
+module Fog
  2
+  module Storage
  3
+    class AWS
  4
+
  5
+      module GetBlobHttpUrl
  6
+
  7
+        def get_blob_http_url(container_name, blob_name, expires = nil, options = {})
  8
+          unless container_name
  9
+            raise ArgumentError.new('container_name is required')
  10
+          end
  11
+          unless blob_name
  12
+            raise ArgumentError.new('blob_name is required')
  13
+          end
  14
+          host, path = [@host, ::File.join(container_name, blob_name)]
  15
+          http_url({
  16
+            :headers  => {},
  17
+            :host     => host,
  18
+            :port     => 80,
  19
+            :method   => 'GET',
  20
+            :path     => path,
  21
+            :query    => options[:query]
  22
+          }, expires)
  23
+        end
  24
+
  25
+      end
  26
+
  27
+      class Real
  28
+
  29
+        include GetBlobHttpUrl
  30
+
  31
+      end
  32
+
  33
+      class Mock # :nodoc:all
  34
+
  35
+        include GetBlobHttpUrl
  36
+
  37
+      end
  38
+    end
  39
+  end
  40
+end
40  lib/fog/azure/requests/storage/get_blob_https_url.rb
... ...
@@ -0,0 +1,40 @@
  1
+module Fog
  2
+  module Storage
  3
+    class AWS
  4
+
  5
+      module GetBlobHttpsUrl
  6
+
  7
+        def get_blob_https_url(container_name, blob_name, expires = nil, options = {})
  8
+          unless container_name
  9
+            raise ArgumentError.new('container_name is required')
  10
+          end
  11
+          unless blob_name
  12
+            raise ArgumentError.new('blob_name is required')
  13
+          end
  14
+          host, path = [@host, ::File.join(container_name, blob_name)]
  15
+          https_url({
  16
+            :headers  => {},
  17
+            :host     => host,
  18
+            :port     => 443,
  19
+            :method   => 'GET',
  20
+            :path     => path,
  21
+            :query    => options[:query]
  22
+          }, expires)
  23
+        end
  24
+
  25
+      end
  26
+
  27
+      class Real
  28
+
  29
+        include GetBlobHttpsUrl
  30
+
  31
+      end
  32
+
  33
+      class Mock # :nodoc:all
  34
+
  35
+        include GetBlobHttpsUrl
  36
+
  37
+      end
  38
+    end
  39
+  end
  40
+end
35  lib/fog/azure/requests/storage/head_blob.rb
... ...
@@ -0,0 +1,35 @@
  1
+module Fog
  2
+  module Storage
  3
+    class Azure
  4
+      class Real
  5
+        def head_blob(container, path, options = {}, &block)
  6
+          unless container
  7
+            raise ArgumentError.new("container is required")
  8
+          end
  9
+          unless path
  10
+            raise ArgumentError.new("path is required")
  11
+          end
  12
+          params = {headers: {}}
  13
+          if snapshot = options.delete('snapshot')
  14
+            params[:query] = {'snapshot' => snapshot}
  15
+          end
  16
+          
  17
+          if block_given?
  18
+            params[:response_block] = Proc.new
  19
+          end
  20
+          
  21
+          request(params.merge!({
  22
+            expects: [200],
  23
+            method: 'HEAD',
  24
+            idempotent: true,
  25
+            path: File.join(container, path) # Fog::Rackspace.escape(path, '/'))
  26
+          }))
  27
+        end
  28
+      end
  29
+      class Mock
  30
+        def head_blob(container, path, options = {}, &block)
  31
+        end
  32
+      end
  33
+    end
  34
+  end
  35
+end
34  lib/fog/azure/storage.rb
@@ -80,6 +80,40 @@ def extract_ms_metadata(dict)
80 80
           end
81 81
           result
82 82
         end
  83
+        
  84
+        def http_url(params, expires)
  85
+          scheme_host_path_query(params.merge(:scheme => 'http', :port => 80), expires)
  86
+        end
  87
+
  88
+        def https_url(params, expires)
  89
+          scheme_host_path_query(params.merge(:scheme => 'https', :port => 443), expires)
  90
+        end
  91
+
  92
+        
  93
+        private
  94
+        def scheme_host_path_query(params, expires)
  95
+          params[:scheme] ||= @scheme
  96
+          if params[:port] == 80 && params[:scheme] == 'http'
  97
+            params.delete(:port)
  98
+          end
  99
+          if params[:port] == 443 && params[:scheme] == 'https'
  100
+            params.delete(:port)
  101
+          end
  102
+          params[:headers] ||= {}
  103
+          #TODO: add signing for shared access signatures
  104
+          #call AWS escape, don't reinvent the wheel
  105
+          params[:path] = Fog::AWS.escape(params[:path]).gsub('%2F', '/')
  106
+          query = []
  107
+          if params[:query]
  108
+            for key, value in params[:query]
  109
+              #call the AWS escape, there is no need to reimplement
  110
+              query << "#{key}=#{Fog::AWS.escape(value)}"
  111
+            end
  112
+          end
  113
+          port_part = params[:port] && ":#{params[:port]}"
  114
+          "#{params[:scheme]}://#{params[:host]}#{port_part}/#{params[:path]}?#{query.join('&')}"
  115
+        end
  116
+        
83 117
       end
84 118
       
85 119
       class Real

0 notes on commit 7aead99

Please sign in to comment.
Something went wrong with that request. Please try again.