fog-google 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +7 -3
  4. data/examples/pubsub/subscriptions.rb +54 -0
  5. data/examples/pubsub/topics.rb +33 -0
  6. data/fog-google.gemspec +2 -2
  7. data/lib/fog/compute/google.rb +4 -884
  8. data/lib/fog/compute/google/mock.rb +871 -0
  9. data/lib/fog/compute/google/real.rb +22 -0
  10. data/lib/fog/dns/google.rb +3 -42
  11. data/lib/fog/dns/google/mock.rb +33 -0
  12. data/lib/fog/dns/google/real.rb +19 -0
  13. data/lib/fog/google.rb +14 -208
  14. data/lib/fog/google/mock.rb +14 -0
  15. data/lib/fog/google/models/pubsub/received_message.rb +40 -0
  16. data/lib/fog/google/models/pubsub/subscription.rb +86 -0
  17. data/lib/fog/google/models/pubsub/subscriptions.rb +32 -0
  18. data/lib/fog/google/models/pubsub/topic.rb +72 -0
  19. data/lib/fog/google/models/pubsub/topics.rb +31 -0
  20. data/lib/fog/google/monitoring.rb +3 -45
  21. data/lib/fog/google/monitoring/mock.rb +35 -0
  22. data/lib/fog/google/monitoring/real.rb +20 -0
  23. data/lib/fog/google/pubsub.rb +59 -0
  24. data/lib/fog/google/pubsub/mock.rb +34 -0
  25. data/lib/fog/google/pubsub/real.rb +20 -0
  26. data/lib/fog/google/requests/pubsub/acknowledge_subscription.rb +46 -0
  27. data/lib/fog/google/requests/pubsub/create_subscription.rb +57 -0
  28. data/lib/fog/google/requests/pubsub/create_topic.rb +36 -0
  29. data/lib/fog/google/requests/pubsub/delete_subscription.rb +28 -0
  30. data/lib/fog/google/requests/pubsub/delete_topic.rb +29 -0
  31. data/lib/fog/google/requests/pubsub/get_subscription.rb +44 -0
  32. data/lib/fog/google/requests/pubsub/get_topic.rb +41 -0
  33. data/lib/fog/google/requests/pubsub/list_subscriptions.rb +39 -0
  34. data/lib/fog/google/requests/pubsub/list_topics.rb +33 -0
  35. data/lib/fog/google/requests/pubsub/publish_topic.rb +61 -0
  36. data/lib/fog/google/requests/pubsub/pull_subscription.rb +77 -0
  37. data/lib/fog/google/shared.rb +191 -0
  38. data/lib/fog/google/sql.rb +3 -50
  39. data/lib/fog/google/sql/mock.rb +40 -0
  40. data/lib/fog/google/sql/real.rb +20 -0
  41. data/lib/fog/google/version.rb +1 -1
  42. data/lib/fog/storage/google_json.rb +4 -99
  43. data/lib/fog/storage/google_json/mock.rb +18 -0
  44. data/lib/fog/storage/google_json/real.rb +64 -0
  45. data/lib/fog/storage/google_json/utils.rb +32 -0
  46. data/lib/fog/storage/google_xml.rb +4 -260
  47. data/lib/fog/storage/google_xml/mock.rb +102 -0
  48. data/lib/fog/storage/google_xml/models/file.rb +14 -4
  49. data/lib/fog/storage/google_xml/real.rb +106 -0
  50. data/lib/fog/storage/google_xml/utils.rb +66 -0
  51. data/tests/models/pubsub/received_message_tests.rb +18 -0
  52. data/tests/models/pubsub/subscription_tests.rb +26 -0
  53. data/tests/models/pubsub/subscriptions_tests.rb +33 -0
  54. data/tests/models/pubsub/topic_tests.rb +18 -0
  55. data/tests/models/pubsub/topics_tests.rb +27 -0
  56. metadata +50 -14
@@ -1,6 +1,9 @@
1
1
  module Fog
2
2
  module Google
3
3
  class SQL < Fog::Service
4
+ autoload :Mock, File.expand_path("../sql/mock", __FILE__)
5
+ autoload :Real, File.expand_path("../sql/real", __FILE__)
6
+
4
7
  requires :google_project
5
8
  recognizes :google_client_email, :google_key_location, :google_key_string, :google_client,
6
9
  :app_name, :app_version, :google_json_key_location, :google_json_key_string
