Class: Fog::Storage::Dtdream::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/dtdream/requests/storage/get_bucket.rb,
lib/fog/dtdream/requests/storage/get_object.rb,
lib/fog/dtdream/requests/storage/put_bucket.rb,
lib/fog/dtdream/requests/storage/copy_object.rb,
lib/fog/dtdream/requests/storage/head_object.rb,
lib/fog/dtdream/requests/storage/list_buckets.rb,
lib/fog/dtdream/requests/storage/list_objects.rb,
lib/fog/dtdream/requests/storage/delete_bucket.rb,
lib/fog/dtdream/requests/storage/delete_object.rb,
lib/fog/dtdream/requests/storage/get_container.rb,
lib/fog/dtdream/requests/storage/get_containers.rb,
lib/fog/dtdream/requests/storage/delete_container.rb,
lib/fog/dtdream/requests/storage/get_object_http_url.rb,
lib/fog/dtdream/requests/storage/get_object_https_url.rb

Instance Method Summary collapse

Instance Method Details

#abort_multipart_upload(bucket, object, endpoint, uploadid) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fog/dtdream/requests/storage/delete_object.rb', line 28

def abort_multipart_upload(bucket, object, endpoint, uploadid)
  if (nil == endpoint)
    location = get_bucket_location(bucket)
    endpoint = "http://"+location+".aliyuncs.com"
  end
  path = object+"?uploadId="+uploadid
  resource = bucket+'/'+path

  ret = request(
          :expects  => 204,
          :method   => 'DELETE',
          :path     => path,
          :bucket   => bucket,
          :resource => resource,
          :endpoint => endpoint
  )

end

#copy_object(source_bucket, source_object, target_bucket, target_object, options = {}) ⇒ Object

Copy object

Parameters

  • source_container_name<~String> - Name of source bucket

  • source_object_name<~String> - Name of source object

  • target_container_name<~String> - Name of bucket to create copy in

  • target_object_name<~String> - Name for new copy of object

  • options<~Hash> - Additional headers options={}



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/dtdream/requests/storage/copy_object.rb', line 13

def copy_object(source_bucket, source_object, target_bucket, target_object, options = {})
  options = options.reject {|key, value| value.nil?}
  bucket = options[:bucket]
  bucket ||= @aliyun_oss_bucket
  source_bucket ||= bucket
  target_bucket ||= bucket
  headers = { 'x-oss-copy-source' => "/#{source_bucket}/#{source_object}" }
  location = get_bucket_location(target_bucket)
  endpoint = "http://"+location+".aliyuncs.com"
  resource = target_bucket+'/'+target_object
  request({
    :expects  => [200, 203],
    :headers  => headers,
    :method   => 'PUT',
    :path     => target_object,
    :bucket   => target_bucket,
    :resource => resource,
    :endpoint => endpoint
  })
end

#delete_bucket(bucket) ⇒ Object

Delete an existing bucket

Parameters

  • container<~String> - Name of container to delete

  • object<~String> - Name of object to delete



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fog/dtdream/requests/storage/delete_bucket.rb', line 11

def delete_bucket(bucket)
  location = get_bucket_location(bucket)
  endpoint = "http://"+location+".aliyuncs.com"
  resource = bucket+'/'
  request(
    :expects  => 204,
    :method   => 'DELETE',
    :bucket   => bucket,
    :resource => resource,
    :endpoint => endpoint
  )
end

#delete_container(container, options = {}) ⇒ Object

Delete an existing container

Parameters

  • container<~String> - Name of container to delete

  • options



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/dtdream/requests/storage/delete_container.rb', line 11

def delete_container(container, options={})

  bucket = options[:bucket]
  bucket ||= @aliyun_oss_bucket
  location = get_bucket_location(bucket)
  endpoint = "http://"+location+".aliyuncs.com"
  object = container+'/'
  resource = bucket+'/'+object

  request(
      :expects  => 204,
      :method   => 'DELETE',
      :path     => object,
      :bucket   => bucket,
      :resource => resource,
      :endpoint => endpoint
  )
end

#delete_object(object, options = {}) ⇒ Object

Delete an existing object

