fog-aliyun 0.0.7

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 (85) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/CODE_OF_CONDUCT.md +13 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +309 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +7 -0
  12. data/fog-aliyun.gemspec +30 -0
  13. data/lib/fog/aliyun.rb +19 -0
  14. data/lib/fog/aliyun/compute.rb +346 -0
  15. data/lib/fog/aliyun/models/compute/vpc.rb +69 -0
  16. data/lib/fog/aliyun/models/compute/vpcs.rb +89 -0
  17. data/lib/fog/aliyun/models/compute/vswitch.rb +70 -0
  18. data/lib/fog/aliyun/models/compute/vswitches.rb +87 -0
  19. data/lib/fog/aliyun/models/storage/directories.rb +45 -0
  20. data/lib/fog/aliyun/models/storage/directory.rb +48 -0
  21. data/lib/fog/aliyun/models/storage/file.rb +197 -0
  22. data/lib/fog/aliyun/models/storage/files.rb +178 -0
  23. data/lib/fog/aliyun/requests/compute/allocate_eip_address.rb +79 -0
  24. data/lib/fog/aliyun/requests/compute/allocate_public_ip_address.rb +63 -0
  25. data/lib/fog/aliyun/requests/compute/associate_eip_address.rb +66 -0
  26. data/lib/fog/aliyun/requests/compute/attach_disk.rb +82 -0
  27. data/lib/fog/aliyun/requests/compute/create_disk.rb +135 -0
  28. data/lib/fog/aliyun/requests/compute/create_image.rb +79 -0
  29. data/lib/fog/aliyun/requests/compute/create_security_group.rb +77 -0
  30. data/lib/fog/aliyun/requests/compute/create_security_group_ip_rule.rb +86 -0
  31. data/lib/fog/aliyun/requests/compute/create_security_group_sg_rule.rb +86 -0
  32. data/lib/fog/aliyun/requests/compute/create_server.rb +188 -0
  33. data/lib/fog/aliyun/requests/compute/create_snapshot.rb +60 -0
  34. data/lib/fog/aliyun/requests/compute/create_vpc.rb +73 -0
  35. data/lib/fog/aliyun/requests/compute/create_vswitch.rb +81 -0
  36. data/lib/fog/aliyun/requests/compute/delete_disk.rb +58 -0
  37. data/lib/fog/aliyun/requests/compute/delete_image.rb +58 -0
  38. data/lib/fog/aliyun/requests/compute/delete_security_group.rb +51 -0
  39. data/lib/fog/aliyun/requests/compute/delete_security_group_ip_rule.rb +85 -0
  40. data/lib/fog/aliyun/requests/compute/delete_security_group_sg_rule.rb +86 -0
  41. data/lib/fog/aliyun/requests/compute/delete_server.rb +48 -0
  42. data/lib/fog/aliyun/requests/compute/delete_snapshot.rb +45 -0
  43. data/lib/fog/aliyun/requests/compute/delete_vpc.rb +52 -0
  44. data/lib/fog/aliyun/requests/compute/delete_vswitch.rb +51 -0
  45. data/lib/fog/aliyun/requests/compute/detach_disk.rb +51 -0
  46. data/lib/fog/aliyun/requests/compute/join_security_group.rb +41 -0
  47. data/lib/fog/aliyun/requests/compute/leave_security_group.rb +41 -0
  48. data/lib/fog/aliyun/requests/compute/list_disks.rb +75 -0
  49. data/lib/fog/aliyun/requests/compute/list_eip_addresses.rb +81 -0
  50. data/lib/fog/aliyun/requests/compute/list_images.rb +85 -0
  51. data/lib/fog/aliyun/requests/compute/list_security_group_rules.rb +74 -0
  52. data/lib/fog/aliyun/requests/compute/list_security_groups.rb +81 -0
  53. data/lib/fog/aliyun/requests/compute/list_server_types.rb +77 -0
  54. data/lib/fog/aliyun/requests/compute/list_servers.rb +74 -0
  55. data/lib/fog/aliyun/requests/compute/list_snapshots.rb +86 -0
  56. data/lib/fog/aliyun/requests/compute/list_vpcs.rb +64 -0
  57. data/lib/fog/aliyun/requests/compute/list_vswitchs.rb +67 -0
  58. data/lib/fog/aliyun/requests/compute/list_zones.rb +44 -0
  59. data/lib/fog/aliyun/requests/compute/modify_vpc.rb +73 -0
  60. data/lib/fog/aliyun/requests/compute/modify_vswitch.rb +73 -0
  61. data/lib/fog/aliyun/requests/compute/reboot_server.rb +44 -0
  62. data/lib/fog/aliyun/requests/compute/release_eip_address.rb +53 -0
  63. data/lib/fog/aliyun/requests/compute/start_server.rb +42 -0
  64. data/lib/fog/aliyun/requests/compute/stop_server.rb +42 -0
  65. data/lib/fog/aliyun/requests/compute/unassociate_eip_address.rb +56 -0
  66. data/lib/fog/aliyun/requests/storage/copy_object.rb +42 -0
  67. data/lib/fog/aliyun/requests/storage/delete_bucket.rb +30 -0
  68. data/lib/fog/aliyun/requests/storage/delete_container.rb +38 -0
  69. data/lib/fog/aliyun/requests/storage/delete_object.rb +53 -0
  70. data/lib/fog/aliyun/requests/storage/get_bucket.rb +148 -0
  71. data/lib/fog/aliyun/requests/storage/get_container.rb +72 -0
  72. data/lib/fog/aliyun/requests/storage/get_containers.rb +76 -0
  73. data/lib/fog/aliyun/requests/storage/get_object.rb +45 -0
  74. data/lib/fog/aliyun/requests/storage/get_object_http_url.rb +43 -0
  75. data/lib/fog/aliyun/requests/storage/get_object_https_url.rb +43 -0
  76. data/lib/fog/aliyun/requests/storage/head_object.rb +34 -0
  77. data/lib/fog/aliyun/requests/storage/list_buckets.rb +47 -0
  78. data/lib/fog/aliyun/requests/storage/list_objects.rb +104 -0
  79. data/lib/fog/aliyun/requests/storage/put_bucket.rb +23 -0
  80. data/lib/fog/aliyun/requests/storage/put_container.rb +35 -0
  81. data/lib/fog/aliyun/requests/storage/put_object.rb +199 -0
  82. data/lib/fog/aliyun/storage.rb +214 -0
  83. data/lib/fog/aliyun/version.rb +5 -0
  84. data/lib/fog/bin/aliyun.rb +31 -0
  85. metadata +227 -0
