fog-aliyun 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/.rubocop_todo.yml +149 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Rakefile +3 -3
  7. data/fog-aliyun.gemspec +16 -13
  8. data/lib/fog/aliyun.rb +8 -8
  9. data/lib/fog/aliyun/compute.rb +99 -113
  10. data/lib/fog/aliyun/models/compute/eip_address.rb +23 -29
  11. data/lib/fog/aliyun/models/compute/eip_addresses.rb +3 -5
  12. data/lib/fog/aliyun/models/compute/image.rb +26 -28
  13. data/lib/fog/aliyun/models/compute/images.rb +2 -6
  14. data/lib/fog/aliyun/models/compute/route_entry.rb +9 -11
  15. data/lib/fog/aliyun/models/compute/route_entrys.rb +7 -7
  16. data/lib/fog/aliyun/models/compute/route_table.rb +10 -11
  17. data/lib/fog/aliyun/models/compute/route_tables.rb +2 -2
  18. data/lib/fog/aliyun/models/compute/security_group.rb +24 -24
  19. data/lib/fog/aliyun/models/compute/security_group_rule.rb +20 -20
  20. data/lib/fog/aliyun/models/compute/security_group_rules.rb +4 -4
  21. data/lib/fog/aliyun/models/compute/security_groups.rb +6 -7
  22. data/lib/fog/aliyun/models/compute/server.rb +42 -43
  23. data/lib/fog/aliyun/models/compute/servers.rb +9 -11
  24. data/lib/fog/aliyun/models/compute/snapshot.rb +15 -15
  25. data/lib/fog/aliyun/models/compute/snapshots.rb +6 -10
  26. data/lib/fog/aliyun/models/compute/volume.rb +36 -40
  27. data/lib/fog/aliyun/models/compute/volumes.rb +7 -11
  28. data/lib/fog/aliyun/models/compute/vpc.rb +18 -19
  29. data/lib/fog/aliyun/models/compute/vpcs.rb +5 -6
  30. data/lib/fog/aliyun/models/compute/vrouter.rb +13 -13
  31. data/lib/fog/aliyun/models/compute/vrouters.rb +4 -5
  32. data/lib/fog/aliyun/models/compute/vswitch.rb +18 -20
  33. data/lib/fog/aliyun/models/compute/vswitches.rb +6 -6
  34. data/lib/fog/aliyun/models/storage/directories.rb +10 -16
  35. data/lib/fog/aliyun/models/storage/directory.rb +8 -8
  36. data/lib/fog/aliyun/models/storage/file.rb +58 -64
  37. data/lib/fog/aliyun/models/storage/files.rb +95 -115
  38. data/lib/fog/aliyun/requests/compute/allocate_eip_address.rb +18 -44
  39. data/lib/fog/aliyun/requests/compute/allocate_public_ip_address.rb +12 -36
  40. data/lib/fog/aliyun/requests/compute/associate_eip_address.rb +16 -40
  41. data/lib/fog/aliyun/requests/compute/attach_disk.rb +19 -22
  42. data/lib/fog/aliyun/requests/compute/create_disk.rb +33 -63
  43. data/lib/fog/aliyun/requests/compute/create_image.rb +21 -21
  44. data/lib/fog/aliyun/requests/compute/create_security_group.rb +16 -16
  45. data/lib/fog/aliyun/requests/compute/create_security_group_egress_ip_rule.rb +22 -63
  46. data/lib/fog/aliyun/requests/compute/create_security_group_egress_sg_rule.rb +23 -61
  47. data/lib/fog/aliyun/requests/compute/create_security_group_ip_rule.rb +22 -63
  48. data/lib/fog/aliyun/requests/compute/create_security_group_sg_rule.rb +23 -61
  49. data/lib/fog/aliyun/requests/compute/create_server.rb +76 -78
  50. data/lib/fog/aliyun/requests/compute/create_snapshot.rb +12 -26
  51. data/lib/fog/aliyun/requests/compute/create_vpc.rb +11 -38
  52. data/lib/fog/aliyun/requests/compute/create_vswitch.rb +13 -40
  53. data/lib/fog/aliyun/requests/compute/delete_disk.rb +8 -35
  54. data/lib/fog/aliyun/requests/compute/delete_image.rb +6 -33
  55. data/lib/fog/aliyun/requests/compute/delete_security_group.rb +13 -13
  56. data/lib/fog/aliyun/requests/compute/delete_security_group_egress_ip_rule.rb +22 -63
  57. data/lib/fog/aliyun/requests/compute/delete_security_group_egress_sg_rule.rb +23 -61
  58. data/lib/fog/aliyun/requests/compute/delete_security_group_ip_rule.rb +22 -62
  59. data/lib/fog/aliyun/requests/compute/delete_security_group_sg_rule.rb +23 -61
  60. data/lib/fog/aliyun/requests/compute/delete_server.rb +15 -15
  61. data/lib/fog/aliyun/requests/compute/delete_snapshot.rb +6 -20
  62. data/lib/fog/aliyun/requests/compute/delete_vpc.rb +9 -26
  63. data/lib/fog/aliyun/requests/compute/delete_vswitch.rb +9 -25
  64. data/lib/fog/aliyun/requests/compute/detach_disk.rb +11 -27
  65. data/lib/fog/aliyun/requests/compute/join_security_group.rb +15 -16
  66. data/lib/fog/aliyun/requests/compute/leave_security_group.rb +15 -16
  67. data/lib/fog/aliyun/requests/compute/list_disks.rb +24 -43
  68. data/lib/fog/aliyun/requests/compute/list_eip_addresses.rb +26 -52
  69. data/lib/fog/aliyun/requests/compute/list_images.rb +21 -24
  70. data/lib/fog/aliyun/requests/compute/list_route_tables.rb +16 -19
  71. data/lib/fog/aliyun/requests/compute/list_security_group_rules.rb +22 -23
  72. data/lib/fog/aliyun/requests/compute/list_security_groups.rb +21 -24
  73. data/lib/fog/aliyun/requests/compute/list_server_types.rb +50 -50
  74. data/lib/fog/aliyun/requests/compute/list_servers.rb +25 -28
  75. data/lib/fog/aliyun/requests/compute/list_snapshots.rb +20 -37
  76. data/lib/fog/aliyun/requests/compute/list_vpcs.rb +12 -29
  77. data/lib/fog/aliyun/requests/compute/list_vrouters.rb +13 -16
  78. data/lib/fog/aliyun/requests/compute/list_vswitchs.rb +14 -31
  79. data/lib/fog/aliyun/requests/compute/list_zones.rb +16 -16
  80. data/lib/fog/aliyun/requests/compute/modify_vpc.rb +17 -17
  81. data/lib/fog/aliyun/requests/compute/modify_vswitch.rb +11 -39
  82. data/lib/fog/aliyun/requests/compute/reboot_server.rb +15 -16
  83. data/lib/fog/aliyun/requests/compute/release_eip_address.rb +12 -36
  84. data/lib/fog/aliyun/requests/compute/start_server.rb +14 -15
  85. data/lib/fog/aliyun/requests/compute/stop_server.rb +13 -14
  86. data/lib/fog/aliyun/requests/compute/unassociate_eip_address.rb +16 -41
  87. data/lib/fog/aliyun/requests/storage/copy_object.rb +11 -14
  88. data/lib/fog/aliyun/requests/storage/delete_bucket.rb +30 -30
  89. data/lib/fog/aliyun/requests/storage/delete_container.rb +11 -14
  90. data/lib/fog/aliyun/requests/storage/delete_object.rb +20 -22
  91. data/lib/fog/aliyun/requests/storage/get_bucket.rb +141 -148
  92. data/lib/fog/aliyun/requests/storage/get_container.rb +26 -38
  93. data/lib/fog/aliyun/requests/storage/get_containers.rb +20 -32
  94. data/lib/fog/aliyun/requests/storage/get_object.rb +12 -12
  95. data/lib/fog/aliyun/requests/storage/get_object_http_url.rb +11 -11
  96. data/lib/fog/aliyun/requests/storage/get_object_https_url.rb +11 -11
  97. data/lib/fog/aliyun/requests/storage/head_object.rb +11 -11
  98. data/lib/fog/aliyun/requests/storage/list_buckets.rb +40 -47
  99. data/lib/fog/aliyun/requests/storage/list_objects.rb +91 -104
  100. data/lib/fog/aliyun/requests/storage/put_bucket.rb +22 -23
  101. data/lib/fog/aliyun/requests/storage/put_container.rb +12 -12
  102. data/lib/fog/aliyun/requests/storage/put_object.rb +100 -110
  103. data/lib/fog/aliyun/storage.rb +209 -214
  104. data/lib/fog/aliyun/version.rb +1 -1
  105. data/lib/fog/bin/aliyun.rb +5 -5
  106. metadata +55 -4