Parameters

  • container<~String> - Name of container to delete

  • object<~String> - Name of object to delete



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/dtdream/requests/storage/delete_object.rb', line 11

def delete_object(object, options={})
  bucket = options[:bucket]
  bucket ||= @aliyun_oss_bucket
  location = get_bucket_location(bucket)
  endpoint = "http://"+location+".aliyuncs.com"
  resource = bucket+'/'+object
  request(
    :expects  => 204,
    :method   => 'DELETE',
    :path     => object,
    :bucket   => bucket,
    :resource => resource,
    :endpoint => endpoint
  )
end

#get_bucket(bucket) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fog/dtdream/requests/storage/get_bucket.rb', line 5

def get_bucket(bucket)
  location = get_bucket_location(bucket)
  endpoint = "http://"+location+".aliyuncs.com"
  resource = bucket+'/'
  ret = request(
          :expects  => [200, 203],
          :method   => 'GET',
          :bucket   => bucket,
          :resource => resource,
          :endpoint => endpoint
  )
  xml = ret.data[:body]
  result = XmlSimple.xml_in(xml)
end

#get_bucket_acl(bucket) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fog/dtdream/requests/storage/get_bucket.rb', line 33

def get_bucket_acl(bucket)
  location = get_bucket_location(bucket)
  endpoint = "http://"+location+".aliyuncs.com"
  attribute = '?acl'
  resource = bucket+'/'+attribute
  ret = request(
          :expects  => [200, 203],
          :method   => 'GET',
          :path     => attribute,
          :bucket   => bucket,
          :resource => resource,
          :endpoint => endpoint
  )
  acl = XmlSimple.xml_in(ret.data[:body])["AccessControlList"][0]["Grant"][0]
end

#get_bucket_CORSRules(bucket) ⇒ Object

href=""1"">AllowedOrigin”=>, “AllowedMethod”=>, “AllowedHeader”=>, “ExposeHeader”=>, “MaxAgeSeconds”=>



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fog/dtdream/requests/storage/get_bucket.rb', line 50

def get_bucket_CORSRules(bucket)
  location = get_bucket_location(bucket)
  endpoint = "http://"+location+".aliyuncs.com"
  attribute = '?cors'
  resource = bucket+'/'+attribute
  ret = request(
          :expects  => [200, 203, 404],
          :method   => 'GET',
          :path     => attribute,
          :bucket   => bucket,
          :resource => resource,
          :endpoint => endpoint
  )
  if 404 != ret.data[:status]
    cors = XmlSimple.xml_in(ret.data[:body])["CORSRule"][0]
  else
    nil
  end
end

#get_bucket_lifecycle(bucket) ⇒ Object

href=""651a67ed-5b4f-4d9b-87ae-49dbaaa4b0ad"">ID”=>, “Prefix”=>, “Status”=>, “Expiration”=>[{“Days”=>]}



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/fog/dtdream/requests/storage/get_bucket.rb', line 71

def get_bucket_lifecycle(bucket)
  location = get_bucket_location(bucket)
  endpoint = "http://"+location+".aliyuncs.com"
  attribute = '?lifecycle'
  resource = bucket+'/'+attribute
  ret = request(
          :expects  => [200, 203, 404],
          :method   => 'GET',
          :path     => attribute,
          :bucket   => bucket,
          :resource => resource,
          :endpoint => endpoint
  )
	  if 404 != ret.data[:status]
    lifecycle = XmlSimple.xml_in(ret.data[:body])["Rule"][0]
  else
    nil
  end	    
end

#get_bucket_location(bucket) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/dtdream/requests/storage/get_bucket.rb', line 20

def get_bucket_location(bucket)
  attribute = '?location'
  resource = bucket+'/'+attribute
  ret = request(
          :expects  => [200, 203],
          :method   => 'GET',
          :path     => attribute,
          :bucket   => bucket,
          :resource => resource
  )
  location = XmlSimple.xml_in(ret.data[:body])
end

#get_bucket_logging(bucket) ⇒ Object

返回log的prefix,如果没有设置log开关,返回nil



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/fog/dtdream/requests/storage/get_bucket.rb', line 92

