Skip to content

Commit

Permalink
Replace multi_json with standard library json
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Apr 23, 2015
1 parent bcfc785 commit 14c01e0
Show file tree
Hide file tree
Showing 27 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Please take care to **never commit credentials to source control**. We strongly

```ruby
require 'json'
creds = JSON.load(File.read('secrets.json'))
creds = JSON.parse(File.read('secrets.json'))
Aws.config[:credentials] = Aws::Credentials.new(creds['AccessKeyId'], creds['SecretAccessKey'])
```

Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-core/aws-sdk-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
spec.bindir = 'bin'
spec.executables << 'aws.rb'

spec.add_dependency('multi_json', '~> 1.0')
spec.add_dependency('json', '~> 1.8')
spec.add_dependency('builder', '~> 3.0')
spec.add_dependency('jmespath', '~> 1.0')

Expand Down
6 changes: 3 additions & 3 deletions aws-sdk-core/features/env.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')

require 'simplecov'
require 'aws-sdk-core'
require 'multi_json'
require 'json'
require 'simplecov'

SimpleCov.command_name('test:integration:aws-sdk-core')

cfg = './integration-test-config.json'

if File.exist?(cfg)
Aws.config = MultiJson.load(File.read(cfg), symbolize_keys: true)
Aws.config = JSON.parse(File.read(cfg), symbolize_names: true)
elsif ENV['AWS_INTEGRATION']
# run integration tests, just don't read a configuration file from disk
else
Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-core/lib/aws-sdk-core.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'jmespath'
require 'multi_json'
require 'json'
require 'seahorse'