@@ -3,17 +3,16 @@ module Fog
3
3
  module Compute
4
4
  class Aliyun
5
5
  class VPC < Fog::Model
6
- identity :id, :aliases => 'VpcId'
7
- attribute :name, :aliases => 'VpcName'
8
- attribute :state, :aliases => 'Status'
9
- attribute :cidr_block, :aliases => 'CidrBlock'
10
- attribute :v_switch_ids, :aliases => 'VSwitchIds'
11
- attribute :description, :aliases => 'Description'
12
- attribute :user_cidrs, :aliases => 'UserCidrs'
13
- attribute :region_id, :aliases => 'RegionId'
14
- attribute :v_router_id, :aliases => 'VRouterId'
15
- attribute :create_at, :aliases => 'CreationTime'
16
-
6
+ identity :id, aliases: 'VpcId'
7
+ attribute :name, aliases: 'VpcName'
8
+ attribute :state, aliases: 'Status'
9
+ attribute :cidr_block, aliases: 'CidrBlock'
10
+ attribute :v_switch_ids, aliases: 'VSwitchIds'
11
+ attribute :description, aliases: 'Description'
12
+ attribute :user_cidrs, aliases: 'UserCidrs'
13
+ attribute :region_id, aliases: 'RegionId'
14
+ attribute :v_router_id, aliases: 'VRouterId'
15
+ attribute :create_at, aliases: 'CreationTime'
17
16
 