def get_bucket_logging(bucket)
  location = get_bucket_location(bucket)
  endpoint = "http://"+location+".aliyuncs.com"
  attribute = '?logging'
  resource = bucket+'/'+attribute
  ret = request(
          :expects  => [200, 203],
          :method   => 'GET',
          :path     => attribute,
          :bucket   => bucket,
          :resource => resource,
          :endpoint => endpoint
  )
  logging = XmlSimple.xml_in(ret.data[:body])["LoggingEnabled"][0]["TargetPrefix"]
end

#get_bucket_referer(bucket) ⇒ Object

href=""true"">AllowEmptyReferer”=>, “RefererList”=>}



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/fog/dtdream/requests/storage/get_bucket.rb', line 109

def get_bucket_referer(bucket)
  location = get_bucket_location(bucket)
  endpoint = "http://"+location+".aliyuncs.com"
  attribute = '?referer'
  resource = bucket+'/'+attribute
  ret = request(
          :expects  => [200, 203],
          :method   => 'GET',
          :path     => attribute,
          :bucket   => bucket,
          :resource => resource,
          :endpoint => endpoint
  )
  referer = XmlSimple.xml_in(ret.data[:body])
end

#get_container(container, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fog/dtdream/requests/storage/get_container.rb', line 5

def get_container(container, options = {})
  options = options.reject {|key, value| value.nil?}

  bucket = options[:bucket]
  bucket ||= @aliyun_oss_bucket

  marker = options[:marker]
  maxKeys = options[:maxKeys]
  delimiter = '/'

  path = ""

  if container == "" || container == "." || container == nil
    prefix = nil
  else
    prefix = container+'/'
  end

  if prefix
    path+="?prefix="+prefix
    if marker
      path+="&marker="+marker
    end
    if maxKeys
      path+="&max-keys="+maxKeys
    end
    if delimiter
      path+="&delimiter="+delimiter
    end
  elsif marker
    path+="?marker="+marker
    if maxKeys
      path+="&max-keys="+maxKeys
    end
    if delimiter
      path+="&delimiter="+delimiter
    end
  elsif maxKeys
    path+="?max-keys="+maxKeys
    if delimiter
      path+="&delimiter="+delimiter
    end
  elsif delimiter
    path+="?delimiter="+delimiter
  end

  location = get_bucket_location(bucket)
  endpoint = "http://"+location+".aliyuncs.com"
  resource = bucket+'/'
  ret = request(
      :expects  => [200, 203, 400],
      :method   => 'GET',
      :path     => path,
      :resource => resource,
      :bucket => bucket
  )
  xml = ret.data[:body]
  result = XmlSimple.xml_in(xml)["CommonPrefixes"]
end

#get_containers(options = {}) ⇒ Object

List existing storage containers

Parameters

  • options<~Hash>:

    • ‘limit’<~Integer> - Upper limit to number of results returned

    • ‘marker’<~String> - Only return objects with name greater than this value

Returns



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fog/dtdream/requests/storage/get_containers.rb', line 14

def get_containers(options = {})
  options = options.reject {|key, value| value.nil?}

  bucket = options[:bucket]
  bucket ||= @aliyun_oss_bucket
  prefix = options[:prefix]
  marker = options[:marker]
  maxKeys = options[:maxKeys]
  delimiter = '/'

  path = ""

  if prefix
    path+="?prefix="+prefix
    if marker
      path+="&marker="+marker
    end
    if maxKeys
      path+="&max-keys="+maxKeys
    end
    if delimiter
      path+="&delimiter="+delimiter
    end

  elsif marker
    path+="?marker="+marker
    if maxKeys
      path+="&max-keys="+maxKeys
    end
    if delimiter
      path+="&delimiter="+delimiter
    end

  elsif maxKeys
    path+="?max-keys="+maxKeys
    if delimiter
      path+="&delimiter="+delimiter
    end
  elsif delimiter
    path+="?delimiter="+delimiter
  end

  location = get_bucket_location(bucket)
  endpoint = "http://"+location+".aliyuncs.com"
  resource = bucket+'/'
  ret = request(
      :expects  => [200, 203, 400],
      :method   => 'GET',
      :path     => path,
      :resource => resource,
      :bucket => bucket
  )
  xml = ret.data[:body]
  result = XmlSimple.xml_in(xml)["CommonPrefixes"]