@@ -0,0 +1,43 @@
1
+ module Fog
2
+ module Storage
3
+ class Aliyun
4
+ class Real
5
+ # Get an expiring object http url
6
+ #
7
+ # ==== Parameters
8
+ # * container<~String> - Name of container containing object
9
+ # * object<~String> - Name of object to get expiring url for
10
+ # * expires<~Time> - An expiry time for this url
11
+ #
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~String> - url for object
15
+ def get_object_http_url_public(object, expires, options = {})
16
+ options = options.reject {|key, value| value.nil?}
17
+ bucket = options[:bucket]
18
+ bucket ||= @aliyun_oss_bucket
19
+ acl = get_bucket_acl(bucket)
20
+ location = get_bucket_location(bucket)
21
+
22
+ if "private" == acl
23
+ expires_time = (Time.now.to_i + expires).to_s
24
+ resource = bucket+'/'+object
25
+ signature = sign("GET", expires_time, nil, resource)
26
+ url = "http://"+bucket+"."+location+".aliyuncs.com/"+object+
27
+ "?OSSAccessKeyId="+@aliyun_accesskey_id+"&Expires="+expires_time+
28
+ "&Signature="+URI.encode(signature,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
29
+ elsif "public-read" == acl or "public-read-write" == acl
30
+ url = "http://"+bucket+"."+location+".aliyuncs.com/"+object
31
+ else
32
+ url = "acl is wrong with value:"+acl
33
+ end
34
+ end
35
+ end
36
+
37
+ class Mock
38
+ def get_object_http_url_public(object, expires, options = {})
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,43 @@
1
+ module Fog
2
+ module Storage
3
+ class Aliyun
4
+ class Real
5
+ # Get an expiring object https url from Cloud Files
6
+ #
7
+ # ==== Parameters
8
+ # * container<~String> - Name of container containing object
9
+ # * object<~String> - Name of object to get expiring url for
10
+ # * expires<~Time> - An expiry time for this url
11
+ #
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~String> - url for object
15
+ def get_object_https_url_public(object, expires, options = {})
16
+ options = options.reject {|key, value| value.nil?}
17
+ bucket = options[:bucket]
18
+ bucket ||= @aliyun_oss_bucket
19
+ acl = get_bucket_acl(bucket)
20
+ location = get_bucket_location(bucket)
21
+
22
+ if "private" == acl
23
+ expires_time = (Time.now.to_i + expires).to_s
24
+ resource = bucket+'/'+object
25
+ signature = sign("GET", expires_time, nil, resource)
26
+ url = "https://"+bucket+"."+location+".aliyuncs.com/"+object+
27
+ "?OSSAccessKeyId="+@aliyun_accesskey_id+"&Expires="+expires_time+
28
+ "&Signature="+URI.encode(signature,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
29
+ elsif "public-read" == acl or "public-read-write" == acl
30
+ url = "https://"+bucket+"."+location+".aliyuncs.com/"+object
31
+ else
32
+ url = "acl is wrong with value:"+acl
33
+ end
34
+ end
35
+ end
36
+
37
+ class Mock
38
+ def get_object_https_url_public(object, expires, options = {})
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,34 @@
1
+ module Fog
2
+ module Storage
3
+ class Aliyun
4
+ class Real
5
+ # Get headers for object
6
+ #
7
+ # ==== Parameters
8
+ # * object<~String> - Name of object to look for
9
+ #
10
+ def head_object(object, options={})
11
+ bucket = options[:bucket]
12
+ bucket ||= @aliyun_oss_bucket
13
+ location = get_bucket_location(bucket)
14
+ endpoint = "http://"+location+".aliyuncs.com"
15
+ resource = bucket+'/'+object
16
+ ret = request(
17
+ :expects => [200, 404],
18
+ :method => 'HEAD',
19
+ :path => object,
20
+ :bucket => bucket,
21
+ :resource => resource,
22
+ :endpoint => endpoint
23
+ )
24
+ return ret
25
+ end
26
+ end
27
+
28
+ class Mock
29
+ def head_object(object, options={})
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,47 @@
1
+ module Fog
2
+ module Storage
3
+ class Aliyun
4
+ class Real
5
+ def list_buckets(options={})
6
+ prefix = options[:prefix]
7
+ marker = options[:marker]
8
+ maxKeys = options[:maxKeys]
9
+
10
+ path = ""
11
+ if prefix
12
+ path+="?prefix="+prefix
13
+ if marker
14
+ path+="&marker="+marker
15
+ end
16
+ if maxKeys
17
+ path+="&max-keys="+maxKeys
18
+ end
19
+
20
+ elsif marker
21
+ path+="?marker="+marker
22
+ if maxKeys
23
+ path+="&max-keys="+maxKeys
24
+ end
25
+
26
+ elsif maxKeys
27
+ path+="?max-keys="+maxKeys
28
+ end
29
+
30
+ ret = request(
31
+ :expects => [200, 203],
32
+ :method => 'GET',
33
+ :path => path
34
+ )
35
+ xml = ret.data[:body]
36
+ result = XmlSimple.xml_in(xml)["Buckets"][0]
37
+ end
38
+
39
+ end
40
+
41
+ class Mock
42
+ def list_buckets(options={})
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,104 @@
1
+ module Fog
2
+ module Storage
3
+ class Aliyun
4
+ class Real
5
+ def list_objects(options={})
6
+ bucket = options[:bucket]
7
+ bucket ||= @aliyun_oss_bucket
8
+ prefix = options[:prefix]
9
+ marker = options[:marker]
10
+ maxKeys = options[:maxKeys]
11
+ delimiter = options[:delimiter]
12
+
13
+ path = ""
14
+ if prefix
15
+ path+="?prefix="+prefix
16
+ if marker
17
+ path+="&marker="+marker
18
+ end
19
+ if maxKeys
20
+ path+="&max-keys="+maxKeys
21
+ end
22
+ if delimiter
23
+ path+="&delimiter="+delimiter
24
+ end
25
+
26
+ elsif marker
27
+ path+="?marker="+marker
28
+ if maxKeys
29
+ path+="&max-keys="+maxKeys
30
+ end
31
+ if delimiter
32
+ path+="&delimiter="+delimiter
33
+ end
34
+
35
+ elsif maxKeys
36
+ path+="?max-keys="+maxKeys
37
+ if delimiter
38
+ path+="&delimiter="+delimiter
39
+ end
40
+ elsif delimiter
41
+ path+="?delimiter="+delimiter
42
+ end
43
+
44
+ location = get_bucket_location(bucket)
45
+ endpoint = "http://"+location+".aliyuncs.com"
46
+ resource = bucket+'/'
47
+ ret = request(
48
+ :expects => [200, 203, 400],
49
+ :method => 'GET',
50
+ :path => path,
51
+ :resource => resource,
52
+ :bucket => bucket
53
+ )
54
+ xml = ret.data[:body]
55
+ result = XmlSimple.xml_in(xml)
56
+ end
57
+
58
+ def list_multipart_uploads(bucket, endpoint, options = {})
59
+ if (nil == endpoint)
60
+ location = get_bucket_location(bucket)
61
+ endpoint = "http://"+location+".aliyuncs.com"
62
+ end
63
+ path = "?uploads"
64
+ resource = bucket+'/'+path
65
+
66
+ ret = request(
67
+ :expects => 200,
68
+ :method => 'GET',
69
+ :path => path,
70
+ :bucket => bucket,
71
+ :resource => resource,
72
+ :endpoint => endpoint
73
+ )
74
+ uploadid = XmlSimple.xml_in(ret.data[:body])["Upload"]
75
+ end
76
+
77
+ def list_parts(bucket, object, endpoint, uploadid, options = {})
78
+ if (nil == endpoint)
79
+ location = get_bucket_location(bucket)
80
+ endpoint = "http://"+location+".aliyuncs.com"
81
+ end
82
+ path = object+"?uploadId="+uploadid
83
+ resource = bucket+'/'+path
84
+
85
+ ret = request(
86
+ :expects => 200,
87
+ :method => 'GET',
88
+ :path => path,
89
+ :bucket => bucket,
90
+ :resource => resource,
91
+ :endpoint => endpoint
92
+ )
93
+ parts = XmlSimple.xml_in(ret.data[:body])["Part"]
94
+ end
95
+
96
+ end
97
+
98
+ class Mock
99
+ def list_objects(options={})
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,23 @@
1
+ module Fog
2
+ module Storage
3
+ class Aliyun
4
+ class Real
5
+ def put_bucket(bucketName)
6
+ resource = bucketName+'/'
7
+ ret = request(
8
+ :expects => [200, 203],
9
+ :method => 'PUT',
10
+ :resource => resource,
11
+ :bucket => bucketName
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def put_bucket(bucketName)
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ module Fog
2
+ module Storage
3
+ class Aliyun
4
+ class Real
5
+ # Create a new container
6
+ #
7
+ # ==== Parameters
8
+ # * name<~String> - Name for container
9
+ #
10
+ def put_container(name, options={})
11
+ bucket = options[:bucket]
12
+ bucket ||= @aliyun_oss_bucket
13
+ location = get_bucket_location(bucket)
14
+ endpoint = "http://"+location+".aliyuncs.com"
15
+
16
+ path = name+'/'
17
+ resource = bucket+'/'+name+'/'
18
+ request(
19
+ :expects => [200, 203],
20
+ :method => 'PUT',
21
+ :path => path,
22
+ :bucket => bucket,
23
+ :resource => resource,
24
+ :endpoint => endpoint
25
+ )
26
+ end
27
+ end
28
+
29
+ class Mock
30
+ def put_container(name, options={})
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,199 @@
1
+ module Fog
2
+ module Storage
3
+ class Aliyun
4
+ class Real
5
+ # Put details for object
6
+ #
7
+ # ==== Parameters
8
+ # * object<~String> - Name of object to look for
9
+ #
10
+ def put_object(object, file=nil, options={})
11
+
12
+ bucket = options[:bucket]
13
+ bucket ||= @aliyun_oss_bucket
14
+ location = get_bucket_location(bucket)
15
+ endpoint = "http://"+location+".aliyuncs.com"
16
+ if (nil == file)
17
+ return put_folder(bucket, object, endpoint)
18
+ end
19
+
20
+ #put multiparts if object's size is over 100m
21
+ if file.size >104857600
22
+ return put_multipart_object(bucket, object, file)
23
+ end
24
+
25
+ body = file.read
26
+
27
+ resource = bucket+'/'+object
28
+ ret = request(
29
+ :expects => [200, 203],
30
+ :method => 'PUT',
31
+ :path => object,
32
+ :bucket => bucket,
33
+ :resource => resource,
34
+ :body => body,
35
+ :endpoint => endpoint
36
+ )
37
+
38
+ end
39
+
40
+ def put_object_with_body(object, body, options={})
41
+
42
+ bucket = options[:bucket]
43
+ bucket ||= @aliyun_oss_bucket
44
+ location = get_bucket_location(bucket)
45
+ endpoint = "http://"+location+".aliyuncs.com"
46
+
47
+ resource = bucket+'/'+object
48
+ ret = request(
49
+ :expects => [200, 203],
50
+ :method => 'PUT',
51
+ :path => object,
52
+ :bucket => bucket,
53
+ :resource => resource,
54
+ :body => body,
55
+ :endpoint => endpoint
56
+ )
57
+
58
+ end
59
+
60
+ def put_folder(bucket, folder, endpoint)
61
+ if (nil == endpoint)
62
+ location = get_bucket_location(bucket)
63
+ endpoint = "http://"+location+".aliyuncs.com"
64
+ end
65
+ path = folder+'/'
66
+ resource = bucket+'/'+folder+'/'
67
+ ret = request(
68
+ :expects => [200, 203],
69
+ :method => 'PUT',
70
+ :path => path,
71
+ :bucket => bucket,
72
+ :resource => resource,
73
+ :endpoint => endpoint
74
+ )
75
+ end
76
+
77
+ def put_multipart_object(bucket, object, file)
78
+
79
+ location = get_bucket_location(bucket)
80
+ endpoint = "http://"+location+".aliyuncs.com"
81
+
82
+ # find the right uploadid
83
+ uploads = list_multipart_uploads(bucket, endpoint)
84
+ if nil != uploads
85
+ upload = uploads.find do |tmpupload| tmpupload["Key"][0] == object end
86
+ else
87
+ upload = nil
88
+ end
89
+
90
+ parts = nil
91
+ uploadedSize = 0
92
+ start_partNumber = 1
93
+ if ( nil != upload )
94
+ uploadId = upload["UploadId"][0]
95
+ parts = list_parts(bucket, object, endpoint, uploadId)
96
+ if ((nil != parts) &&(0 != parts.size))
97
+ if (parts[-1]["Size"][0].to_i != 5242880)
98
+ # the part is the last one, if its size is over 5m, then finish this upload
99
+ complete_multipart_upload(bucket, object, endpoint, uploadId)
100
+ return
101
+ end
102
+ uploadedSize = (parts[0]["Size"][0].to_i * (parts.size - 1)) + parts[-1]["Size"][0].to_i
103
+ start_partNumber = parts[-1]["PartNumber"][0].to_i + 1
104
+ end
105
+ else
106
+ #create upload ID
107
+ uploadId = initiate_multipart_upload(bucket, object, endpoint)
108
+ end
109
+
110
+ if (file.size <= uploadedSize)
111
+ complete_multipart_upload(bucket, object, endpoint, uploadId)
112
+ return
113
+ end
114
+
115
+ end_partNumber = (file.size + 5242880 -1) / 5242880
116
+ file.seek(uploadedSize)
117
+
118
+ for i in start_partNumber..end_partNumber
119
+ body = file.read(5242880)
120
+ upload_part(bucket, object, endpoint, i.to_s, uploadId, body)
121
+ end
122
+
123
+ complete_multipart_upload(bucket, object, endpoint, uploadId)
124
+ end
125
+
126
+ def initiate_multipart_upload(bucket, object, endpoint)
127
+ if (nil == endpoint)
128
+ location = get_bucket_location(bucket)
129
+ endpoint = "http://"+location+".aliyuncs.com"
130
+ end
131
+ path = object+"?uploads"
132
+ resource = bucket+'/'+path
133
+ ret = request(
134
+ :expects => 200,
135
+ :method => 'POST',
136
+ :path => path,
137
+ :bucket => bucket,
138
+ :resource => resource,
139
+ :endpoint => endpoint
140
+ )
141
+ uploadid = XmlSimple.xml_in(ret.data[:body])["UploadId"][0]
142
+ end
143
+
144
+ def upload_part(bucket, object, endpoint, partNumber, uploadId, body)
145
+ if (nil == endpoint)
146
+ location = get_bucket_location(bucket)
147
+ endpoint = "http://"+location+".aliyuncs.com"
148
+ end
149
+ path = object+"?partNumber="+partNumber+"&uploadId="+uploadId
150
+ resource = bucket+'/'+path
151
+ ret = request(
152
+ :expects => [200, 203],
153
+ :method => 'PUT',
154
+ :path => path,
155
+ :bucket => bucket,
156
+ :resource => resource,
157
+ :body => body,
158
+ :endpoint => endpoint
159
+ )
160
+ end
161
+
162
+ def complete_multipart_upload(bucket, object, endpoint, uploadId)
163
+ if (nil == endpoint)
164
+ location = get_bucket_location(bucket)
165
+ endpoint = "http://"+location+".aliyuncs.com"
166
+ end
167
+ parts = list_parts(bucket, object, endpoint, uploadId, options = {})
168
+ request_part = Array.new
169
+ if parts.size == 0
170
+ return
171
+ end
172
+ for i in 0..(parts.size-1)
173
+ part = parts[i]
174
+ request_part[i] = {"PartNumber"=>part["PartNumber"], "ETag"=>part["ETag"]}
175
+ end
176
+ body = XmlSimple.xml_out({"Part"=>request_part},'RootName'=>'CompleteMultipartUpload')
177
+
178
+ path = object+"?uploadId="+uploadId
179
+ resource = bucket+'/'+path
180
+ ret = request(
181
+ :expects => 200,
182
+ :method => 'POST',
183
+ :path => path,
184
+ :bucket => bucket,
185
+ :resource => resource,
186
+ :endpoint => endpoint,
187
+ :body => body
188
+ )
189
+
190
+ end
191
+ end
192
+
193
+ class Mock
194
+ def put_object(object, file=nil, options={})
195
+ end
196
+ end
197
+ end
198
+ end
199
+ end