fog 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/Gemfile.lock +1 -1
  2. data/README.rdoc +1 -0
  3. data/fog.gemspec +44 -1
  4. data/lib/fog.rb +2 -1
  5. data/lib/fog/bin.rb +2 -0
  6. data/lib/fog/google.rb +22 -0
  7. data/lib/fog/google/bin.rb +20 -0
  8. data/lib/fog/google/models/storage/directories.rb +43 -0
  9. data/lib/fog/google/models/storage/directory.rb +48 -0
  10. data/lib/fog/google/models/storage/file.rb +87 -0
  11. data/lib/fog/google/models/storage/files.rb +94 -0
  12. data/lib/fog/google/parsers/storage/access_control_list.rb +46 -0
  13. data/lib/fog/google/parsers/storage/copy_object.rb +22 -0
  14. data/lib/fog/google/parsers/storage/get_bucket.rb +46 -0
  15. data/lib/fog/google/parsers/storage/get_bucket_logging.rb +40 -0
  16. data/lib/fog/google/parsers/storage/get_bucket_object_versions.rb +88 -0
  17. data/lib/fog/google/parsers/storage/get_bucket_versioning.rb +24 -0
  18. data/lib/fog/google/parsers/storage/get_request_payment.rb +20 -0
  19. data/lib/fog/google/parsers/storage/get_service.rb +32 -0
  20. data/lib/fog/google/requests/storage/copy_object.rb +72 -0
  21. data/lib/fog/google/requests/storage/delete_bucket.rb +46 -0
  22. data/lib/fog/google/requests/storage/delete_object.rb +50 -0
  23. data/lib/fog/google/requests/storage/get_bucket.rb +110 -0
  24. data/lib/fog/google/requests/storage/get_bucket_acl.rb +55 -0
  25. data/lib/fog/google/requests/storage/get_object.rb +104 -0
  26. data/lib/fog/google/requests/storage/get_object_acl.rb +66 -0
  27. data/lib/fog/google/requests/storage/get_object_torrent.rb +55 -0
  28. data/lib/fog/google/requests/storage/get_object_url.rb +54 -0
  29. data/lib/fog/google/requests/storage/get_service.rb +53 -0
  30. data/lib/fog/google/requests/storage/head_object.rb +64 -0
  31. data/lib/fog/google/requests/storage/put_bucket.rb +68 -0
  32. data/lib/fog/google/requests/storage/put_bucket_acl.rb +80 -0
  33. data/lib/fog/google/requests/storage/put_object.rb +71 -0
  34. data/lib/fog/google/requests/storage/put_object_url.rb +54 -0
  35. data/lib/fog/google/storage.rb +192 -0
  36. data/spec/google/models/storage/directories_spec.rb +49 -0
  37. data/spec/google/models/storage/directory_spec.rb +83 -0
  38. data/spec/google/models/storage/file_spec.rb +121 -0
  39. data/spec/google/models/storage/files_spec.rb +141 -0
  40. data/spec/google/requests/storage/copy_object_spec.rb +61 -0
  41. data/spec/google/requests/storage/delete_bucket_spec.rb +35 -0
  42. data/spec/google/requests/storage/delete_object_spec.rb +38 -0
  43. data/spec/google/requests/storage/get_bucket_spec.rb +110 -0
  44. data/spec/google/requests/storage/get_object_spec.rb +58 -0
  45. data/spec/google/requests/storage/get_service_spec.rb +32 -0
  46. data/spec/google/requests/storage/head_object_spec.rb +26 -0
  47. data/spec/google/requests/storage/put_bucket_spec.rb +21 -0
  48. data/spec/google/requests/storage/put_object_spec.rb +43 -0
  49. metadata +45 -2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fog (0.3.1)
4
+ fog (0.3.2)
5
5
  builder
6
6
  excon (>= 0.2.1)
7
7
  formatador (>= 0.0.15)
data/README.rdoc CHANGED
@@ -95,6 +95,7 @@ Play around and use the console to explore or check out the {getting started gui
95
95
  You should try out the (varying) support fog has for:
96
96
  * {AWS}[http://aws.amazon.com] [{EC2}[http://aws.amazon.com/ec2], {ELB}[http://aws.amazon.com/elasticloadbalancing], {S3}[http://aws.amazon.com/s3], {SimpleDB}[http://aws.amazon.com/simpledb]]
97
97
  * {Blue Box Group}[http://www.blueboxgrp.com] [{Blocks}[http://www.blueboxgrp.com/blocks]]
98
+ * {Google}[http://www.google.com] [{Storage}[http://code.google.com/apis/storage]]
98
99
  * {Rackspace}[http://www.rackspace.com] [{Files}[http://www.rackspacecloud.com/cloud_hosting_products/files], {Servers}[http://www.rackspacecloud.com/cloud_hosting_products/servers]]
99
100
  * {Slicehost}[http://www.slicehost.com]
100
101
  * {Terremark}[http://www.terremark.com] [{vCloud Express}[http://vcloudexpress.terremark.com]]
data/fog.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  ## If your rubyforge_project name is different, then edit it and comment out
8
8
  ## the sub! line in the Rakefile
9
9
  s.name = 'fog'
10
- s.version = '0.3.1'
10
+ s.version = '0.3.2'
11
11
  s.date = '2010-09-24'
12
12
  s.rubyforge_project = 'fog'
13
13
 
@@ -263,6 +263,36 @@ Gem::Specification.new do |s|
263
263
  lib/fog/go_grid/requests/compute/grid_server_get.rb
264
264
  lib/fog/go_grid/requests/compute/grid_server_list.rb
265
265
  lib/fog/go_grid/requests/compute/grid_server_power.rb
266
+ lib/fog/google.rb
267
+ lib/fog/google/bin.rb
268
+ lib/fog/google/models/storage/directories.rb
269
+ lib/fog/google/models/storage/directory.rb
270
+ lib/fog/google/models/storage/file.rb
271
+ lib/fog/google/models/storage/files.rb
272
+ lib/fog/google/parsers/storage/access_control_list.rb
273
+ lib/fog/google/parsers/storage/copy_object.rb
274
+ lib/fog/google/parsers/storage/get_bucket.rb
275
+ lib/fog/google/parsers/storage/get_bucket_logging.rb
276
+ lib/fog/google/parsers/storage/get_bucket_object_versions.rb
277
+ lib/fog/google/parsers/storage/get_bucket_versioning.rb
278
+ lib/fog/google/parsers/storage/get_request_payment.rb
279
+ lib/fog/google/parsers/storage/get_service.rb
280
+ lib/fog/google/requests/storage/copy_object.rb
281
+ lib/fog/google/requests/storage/delete_bucket.rb
282
+ lib/fog/google/requests/storage/delete_object.rb
283
+ lib/fog/google/requests/storage/get_bucket.rb
284
+ lib/fog/google/requests/storage/get_bucket_acl.rb
285
+ lib/fog/google/requests/storage/get_object.rb
286
+ lib/fog/google/requests/storage/get_object_acl.rb
287
+ lib/fog/google/requests/storage/get_object_torrent.rb
288
+ lib/fog/google/requests/storage/get_object_url.rb
289
+ lib/fog/google/requests/storage/get_service.rb
290
+ lib/fog/google/requests/storage/head_object.rb
291
+ lib/fog/google/requests/storage/put_bucket.rb
292
+ lib/fog/google/requests/storage/put_bucket_acl.rb
293
+ lib/fog/google/requests/storage/put_object.rb
294
+ lib/fog/google/requests/storage/put_object_url.rb
295
+ lib/fog/google/storage.rb
266
296
  lib/fog/hmac.rb
267
297
  lib/fog/linode.rb
268
298
  lib/fog/linode/bin.rb
@@ -544,6 +574,19 @@ Gem::Specification.new do |s|
544
574
  spec/bluebox/models/compute/server_spec.rb
545
575
  spec/bluebox/models/compute/servers_spec.rb
546
576
  spec/compact_progress_bar_formatter.rb
577
+ spec/google/models/storage/directories_spec.rb
578
+ spec/google/models/storage/directory_spec.rb
579
+ spec/google/models/storage/file_spec.rb
580
+ spec/google/models/storage/files_spec.rb
581
+ spec/google/requests/storage/copy_object_spec.rb
582
+ spec/google/requests/storage/delete_bucket_spec.rb
583
+ spec/google/requests/storage/delete_object_spec.rb
584
+ spec/google/requests/storage/get_bucket_spec.rb
585
+ spec/google/requests/storage/get_object_spec.rb
586
+ spec/google/requests/storage/get_service_spec.rb
587
+ spec/google/requests/storage/head_object_spec.rb
588
+ spec/google/requests/storage/put_bucket_spec.rb
589
+ spec/google/requests/storage/put_object_spec.rb
547
590
  spec/lorem.txt
548
591
  spec/rackspace/models/compute/flavors_spec.rb
549
592
  spec/rackspace/models/compute/server_spec.rb
data/lib/fog.rb CHANGED
@@ -32,7 +32,7 @@ require 'fog/ssh'
32
32
  module Fog
33
33
 
34
34
  unless const_defined?(:VERSION)
35
- VERSION = '0.3.1'
35
+ VERSION = '0.3.2'
36
36
  end
37
37
 
38
38
  module Mock
@@ -94,3 +94,4 @@ require 'fog/rackspace'
94
94
  require 'fog/slicehost'
95
95
  require 'fog/terremark'
96
96
  require 'fog/vcloud'
97
+ require 'fog/google'
data/lib/fog/bin.rb CHANGED
@@ -8,6 +8,7 @@ module Fog
8
8
  ::AWS,
9
9
  ::Bluebox,
10
10
  ::GoGrid,
11
+ ::Google,
11
12
  ::Linode,
12
13
  ::Local,
13
14
  ::NewServers,
@@ -68,6 +69,7 @@ end
68
69
  require 'fog/aws/bin'
69
70
  require 'fog/bluebox/bin'
70
71
  require 'fog/go_grid/bin'
72
+ require 'fog/google/bin'
71
73
  require 'fog/linode/bin'
72
74
  require 'fog/local/bin'
73
75
  require 'fog/new_servers/bin'
data/lib/fog/google.rb ADDED
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Google
3
+
4
+ extend Fog::Provider
5
+
6
+ service_path 'fog/google'
7
+ service 'storage'
8
+
9
+ class Mock
10
+
11
+ def self.etag
12
+ hex(32)
13
+ end
14
+
15
+ def self.hex(length)
16
+ max = ('f' * length).to_i(16)
17
+ rand(max).to_s(16)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ class Google < Fog::Bin
2
+ class << self
3
+
4
+ def [](service)
5
+ @@connections ||= Hash.new do |hash, key|
6
+ hash[key] = case key
7
+ when :storage
8
+ Fog::Google::Storage.new
9
+ end
10
+ end
11
+ @@connections[service]
12
+ end
13
+
14
+ def services
15
+ [:storage]
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,43 @@
1
+ require 'fog/collection'
2
+ require 'fog/google/models/storage/directory'
3
+
4
+ module Fog
5
+ module Google
6
+ class Storage
7
+
8
+ class Directories < Fog::Collection
9
+
10
+ model Fog::Google::Storage::Directory
11
+
12
+ def all
13
+ data = connection.get_service.body['Buckets']
14
+ load(data)
15
+ end
16
+
17
+ def get(key, options = {})
18
+ remap_attributes(options, {
19
+ :delimiter => 'delimiter',
20
+ :marker => 'marker',
21
+ :max_keys => 'max-keys',
22
+ :prefix => 'prefix'
23
+ })
24
+ data = connection.get_bucket(key, options).body
25
+ directory = new(:key => data['Name'])
26
+ options = {}
27
+ for k, v in data
28
+ if ['Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(k)
29
+ options[k] = v
30
+ end
31
+ end
32
+ directory.files.merge_attributes(options)
33
+ directory.files.load(data['Contents'])
34
+ directory
35
+ rescue Excon::Errors::NotFound
36
+ nil
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,48 @@
1
+ require 'fog/model'
2
+ require 'fog/google/models/storage/files'
3
+
4
+ module Fog
5
+ module Google
6
+ class Storage
7
+
8
+ class Directory < Fog::Model
9
+ extend Fog::Deprecation
10
+ deprecate(:name, :key)
11
+ deprecate(:name=, :key=)
12
+
13
+ identity :key, :aliases => ['Name', 'name']
14
+
15
+ attribute :creation_date, :aliases => 'CreationDate'
16
+
17
+ def destroy
18
+ requires :key
19
+ connection.delete_bucket(key)
20
+ true
21
+ rescue Excon::Errors::NotFound
22
+ false
23
+ end
24
+
25
+ def files
26
+ @files ||= begin
27
+ Fog::Google::Storage::Files.new(
28
+ :directory => self,
29
+ :connection => connection
30
+ )
31
+ end
32
+ end
33
+
34
+ def save
35
+ requires :key
36
+ options = {}
37
+ if @location
38
+ options['LocationConstraint'] = @location
39
+ end
40
+ connection.put_bucket(key, options)
41
+ true
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,87 @@
1
+ require 'fog/model'
2
+
3
+ module Fog
4
+ module Google
5
+ class Storage
6
+
7
+ class File < Fog::Model
8
+
9
+ identity :key, :aliases => 'Key'
10
+
11
+ attr_accessor :body
12
+ attribute :content_length, :aliases => 'Content-Length'
13
+ attribute :content_type, :aliases => 'Content-Type'
14
+ attribute :etag, :aliases => ['Etag', 'ETag']
15
+ attribute :last_modified, :aliases => ['Last-Modified', 'LastModified']
16
+ attribute :owner, :aliases => 'Owner'
17
+ attribute :size, :aliases => 'Size'
18
+ attribute :storage_class, :aliases => 'StorageClass'
19
+
20
+ def body
21
+ @body ||= if last_modified && (file = collection.get(identity))
22
+ file.body
23
+ else
24
+ ''
25
+ end
26
+ end
27
+
28
+ def directory
29
+ @directory
30
+ end
31
+
32
+ def copy(target_directory_key, target_file_key)
33
+ requires :directory, :key
34
+ data = connection.copy_object(directory.key, @key, target_directory_key, target_file_key).body
35
+ target_directory = connection.directories.new(:key => target_directory_key)
36
+ target_file = target_directory.files.new(attributes.merge!(:key => target_file_key))
37
+ copy_data = {}
38
+ for key, value in data
39
+ if ['ETag', 'LastModified'].include?(key)
40
+ copy_data[key] = value
41
+ end
42
+ end
43
+ target_file.merge_attributes(copy_data)
44
+ target_file
45
+ end
46
+
47
+ def destroy
48
+ requires :directory, :key
49
+ begin
50
+ connection.delete_object(directory.key, @key)
51
+ rescue Excon::Errors::NotFound
52
+ end
53
+ true
54
+ end
55
+
56
+ def owner=(new_owner)
57
+ if new_owner
58
+ @owner = {
59
+ :display_name => new_owner['DisplayName'],
60
+ :id => new_owner['ID']
61
+ }
62
+ end
63
+ end
64
+
65
+ def save(options = {})
66
+ requires :body, :directory, :key
67
+ data = connection.put_object(directory.key, @key, @body, options)
68
+ @etag = data.headers['ETag']
69
+ true
70
+ end
71
+
72
+ def url(expires)
73
+ requires :key
74
+ collection.get_url(key, expires)
75
+ end
76
+
77
+ private
78
+
79
+ def directory=(new_directory)
80
+ @directory = new_directory
81
+ end
82
+
83
+ end
84
+
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,94 @@
1
+ require 'fog/collection'
2
+ require 'fog/google/models/storage/file'
3
+
4
+ module Fog
5
+ module Google
6
+ class Storage
7
+
8
+ class Files < Fog::Collection
9
+
10
+ attribute :delimiter, :aliases => 'Delimiter'
11
+ attribute :directory
12
+ attribute :is_truncated, :aliases => 'IsTruncated'
13
+ attribute :marker, :aliases => 'Marker'
14
+ attribute :max_keys, :aliases => ['MaxKeys', 'max-keys']
15
+ attribute :prefix, :aliases => 'Prefix'
16
+
17
+ model Fog::Google::Storage::File
18
+
19
+ def all(options = {})
20
+ requires :directory
21
+ options = {
22
+ 'delimiter' => @delimiter,
23
+ 'marker' => @marker,
24
+ 'max-keys' => @max_keys,
25
+ 'prefix' => @prefix
26
+ }.merge!(options)
27
+ options = options.reject {|key,value| value.nil? || value.to_s.empty?}
28
+ merge_attributes(options)
29
+ parent = directory.collection.get(
30
+ directory.key,
31
+ options
32
+ )
33
+ if parent
34
+ merge_attributes(parent.files.attributes)
35
+ load(parent.files.map {|file| file.attributes})
36
+ else
37
+ nil
38
+ end
39
+ end
40
+
41
+ def get(key, options = {}, &block)
42
+ requires :directory
43
+ data = connection.get_object(directory.key, key, options, &block)
44
+ file_data = {
45
+ :body => data.body,
46
+ :key => key
47
+ }
48
+ for key, value in data.headers
49
+ if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key)
50
+ file_data[key] = value
51
+ end
52
+ end
53
+ new(file_data)
54
+ rescue Excon::Errors::NotFound
55
+ nil
56
+ end
57
+
58
+ def get_url(key, expires)
59
+ requires :directory
60
+ connection.get_object_url(directory.key, key, expires)
61
+ end
62
+
63
+ def head(key, options = {})
64
+ requires :directory
65
+ data = connection.head_object(directory.key, key, options)
66
+ file_data = {
67
+ :key => key
68
+ }
69
+ for key, value in data.headers
70
+ if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key)
71
+ file_data[key] = value
72
+ end
73
+ end
74
+ new(file_data)
75
+ rescue Excon::Errors::NotFound
76
+ nil
77
+ end
78
+
79
+ def new(attributes = {})
80
+ requires :directory
81
+ super({ :directory => directory }.merge!(attributes))
82
+ end
83
+
84
+ private
85
+
86
+ def directory=(new_directory)
87
+ @directory = new_directory
88
+ end
89
+
90
+ end
91
+
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,46 @@
1
+ module Fog
2
+ module Parsers
3
+ module Google
4
+ module Storage
5
+
6
+ class AccessControlList < Fog::Parsers::Base
7
+
8
+ def reset
9
+ @in_access_control_list = false
10
+ @grant = { 'Grantee' => {} }
11
+ @response = { 'Owner' => {}, 'AccessControlList' => [] }
12
+ end
13
+
14
+ def start_element(name, attrs = [])
15
+ super
16
+ if name == 'AccessControlList'
17
+ @in_access_control_list = true
18
+ end
19
+ end
20
+
21
+ def end_element(name)
22
+ case name
23
+ when 'AccessControlList'
24
+ @in_access_control_list = false
25
+ when 'Grant'
26
+ @response['AccessControlList'] << @grant
27
+ @grant = { 'Grantee' => {} }
28
+ when 'DisplayName', 'ID'
29
+ if @in_access_control_list
30
+ @grant['Grantee'][name] = @value
31
+ else
32
+ @response['Owner'][name] = @value
33
+ end
34
+ when 'Permission'
35
+ @grant[name] = @value
36
+ when 'URI'
37
+ @grant['Grantee'][name] = @value
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end