18
17
  def ready?
19
18
  requires :state
@@ -39,20 +38,20 @@ module Fog
39
38
  def vswitches
40
39
  @vswitches ||= begin
41
40
  Fog::Compute::Aliyun::Vswitches.new(
42
- :vpc => self,
43
- :service => service
41
+ vpc: self,
42
+ service: service
44
43
  )
45
44
  end
46
45
  end
47
46
 
48
47
  def vrouter
49
48
  requires :v_router_id
50
- Fog::Compute::Aliyun::Vrouters.new(:service=>service).all('vRouterId'=>v_router_id)[0]
49
+ Fog::Compute::Aliyun::Vrouters.new(service: service).all('vRouterId' => v_router_id)[0]
51
50
  end
52
51
 
53
52
  def security_groups
54
53
  requires :id
55
- Fog::Compute::Aliyun::SecurityGroups.new(:service=>service).all(:vpcId=>id)
54
+ Fog::Compute::Aliyun::SecurityGroups.new(service: service).all(vpcId: id)
56
55
  end
57
56
  # Create a vpc
58
57
  #
@@ -65,11 +64,11 @@ module Fog
65
64
  # As such, it yields an InvalidGroup.Duplicate exception if you attempt to save an existing vpc.
66
65
  #
67
66
 
68
- def save(options={})
67
+ def save(options = {})
69
68
  requires :cidr_block
70
- options[:name]=name if name
71
- options[:description]=description if description
72
- data = Fog::JSON.decode(service.create_vpc(cidr_block,options).body)
69
+ options[:name] = name if name
70
+ options[:description] = description if description
71
+ Fog::JSON.decode(service.create_vpc(cidr_block, options).body)
73
72
  true
74
73
  end
75
74
  end
@@ -5,7 +5,6 @@ module Fog
5
5
  module Compute
6
6
  class Aliyun
7
7
  class Vpcs < Fog::Collection
8
-
9
8
  model Fog::Compute::Aliyun::VPC
10
9
 
11
10
  # Creates a new VPC
@@ -16,7 +15,7 @@ module Fog
16
15
  #
17
16
  # Returns the details of the new VPC
18
17
  #
19
- #>> Aliyun.vpcs.new
18
+ # >> Aliyun.vpcs.new
20
19
  # <Fog::Aliyun::VPC::VPC
21
20
  # id=nil,
22
21
  # state=nil,
@@ -35,7 +34,7 @@ module Fog
35
34
  #
36
35
  # Returns an array of all VPCs
37
36
  #
38
- #>> Aliyun.vpcs.all
37
+ # >> Aliyun.vpcs.all
39
38
  # <Fog::Aliyun::VPC::VPCs
40
39
  # [
41
40
  # <Fog::Aliyun::VPC::VPC
@@ -49,7 +48,7 @@ module Fog
49
48
  def all(filters_arg = {})
