mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Revert "Updated gem spec to require json rather than multi_json"
This reverts commits:66638b25d7
,3f0314dbd1
, and18ce4b7eca
. Since google-api-client was added as a dependency inafa9b025e9
, multi_json is a de facto dependency of fog, so this is a needless layer. If #1034 is still an issue, I'd be happy to ship a version of multi_json that requires rubygems >= 1.3.5.
This commit is contained in:
parent
ca945a0432
commit
f2bd2404d1
38 changed files with 61 additions and 152 deletions
2
Gemfile
2
Gemfile
|
@ -1,5 +1,3 @@
|
|||
source "https://rubygems.org"
|
||||
|
||||
gemspec
|
||||
|
||||
gem "multi_json", '~>1.0'
|
||||
|
|
|
@ -43,7 +43,7 @@ Gem::Specification.new do |s|
|
|||
s.add_dependency('builder')
|
||||
s.add_dependency('excon', '~>0.20')
|
||||
s.add_dependency('formatador', '~>0.2.0')
|
||||
s.add_dependency('json', '~>1.7')
|
||||
s.add_dependency('multi_json', '~>1.0')
|
||||
s.add_dependency('mime-types')
|
||||
s.add_dependency('net-scp', '~>1.1')
|
||||
s.add_dependency('net-ssh', '>=2.1.3')
|
||||
|
|
|
@ -1,51 +1,7 @@
|
|||
require 'singleton'
|
||||
require 'fog/core/logger'
|
||||
require 'multi_json'
|
||||
|
||||
module Fog
|
||||
class JSON
|
||||
include Singleton
|
||||
|
||||
class LoadError < StandardError
|
||||
attr_reader :data
|
||||
def initialize(message='', backtrace=[], data='')
|
||||
super(message)
|
||||
self.set_backtrace(backtrace)
|
||||
@data = data
|
||||
end
|
||||
end
|
||||
|
||||
module LegacyJSON
|
||||
def encode(obj)
|
||||
::JSON.generate(obj)
|
||||
end
|
||||
|
||||
def decode(obj)
|
||||
::JSON.parse(obj)
|
||||
rescue ::JSON::ParserError => e
|
||||
raise LoadError.new(e.message, e.backtrace, obj)
|
||||
end
|
||||
end
|
||||
|
||||
module NewJSON
|
||||
def encode(obj)
|
||||
::MultiJson.encode(obj)
|
||||
end
|
||||
|
||||
def decode(obj)
|
||||
::MultiJson.decode(obj)
|
||||
rescue MultiJson::LoadError => e
|
||||
raise LoadError.new(e.message, e.backtrace, obj)
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
require 'multi_json'
|
||||
include NewJSON
|
||||
rescue Exception
|
||||
Fog::Logger.deprecation "Defaulting to json library for json parsing. Please consider using multi_json library for the greatest performance/flexibility."
|
||||
require 'json'
|
||||
include LegacyJSON
|
||||
end
|
||||
module JSON
|
||||
|
||||
def self.sanitize(data)
|
||||
case data
|
||||
|
@ -64,12 +20,14 @@ module Fog
|
|||
|
||||
# Do the MultiJson introspection at this level so we can define our encode/decode methods and perform
|
||||
# the introspection only once rather than once per call.
|
||||
|
||||
def self.encode(obj)
|
||||
Fog::JSON.instance.encode(obj)
|
||||
MultiJson.encode(obj)
|
||||
end
|
||||
|
||||
def self.decode(obj)
|
||||
Fog::JSON.instance.decode(obj)
|
||||
MultiJson.decode(obj)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -47,6 +47,8 @@ module Fog
|
|||
class Real
|
||||
|
||||
def initialize(options={})
|
||||
require 'multi_json'
|
||||
|
||||
@dreamhost_api_key = options[:dreamhost_api_key]
|
||||
if options[:dreamhost_url]
|
||||
uri = URI.parse(options[:dreamhost_url])
|
||||
|
@ -71,7 +73,7 @@ module Fog
|
|||
response = @connection.request(params)
|
||||
|
||||
unless response.body.empty?
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
response.body = MultiJson.decode(response.body)
|
||||
end
|
||||
if response.body['result'] != 'success'
|
||||
raise response.body['data']
|
||||
|
|
|
@ -25,7 +25,7 @@ module Fog
|
|||
if message.nil? and !data.values.first.nil?
|
||||
message = data.values.first['message']
|
||||
end
|
||||
rescue Fog::JSON::LoadError
|
||||
rescue MultiJson::DecodeError
|
||||
message = error.response.body #### body is not in JSON format, so just return as is
|
||||
end
|
||||
end
|
||||
|
|
|
@ -95,6 +95,7 @@ module Fog
|
|||
end
|
||||
|
||||
def initialize(options={})
|
||||
require 'multi_json'
|
||||
@openstack_username = options[:openstack_username] || 'admin'
|
||||
@openstack_tenant = options[:openstack_tenant] || 'admin'
|
||||
@openstack_auth_uri = URI.parse(options[:openstack_auth_url])
|
||||
|
@ -245,7 +246,7 @@ module Fog
|
|||
end
|
||||
end
|
||||
unless response.body.empty?
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
response.body = MultiJson.decode(response.body)
|
||||
end
|
||||
response
|
||||
end
|
||||
|
|
|
@ -46,6 +46,7 @@ module Fog
|
|||
end
|
||||
|
||||
def initialize(options={})
|
||||
require 'multi_json'
|
||||
@openstack_username = options[:openstack_username]
|
||||
@openstack_tenant = options[:openstack_tenant]
|
||||
@openstack_auth_uri = URI.parse(options[:openstack_auth_url])
|
||||
|
@ -93,6 +94,8 @@ module Fog
|
|||
attr_reader :current_tenant
|
||||
|
||||
def initialize(options={})
|
||||
require 'multi_json'
|
||||
|
||||
@openstack_auth_token = options[:openstack_auth_token]
|
||||
|
||||
unless @openstack_auth_token
|
||||
|
@ -165,7 +168,7 @@ module Fog
|
|||
end
|
||||
end
|
||||
unless response.body.empty?
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
response.body = MultiJson.decode(response.body)
|
||||
end
|
||||
response
|
||||
end
|
||||
|
|
|
@ -113,6 +113,8 @@ module Fog
|
|||
attr_reader :current_tenant
|
||||
|
||||
def initialize(options={})
|
||||
require 'multi_json'
|
||||
|
||||
@openstack_auth_token = options[:openstack_auth_token]
|
||||
|
||||
unless @openstack_auth_token
|
||||
|
@ -185,7 +187,7 @@ module Fog
|
|||
end
|
||||
end
|
||||
unless response.body.empty?
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
response.body = MultiJson.decode(response.body)
|
||||
end
|
||||
response
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ module Fog
|
|||
def allocate_address(pool = nil)
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode({'pool' => pool}),
|
||||
:body => MultiJson.encode({'pool' => pool}),
|
||||
:expects => [200, 202],
|
||||
:method => 'POST',
|
||||
:path => 'os-floating-ips.json'
|
||||
|
|
|
@ -11,7 +11,7 @@ module Fog
|
|||
}
|
||||
}
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:body => MultiJson.encode(data),
|
||||
:expects => [200, 202],
|
||||
:method => 'POST',
|
||||
:path => "servers/%s/os-volume_attachments" % [server_id]
|
||||
|
|
|
@ -29,7 +29,7 @@ module Fog
|
|||
end
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:body => MultiJson.encode(data),
|
||||
:expects => [200, 202],
|
||||
:method => 'POST',
|
||||
:path => '/os-volumes_boot.json'
|
||||
|
|
|
@ -35,7 +35,7 @@ module Fog
|
|||
}
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:body => MultiJson.encode(data),
|
||||
:expects => 200,
|
||||
:method => 'POST',
|
||||
:path => 'flavors'
|
||||
|
|
|
@ -14,7 +14,7 @@ module Fog
|
|||
data['keypair']['public_key'] = public_key unless public_key.nil?
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:body => MultiJson.encode(data),
|
||||
:expects => 200,
|
||||
:method => 'POST',
|
||||
:path => 'os-keypairs.json'
|
||||
|
|
|
@ -12,7 +12,7 @@ module Fog
|
|||
}
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:body => MultiJson.encode(data),
|
||||
:expects => 200,
|
||||
:method => 'POST',
|
||||
:path => 'os-security-groups.json'
|
||||
|
|
|
@ -18,7 +18,7 @@ module Fog
|
|||
request(
|
||||
:expects => 200,
|
||||
:method => 'POST',
|
||||
:body => Fog::JSON.encode(data),
|
||||
:body => MultiJson.encode(data),
|
||||
:path => 'os-security-group-rules.json'
|
||||
)
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@ module Fog
|
|||
data['volume'][key] = options[key]
|
||||
end
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:body => MultiJson.encode(data),
|
||||
:expects => [200, 202],
|
||||
:method => 'POST',
|
||||
:path => "os-volumes"
|
||||
|
|
|
@ -14,7 +14,7 @@ module Fog
|
|||
}
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:body => MultiJson.encode(data),
|
||||
:expects => [200, 202],
|
||||
:method => 'POST',
|
||||
:path => "os-snapshots"
|
||||
|
|
|
@ -11,7 +11,7 @@ module Fog
|
|||
:method => 'GET',
|
||||
:path => '/v2.0/tenants'
|
||||
})
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
response.body = MultiJson.decode(response.body)
|
||||
response
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ module Fog
|
|||
def update_quota(tenant_id, options = {})
|
||||
options['tenant_id'] = tenant_id
|
||||
request(
|
||||
:body => Fog::JSON.encode({ 'quota_set' => options }),
|
||||
:body => MultiJson.encode({ 'quota_set' => options }),
|
||||
:expects => 200,
|
||||
:method => 'PUT',
|
||||
:path => "/os-quota-sets/#{tenant_id}"
|
||||
|
|
|
@ -26,7 +26,7 @@ module Fog
|
|||
data = { 'tenant_id' => tenant_id }
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:body => MultiJson.encode(data),
|
||||
:expects => [200, 202],
|
||||
:method => 'POST',
|
||||
:path => "users/#{user_id}/credentials/OS-EC2"
|
||||
|
|
|
@ -10,7 +10,7 @@ module Fog
|
|||
}
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:body => MultiJson.encode(data),
|
||||
:expects => [200, 202],
|
||||
:method => 'POST',
|
||||
:path => '/OS-KSADM/roles'
|
||||
|
|
|
@ -15,7 +15,7 @@ module Fog
|
|||
}
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:body => MultiJson.encode(data),
|
||||
:expects => [200, 202],
|
||||
:method => 'POST',
|
||||
:path => '/users'
|
||||
|
|
|
@ -6,7 +6,7 @@ module Fog
|
|||
def update_user(user_id, options = {})
|
||||
url = options.delete('url') || "/users/#{user_id}"
|
||||
request(
|
||||
:body => Fog::JSON.encode({ 'user' => options }),
|
||||
:body => MultiJson.encode({ 'user' => options }),
|
||||
:expects => 200,
|
||||
:method => 'PUT',
|
||||
:path => url
|
||||
|
|
|
@ -11,7 +11,7 @@ module Fog
|
|||
data = { 'memberships' => members }
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:body => MultiJson.encode(data),
|
||||
:expects => [200, 202],
|
||||
:method => 'PUT',
|
||||
:path => "images/#{image_id}/members"
|
||||
|
|
|
@ -17,7 +17,7 @@ module Fog
|
|||
data['volume'][key] = options[key]
|
||||
end
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:body => MultiJson.encode(data),
|
||||
:expects => [200, 202],
|
||||
:method => 'POST',
|
||||
:path => "volumes"
|
||||
|
|
|
@ -14,7 +14,7 @@ module Fog
|
|||
}
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:body => MultiJson.encode(data),
|
||||
:expects => [200, 202],
|
||||
:method => 'POST',
|
||||
:path => "snapshots"
|
||||
|
|
|
@ -56,6 +56,7 @@ module Fog
|
|||
end
|
||||
|
||||
def initialize(options={})
|
||||
require 'multi_json'
|
||||
@openstack_username = options[:openstack_username]
|
||||
@openstack_tenant = options[:openstack_tenant]
|
||||
@openstack_auth_uri = URI.parse(options[:openstack_auth_url])
|
||||
|
@ -102,6 +103,8 @@ module Fog
|
|||
attr_reader :current_tenant
|
||||
|
||||
def initialize(options={})
|
||||
require 'multi_json'
|
||||
|
||||
@openstack_auth_token = options[:openstack_auth_token]
|
||||
|
||||
unless @openstack_auth_token
|
||||
|
@ -174,7 +177,7 @@ module Fog
|
|||
end
|
||||
end
|
||||
unless response.body.empty?
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
response.body = MultiJson.decode(response.body)
|
||||
end
|
||||
response
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require File.join(File.dirname(__FILE__), 'core')
|
||||
require 'fog/core'
|
||||
require 'fog/rackspace/mock_data'
|
||||
require 'fog/rackspace/service'
|
||||
require 'fog/rackspace/errors'
|
||||
|
|
|
@ -98,7 +98,7 @@ module Fog
|
|||
request :delete_network
|
||||
|
||||
class Mock < Fog::Rackspace::Service
|
||||
include Fog::Rackspace::MockData
|
||||
include Fog::Rackspace::MockData
|
||||
|
||||
def initialize(options)
|
||||
@rackspace_api_key = options[:rackspace_api_key]
|
||||
|
@ -122,7 +122,7 @@ module Fog
|
|||
end
|
||||
|
||||
class Real < Fog::Rackspace::Service
|
||||
|
||||
|
||||
def initialize(options = {})
|
||||
@rackspace_api_key = options[:rackspace_api_key]
|
||||
@rackspace_username = options[:rackspace_username]
|
||||
|
@ -134,7 +134,7 @@ module Fog
|
|||
authenticate
|
||||
|
||||
deprecation_warnings(options)
|
||||
|
||||
|
||||
@persistent = options[:persistent] || false
|
||||
@connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
|
||||
end
|
||||
|
@ -163,13 +163,13 @@ module Fog
|
|||
unless response.body.empty?
|
||||
begin
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
rescue Fog::JSON::LoadError
|
||||
rescue MultiJson::DecodeError => e
|
||||
response.body = {}
|
||||
end
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
|
||||
def authenticate
|
||||
options = {
|
||||
:rackspace_api_key => @rackspace_api_key,
|
||||
|
@ -228,7 +228,7 @@ module Fog
|
|||
|
||||
def append_tenant_v1(credentials)
|
||||
account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1]
|
||||
|
||||
|
||||
endpoint = @rackspace_endpoint || credentials['X-Server-Management-Url'] || DFW_ENDPOINT
|
||||
@uri = URI.parse(endpoint)
|
||||
@uri.path = "#{@uri.path}/#{account_id}"
|
||||
|
|
|
@ -71,9 +71,9 @@ module Fog
|
|||
|
||||
module UserUtils
|
||||
def update_riakcs_user(key_id, user)
|
||||
response = @s3_connection.put_object('riak-cs', "user/#{key_id}", Fog::JSON.encode(user), { 'Content-Type' => 'application/json' })
|
||||
response = @s3_connection.put_object('riak-cs', "user/#{key_id}", MultiJson.encode(user), { 'Content-Type' => 'application/json' })
|
||||
if !response.body.empty?
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
response.body = MultiJson.decode(response.body)
|
||||
end
|
||||
response
|
||||
end
|
||||
|
|
|
@ -48,6 +48,8 @@ module Fog
|
|||
|
||||
def initialize(options = {})
|
||||
require 'mime/types'
|
||||
require 'multi_json'
|
||||
|
||||
configure_uri_options(options)
|
||||
@riakcs_access_key_id = options[:riakcs_access_key_id]
|
||||
@riakcs_secret_access_key = options[:riakcs_secret_access_key]
|
||||
|
@ -87,7 +89,7 @@ module Fog
|
|||
end
|
||||
end
|
||||
if !response.body.empty? && parse_response
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
response.body = MultiJson.decode(response.body)
|
||||
end
|
||||
response
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ module Fog
|
|||
class Provisioning
|
||||
class Real
|
||||
def create_user(email, name, options = {})
|
||||
payload = Fog::JSON.encode({ :email => email, :name => name })
|
||||
payload = MultiJson.encode({ :email => email, :name => name })
|
||||
headers = { 'Content-Type' => 'application/json' }
|
||||
|
||||
if(options[:anonymous])
|
||||
|
@ -20,7 +20,7 @@ module Fog
|
|||
if !response.body.empty?
|
||||
case response.headers['Content-Type']
|
||||
when 'application/json'
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
response.body = MultiJson.decode(response.body)
|
||||
end
|
||||
end
|
||||
response
|
||||
|
|
|
@ -7,7 +7,7 @@ module Fog
|
|||
|
||||
def get_user(key_id)
|
||||
response = @s3_connection.get_object('riak-cs', "user/#{key_id}", { 'Accept' => 'application/json' })
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
response.body = MultiJson.decode(response.body)
|
||||
response
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ module Fog
|
|||
|
||||
boundary = extract_boundary(response.headers['Content-Type'])
|
||||
parts = parse(response.body, boundary)
|
||||
decoded = parts.map { |part| Fog::JSON.decode(part[:body]) }
|
||||
decoded = parts.map { |part| MultiJson.decode(part[:body]) }
|
||||
|
||||
response.body = decoded.flatten
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ module Fog
|
|||
response = @connection.get_object('riak-cs', ["usage", request_uri(access_key_id, options)].join("/"))
|
||||
|
||||
if !response.body.empty?
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
response.body = MultiJson.decode(response.body)
|
||||
end
|
||||
response
|
||||
end
|
||||
|
|
|
@ -42,6 +42,7 @@ module Fog
|
|||
|
||||
def initialize(options = {})
|
||||
require 'mime/types'
|
||||
require 'multi_json'
|
||||
|
||||
configure_uri_options(options)
|
||||
@riakcs_access_key_id = options[:riakcs_access_key_id]
|
||||
|
|
|
@ -14,6 +14,7 @@ module Fog
|
|||
changelog << ('=' * changelog[0].length)
|
||||
changelog << ''
|
||||
|
||||
require 'multi_json'
|
||||
github_repo_data = Fog::JSON.decode(Excon.get('https://api.github.com/repos/fog/fog', :headers => {'User-Agent' => 'geemus'}).body)
|
||||
data = github_repo_data.reject {|key, value| !['forks', 'open_issues', 'watchers'].include?(key)}
|
||||
github_collaborator_data = Fog::JSON.decode(Excon.get('https://api.github.com/repos/fog/fog/collaborators', :headers => {'User-Agent' => 'geemus'}).body)
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
Shindo.tests('Fog#JSON', 'core') do
|
||||
|
||||
TEST_HASH = {'quantity' => 4}
|
||||
VALID_JSON = "{\"quantity\":4}"
|
||||
|
||||
tests('LegacyJSON') do
|
||||
|
||||
begin
|
||||
require 'json'
|
||||
rescue => e
|
||||
returns('Failed to load JSON library', true) { false }
|
||||
end
|
||||
|
||||
pending? unless defined? ::JSON
|
||||
|
||||
class LegacyJSONTester
|
||||
include Fog::JSON::LegacyJSON
|
||||
end
|
||||
|
||||
@tester = LegacyJSONTester.new
|
||||
tests('encode').returns(VALID_JSON) do
|
||||
@tester.encode(TEST_HASH)
|
||||
end
|
||||
|
||||
tests('decode').returns(TEST_HASH) do
|
||||
@tester.decode(VALID_JSON)
|
||||
end
|
||||
|
||||
tests('invalid decode').raises(Fog::JSON::LoadError) do
|
||||
@tester.decode("I am not json")
|
||||
end
|
||||
end
|
||||
|
||||
tests('NewJSON') do
|
||||
|
||||
begin
|
||||
require 'multi_json'
|
||||
rescue => e
|
||||
returns('Failed to load multi_json library', true) { false }
|
||||
end
|
||||
|
||||
pending unless defined? ::MultiJson
|
||||
|
||||
class NewJSONTester
|
||||
include Fog::JSON::NewJSON
|
||||
end
|
||||
|
||||
@tester = NewJSONTester.new
|
||||
tests('encode').returns(VALID_JSON) do
|
||||
@tester.encode(TEST_HASH)
|
||||
end
|
||||
|
||||
tests('decode').returns(TEST_HASH) do
|
||||
@tester.decode(VALID_JSON)
|
||||
end
|
||||
|
||||
tests('invalid decode').raises(Fog::JSON::LoadError) do
|
||||
@tester.decode("I am not json")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue