fog 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe 'Fog::Google::Storage::Directories' do
4
+
5
+ describe "#all" do
6
+
7
+ it "should include persisted directories" do
8
+ @directory = Google[:storage].directories.create(:key => 'fogdirectorykey')
9
+ Google[:storage].directories.all.map {|directory| @directory.key}.should include('fogdirectorykey')
10
+ @directory.destroy
11
+ end
12
+
13
+ end
14
+
15
+ describe "#create" do
16
+
17
+ it "should exist on google storage" do
18
+ directory = Google[:storage].directories.create(:key => 'fogdirectorykey')
19
+ Google[:storage].directories.get(directory.key).should_not be_nil
20
+ directory.destroy
21
+ end
22
+
23
+ end
24
+
25
+ describe "#get" do
26
+
27
+ it "should return a Fog::Google::Storage::Directory if a matching directory exists" do
28
+ directory = Google[:storage].directories.create(:key => 'fogdirectorykey')
29
+ get = Google[:storage].directories.get('fogdirectorykey')
30
+ directory.attributes.should == get.attributes
31
+ directory.destroy
32
+ end
33
+
34
+ it "should return nil if no matching directory exists" do
35
+ Google[:storage].directories.get('fognotadirectory').should be_nil
36
+ end
37
+
38
+ end
39
+
40
+ describe "#reload" do
41
+
42
+ it "should reload data" do
43
+ directories = Google[:storage].directories
44
+ directories.should == directories.reload
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,83 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+ require File.dirname(__FILE__) + '/../../../../lib/fog/google/models/storage/directory'
3
+
4
+ describe 'Fog::Google::Storage::Directory' do
5
+
6
+ describe "#initialize" do
7
+
8
+ it "should remap attributes from parser" do
9
+ now = Time.now
10
+ directory = Fog::Google::Storage::Directory.new(
11
+ 'CreationDate' => now,
12
+ 'Name' => 'directorykey'
13
+ )
14
+ directory.creation_date.should == now
15
+ directory.key.should == 'directorykey'
16
+ end
17
+
18
+ end
19
+
20
+ describe "#collection" do
21
+
22
+ it "should be the directories the directory is related to" do
23
+ directories = Google[:storage].directories
24
+ directories.new.collection.should == directories
25
+ end
26
+
27
+ end
28
+
29
+ describe "#destroy" do
30
+
31
+ it "should return true if the directory is deleted" do
32
+ directory = Google[:storage].directories.create(:key => 'fogmodeldirectory')
33
+ directory.destroy.should be_true
34
+ end
35
+
36
+ it "should return false if the directory does not exist" do
37
+ directory = Google[:storage].directories.new(:key => 'fogmodeldirectory')
38
+ directory.destroy.should be_false
39
+ end
40
+
41
+ end
42
+
43
+ describe "#reload" do
44
+
45
+ before(:each) do
46
+ @directory = Google[:storage].directories.create(:key => 'fogmodeldirectory')
47
+ @reloaded = @directory.reload
48
+ end
49
+
50
+ after(:each) do
51
+ @directory.destroy
52
+ end
53
+
54
+ it "should reset attributes to remote state" do
55
+ @directory.attributes.should == @reloaded.attributes
56
+ end
57
+
58
+ end
59
+
60
+ describe "#save" do
61
+
62
+ before(:each) do
63
+ @directory = Google[:storage].directories.new(:key => 'fogmodeldirectory')
64
+ end
65
+
66
+ it "should not exist in directories before save" do
67
+ Google[:storage].directories.all.map {|directory| directory.key}.include?(@directory.key).should be_false
68
+ end
69
+
70
+ it "should return true when it succeeds" do
71
+ @directory.save.should be_true
72
+ @directory.destroy
73
+ end
74
+
75
+ it "should exist in directories after save" do
76
+ @directory.save
77
+ Google[:storage].directories.all.map {|directory| directory.key}.include?(@directory.key).should be_true
78
+ @directory.destroy
79
+ end
80
+
81
+ end
82
+
83
+ end
@@ -0,0 +1,121 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe 'Fog::Google::Storage::File' do
4
+
5
+ before(:each) do
6
+ @directory = Google[:storage].directories.create(:key => 'fogdirectoryname')
7
+ end
8
+
9
+ after(:each) do
10
+ @directory.destroy
11
+ end
12
+
13
+ describe "#initialize" do
14
+
15
+ it "should remap attributes from parser" do
16
+ now = Time.now
17
+ directory = Fog::Google::Storage::File.new(
18
+ 'Content-Length' => 10,
19
+ 'Content-Type' => 'contenttype',
20
+ 'Etag' => 'etag',
21
+ 'Key' => 'key',
22
+ 'Last-Modified' => now,
23
+ 'Size' => 10,
24
+ 'StorageClass' => 'storageclass'
25
+ )
26
+ directory.content_length == 10
27
+ directory.content_type.should == 'contenttype'
28
+ directory.etag.should == 'etag'
29
+ directory.key.should == 'key'
30
+ directory.last_modified.should == now
31
+ directory.size.should == 10
32
+ directory.storage_class.should == 'storageclass'
33
+
34
+ directory = Fog::Google::Storage::File.new(
35
+ 'ETag' => 'etag',
36
+ 'LastModified' => now
37
+ )
38
+ directory.etag.should == 'etag'
39
+ directory.last_modified.should == now
40
+ end
41
+
42
+ end
43
+
44
+ describe "#directory" do
45
+
46
+ it "should be the directory the file is related to" do
47
+ @file = @directory.files.new(:key => 'foo')
48
+ @file.directory.should == @directory
49
+ end
50
+
51
+ end
52
+
53
+ describe "#copy" do
54
+
55
+ it "should return a Fog::Google::Storage::File with matching attributes" do
56
+ other_directory = Google[:storage].directories.create(:key => 'fogotherdirectoryname')
57
+ data = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
58
+ file = @directory.files.create(:key => 'fogfilename', :body => data)
59
+ other_file = file.copy('fogotherdirectoryname', 'fogotherfilename')
60
+ file.reload.attributes.reject{|key,value| [:key, :last_modified].include?(key)}.should == other_file.reload.attributes.reject{|key,value| [:key, :last_modified].include?(key)}
61
+ other_file.destroy
62
+ file.destroy
63
+ other_directory.destroy
64
+ end
65
+
66
+ end
67
+
68
+ describe "#destroy" do
69
+
70
+ it "should return true if the file is deleted" do
71
+ data = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
72
+ file = @directory.files.create(:key => 'fogfilename', :body => data)
73
+ file.destroy.should be_true
74
+ end
75
+
76
+ it "should return true if the file does not exist" do
77
+ file = @directory.files.new(:key => 'fogfilename')
78
+ file.destroy.should be_true
79
+ end
80
+
81
+ end
82
+
83
+ describe "#reload" do
84
+
85
+ it "should reset attributes to remote state" do
86
+ data = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
87
+ file = @directory.files.create(:key => 'fogfilename', :body => data)
88
+ file.last_modified = Time.now
89
+ file.reload.attributes.should == file.attributes
90
+ file.destroy
91
+ end
92
+
93
+ end
94
+
95
+ describe "#save" do
96
+
97
+ it "should return the success value" do
98
+ data = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
99
+ file = @directory.files.new(:key => 'fogfilename', :body => data)
100
+ file.save.should be_true
101
+ file.destroy
102
+ end
103
+
104
+ end
105
+
106
+ # describe "#url" do
107
+ #
108
+ # it "should return a signed expiring url" do
109
+ # data = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
110
+ # file = @directory.files.create(:key => 'fogfilename', :body => data)
111
+ # url = file.url(Time.now + 60 * 10)
112
+ # url.should include("fogfilename", "Expires")
113
+ # unless Fog.mocking?
114
+ # open(url).read.should == File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r').read
115
+ # end
116
+ # file.destroy
117
+ # end
118
+ #
119
+ # end
120
+
121
+ end
@@ -0,0 +1,141 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+ require 'pp'
3
+
4
+ describe 'Fog::Google::Storage::Files' do
5
+
6
+ before(:each) do
7
+ dirname = "fogdirname"
8
+ # dirname = "fog#{Time.now.to_f}"
9
+ @directory = Google[:storage].directories.create(:key => dirname)
10
+ end
11
+
12
+ after(:each) do
13
+ until @directory.files.reload.empty?
14
+ @directory.files.each {|file| file.destroy}
15
+ end
16
+ @directory.destroy
17
+ end
18
+
19
+ describe "#initialize" do
20
+
21
+ it "should remap attributes from parser" do
22
+ files = Fog::Google::Storage::Files.new(
23
+ 'IsTruncated' => true,
24
+ 'Marker' => 'marker',
25
+ 'MaxKeys' => 1,
26
+ 'Prefix' => 'prefix'
27
+ )
28
+ files.is_truncated.should == true
29
+ files.marker.should == 'marker'
30
+ files.max_keys.should == 1
31
+ files.prefix.should == 'prefix'
32
+ end
33
+
34
+ end
35
+
36
+ describe "#all" do
37
+
38
+ it "should return nil if the directory does not exist" do
39
+ directory = Google[:storage].directories.new(:key => 'notadirectory')
40
+ directory.files.all.should be_nil
41
+ end
42
+
43
+ it "should return 10 files and report truncated" do
44
+ 10.times do |n|
45
+ @directory.files.create(:key => "file-#{n}")
46
+ end
47
+ response = @directory.files.all
48
+ response.should have(10).items
49
+ response.is_truncated.should_not be_true
50
+ end
51
+
52
+ # it "should limit the max_keys to 10" do
53
+ # 10.times do |n|
54
+ # @directory.files.create(:key => "file-#{n}")
55
+ # end
56
+ # response = @directory.files.all(:max_keys => 20)
57
+ # response.should have(10).items
58
+ # response.max_keys.should == 20
59
+ # response.is_truncated.should be_true
60
+ # end
61
+
62
+ end
63
+
64
+ describe "#create" do
65
+
66
+ it "should exist on google storage" do
67
+ data = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
68
+ file = @directory.files.create(:key => 'fogfilename', :body => data)
69
+ @directory.files.get('fogfilename').should_not be_nil
70
+ file.destroy
71
+ end
72
+
73
+ end
74
+
75
+ describe "#get" do
76
+
77
+ before(:each) do
78
+ @data = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
79
+ @file = @directory.files.create(:key => 'fogfilename', :body => @data)
80
+ end
81
+
82
+ after(:each) do
83
+ @file.destroy
84
+ end
85
+
86
+ it "should return a Fog::Google::Storage::File with metadata and data" do
87
+ @file.reload
88
+ @file.body.should_not be_nil
89
+ # @file.content_length.should_not be_nil
90
+ @file.etag.should_not be_nil
91
+ @file.last_modified.should_not be_nil
92
+ @file.destroy
93
+ end
94
+
95
+ it "should return chunked data if given a block" do
96
+ data = ''
97
+ @directory.files.get('fogfilename') do |chunk|
98
+ data << chunk
99
+ end
100
+ data.should == File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r').read
101
+ end
102
+
103
+ end
104
+
105
+ describe "#get_url" do
106
+
107
+ it "should return a url" do
108
+ data = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
109
+ file = @directory.files.new(:key => 'fogfilename', :body => data)
110
+ file.save({'x-goog-acl' => 'public-read'})
111
+ url = @directory.files.get_url('fogfilename', Time.now + 60 * 10)
112
+ unless Fog.mocking?
113
+ open(url).read.should == File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r').read
114
+ end
115
+ file.destroy
116
+ end
117
+
118
+ end
119
+
120
+ describe "#head" do
121
+
122
+ it "should return a Fog::Google::Storage::File with metadata" do
123
+ data = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
124
+ file = @directory.files.create(:key => 'fogfilename', :body => data)
125
+ file = @directory.files.get('fogfilename')
126
+ file.etag.should_not be_nil
127
+ file.last_modified.should_not be_nil
128
+ file.destroy
129
+ end
130
+
131
+ end
132
+
133
+ describe "#reload" do
134
+
135
+ it "should reload data" do
136
+ @directory.files.reload.should == @directory.files
137
+ end
138
+
139
+ end
140
+
141
+ end
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe 'Storage.copy_object' do
4
+ describe 'success' do
5
+
6
+ before(:each) do
7
+ Google[:storage].put_bucket('fogcopyobjectsource')
8
+ Google[:storage].put_object('fogcopyobjectsource', 'fog_copy_object_source', lorem_file)
9
+ Google[:storage].put_bucket('fogcopyobjectdestination')
10
+ end
11
+
12
+ after(:each) do
13
+ Google[:storage].delete_object('fogcopyobjectdestination', 'fog_copy_object_destination')
14
+ Google[:storage].delete_bucket('fogcopyobjectdestination')
15
+ Google[:storage].delete_object('fogcopyobjectsource', 'fog_copy_object_source')
16
+ Google[:storage].delete_bucket('fogcopyobjectsource')
17
+ end
18
+
19
+ it 'should return proper attributes' do
20
+ actual = Google[:storage].copy_object(
21
+ 'fogcopyobjectsource', 'fog_copy_object_source',
22
+ 'fogcopyobjectdestination', 'fog_copy_object_destination'
23
+ )
24
+ actual.status.should == 200
25
+ actual.body['ETag'].should be_a(String)
26
+ actual.body['LastModified'].should be_a(Time)
27
+ end
28
+
29
+ end
30
+ describe 'failure' do
31
+
32
+ it 'should raise a NotFound error if the source_bucket does not exist' do
33
+ lambda {
34
+ Google[:storage].copy_object(
35
+ 'fognotabucket', 'fog_copy_object_source',
36
+ 'fogcopyobjectdestination', 'fog_copy_object_destination'
37
+ )
38
+ }.should raise_error(Excon::Errors::NotFound)
39
+ end
40
+
41
+ it 'should raise a NotFound error if the source_object does not exist' do
42
+ lambda {
43
+ Google[:storage].copy_object(
44
+ 'fogcopyobjectsource', 'fog_not_an_object',
45
+ 'fogcopyobjectdestination', 'fog_copy_object_destination'
46
+ )
47
+ }.should raise_error(Excon::Errors::NotFound)
48
+ end
49
+
50
+ it 'should raise a NotFound error if the target_bucket does not exist' do
51
+ lambda {
52
+ Google[:storage].copy_object(
53
+ 'fogcopyobjectsource', 'fog_copy_object_source',
54
+ 'fognotabucket', 'fog_copy_object_destination'
55
+ )
56
+ }.should raise_error(Excon::Errors::NotFound)
57
+ end
58
+
59
+ end
60
+
61
+ end