end

#get_object(object, range = nil, options = {}) ⇒ Object

Get details for object

Parameters

  • container<~String> - Name of container to look in

  • object<~String> - Name of object to look for



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/dtdream/requests/storage/get_object.rb', line 11

def get_object(object, range = nil, options = {})
  options = options.reject {|key, value| value.nil?}
  bucket = options[:bucket]
  bucket ||= @aliyun_oss_bucket
  endpoint = options[:endpoint]
  if (nil == endpoint)
    location = get_bucket_location(bucket)
    endpoint = "http://"+location+".aliyuncs.com"
  end
  resource = bucket+'/'+object
  para = {
    :expects  => [200, 206, 404],
    :method   => 'GET',
    :path     => object,
    :bucket   => bucket,
    :resource => resource,
    :endpoint => endpoint
  }

  if range
    rangeStr = "bytes="+range
    para[:headers] = {'Range' => rangeStr}
  end

  response = request(para)
  response.data
end

#get_object_http_url_public(object, expires, options = {}) ⇒ Object

Get an expiring object http url

Parameters

  • container<~String> - Name of container containing object

  • object<~String> - Name of object to get expiring url for

  • expires<~Time> - An expiry time for this url

Returns

  • response<~Excon::Response>:

    • body<~String> - url for object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/dtdream/requests/storage/get_object_http_url.rb', line 15

