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
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Parsers
3
+ module Google
4
+ module Storage
5
+
6
+ class CopyObject < Fog::Parsers::Base
7
+
8
+ def end_element(name)
9
+ case name
10
+ when 'ETag'
11
+ @response[name] = @value.gsub('"', '')
12
+ when 'LastModified'
13
+ @response[name] = Time.parse(@value)
14
+ end
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,46 @@
1
+ module Fog
2
+ module Parsers
3
+ module Google
4
+ module Storage
5
+
6
+ class GetBucket < Fog::Parsers::Base
7
+
8
+ def reset
9
+ @object = { 'Owner' => {} }
10
+ @response = { 'Contents' => [] }
11
+ end
12
+
13
+ def end_element(name)
14
+ case name
15
+ when 'Contents'
16
+ @response['Contents'] << @object
17
+ @object = { 'Owner' => {} }
18
+ when 'DisplayName', 'ID'
19
+ @object['Owner'][name] = @value
20
+ when 'ETag'
21
+ @object[name] = @value.gsub('"', '')
22
+ when 'IsTruncated'
23
+ if @value == 'true'
24
+ @response['IsTruncated'] = true
25
+ else
26
+ @response['IsTruncated'] = false
27
+ end
28
+ when 'LastModified'
29
+ @object['LastModified'] = Time.parse(@value)
30
+ when 'Marker', 'Name', 'Prefix'
31
+ @response[name] = @value
32
+ when 'MaxKeys'
33
+ @response['MaxKeys'] = @value.to_i
34
+ when 'Size'
35
+ @object['Size'] = @value.to_i
36
+ when 'Delimeter', 'Key', 'Name', 'StorageClass'
37
+ @object[name] = @value
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,40 @@
1
+ module Fog
2
+ module Parsers
3
+ module Google
4
+ module Storage
5
+
6
+ class AccessControlList < Fog::Parsers::Base
7
+
8
+ def reset
9
+ @grant = { 'Grantee' => {} }
10
+ @response = { 'BucketLoggingStatus' => {} }
11
+ end
12
+
13
+ def end_element(name)
14
+ case name
15
+ when 'DisplayName', 'ID'
16
+ if @in_access_control_list
17
+ @grant['Grantee'][name] = @value
18
+ else
19
+ @response['Owner'][name] = @value
20
+ end
21
+ when 'Grant'
22
+ @response['BucketLoggingStatus']['LoggingEnabled']['TargetGrants'] << @grant
23
+ @grant = { 'Grantee' => {} }
24
+ when 'LoggingEnabled'
25
+ @response['BucketLoggingStatus']['LoggingEnabled'] = { 'TargetGrants' => [] }
26
+ when 'Permission'
27
+ @grant[name] = @value
28
+ when 'TargetBucket', 'TargetPrefix'
29
+ @response['BucketLoggingStatus'][name] = @value
30
+ when 'URI'
31
+ @grant['Grantee'][name] = @value
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,88 @@
1
+ module Fog
2
+ module Parsers
3
+ module Google
4
+ module Storage
5
+
6
+ class GetBucketObjectVersions < Fog::Parsers::Base
7
+
8
+ def reset
9
+ @delete_marker = { 'Owner' => {} }
10
+ @version = { 'Owner' => {} }
11
+
12
+ @in_delete_marke = false
13
+ @in_version = false
14
+
15
+ @response = { 'Versions' => [] }
16
+ end
17
+
18
+ def start_element(name, attrs = [])
19
+ super
20
+ case name
21
+ when 'DeleteMarker'
22
+ @in_delete_marker = true
23
+ when 'Version'
24
+ @in_version = true
25
+ end
26
+ end
27
+
28
+ def end_element(name)
29
+ case name
30
+ when 'DeleteMarker'
31
+ @response['Versions'] << {'DeleteMarker' => @delete_marker }
32
+ @delete_marker = { 'Owner' => {} }
33
+ @in_delete_marker = false
34
+ when 'Version'
35
+ @response['Versions'] << {'Version' => @version }
36
+ @version = { 'Owner' => {} }
37
+ @in_version = false
38
+ when 'DisplayName', 'ID'
39
+ if @in_delete_marker
40
+ @delete_marker
41
+ elsif @in_version
42
+ @version
43
+ end['Owner'][name] = @value
44
+ when 'ETag'
45
+ @version[name] = @value.gsub('"', '')
46
+ when 'IsLatest'
47
+ if @in_delete_marker
48
+ @delete_marker
49
+ elsif @in_version
50
+ @version
51
+ end['IsLatest'] = if @value == 'true'
52
+ true
53
+ else
54
+ false
55
+ end
56
+ when 'IsTruncated'
57
+ if @value == 'true'
58
+ @response['IsTruncated'] = true
59
+ else
60
+ @response['IsTruncated'] = false
61
+ end
62
+ when 'LastModified'
63
+ if @in_delete_marker
64
+ @delete_marker
65
+ elsif @in_version
66
+ @version
67
+ end['LastModified'] = Time.parse(@value)
68
+ when 'KeyMarker', 'Name', 'Prefix', 'VersionIdMarker'
69
+ @response[name] = @value
70
+ when 'MaxKeys'
71
+ @response['MaxKeys'] = @value.to_i
72
+ when 'Size'
73
+ @version['Size'] = @value.to_i
74
+ when 'Key', 'Name', 'StorageClass', 'VersionId'
75
+ if @in_delete_marker
76
+ @delete_marker
77
+ elsif @in_version
78
+ @version
79
+ end[name] = @value
80
+ end
81
+ end
82
+
83
+ end
84
+
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,24 @@
1
+ module Fog
2
+ module Parsers
3
+ module Google
4
+ module Storage
5
+
6
+ class GetBucketVersioning < Fog::Parsers::Base
7
+
8
+ def reset
9
+ @response = { 'VersioningConfiguration' => {} }
10
+ end
11
+
12
+ def end_element(name)
13
+ case name
14
+ when 'Status'
15
+ @response['VersioningConfiguration'][name] = @value
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ module Fog
2
+ module Parsers
3
+ module Google
4
+ module Storage
5
+
6
+ class GetRequestPayment < Fog::Parsers::Base
7
+
8
+ def end_element(name)
9
+ case name
10
+ when 'Payer'
11
+ @response[name] = @value
12
+ end
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,32 @@
1
+ module Fog
2
+ module Parsers
3
+ module Google
4
+ module Storage
5
+
6
+ class GetService < Fog::Parsers::Base
7
+
8
+ def reset
9
+ @bucket = {}
10
+ @response = { 'Owner' => {}, 'Buckets' => [] }
11
+ end
12
+
13
+ def end_element(name)
14
+ case name
15
+ when 'Bucket'
16
+ @response['Buckets'] << @bucket
17
+ @bucket = {}
18
+ when 'CreationDate'
19
+ @bucket['CreationDate'] = Time.parse(@value)
20
+ when 'DisplayName', 'ID'
21
+ @response['Owner'][name] = @value
22
+ when 'Name'
23
+ @bucket[name] = @value
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,72 @@
1
+ module Fog
2
+ module Google
3
+ class Storage
4
+ class Real
5
+
6
+ require 'fog/google/parsers/storage/copy_object'
7
+
8
+ # Copy an object from one Google Storage bucket to another
9
+ #
10
+ # ==== Parameters
11
+ # * source_bucket_name<~String> - Name of source bucket
12
+ # * source_object_name<~String> - Name of source object
13
+ # * target_bucket_name<~String> - Name of bucket to create copy in
14
+ # * target_object_name<~String> - Name for new copy of object
15
+ # * options<~Hash>:
16
+ # * 'x-goog-metadata-directive'<~String> - Specifies whether to copy metadata from source or replace with data in request. Must be in ['COPY', 'REPLACE']
17
+ # * 'x-goog-copy_source-if-match'<~String> - Copies object if its etag matches this value
18
+ # * 'x-goog-copy_source-if-modified_since'<~Time> - Copies object it it has been modified since this time
19
+ # * 'x-goog-copy_source-if-none-match'<~String> - Copies object if its etag does not match this value
20
+ # * 'x-goog-copy_source-if-unmodified-since'<~Time> - Copies object it it has not been modified since this time
21
+ #
22
+ # ==== Returns
23
+ # * response<~Excon::Response>:
24
+ # * body<~Hash>:
25
+ # * 'ETag'<~String> - etag of new object
26
+ # * 'LastModified'<~Time> - date object was last modified
27
+ #
28
+ def copy_object(source_bucket_name, source_object_name, target_bucket_name, target_object_name, options = {})
29
+ headers = { 'x-goog-copy-source' => "/#{source_bucket_name}/#{source_object_name}" }.merge!(options)
30
+ request({
31
+ :expects => 200,
32
+ :headers => headers,
33
+ :host => "#{target_bucket_name}.#{@host}",
34
+ :method => 'PUT',
35
+ :parser => Fog::Parsers::Google::Storage::CopyObject.new,
36
+ :path => CGI.escape(target_object_name)
37
+ })
38
+ end
39
+
40
+ end
41
+
42
+ class Mock
43
+
44
+ def copy_object(source_bucket_name, source_object_name, target_bucket_name, target_object_name, options = {})
45
+ response = Excon::Response.new
46
+ source_bucket = @data[:buckets][source_bucket_name]
47
+ source_object = source_bucket && source_bucket[:objects][source_object_name]
48
+ target_bucket = @data[:buckets][target_bucket_name]
49
+
50
+ if source_object && target_bucket
51
+ response.status = 200
52
+ target_object = source_object.dup
53
+ target_object.merge!({
54
+ 'Name' => target_object_name
55
+ })
56
+ target_bucket[:objects][target_object_name] = target_object
57
+ response.body = {
58
+ 'ETag' => target_object['ETag'],
59
+ 'LastModified' => Time.parse(target_object['LastModified'])
60
+ }
61
+ else
62
+ response.status = 404
63
+ raise(Excon::Errors.status_error({:expects => 200}, response))
64
+ end
65
+
66
+ response
67
+ end
68
+
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,46 @@
1
+ module Fog
2
+ module Google
3
+ class Storage
4
+ class Real
5
+
6
+ # Delete an Google Storage bucket
7
+ #
8
+ # ==== Parameters
9
+ # * bucket_name<~String> - name of bucket to delete
10
+ #
11
+ # ==== Returns
12
+ # * response<~Excon::Response>:
13
+ # * status<~Integer> - 204
14
+ def delete_bucket(bucket_name)
15
+ request({
16
+ :expects => 204,
17
+ :headers => {},
18
+ :host => "#{bucket_name}.#{@host}",
19
+ :method => 'DELETE'
20
+ })
21
+ end
22
+
23
+ end
24
+
25
+ class Mock
26
+
27
+ def delete_bucket(bucket_name)
28
+ response = Excon::Response.new
29
+ if @data[:buckets][bucket_name].nil?
30
+ response.status = 404
31
+ raise(Excon::Errors.status_error({:expects => 204}, response))
32
+ elsif @data[:buckets][bucket_name] && !@data[:buckets][bucket_name][:objects].empty?
33
+ response.status = 409
34
+ raise(Excon::Errors.status_error({:expects => 204}, response))
35
+ else
36
+ @data[:buckets].delete(bucket_name)
37
+ response.status = 204
38
+ end
39
+ response
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,50 @@
1
+ module Fog
2
+ module Google
3
+ class Storage
4
+ class Real
5
+
6
+ # Delete an object from Google Storage
7
+ #
8
+ # ==== Parameters
9
+ # * bucket_name<~String> - Name of bucket containing object to delete
10
+ # * object_name<~String> - Name of object to delete
11
+ #
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * status<~Integer> - 204
15
+ def delete_object(bucket_name, object_name)
16
+ request({
17
+ :expects => 204,
18
+ :headers => {},
19
+ :host => "#{bucket_name}.#{@host}",
20
+ :idempotent => true,
21
+ :method => 'DELETE',
22
+ :path => CGI.escape(object_name)
23
+ })
24
+ end
25
+
26
+ end
27
+
28
+ class Mock
29
+
30
+ def delete_object(bucket_name, object_name)
31
+ response = Excon::Response.new
32
+ if bucket = @data[:buckets][bucket_name]
33
+ if object = bucket[:objects][object_name]
34
+ response.status = 204
35
+ bucket[:objects].delete(object_name)
36
+ else
37
+ response.status = 404
38
+ raise(Excon::Errors.status_error({:expects => 204}, response))
39
+ end
40
+ else
41
+ response.status = 404
42
+ raise(Excon::Errors.status_error({:expects => 204}, response))
43
+ end
44
+ response
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end