50
49
  unless filters_arg.is_a?(Hash)
51
50
  Fog::Logger.warning("all with #{filters_arg.class} param is deprecated, use all('vpcId' => []) instead [light_black](#{caller.first})[/]")
52
- filters_arg = {'vpcId' => [*filters_arg]}
51
+ filters_arg = { 'vpcId' => [*filters_arg] }
53
52
  end
54
53
  data = Fog::JSON.decode(service.list_vpcs(filters_arg).body)['Vpcs']['Vpc']
55
54
  load(data)
@@ -63,7 +62,7 @@ module Fog
63
62
  #
64
63
  # ==== Returns
65
64
  #
66
- #>> Aliyun.vpcs.get("vpc-12345678")
65
+ # >> Aliyun.vpcs.get("vpc-12345678")
67
66
  # <Fog::Aliyun::Compute::VPC
68
67
  # id="vpc-12345678",
69
68
  # TODO
@@ -72,7 +71,7 @@ module Fog
72
71
 
73
72
  def get(vpcId)
74
73
  if vpcId
75
- $vpc=self.class.new(:service => service).all('vpcId' => vpcId)[0]
74
+ $vpc = self.class.new(service: service).all('vpcId' => vpcId)[0]
76
75
  end
77
76
  end
78
77
  end
@@ -3,25 +3,25 @@ module Fog
3
3
  module Compute
4
4
  class Aliyun
5
5
  class VRouter < Fog::Model
6
- identity :id, :aliases => 'VRouterId'
6
+ identity :id, aliases: 'VRouterId'
7
7
 
8
- attribute :name, :aliases => 'VRouterName'
9
- attribute :route_table_ids, :aliases => 'RouteTableIds'
10
- attribute :created_at, :aliases => 'CreationTime'
11
- attribute :description, :aliases => 'Description'
12
- attribute :region_id, :aliases => 'RegionId'
13
- attribute :vpc_id, :aliases => 'VpcId'
8
+ attribute :name, aliases: 'VRouterName'
9
+ attribute :route_table_ids, aliases: 'RouteTableIds'
10
+ attribute :created_at, aliases: 'CreationTime'
11
+ attribute :description, aliases: 'Description'
12
+ attribute :region_id, aliases: 'RegionId'
13
+ attribute :vpc_id, aliases: 'VpcId'
14
14
 
15
15
  def vpc
16
16
  requires :vpc_id
17
- $vpc=Fog::Compute::Aliyun::Vpcs.new(:service=>service).all('vpcId'=>vpc_id)[0]
17
+ $vpc = Fog::Compute::Aliyun::Vpcs.new(service: service).all('vpcId' => vpc_id)[0]
18
18
  end
19
19
 
20
20
  def route_tables
21
21
  @route_tables ||= begin
22
22
  Fog::Compute::Aliyun::RouteTables.new(
23
- :v_router => self,
24
- :service => service
23
+ v_router: self,
24
+ service: service
25
25
  )
26
26
  end
27
27
  end
@@ -30,6 +30,6 @@ module Fog
30
30
  end
31
31
  end
32
32
 
33
- # "VRouters"=>{"VRouter"=>[{"VRouterName"=>"", "RouteTableIds"=>{"RouteTableId"=>["vtb-2504onoxh"]},
34
- # "CreationTime"=>"2015-08-03T11:23:35Z", "Description"=>"", "RegionId"=>"cn-beijing",
35
- # "VRouterId"=>"vrt-25azmd2wm", "VpcId"=>"vpc-25mj6mguq"}]}
33
+ # "VRouters"=>{"VRouter"=>[{"VRouterName"=>"", "RouteTableIds"=>{"RouteTableId"=>["vtb-2504onoxh"]},
34
+ # "CreationTime"=>"2015-08-03T11:23:35Z", "Description"=>"", "RegionId"=>"cn-beijing",
35
+ # "VRouterId"=>"vrt-25azmd2wm", "VpcId"=>"vpc-25mj6mguq"}]}
@@ -5,7 +5,6 @@ module Fog
5
5
  module Compute
6
6
  class Aliyun
7
7
  class Vrouters < Fog::Collection
8
-
9
8
  model Fog::Compute::Aliyun::VRouter
10
9
 
11
10
  # Returns an array of all VPCs that have been created
@@ -16,7 +15,7 @@ module Fog
16
15
  #