@@ -75,56 +78,6 @@ module Fog
75
78
 
76
79
  # Tier
77
80
  request :list_tiers
78
-
79
- class Mock
80
- include Fog::Google::Shared
81
-
82
- def initialize(options)
83
- shared_initialize(options[:google_project], GOOGLE_SQL_API_VERSION, GOOGLE_SQL_BASE_URL)
84
- end
85
-
86
- def self.data
87
- @data ||= Hash.new do |hash, key|
88
- hash[key] = {
89
- :backup_runs => {},
90
- :instances => {},
91
- :operations => {},
92
- :ssl_certs => {}
93
- }
94
- end
95
- end
96
-
97
- def self.reset
98
- @data = nil
99
- end
100
-
101
- def data
102
- self.class.data[project]
103
- end
104
-
105
- def reset_data
106
- self.class.data.delete(project)
107
- end
108
-
109
- def random_operation
110
- "operation-#{Fog::Mock.random_numbers(13)}-#{Fog::Mock.random_hex(13)}-#{Fog::Mock.random_hex(8)}"
111
- end
112
- end
113
-
114
- class Real
115
- include Fog::Google::Shared
116
-
117
- attr_accessor :client
118
- attr_reader :sql
119
-
120
- def initialize(options)
121
- shared_initialize(options[:google_project], GOOGLE_SQL_API_VERSION, GOOGLE_SQL_BASE_URL)
122
- options.merge!(:google_api_scope_url => GOOGLE_SQL_API_SCOPE_URLS.join(" "))
123
-
124
- @client = initialize_google_client(options)
125
- @sql = @client.discovered_api("sqladmin", api_version)
126
- end
127
- end
128
81
  end
129
82
  end
130
83
  end
@@ -0,0 +1,40 @@
1
+ module Fog
2
+ module Google
3
+ class SQL
4
+ class Mock
5
+ include Fog::Google::Shared
6
+
7
+ def initialize(options)
8
+ shared_initialize(options[:google_project], GOOGLE_SQL_API_VERSION, GOOGLE_SQL_BASE_URL)
9
+ end
10
+
11
+ def self.data
12
+ @data ||= Hash.new do |hash, key|
13
+ hash[key] = {
14
+ :backup_runs => {},
15
+ :instances => {},
16
+ :operations => {},
17
+ :ssl_certs => {}
18
+ }
19
+ end
20
+ end
21
+
22
+ def self.reset
23
+ @data = nil
24
+ end
25
+
26
+ def data
27
+ self.class.data[project]
28
+ end
29
+
30
+ def reset_data
31
+ self.class.data.delete(project)
32
+ end
33
+
34
+ def random_operation
35
+ "operation-#{Fog::Mock.random_numbers(13)}-#{Fog::Mock.random_hex(13)}-#{Fog::Mock.random_hex(8)}"
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ module Fog
2
+ module Google
3
+ class SQL
4
+ class Real
5
+ include Fog::Google::Shared
6
+
7
+ attr_accessor :client
8
+ attr_reader :sql
9
+
10
+ def initialize(options)
11
+ shared_initialize(options[:google_project], GOOGLE_SQL_API_VERSION, GOOGLE_SQL_BASE_URL)
12
+ options[:google_api_scope_url] = GOOGLE_SQL_API_SCOPE_URLS.join(" ")
13
+
14
+ @client = initialize_google_client(options)
15
+ @sql = @client.discovered_api("sqladmin", api_version)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Google
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0".freeze
4
4
  end
5
5
  end
@@ -1,6 +1,10 @@
1
1
  module Fog
2
2
  module Storage
3
3
  class GoogleJSON < Fog::Service
4
+ autoload :Mock, File.expand_path("../google_json/mock", __FILE__)
5
+ autoload :Real, File.expand_path("../google_json/real", __FILE__)
6
+ autoload :Utils, File.expand_path("../google_json/utils", __FILE__)
7
+
4
8
  requires :google_project
5
9
  recognizes :google_client_email, :google_key_location, :google_key_string, :google_client,
6
10
  :app_name, :app_version, :google_json_key_location, :google_json_key_string
@@ -42,105 +46,6 @@ module Fog
42
46
  request :put_object
43
47
  request :put_object_acl
44
48
  request :put_object_url