def get_object_http_url_public(object, expires, options = {})
  options = options.reject {|key, value| value.nil?}
  bucket = options[:bucket]
  bucket ||= @aliyun_oss_bucket
  acl = get_bucket_acl(bucket)
  location = get_bucket_location(bucket)
  
  if "private" == acl
    expires_time = (Time.now.to_i + expires).to_s
    resource = bucket+'/'+object
    signature = sign("GET", expires_time, nil, resource)
    url = "http://"+bucket+"."+location+".aliyuncs.com/"+object+
             "?OSSAccessKeyId="+@aliyun_accesskey_id+"&Expires="+expires_time+
             "&Signature="+URI.encode(signature,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
  elsif "public-read" == acl or "public-read-write" == acl
    url = "http://"+bucket+"."+location+".aliyuncs.com/"+object
  else
    url = "acl is wrong with value:"+acl
  end
end

#get_object_https_url_public(object, expires, options = {}) ⇒ Object

Get an expiring object https url from Cloud Files

Parameters

  • container<~String> - Name of container containing object

  • object<~String> - Name of object to get expiring url for

  • expires<~Time> - An expiry time for this url

Returns

  • response<~Excon::Response>:

    • body<~String> - url for object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/dtdream/requests/storage/get_object_https_url.rb', line 15

def get_object_https_url_public(object, expires, options = {})
  options = options.reject {|key, value| value.nil?}
  bucket = options[:bucket]
  bucket ||= @aliyun_oss_bucket
  acl = get_bucket_acl(bucket)
  location = get_bucket_location(bucket)
  
  if "private" == acl
    expires_time = (Time.now.to_i + expires).to_s
    resource = bucket+'/'+object
    signature = sign("GET", expires_time, nil, resource)
    url = "https://"+bucket+"."+location+".aliyuncs.com/"+object+
             "?OSSAccessKeyId="+@aliyun_accesskey_id+"&Expires="+expires_time+
             "&Signature="+URI.encode(signature,'/[^!*\'()\;?:@#&%=+$,{}[]<>`" ')
  elsif "public-read" == acl or "public-read-write" == acl
    url = "https://"+bucket+"."+location+".aliyuncs.com/"+object
  else
    url = "acl is wrong with value:"+acl
  end
end

#head_object(object, options = {}) ⇒ Object

Get headers for object

Parameters

  • container<~String> - Name of container to look in

  • object<~String> - Name of object to look for



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/dtdream/requests/storage/head_object.rb', line 11

def head_object(object, options={})
  bucket = options[:bucket]
  bucket ||= @aliyun_oss_bucket
  location = get_bucket_location(bucket)
  endpoint = "http://"+location+".aliyuncs.com"
  resource = bucket+'/'+object
  ret = request(
    :expects  => [200, 404],
    :method   => 'HEAD',
    :path     => object,
    :bucket   => bucket,
    :resource => resource,
    :endpoint => endpoint
  )
  return ret
end

#list_buckets(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/dtdream/requests/storage/list_buckets.rb', line 5

def list_buckets(options={})
  prefix = options[:prefix]
  marker = options[:marker]
  maxKeys = options[:maxKeys]
  
  path = ""
  
  if prefix
    path+="?prefix="+prefix
    if marker
      path+="&marker="+marker
    end
    if maxKeys
      path+="&max-keys="+maxKeys
    end
    
  elsif marker
    path+="?marker="+marker
    if maxKeys
      path+="&max-keys="+maxKeys
    end
    
  elsif maxKeys
    path+="?max-keys="+maxKeys
  end
  
  ret = request(
          :expects  => [200, 203],
          :method   => 'GET',
          :path     => path
  )
  xml = ret.data[:body]
  result = XmlSimple.xml_in(xml)["Buckets"][0]
end

#list_multipart_uploads(bucket, endpoint, options = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fog/dtdream/requests/storage/list_objects.rb', line 59

def list_multipart_uploads(bucket, endpoint, options = {})
  if (nil == endpoint)
    location = get_bucket_location(bucket)
    endpoint = "http://"+location+".aliyuncs.com"
  end
  path = "?uploads"
  resource = bucket+'/'+path

  ret = request(
          :expects  => 200,
          :method   => 'GET',
          :path     => path,
          :bucket   => bucket,
          :resource => resource,
          :endpoint => endpoint
  )
  uploadid = XmlSimple.xml_in(ret.data[:body])["Upload"]

end

#list_objects(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fog/dtdream/requests/storage/list_objects.rb', line 5

def list_objects(options={})
  bucket = options[:bucket]
  bucket ||= @aliyun_oss_bucket
  prefix = options[:prefix]
  marker = options[:marker]
  maxKeys = options[:maxKeys]
  delimiter = options[:delimiter]
  
  path = ""
  
  if prefix
    path+="?prefix="+prefix
    if marker
      path+="&marker="+marker
    end
    if maxKeys
      path+="&max-keys="+maxKeys
    end
    if delimiter
      path+="&delimiter="+delimiter
    end
    
  elsif marker
    path+="?marker="+marker
    if maxKeys
      path+="&max-keys="+maxKeys
    end
    if delimiter
      path+="&delimiter="+delimiter
    end
    
  elsif maxKeys
    path+="?max-keys="+maxKeys
    if delimiter
      path+="&delimiter="+delimiter
    end
  elsif delimiter
      path+="?delimiter="+delimiter
  end
  
  location = get_bucket_location(bucket)
  endpoint = "http://"+location+".aliyuncs.com"
  resource = bucket+'/'
  ret = request(
          :expects  => [200, 203, 400],
          :method   => 'GET',
          :path     => path,
          :resource => resource,
          :bucket => bucket
  )
  xml = ret.data[:body]
  result = XmlSimple.xml_in(xml)
end

#list_parts(bucket, object, endpoint, uploadid, options = {}) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/fog/dtdream/requests/storage/list_objects.rb', line 79

def list_parts(bucket, object, endpoint, uploadid, options = {})
  if (nil == endpoint)
    location = get_bucket_location(bucket)
    endpoint = "http://"+location+".aliyuncs.com"
  end
  path = object+"?uploadId="+uploadid
  resource = bucket+'/'+path

  ret = request(
          :expects  => 200,
          :method   => 'GET',
          :path     => path,
          :bucket   => bucket,
          :resource => resource,
          :endpoint => endpoint
  )
  parts = XmlSimple.xml_in(ret.data[:body])["Part"]
end

#put_bucket(bucketName) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/fog/dtdream/requests/storage/put_bucket.rb', line 5

def put_bucket(bucketName)
  
  resource = bucketName+'/'
  ret = request(
          :expects  => [200, 203],
          :method   => 'PUT',
          :resource => resource,
          :bucket => bucketName
  )
end