17
16
  # Returns an array of all VPCs
18
17
  #
19
- #>> Aliyun.vrouters.all
18
+ # >> Aliyun.vrouters.all
20
19
  # <Fog::Aliyun::Compute::VRouters
21
20
  # [
22
21
  # <Fog::Aliyun::Compute::VRouter
@@ -30,7 +29,7 @@ module Fog
30
29
  def all(filters_arg = {})
31
30
  unless filters_arg.is_a?(Hash)
32
31
  Fog::Logger.warning("all with #{filters_arg.class} param is deprecated, use all('vRouterId' => "") instead [light_black](#{caller.first})[/]")
33
- filters_arg = {'vRouterId' => filters_arg}
32
+ filters_arg = { 'vRouterId' => filters_arg }
34
33
  end
35
34
  data = Fog::JSON.decode(service.list_vrouters(filters_arg).body)['VRouters']['VRouter']
36
35
  load(data)
@@ -44,7 +43,7 @@ module Fog
44
43
  #
45
44
  # ==== Returns
46
45
  #
47
- #>> Aliyun.vpcs.get("vpc-12345678")
46
+ # >> Aliyun.vpcs.get("vpc-12345678")
48
47
  # <Fog::Aliyun::Compute::VPC
49
48
  # id="vpc-12345678",
50
49
  # TODO
@@ -53,7 +52,7 @@ module Fog
53
52
 
54
53
  def get(vRouterId)
55
54
  if vRouterId
56
- self.class.new(:service => service).all('vRouterId' => vRouterId)[0]
55
+ self.class.new(service: service).all('vRouterId' => vRouterId)[0]
57
56
  end
58
57
  end
59
58
  end
@@ -3,17 +3,17 @@ module Fog
3
3
  module Compute
4
4
  class Aliyun
5
5
  class Vswitch < Fog::Model
6
- identity :id, :aliases => 'VSwitchId'
7
- attribute :vpc_id, :aliases => 'VpcId'
8
- attribute :zone_id, :aliases => 'ZoneId'
9
- attribute :name, :aliases => 'VSwitchName'
10
- attribute :available_ip_count, :aliases => 'AvailableIpAddressCount'
11
- attribute :state, :aliases => 'Status'
12
- attribute :cidr_block, :aliases => 'CidrBlock'
13
- attribute :description, :aliases => 'Description'
14
- attribute :region_id, :aliases => 'RegionId'
15
- attribute :create_at, :aliases => 'CreationTime'
16
- def initialize(attributes={})
6
+ identity :id, aliases: 'VSwitchId'
7
+ attribute :vpc_id, aliases: 'VpcId'
8
+ attribute :zone_id, aliases: 'ZoneId'
9
+ attribute :name, aliases: 'VSwitchName'
10
+ attribute :available_ip_count, aliases: 'AvailableIpAddressCount'
11
+ attribute :state, aliases: 'Status'
12
+ attribute :cidr_block, aliases: 'CidrBlock'
13
+ attribute :description, aliases: 'Description'
14
+ attribute :region_id, aliases: 'RegionId'
15
+ attribute :create_at, aliases: 'CreationTime'
16
+ def initialize(attributes = {})
17
17
  super
18
18
  end
19
19
 
@@ -49,23 +49,21 @@ module Fog
49
49
  # As such, it yields an InvalidGroup.Duplicate exception if you attempt to save an existing vpc.
50
50
  #
51
51
 
52
- def save(options={})
53
- requires :vpc,:cidr_block
52
+ def save(options = {})
53
+ requires :vpc, :cidr_block
54
54
  options[:name] = name if name
55
- options[:description]=description if description
56
- data = Fog::JSON.decode(service.create_vswitch(vpc.id, cidr_block,options).body)
57
-
55
+ options[:description] = description if description
56
+ Fog::JSON.decode(service.create_vswitch(vpc.id, cidr_block, options).body)
58
57
  true
59
58
  end
60
59
 
61
60
  def vpc
62
61
  $vpc
63
62
  end
64
-
65
- def all()
66
- data = Fog::JSON.decode(service.list_vswitchs(vpc_id).body)['VSwitches']['VSwitch']
67
- end
68
63
 
64
+ def all
65
+ Fog::JSON.decode(service.list_vswitchs(vpc_id).body)['VSwitches']['VSwitch']
66
+ end
69
67
  end
70
68
  end
71
69
  end
@@ -17,7 +17,7 @@ module Fog
17
17
  #