45
-
46
- module Utils
47
- def http_url(params, expires)
48
- "http://" << host_path_query(params, expires)
49
- end
50
-
51
- def https_url(params, expires)
52
- "https://" << host_path_query(params, expires)
53
- end
54
-
55
- def url(params, expires)
56
- Fog::Logger.deprecation("Fog::Storage::Google => #url is deprecated, use #https_url instead [light_black](#{caller.first})[/]")
57
- https_url(params, expires)
58
- end
59
-
60
- private
61
-
62
- def host_path_query(params, expires)
63
- params[:headers]["Date"] = expires.to_i
64
- params[:path] = CGI.escape(params[:path]).gsub("%2F", "/")
65
- query = [params[:query]].compact
66
- query << "GoogleAccessId=#{@client.authorization.issuer}"
67
- query << "Signature=#{CGI.escape(signature(params))}"
68
- query << "Expires=#{params[:headers]['Date']}"
69
- "#{params[:host]}/#{params[:path]}?#{query.join('&')}"
70
- end
71
- end
72
-
73
- class Mock
74
- include Utils
75
- include Fog::Google::Shared
76
-
77
- def initialize(options = {})
78
- shared_initialize(options[:google_project], GOOGLE_STORAGE_JSON_API_VERSION, GOOGLE_STORAGE_JSON_BASE_URL)
79
- end
80
-
81
- def signature(_params)
82
- "foo"
83
- end
84
- end
85
-
86
- class Real
87
- include Utils
88
- include Fog::Google::Shared
89
-
90
- attr_accessor :client
91
- attr_reader :storage_json
92
-
93
- def initialize(options = {})
94
- shared_initialize(options[:google_project], GOOGLE_STORAGE_JSON_API_VERSION, GOOGLE_STORAGE_JSON_BASE_URL)
95
- options.merge!(:google_api_scope_url => GOOGLE_STORAGE_JSON_API_SCOPE_URLS.join(" "))
96
- @host = options[:host] || "storage.googleapis.com"
97
-
98
- @client = initialize_google_client(options)
99
- @storage_json = @client.discovered_api("storage", api_version)
100
- end
101
-
102
- def signature(params)
103
- string_to_sign =
104
- <<-DATA
105
- #{params[:method]}
106
- #{params[:headers]['Content-MD5']}
107
- #{params[:headers]['Content-Type']}
108
- #{params[:headers]['Date']}
109
- DATA
110
-
111
- google_headers = {}
112
- canonical_google_headers = ""
113
- for key, value in params[:headers]
114
- google_headers[key] = value if key[0..6] == "x-goog-"
115
- end
116
-
117
- google_headers = google_headers.sort { |x, y| x[0] <=> y[0] }
118
- for key, value in google_headers
119
- canonical_google_headers << "#{key}:#{value}\n"
120
- end
121
- string_to_sign << "#{canonical_google_headers}"
122
-
123
- canonical_resource = "/"
124
- if subdomain = params.delete(:subdomain)
125
- canonical_resource << "#{CGI.escape(subdomain).downcase}/"
126
- end
127
- canonical_resource << "#{params[:path]}"
128
- canonical_resource << "?"
129
- for key in (params[:query] || {}).keys
130
- if %w(acl cors location logging requestPayment torrent versions versioning).include?(key)
131
- canonical_resource << "#{key}&"
132
- end
133
- end
134
- canonical_resource.chop!
135
- string_to_sign << "#{canonical_resource}"
136
-
137
- key = OpenSSL::PKey::RSA.new(@client.authorization.signing_key)
138
- digest = OpenSSL::Digest::SHA256.new
139
- signed_string = key.sign(digest, string_to_sign)
140
-
141
- Base64.encode64(signed_string).chomp!
142
- end
143
- end
144
49
  end
145
50
  end
146
51
  end
@@ -0,0 +1,18 @@
1
+ module Fog
2
+ module Storage
3
+ class GoogleJSON
4
+ class Mock
5
+ include Utils
6
+ include Fog::Google::Shared
7
+
8
+ def initialize(options = {})
9
+ shared_initialize(options[:google_project], GOOGLE_STORAGE_JSON_API_VERSION, GOOGLE_STORAGE_JSON_BASE_URL)
10
+ end
11
+
12
+ def signature(_params)
13
+ "foo"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,64 @@
1
+ module Fog
2
+ module Storage
3
+ class GoogleJSON
4
+ class Real
5
+ include Utils
6
+ include Fog::Google::Shared
7
+
8
+ attr_accessor :client
9
+ attr_reader :storage_json
10
+
11
+ def initialize(options = {})
12
+ shared_initialize(options[:google_project], GOOGLE_STORAGE_JSON_API_VERSION, GOOGLE_STORAGE_JSON_BASE_URL)
13
+ options[:google_api_scope_url] = GOOGLE_STORAGE_JSON_API_SCOPE_URLS.join(" ")
14
+ @host = options[:host] || "storage.googleapis.com"
15
+
16
+ @client = initialize_google_client(options)
17
+ @storage_json = @client.discovered_api("storage", api_version)
18
+ end
19
+
20
+ def signature(params)
21
+ string_to_sign =
22
+ <<-DATA
23
+ #{params[:method]}
24
+ #{params[:headers]['Content-MD5']}
25
+ #{params[:headers]['Content-Type']}
26
+ #{params[:headers]['Date']}
27
+ DATA
28
+
29
+ google_headers = {}
30
+ canonical_google_headers = ""
31
+ params[:headers].each do |key, value|
32
+ google_headers[key] = value if key[0..6] == "x-goog-"
33
+ end
34
+
35
+ google_headers = google_headers.sort { |x, y| x[0] <=> y[0] }
36
+ google_headers.each do |key, value|
37
+ canonical_google_headers << "#{key}:#{value}\n"
38
+ end
39
+ string_to_sign << canonical_google_headers.to_s
40
+
41
+ canonical_resource = "/"
42
+ if subdomain = params.delete(:subdomain)
43
+ canonical_resource << "#{CGI.escape(subdomain).downcase}/"
44
+ end
45
+ canonical_resource << params[:path].to_s
46
+ canonical_resource << "?"
47
+ for key in (params[:query] || {}).keys
48
+ if %w(acl cors location logging requestPayment torrent versions versioning).include?(key)
49
+ canonical_resource << "#{key}&"
50
+ end
51
+ end
52
+ canonical_resource.chop!
53
+ string_to_sign << canonical_resource.to_s
54
+
55
+ key = OpenSSL::PKey::RSA.new(@client.authorization.signing_key)
56
+ digest = OpenSSL::Digest::SHA256.new
57
+ signed_string = key.sign(digest, string_to_sign)
58
+
59
+ Base64.encode64(signed_string).chomp!
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,32 @@
1
+ module Fog
2
+ module Storage
3
+ class GoogleJSON
4
+ module Utils
5
+ def http_url(params, expires)
6
+ "http://" << host_path_query(params, expires)
7
+ end
8
+
9
+ def https_url(params, expires)
10
+ "https://" << host_path_query(params, expires)
11
+ end
12
+
13
+ def url(params, expires)
14
+ Fog::Logger.deprecation("Fog::Storage::Google => #url is deprecated, use #https_url instead [light_black](#{caller.first})[/]")
15
+ https_url(params, expires)
16
+ end
17
+
18
+ private
19
+
20
+ def host_path_query(params, expires)
21
+ params[:headers]["Date"] = expires.to_i
22
+ params[:path] = CGI.escape(params[:path]).gsub("%2F", "/")
23
+ query = [params[:query]].compact
24
+ query << "GoogleAccessId=#{@client.authorization.issuer}"
25
+ query << "Signature=#{CGI.escape(signature(params))}"
26
+ query << "Expires=#{params[:headers]['Date']}"
27
+ "#{params[:host]}/#{params[:path]}?#{query.join('&')}"
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,6 +1,10 @@
1
1
  module Fog
2
2
  module Storage
3
3
  class GoogleXML < Fog::Service
4
+ autoload :Mock, File.expand_path("../google_xml/mock", __FILE__)
5
+ autoload :Real, File.expand_path("../google_xml/real", __FILE__)
6
+ autoload :Utils, File.expand_path("../google_xml/utils", __FILE__)
7
+
4
8
  requires :google_storage_access_key_id, :google_storage_secret_access_key
5
9
  recognizes :host, :port, :scheme, :persistent, :path_style
6
10
 
@@ -29,266 +33,6 @@ module Fog
29
33
  request :put_object
30
34
  request :put_object_acl
31
35
  request :put_object_url
