Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions lib/fog/aliyun/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,18 @@ def reload

def request(params)
begin
response = @connection.request(params.merge(headers: {
headers = {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'X-Auth-Token' => @auth_token
}.merge!(params[:headers] || {}),
path: "#{@path}/#{params[:path]}",
query: params[:query]))
}.merge!(params[:headers] || {})

request_params = params.merge(
headers: headers,
path: "#{@path}/#{params[:path]}",
query: params[:query])

response = @connection.request(request_params)
rescue Excon::Errors::HTTPStatusError => error
raise case error
when Excon::Errors::NotFound
Expand All @@ -316,7 +321,7 @@ def request(params)
end
end

response.body = Fog::JSON.decode(response.body) if !response.body.empty? && response.get_header('Content-Type') == 'application/json'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value often comes back as application/json; charset=utf-8which fails the exact-string matching used before.

response.body = Fog::JSON.decode(response.body) if !response.body.empty? && response.get_header('Content-Type').start_with?('application/json')

response
end
Expand All @@ -339,7 +344,7 @@ def VPCrequest(params)
end
end

response.body = Fog::JSON.decode(response.body) if !response.body.empty? && response.get_header('Content-Type') == 'application/json'
response.body = Fog::JSON.decode(response.body) if !response.body.empty? && response.get_header('Content-Type').start_with?('application/json')

response
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/eip_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def save(options = {})
options[:bandwidth] = bandwidth if bandwidth
options[:internet_charge_type] = charge_type if charge_type

data = Fog::JSON.decode(service.allocate_eip_address(options).body)
data = service.allocate_eip_address(options).body
merge_attributes(data)
true
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/eip_addresses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EipAddresses < Fog::Collection
model Fog::Compute::Aliyun::EipAddress

def all(filters_arg = {})
data = Fog::JSON.decode(service.list_eip_addresses(filters_arg).body)['EipAddresses']['EipAddress']
data = service.list_eip_addresses(filters_arg).body['EipAddresses']['EipAddress']
load(data)
# load(data['volumeSet'])
# if server
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def save(options = {})
requires :snapshot_id
options[:name] = name if name
options[:description] = description if description
data = Fog::JSON.decode(service.create_image(snapshot_id, options).body)
data = service.create_image(snapshot_id, options).body
merge_attributes(data)
true
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def all(filters_arg = {})
Fog::Logger.deprecation("all with #{filters_arg.class} param is deprecated, use all('diskIds' => []) instead [light_black](#{caller.first})[/]")
filters_arg = { imageId: filters_arg }
end
data = Fog::JSON.decode(service.list_images(filters_arg).body)['Images']['Image']
data = service.list_images(filters_arg).body['Images']['Image']
load(data)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/route_entrys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RouteEntrys < Fog::Collection
def all(options = {})
requires :route_table
options[:routeTableId] = route_table.id
data = Fog::JSON.decode(service.list_route_tables(route_table.v_router_id, options).body)['RouteTables']['RouteTable'][0]['RouteEntrys']['RouteEntry']
data = service.list_route_tables(route_table.v_router_id, options).body['RouteTables']['RouteTable'][0]['RouteEntrys']['RouteEntry']
load(data)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/route_tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RouteTables < Fog::Collection

def all(options = {})
requires :v_router
data = Fog::JSON.decode(service.list_route_tables(v_router.id, options).body)['RouteTables']['RouteTable']
data = service.list_route_tables(v_router.id, options).body['RouteTables']['RouteTable']
load(data)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/security_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def save(options = {})
options[:vpcId] = vpc_id if vpc_id
options[:name] = name if name
options[:description] = description if description
Fog::JSON.decode(service.create_security_group(options).body)
service.create_security_group(options).body
true
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/security_group_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SecurityGroupRules < Fog::Collection
attribute :security_group_id

def get(security_group_id, options = {})
data = Fog::JSON.decode(service.list_security_group_rules(security_group_id, options).body)
data = service.list_security_group_rules(security_group_id, options).body
self.security_group_id = data['SecurityGroupId']
permissions = data['Permissions']['Permission']
permissions.each do |permission|
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/security_groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SecurityGroups < Fog::Collection
model Fog::Compute::Aliyun::SecurityGroup