Seahorse::Util.irregular_inflections({
Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-core/lib/aws-sdk-core/api/docstrings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Docstrings
def self.apply(client_class, path)
api = client_class.api.definition
docs = File.open(path, 'r', encoding: 'UTF-8') { |f| f.read }
docs = MultiJson.load(docs)
docs = JSON.parse(docs)

api['documentation'] = docs['service']

Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-core/lib/aws-sdk-core/endpoint_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class EndpointProvider
PATH = File.join(File.dirname(__FILE__), '..', '..', 'endpoints.json')

# @api private
RULES = MultiJson.load(File.read(PATH))['endpoints']
RULES = JSON.parse(File.read(PATH))['endpoints']

class << self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def backoff(backoff)
end

def refresh
credentials = MultiJson.load(get_credentials)
credentials = JSON.parse(get_credentials)
@access_key_id = credentials['AccessKeyId']
@secret_access_key = credentials['SecretAccessKey']
@session_token = credentials['Token']
Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-core/lib/aws-sdk-core/json/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Builder
# @param [Hash] params
# @return [String<JSON>]
def to_json(shape, params)
MultiJson.dump(format(shape, params))
JSON.dump(format(shape, params))
end

private
Expand Down
4 changes: 2 additions & 2 deletions aws-sdk-core/lib/aws-sdk-core/json/error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def call(context)
private

def extract_error(body, context)
json = MultiJson.load(body)
json = JSON.parse(body)
code = error_code(json, context)
message = error_message(code, json)
[code, message]
rescue MultiJson::ParseError
rescue JSON::ParserError
[http_status_error_code(context), '']
end

Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-core/lib/aws-sdk-core/json/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Parser
# @param [Hash, Array, nil] target
# @return [Hash]
def parse(shape, json, target = nil)
parse_shape(shape, MultiJson.load(json, max_nesting: false), target)
parse_shape(shape, JSON.parse(json, max_nesting: false), target)
end

private
Expand Down
4 changes: 2 additions & 2 deletions aws-sdk-core/lib/aws-sdk-core/json/simple_body_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def call(context)
private

def build_json(context)
context.http_request.body = MultiJson.dump(context.params)
context.http_request.body = JSON.dump(context.params)
end

def parse_json(context)
MultiJson.load(context.http_response.body_contents)
JSON.parse(context.http_response.body_contents)
end

end
Expand Down
4 changes: 2 additions & 2 deletions aws-sdk-core/lib/seahorse/client/plugins/json_simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class JsonSimple < Plugin
class Handler < Client::Handler

def call(context)
context.http_request.body = MultiJson.dump(context.params)
context.http_request.body = JSON.dump(context.params)
@handler.call(context).on_success do |response|
response.error = nil
response.data = MultiJson.load(context.http_response.body_contents)
response.data = JSON.parse(context.http_response.body_contents)
end
end

Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-core/lib/seahorse/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def uri_escape(string)
end

def load_json(path)
MultiJson.load(File.open(path, 'r', encoding: 'UTF-8') { |f| f.read })
JSON.parse(File.open(path, 'r', encoding: 'UTF-8') { |f| f.read })
end

end
Expand Down
14 changes: 7 additions & 7 deletions aws-sdk-core/spec/protocols_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'
require 'multi_json'
require 'json'
require 'rexml/document'
require 'spec_helper'

def fixtures
fixtures = {}
Expand All @@ -18,7 +18,7 @@ def fixtures

def each_test_case(context, fixture_path)
return unless fixture_path
MultiJson.load(File.read(fixture_path)).each do |suite|
JSON.parse(File.read(fixture_path)).each do |suite|
describe(suite['description'].inspect) do
suite['cases'].each.with_index do |test_case,n|
describe("case: #{n}") do
Expand Down Expand Up @@ -118,12 +118,12 @@ def match_req_body(group, suite, test_case, http_req)
body = body.split('&').sort.join('&')
expected_body = expected_body.split('&').sort.join('&')
when 'json'
body = MultiJson.load(body) unless body == ''
expected_body = MultiJson.load(expected_body)
body = JSON.parse(body) unless body == ''
expected_body = JSON.parse(expected_body)
when 'rest-json'
if body[0] == '{'
body = MultiJson.load(body)
expected_body = MultiJson.load(expected_body)
body = JSON.parse(body)
expected_body = JSON.parse(expected_body)
end
when 'rest-xml'
body = normalize_xml(body)
Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-resources/features/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
cfg = './integration-test-config.json'

if File.exist?(cfg)
Aws.config = MultiJson.load(File.read(cfg), symbolize_keys: true)
Aws.config = JSON.parse(File.read(cfg), symbolize_names: true)
elsif ENV['AWS_INTEGRATION']
# run integration tests, just don't read a configuration file from disk
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ module S3
# @keys = keys
# @encryption_materials = Aws::S3::Encryption::Materials.new(
# key: @keys[default_key_name],
# description: MultiJson.dump(key: default_key_name),
# description: JSON.dump(key: default_key_name),
# )
# end
#
# attr_reader :encryption_materials
#
# def key_for(matdesc)
# key_name = MultiJson.load(matdesc)['key']
# key_name = JSON.parse(matdesc)['key']
# if key = @keys[key_name]
# key
# else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def envelope_from_metadata(context)

def envelope_from_instr_file(context)
suffix = context[:encryption][:instruction_file_suffix]
MultiJson.load(context.client.get_object(
JSON.parse(context.client.get_object(
bucket: context.params[:bucket],
key: context.params[:key] + suffix
).body.read)
rescue S3::Errors::ServiceError, MultiJson::ParseError
rescue S3::Errors::ServiceError, JSON::ParserError
nil
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def apply_encryption_envelope(context, envelope)
context.client.put_object(
bucket: context.params[:bucket],
key: context.params[:key] + suffix,
body: MultiJson.dump(envelope)
body: JSON.dump(envelope)
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def validate_key(key)
end

def validate_desc(description)
MultiJson.load(description)
JSON.parse(description)
description
rescue MultiJson::ParseError
rescue JSON::ParserError
msg = "expected description to be a valid JSON document string"
raise ArgumentError, msg
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'openssl'
require 'base64'
require 'multi_json'
require 'json'
require 'openssl'

module Aws
module S3
Expand Down Expand Up @@ -597,7 +597,7 @@ def policy(datetime)
signature_fields(datetime).each do |name, value|
policy['conditions'] << { name => value }
end
base64(MultiJson.dump(policy))
base64(JSON.dump(policy))
end

def signature_fields(datetime)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'base64'
require 'json'
require 'net/http'
require 'openssl'
require 'base64'
require 'multi_json'

module Aws
module SNS
Expand Down Expand Up @@ -59,7 +59,7 @@ def authentic?(message_body)
# @raise [VerificationError] Raised when the given message has failed
# verification.
def authenticate!(message_body)
msg = MultiJson.load(message_body)
msg = JSON.parse(message_body)
if public_key(msg).verify(sha1, signature(msg), canonical_string(msg))
true
else
Expand Down
4 changes: 2 additions & 2 deletions aws-sdk-resources/spec/services/s3/encryption/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ module Encryption
# first request stores the encryption materials in the instruction file
expect(
a_request(:put, "https://bucket.s3-us-west-1.amazonaws.com/key.instruction").with(
:body => MultiJson.dump(
:body => JSON.dump(
'x-amz-key'=>'gX+a4JQYj7FP0y5TAAvxTz4e2l0DvOItbXByml/NPtKQcUlsoGHoYR/T0TuYHcNj',
'x-amz-iv' => 'TO5mQgtOzWkTfoX4RE5tsA==',
'x-amz-matdesc' => '{}',
Expand Down Expand Up @@ -231,7 +231,7 @@ def stub_encrypted_get_with_instruction_file(suffix = '.instruction')
to_return(body: encrypted_body)
stub_request(:get, "https://bucket.s3-us-west-1.amazonaws.com/key#{suffix}").
to_return(
:body => MultiJson.dump(
:body => JSON.dump(
'x-amz-key'=>'gX+a4JQYj7FP0y5TAAvxTz4e2l0DvOItbXByml/NPtKQcUlsoGHoYR/T0TuYHcNj',
'x-amz-iv' => 'TO5mQgtOzWkTfoX4RE5tsA==',
'x-amz-matdesc' => '{}',
Expand Down
6 changes: 3 additions & 3 deletions aws-sdk-resources/spec/services/s3/presigned_post_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'
require 'base64'
require 'multi_json'
require 'json'
require 'spec_helper'

module Aws
module S3
Expand All @@ -17,7 +17,7 @@ module S3
let(:post) { PresignedPost.new(creds, region, bucket, options) }

def decode(policy)
MultiJson.load(Base64.decode64(policy))
JSON.parse(Base64.decode64(policy))
end

def policy(post)
Expand Down
22 changes: 11 additions & 11 deletions aws-sdk-resources/spec/services/sns/message_verifier_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'json'
require 'spec_helper'
require 'multi_json'

module Aws
module SNS
Expand Down Expand Up @@ -69,36 +69,36 @@ module SNS
end

it 'raises when the SigningCertURL is not https' do
msg = MultiJson.load(message)
msg = JSON.parse(message)
msg['SigningCertURL'] = msg['SigningCertURL'].sub(/https/, 'http')
msg = MultiJson.dump(msg)
msg = JSON.dump(msg)
expect {
verifier.authenticate!(msg)
}.to raise_error(MessageVerifier::VerificationError, /must be https/)
end

it 'raises when the SigningCertURL is not AWS hosted' do
msg = MultiJson.load(message)
msg = JSON.parse(message)
msg['SigningCertURL'] = 'https://internetbadguys.com/cert.pem'
msg = MultiJson.dump(msg)
msg = JSON.dump(msg)
expect {
verifier.authenticate!(msg)
}.to raise_error(MessageVerifier::VerificationError, /hosted by AWS/)
end

it 'raises when the SigningCertURL is not a pem file' do
msg = MultiJson.load(message)
msg = JSON.parse(message)
msg['SigningCertURL'] = msg['SigningCertURL'].sub(/pem$/, 'key')
msg = MultiJson.dump(msg)
msg = JSON.dump(msg)
expect {
verifier.authenticate!(msg)
}.to raise_error(MessageVerifier::VerificationError, /a \.pem file/)
end

it 'raises when the message signature fails validation' do
msg = MultiJson.load(message)
msg = JSON.parse(message)
msg['Signature'] = 'bad'
msg = MultiJson.dump(msg)
msg = JSON.dump(msg)
expect {
verifier.authenticate!(msg)
}.to raise_error(MessageVerifier::VerificationError, /cannot be verified/)
Expand Down Expand Up @@ -142,9 +142,9 @@ module SNS
end

it 'returns false if the message can not be authenticated' do
msg = MultiJson.load(message)
msg = JSON.parse(message)
msg['Signature'] = 'bad'
msg = MultiJson.dump(msg)
msg = JSON.dump(msg)
expect(verifier.authentic?(msg)).to be(false)
end

Expand Down
2 changes: 1 addition & 1 deletion aws-sdk-resources/tasks/resources.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace :resources do
Dir.glob("aws-sdk-core/apis/*.resources.json").each do |path|
puts path
data = File.open(path, 'r', encoding:'UTF-8') { |f| f.read }
data = ResourceDefinitionFormatter.new.format_json(JSON.load(data))
data = ResourceDefinitionFormatter.new.format_json(JSON.parse(data))
File.open(path, 'w', encoding:'UTF-8') { |f| f.write(data + "\n") }
end
end
Expand Down
2 changes: 1 addition & 1 deletion developer_guide/content/sections/credential_management.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The following JSON document and Ruby code demonstrate loading credentials from d
require 'aws-sdk'
require 'json'

creds = JSON.load(File.read('~/secrets.json'))
creds = JSON.parse(File.read('~/secrets.json'))
creds = Aws::Credentials.new(creds['accessKeyId'], creds['secretAccessKey'])

Aws.config[:credentials] = creds
Expand Down
2 changes: 1 addition & 1 deletion doc-src/plugins/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def document_data_attribute_getters(yard_class, resource_class)
endpoint = resource_class.client_class.api.metadata('endpointPrefix')
version = resource_class.client_class.api.version
definition = File.read("aws-sdk-core/apis/#{endpoint}/#{version}/resources-1.json")
definition = MultiJson.load(definition)
definition = JSON.parse(definition)
definition = definition['resources'][resource_name]
if shape_name = definition['shape']

Expand Down

0 comments on commit 14c01e0

Please sign in to comment.