18
18
  # Returns the details of the new VPC
19
19
  #
20
- #>> Aliyun.vpcs.new
20
+ # >> Aliyun.vpcs.new
21
21
  # <Fog::Aliyun::VPC::VPC
22
22
  # id=nil,
23
23
  # state=nil,
@@ -26,7 +26,7 @@ module Fog
26
26
  # tags=nil
27
27
  # tenancy=nil
28
28
  # >
29
-
29
+
30
30
  # Returns an array of all VPCs that have been created
31
31
  #
32
32
  # Aliyun.vpcs.all
@@ -35,7 +35,7 @@ module Fog
35
35
  #
36
36
  # Returns an array of all VPCs
37
37
  #
38
- #>> Aliyun.vpcs.all
38
+ # >> Aliyun.vpcs.all
39
39
  # <Fog::Aliyun::VPC::VPCs
40
40
  # filters={}
41
41
  # [
@@ -47,7 +47,7 @@ module Fog
47
47
  # >
48
48
  #
49
49
 
50
- def all(options={})
50
+ def all(options = {})
51
51
  requires :vpc
52
52
  data = Fog::JSON.decode(service.list_vswitchs(vpc.id, options).body)['VSwitches']['VSwitch']
53
53
  load(data)
@@ -61,7 +61,7 @@ module Fog
61
61
  #
62
62
  # ==== Returns
63
63
  #
64
- #>> Aliyun.vpcs.get("vpc-12345678")
64
+ # >> Aliyun.vpcs.get("vpc-12345678")
65
65
  # <Fog::Aliyun::Compute::VPC
66
66
  # id="vpc-12345678",
67
67
  # TODO
@@ -71,7 +71,7 @@ module Fog
71
71
  def get(vswitchId)
72
72
  requires :vpc
73
73
  if vswitchId
74
- self.class.new(:service => service,:vpc=>vpc).all(:vSwitchId=>vswitchId)[0]
74
+ self.class.new(service: service, vpc: vpc).all(vSwitchId: vswitchId)[0]
75
75
  end
76
76
  end
77
77
  end
@@ -8,33 +8,27 @@ module Fog
8
8
  model Fog::Storage::Aliyun::Directory
9
9
 
10
10
  def all
11
- containers = service.get_containers()
12
- if nil == containers
13
- return nil
14
- end
15
- data = Array.new
11
+ containers = service.get_containers
12
+ return nil if nil == containers
13
+ data = []
16
14
  i = 0
17
15
  containers.each do |entry|
18
- key = entry["Prefix"][0]
16
+ key = entry['Prefix'][0]
19
17
  key[-1] = ''
20
- data[i] = {:key=>key}
21
- i = i + 1
18
+ data[i] = { key: key }
19
+ i += 1
22
20
  end
23
21
 
24
22
  load(data)
25
23
  end
26
24
 
27
25
  def get(key, options = {})
28
- if key != nil && key != "" && key != '.'
29
- dir = key+'/'
26
+ if !key.nil? && key != '' && key != '.'
27
+ dir = key + '/'
30
28
  ret = service.head_object(dir, options)
31
- if ret.data[:status] == 200
32
- new(:key => key)
33
- else
34
- nil
35
- end
29
+ new(key: key) if ret.data[:status] == 200
36
30
  else
37
- new(:key => "")
31
+ new(key: '')
38
32
  end
39
33
  rescue Fog::Storage::Aliyun::NotFound
40
34
  nil
@@ -5,21 +5,21 @@ module Fog
5
5
  module Storage
6
6
  class Aliyun
7
7
  class Directory < Fog::Model
8
- identity :key
8
+ identity :key
9
9
 
10
10
  def destroy
11
11
  requires :key
12
- prefix = key+'/'
13
- ret = service.list_objects(:prefix=>prefix)["Contents"]
14
-
12
+ prefix = key + '/'
13
+ ret = service.list_objects(prefix: prefix)['Contents']
14
+
15
15
  if ret.nil?
16
- puts " Not found: Direction not exist!"
16
+ puts ' Not found: Direction not exist!'
17
17
  false
18
18
  elsif ret.size == 1
19
19
  service.delete_container(key)
20
20
  true
21
21
  else
22
- raise Fog::Storage::Aliyun::Error, " Forbidden: Direction not empty!"
22
+ raise Fog::Storage::Aliyun::Error, ' Forbidden: Direction not empty!'
23
23
  false