def all(options = {})
data = Fog::JSON.decode(service.list_security_groups(options).body)['SecurityGroups']['SecurityGroup']
data = service.list_security_groups(options).body['SecurityGroups']['SecurityGroup']
load(data)
# ['Images']['Image']
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def save(options = {})
requires :volume_id
options[:name] = name if name
options[:description] = description if description
data = Fog::JSON.decode(service.create_snapshot(volume_id, options).body)
data = service.create_snapshot(volume_id, options).body
merge_attributes(data)
true
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/snapshots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def all(filters_arg = {})
volume_type = filters_arg[:volume_type]
filters_arg[:diskId] = volume_id if volume_id
filters_arg[:sourseDiskType] = volume_type if volume_type
data = Fog::JSON.decode(service.list_snapshots(filters_arg).body)['Snapshots']['Snapshot']
data = service.list_snapshots(filters_arg).body['Snapshots']['Snapshot']
load(data)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/fog/aliyun/models/compute/volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def save(options = {})
options[:name] = name if name
options[:description] = description if description
if snapshot_id
data = Fog::JSON.decode(service.create_disk_by_snapshot(snapshot_id, options).body)
data = service.create_disk_by_snapshot(snapshot_id, options).body
merge_attributes(data)
elsif size
data = Fog::JSON.decode(service.create_disk(size, options).body)
data = service.create_disk(size, options).body
merge_attributes(data)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/volumes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def all(filters_arg = {})
Fog::Logger.deprecation("all with #{filters_arg.class} param is deprecated, use all('diskIds' => []) instead [light_black](#{caller.first})[/]")
filters_arg = { 'diskIds' => [*filters_arg] }
end
data = Fog::JSON.decode(service.list_disks(filters_arg).body)['Disks']['Disk']
data = service.list_disks(filters_arg).body['Disks']['Disk']
load(data)
# load(data['volumeSet'])
# if server
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/vpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def save(options = {})
requires :cidr_block
options[:name] = name if name
options[:description] = description if description
Fog::JSON.decode(service.create_vpc(cidr_block, options).body)
service.create_vpc(cidr_block, options).body
true
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/vpcs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def all(filters_arg = {})
Fog::Logger.warning("all with #{filters_arg.class} param is deprecated, use all('vpcId' => []) instead [light_black](#{caller.first})[/]")
filters_arg = { 'vpcId' => [*filters_arg] }
end
data = Fog::JSON.decode(service.list_vpcs(filters_arg).body)['Vpcs']['Vpc']
data = service.list_vpcs(filters_arg).body['Vpcs']['Vpc']
load(data)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/vrouters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def all(filters_arg = {})
Fog::Logger.warning("all with #{filters_arg.class} param is deprecated, use all('vRouterId' => "") instead [light_black](#{caller.first})[/]")
filters_arg = { 'vRouterId' => filters_arg }
end
data = Fog::JSON.decode(service.list_vrouters(filters_arg).body)['VRouters']['VRouter']
data = service.list_vrouters(filters_arg).body['VRouters']['VRouter']
load(data)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/fog/aliyun/models/compute/vswitch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def save(options = {})
requires :vpc, :cidr_block
options[:name] = name if name
options[:description] = description if description
Fog::JSON.decode(service.create_vswitch(vpc.id, cidr_block, options).body)
service.create_vswitch(vpc.id, cidr_block, options).body
true
end

Expand All @@ -64,7 +64,7 @@ def vpc
end

def all
Fog::JSON.decode(service.list_vswitchs(vpc_id).body)['VSwitches']['VSwitch']
service.list_vswitchs(vpc_id).body['VSwitches']['VSwitch']
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/vswitches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Vswitches < Fog::Collection

def all(options = {})
requires :vpc
data = Fog::JSON.decode(service.list_vswitchs(vpc.id, options).body)['VSwitches']['VSwitch']
data = service.list_vswitchs(vpc.id, options).body['VSwitches']['VSwitch']
load(data)
end

Expand Down