From 6dee2184e82abcce5a3e97fc3fa934a9187648b0 Mon Sep 17 00:00:00 2001 From: Brad Gignac Date: Wed, 27 Jun 2012 11:15:16 -0400 Subject: [PATCH] [rackspace|identity] Better checking around hash/array responses. Instead of simply checking for the existence of a key in Identity API responses, this checks the type of the expected response. This should be a less fragile way of handling hash/array responses. --- lib/fog/rackspace/requests/identity/list_credentials.rb | 2 +- lib/fog/rackspace/requests/identity/list_tenants.rb | 2 +- lib/fog/rackspace/requests/identity/list_user_roles.rb | 2 +- lib/fog/rackspace/requests/identity/list_users.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/fog/rackspace/requests/identity/list_credentials.rb b/lib/fog/rackspace/requests/identity/list_credentials.rb index 1f8eac1fe..07da4aa28 100644 --- a/lib/fog/rackspace/requests/identity/list_credentials.rb +++ b/lib/fog/rackspace/requests/identity/list_credentials.rb @@ -9,7 +9,7 @@ module Fog :path => "users/#{user_id}/OS-KSADM/credentials" ) - if response.body.include? 'credential' + unless response.body['credentials'].is_a?(Array) response.body['credentials'] = [response.body['credential']] response.body.delete('credential') end diff --git a/lib/fog/rackspace/requests/identity/list_tenants.rb b/lib/fog/rackspace/requests/identity/list_tenants.rb index 2bc6000d6..04102a48d 100644 --- a/lib/fog/rackspace/requests/identity/list_tenants.rb +++ b/lib/fog/rackspace/requests/identity/list_tenants.rb @@ -9,7 +9,7 @@ module Fog :path => 'tenants' ) - if response.body.include? 'tenant' + unless response.body['tenants'].is_a?(Array) response.body['tenants'] = [response.body['tenant']] response.body.delete('tenant') end diff --git a/lib/fog/rackspace/requests/identity/list_user_roles.rb b/lib/fog/rackspace/requests/identity/list_user_roles.rb index c0f5dc3b4..5e22bd580 100644 --- a/lib/fog/rackspace/requests/identity/list_user_roles.rb +++ b/lib/fog/rackspace/requests/identity/list_user_roles.rb @@ -9,7 +9,7 @@ module Fog :path => "users/#{user_id}/roles" ) - if response.body.include? 'role' + unless response.body['roles'].is_a?(Array) response.body['roles'] = [response.body['role']] response.body.delete('role') end diff --git a/lib/fog/rackspace/requests/identity/list_users.rb b/lib/fog/rackspace/requests/identity/list_users.rb index a581d9f0b..f4dfd073e 100644 --- a/lib/fog/rackspace/requests/identity/list_users.rb +++ b/lib/fog/rackspace/requests/identity/list_users.rb @@ -9,7 +9,7 @@ module Fog :path => 'users' ) - if response.body.include? 'user' + unless response.body['users'].is_a?(Array) response.body['users'] = [response.body['user']] response.body.delete('user') end