24
24
  end
25
25
  end
@@ -27,8 +27,8 @@ module Fog
27
27
  def files
28
28
  @files ||= begin
29
29
  Fog::Storage::Aliyun::Files.new(
30
- :directory => self,
31
- :service => service
30
+ directory: self,
31
+ service: service
32
32
  )
33
33
  end
34
34
  end
@@ -4,23 +4,23 @@ module Fog
4
4
  module Storage
5
5
  class Aliyun
6
6
  class File < Fog::Model
7
- identity :key, :aliases => 'name'
8
- attribute :date, :aliases => 'Date'
9
- attribute :content_length, :aliases => 'Content-Length', :type => :integer
10
- attribute :content_type, :aliases => 'Content-Type'
11
- attribute :connection, :aliases => 'Connection'
12
- attribute :content_disposition, :aliases => 'Content-Disposition'
13
- attribute :etag, :aliases => 'Etag'
14
- attribute :last_modified, :aliases => 'Last-Modified', :type => :time
15
- attribute :accept_ranges, :aliases => 'Accept-Ranges'
16
- attribute :server, :aliases => 'Server'
17
- attribute :object_type, :aliases => 'x-oss-object-type'
7
+ identity :key, aliases: 'name'
8
+ attribute :date, aliases: 'Date'
9
+ attribute :content_length, aliases: 'Content-Length', type: :integer
10
+ attribute :content_type, aliases: 'Content-Type'
11
+ attribute :connection, aliases: 'Connection'
12
+ attribute :content_disposition, aliases: 'Content-Disposition'
13
+ attribute :etag, aliases: 'Etag'
14
+ attribute :last_modified, aliases: 'Last-Modified', type: :time
15
+ attribute :accept_ranges, aliases: 'Accept-Ranges'
16
+ attribute :server, aliases: 'Server'
17
+ attribute :object_type, aliases: 'x-oss-object-type'
18
18
 
19
19
  def body
20
20
  attributes[:body] ||= if last_modified
21
- collection.get(identity).body
22
- else
23
- ''
21
+ collection.get(identity).body
22
+ else
23
+ ''
24
24
  end
25
25
  end
26
26
 
@@ -28,34 +28,32 @@ module Fog
28
28
  attributes[:body] = new_body
29
29
  end
30
30
 
31
- def directory
32
- @directory
33
- end
31
+ attr_reader :directory
34
32
 
35
- def copy(target_directory_key, target_file_key, options={})
33
+ def copy(target_directory_key, target_file_key, options = {})
36
34
  requires :directory, :key
37
- if directory.key == ""
38
- source_object = key
39
- else
40
- source_object = directory.key+"/"+key
41
- end
42
- if target_directory_key == ""
35
+ source_object = if directory.key == ''
36
+ key
37
+ else
38
+ directory.key + '/' + key
39
+ end
40
+ if target_directory_key == ''
43
41
  target_object = target_file_key
44
42
  else
45
- target_object = target_directory_key+"/"+target_file_key
43
+ target_object = target_directory_key + '/' + target_file_key
46
44
  end
47
45
  service.copy_object(nil, source_object, nil, target_object, options)
48
- target_directory = service.directories.new(:key => target_directory_key)
46
+ target_directory = service.directories.new(key: target_directory_key)
49
47
  target_directory.files.get(target_file_key)
50
48
  end
51
49
 
52
50
  def destroy
53
51
  requires :directory, :key
54
- if directory.key == ""
55
- object = key
56
- else
57
- object = directory.key+"/"+key
58
- end
52
+ object = if directory.key == ''
53
+ key
54
+ else
55
+ directory.key + '/' + key
56
+ end
59
57
  service.delete_object(object)
60
58
  true
61
59
  end
@@ -67,8 +65,8 @@ module Fog
67
65
  def owner=(new_owner)
68
66
  if new_owner
69
67
  attributes[:owner] = {
70
- :display_name => new_owner['DisplayName'],
71
- :id => new_owner['ID']
68
+ display_name: new_owner['DisplayName'],
69
+ id: new_owner['ID']
72
70
  }
73
71
  end
74
72
  end
@@ -87,32 +85,30 @@ module Fog
87
85
  #
88
86
  def url(expires, options = {})
89
87
  requires :directory, :key