32
-
33
- module Utils
34
- def http_url(params, expires)
35
- "http://" << host_path_query(params, expires)
36
- end
37
-
38
- def https_url(params, expires)
39
- "https://" << host_path_query(params, expires)
40
- end
41
-
42
- def url(params, expires)
43
- Fog::Logger.deprecation("Fog::Storage::Google => #url is deprecated, use #https_url instead [light_black](#{caller.first})[/]")
44
- https_url(params, expires)
45
- end
46
-
47
- private
48
-
49
- def host_path_query(params, expires)
50
- params[:headers]["Date"] = expires.to_i
51
- params[:path] = CGI.escape(params[:path]).gsub("%2F", "/")
52
- query = [params[:query]].compact
53
- query << "GoogleAccessId=#{@google_storage_access_key_id}"
54
- query << "Signature=#{CGI.escape(signature(params))}"
55
- query << "Expires=#{params[:headers]['Date']}"
56
- "#{params[:host]}/#{params[:path]}?#{query.join('&')}"
57
- end
58
-
59
- def request_params(params)
60
- subdomain = params[:host].split(".#{@host}").first
61
- if @path_style || subdomain !~ /^(?!goog)(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]$/
62
- if subdomain =~ /_/
63
- # https://github.com/fog/fog/pull/1258#issuecomment-10248620.
64
- Fog::Logger.warning("fog: the specified google storage bucket name (#{subdomain}) is not DNS compliant (only characters a through z, digits 0 through 9, and the hyphen).")
65
- else
66
- # - Bucket names must contain only lowercase letters, numbers, dashes (-), underscores (_), and dots (.). Names containing dots require verification.
67
- # - Bucket names must start and end with a number or letter.
68
- # - Bucket names must contain 3 to 63 characters. Names containing dots can contain up to 222 characters, but each dot-separated component can be no longer than 63 characters.
69
- # - Bucket names cannot be represented as an IP address in dotted-decimal notation (for example, 192.168.5.4).
70
- # - Bucket names cannot begin with the "goog" prefix.
71
- # - Also, for DNS compliance, you should not have a period adjacent to another period or dash. For example, ".." or "-." or ".-" are not acceptable.
72
- Fog::Logger.warning("fog: the specified google storage bucket name (#{subdomain}) is not a valid dns name. See: https://developers.google.com/storage/docs/bucketnaming") unless @path_style
73
- end
74
-
75
- params[:host] = params[:host].split("#{subdomain}.")[-1]
76
- if params[:path]
77
- params[:path] = "#{subdomain}/#{params[:path]}"
78
- else
79
- params[:path] = "#{subdomain}"
80
- end
81
- subdomain = nil
82
- end
83
-
84
- params[:subdomain] = subdomain if subdomain && subdomain != @host
85
-
86
- params[:scheme] ||= @scheme
87
- params[:port] ||= @port
88
- params
89
- end
90
- end
91
-
92
- class Mock
93
- include Utils
94
-
95
- def self.acls(type)
96
- case type
97
- when "private"
98
- {
99
- "AccessControlList" => [
100
- {
101
- "Permission" => "FULL_CONTROL",
102
- "Scope" => { "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0", "type" => "UserById" }
103
- }
104
- ],
105
- "Owner" => { "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0" }
106
- }
107
- when "public-read"
108
- {
109
- "AccessControlList" => [
110
- {
111
- "Permission" => "FULL_CONTROL",
112
- "Scope" => { "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0", "type" => "UserById" }
113
- },
114
- {
115
- "Permission" => "READ",
116
- "Scope" => { "type" => "AllUsers" }
117
- }
118
- ],
119
- "Owner" => { "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0" }
120
- }
121
- when "public-read-write"
122
- {
123
- "AccessControlList" => [
124
- {
125
- "Permission" => "FULL_CONTROL",
126
- "Scope" => { "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0", "type" => "UserById" }
127
- },
128
- {
129
- "Permission" => "READ",
130
- "Scope" => { "type" => "AllUsers" }
131
- },
132
- {
133
- "Permission" => "WRITE",
134
- "Scope" => { "type" => "AllUsers" }
135
- }
136
- ],
137
- "Owner" => { "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0" }
138
- }
139
- when "authenticated-read"
140
- {
141
- "AccessControlList" => [
142
- {
143
- "Permission" => "FULL_CONTROL",
144
- "Scope" => { "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0", "type" => "UserById" }
145
- },
146
- {
147
- "Permission" => "READ",
148
- "Scope" => { "type" => "AllAuthenticatedUsers" }
149
- }
150
- ],
151
- "Owner" => { "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0" }
152
- }
153
- end
154
- end
155
-
156
- def self.data
157
- @data ||= Hash.new do |hash, key|
158
- hash[key] = {
159
- :acls => {
160
- :bucket => {},
161
- :object => {}
162
- },
163
- :buckets => {}
164
- }
165
- end
166
- end
167
-
168
- def self.reset
169
- @data = nil
170
- end
171
-
172
- def initialize(options = {})
173
- @google_storage_access_key_id = options[:google_storage_access_key_id]
174
- end
175
-
176
- def data
177
- self.class.data[@google_storage_access_key_id]
178
- end
179
-
180
- def reset_data
181
- self.class.data.delete(@google_storage_access_key_id)
182
- end
183
-
184
- def signature(_params)
185
- "foo"
186
- end
187
- end
188
-
189
- class Real
190
- include Utils
191
-
192
- # Initialize connection to Google Storage
193
- #
194
- # ==== Notes
195
- # options parameter must include values for :google_storage_access_key_id and
196
- # :google_storage_secret_access_key in order to create a connection
197
- #
198
- # ==== Examples
199
- # google_storage = Storage.new(
200
- # :google_storage_access_key_id => your_google_storage_access_key_id,
201
- # :google_storage_secret_access_key => your_google_storage_secret_access_key
202
- # )
203
- #
204
- # ==== Parameters
205
- # * options<~Hash> - config arguments for connection. Defaults to {}.
206
- #
207
- # ==== Returns
208
- # * Storage object with connection to google.
209
- def initialize(options = {})
210
- @google_storage_access_key_id = options[:google_storage_access_key_id]
211
- @google_storage_secret_access_key = options[:google_storage_secret_access_key]
212
- @connection_options = options[:connection_options] || {}
213
- @hmac = Fog::HMAC.new("sha1", @google_storage_secret_access_key)
214
- @host = options[:host] || "storage.googleapis.com"
215
- @persistent = options.fetch(:persistent, true)
216
- @port = options[:port] || 443
217
- @scheme = options[:scheme] || "https"
218
- @path_style = options[:path_style] || false
219
- end
220
-
221
- def reload
222
- @connection.reset if @connection
223
- end
224
-
225
- def signature(params)
226
- string_to_sign =
227
- <<-DATA
228
- #{params[:method]}
229
- #{params[:headers]['Content-MD5']}
230
- #{params[:headers]['Content-Type']}
231
- #{params[:headers]['Date']}
232
- DATA
233
-
234
- google_headers = {}
235
- canonical_google_headers = ""
236
- for key, value in params[:headers]
237
- google_headers[key] = value if key[0..6] == "x-goog-"
238
- end
239
-
240
- google_headers = google_headers.sort { |x, y| x[0] <=> y[0] }
241
- for key, value in google_headers
242
- canonical_google_headers << "#{key}:#{value}\n"
243
- end
244
- string_to_sign << "#{canonical_google_headers}"
245
-
246
- canonical_resource = "/"
247
- if subdomain = params.delete(:subdomain)
248
- canonical_resource << "#{CGI.escape(subdomain).downcase}/"
249
- end
250
- canonical_resource << "#{params[:path]}"
251
- canonical_resource << "?"
252
- for key in (params[:query] || {}).keys
253
- if %w(acl cors location logging requestPayment torrent versions versioning).include?(key)
254
- canonical_resource << "#{key}&"
255
- end
256
- end
257
- canonical_resource.chop!
258
- string_to_sign << "#{canonical_resource}"
259
-
260
- signed_string = @hmac.sign(string_to_sign)
261
- Base64.encode64(signed_string).chomp!
262
- end
263
-
264
- def connection(scheme, host, port)
265
- uri = "#{scheme}://#{host}:#{port}"
266
- if @persistent
267
- unless uri == @connection_uri
268
- @connection_uri = uri
269
- reload
270
- @connection = nil
271
- end
272
- else
273
- @connection = nil
274
- end
275
- @connection ||= Fog::XML::Connection.new(uri, @persistent, @connection_options)
276
- end
277
-
278
- private
279
-
280
- def request(params, &block)
281
- params = request_params(params)
282
- scheme = params.delete(:scheme)
283
- host = params.delete(:host)
284
- port = params.delete(:port)
285
-
286
- params[:headers]["Date"] = Fog::Time.now.to_date_header
287
- params[:headers]["Authorization"] = "GOOG1 #{@google_storage_access_key_id}:#{signature(params)}"
288
-
289
- connection(scheme, host, port).request(params, &block)
290
- end
291
- end
292
36
  end
293
37
  end
294
38
  end