90
- if directory.key == ""
91
- object = key
92
- else
93
- object = directory.key+"/"+key
94
- end
95
- self.service.get_object_http_url_public(object, expires, options)
88
+ object = if directory.key == ''
89
+ key
90
+ else
91
+ directory.key + '/' + key
92
+ end
93
+ service.get_object_http_url_public(object, expires, options)
96
94
  end
97
95
 
98
96
  def public_url
99
97
  requires :key
100
- self.collection.get_url(self.key)
98
+ collection.get_url(key)
101
99
  end
102
100
 
103
101
  def save(options = {})
104
102
  requires :body, :directory, :key
105
103
  options['Content-Type'] = content_type if content_type
106
104
  options['Content-Disposition'] = content_disposition if content_disposition
107
- options['Access-Control-Allow-Origin'] = access_control_allow_origin if access_control_allow_origin
108
- options['Origin'] = origin if origin
109
105
  options.merge!(metadata_to_headers)
110
106
 
111
- if directory.key == ""
112
- object = key
113
- else
114
- object = directory.key+"/"+key
115
- end
107
+ object = if directory.key == ''
108
+ key
109
+ else
110
+ directory.key + '/' + key
111
+ end
116
112
  if body.is_a?(::File)
117
113
  data = service.put_object(object, body, options).data
118
114
  elsif body.is_a?(String)
@@ -130,36 +126,34 @@ module Fog
130
126
 
131
127
  private
132
128
 
133
- def directory=(new_directory)
134
- @directory = new_directory
135
- end
129
+ attr_writer :directory
136
130
 
137
131
  def refresh_metadata
138
- metadata.reject! {|k, v| v.nil? }
132
+ metadata.reject! { |_k, v| v.nil? }
139
133
  end
140
134
 
141
135
  def headers_to_metadata
142
136
  key_map = key_mapping
143
- Hash[metadata_attributes.map {|k, v| [key_map[k], v] }]
137
+ Hash[metadata_attributes.map { |k, v| [key_map[k], v] }]
144
138
  end
145
139
 
146
140
  def key_mapping
147
141
  key_map = metadata_attributes
148
- key_map.each_pair {|k, v| key_map[k] = header_to_key(k)}
142
+ key_map.each_pair { |k, _v| key_map[k] = header_to_key(k) }
149
143
  end
150
144
 
151
145
  def header_to_key(opt)
152
- opt.gsub(metadata_prefix, '').split('-').map {|k| k[0, 1].downcase + k[1..-1]}.join('_').to_sym
146
+ opt.gsub(metadata_prefix, '').split('-').map { |k| k[0, 1].downcase + k[1..-1] }.join('_').to_sym
153
147
  end
154
148
 
155
149
  def metadata_to_headers
156
150
  header_map = header_mapping
157
- Hash[metadata.map {|k, v| [header_map[k], v] }]
151
+ Hash[metadata.map { |k, v| [header_map[k], v] }]
158
152
  end
159
153
 
160
154
  def header_mapping
161
155
  header_map = metadata.dup
162
- header_map.each_pair {|k, v| header_map[k] = key_to_header(k)}
156
+ header_map.each_pair { |k, _v| header_map[k] = key_to_header(k) }
163
157
  end
164
158
 
165
159
  def key_to_header(key)
@@ -168,14 +162,14 @@ module Fog
168
162
 
169
163
  def metadata_attributes
170
164
  if last_modified
171
- if directory.key == ""
172
- object = key
173
- else
174
- object = directory.key+"/"+key
175
- end
165
+ object = if directory.key == ''
166
+ key
167
+ else
168
+ directory.key + '/' + key
169
+ end
176
170
 
177
171
  headers = service.head_object(object).data[:headers]
178
- headers.reject! {|k, v| !metadata_attribute?(k)}
172
+ headers.reject! { |k, _v| !metadata_attribute?(k) }
179
173
  else
180
174
  {}
181
175
  end
@@ -186,11 +180,11 @@ module Fog
186
180
  end
187
181
 
188
182
  def metadata_prefix
189
- "X-Object-Meta-"
183
+ 'X-Object-Meta-'
190
184
  end
191
185
 
192
186
  def update_attributes_from(data)
193
- merge_attributes(data[:headers].reject {|key, value| ['Content-Length', 'Content-Type'].include?(key)})
187
+ merge_attributes(data[:headers].reject { |key, _value| ['Content-Length', 'Content-Type'].include?(key) })
194
188
  end
195
189
  end
196
190
  end