From e40d4dfb0af1d69425033c0d781823d1924f763e Mon Sep 17 00:00:00 2001 From: Juli Tera Date: Fri, 15 Nov 2024 12:51:46 -0800 Subject: [PATCH 1/3] Update json load --- .../spec/aws-sdk-code-generator/shared_example_spec.rb | 4 ++-- build_tools/custom_service.rb | 2 +- build_tools/services.rb | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/build_tools/aws-sdk-code-generator/spec/aws-sdk-code-generator/shared_example_spec.rb b/build_tools/aws-sdk-code-generator/spec/aws-sdk-code-generator/shared_example_spec.rb index 3c8b82b8f64..ef9a787105e 100644 --- a/build_tools/aws-sdk-code-generator/spec/aws-sdk-code-generator/shared_example_spec.rb +++ b/build_tools/aws-sdk-code-generator/spec/aws-sdk-code-generator/shared_example_spec.rb @@ -7,11 +7,11 @@ module AwsSdkCodeGenerator let(:dir) { File.dirname(__FILE__) } let(:example_path) { File.join(dir, '..', 'fixtures', 'shared_examples', 'examples.json') } - let(:example_file) { File.open(example_path, 'rb') {|file| JSON.load(file.read)} } + let(:example_file) { JSON.load_file(example_path) } let(:examples) {example_file['examples']} let(:api_path) { File.join(dir, '..', 'fixtures', 'shared_examples', 'api.json') } - let(:s3_api) { File.open(api_path, 'rb') {|file| JSON.load(file.read)} } + let(:s3_api) { JSON.load_file(api_path) } def load_example_input(operation_name) example = examples[operation_name][0] diff --git a/build_tools/custom_service.rb b/build_tools/custom_service.rb index 33a4827f65b..d90927fb21e 100644 --- a/build_tools/custom_service.rb +++ b/build_tools/custom_service.rb @@ -52,7 +52,7 @@ def build private def load_json(model_dir) - JSON.load(File.read(model_path(model_dir))) + JSON.load_file(model_path(model_dir)) end def model_path(model_dir) diff --git a/build_tools/services.rb b/build_tools/services.rb index 67a5ed670c5..2eb72723bed 100644 --- a/build_tools/services.rb +++ b/build_tools/services.rb @@ -56,7 +56,7 @@ def services end def manifest - JSON.load(File.read(@manifest_path)) + JSON.load_file(@manifest_path) end def build_service(svc_name, config) @@ -84,13 +84,13 @@ def build_service(svc_name, config) end def load_api(svc_name, models_dir) - api = JSON.load(File.read(model_path('api-2.json', models_dir))) + api = JSON.load_file(model_path('api-2.json', models_dir)) BuildTools::Customizations.apply_api_customizations(svc_name, api) api end def load_docs(svc_name, models_dir) - docs = JSON.load(File.read(model_path('docs-2.json', models_dir))) + docs = JSON.load_file(model_path('docs-2.json', models_dir)) BuildTools::Customizations.apply_doc_customizations(svc_name, docs) docs end @@ -98,7 +98,7 @@ def load_docs(svc_name, models_dir) def load_examples(svc_name, models_dir) path = model_path('examples-1.json', models_dir) if path - examples = JSON.load(File.read(path)) + examples = JSON.load_file(path) BuildTools::Customizations.apply_example_customizations(svc_name, examples) examples else @@ -109,7 +109,7 @@ def load_examples(svc_name, models_dir) def load_smoke(svc_name, models_dir) path = model_path('smoke-2.json', models_dir) if path - smoke = JSON.load(File.read(path)) + smoke = JSON.load_file(path) BuildTools::Customizations.apply_smoke_customizations(svc_name, smoke) smoke else From 2a0aa42c9e7b8d705d44f9ef60f785d9ceb56d56 Mon Sep 17 00:00:00 2001 From: Juli Tera Date: Fri, 15 Nov 2024 12:52:36 -0800 Subject: [PATCH 2/3] Update json pin --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 039465de5ea..73f0cd9ea07 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ if defined?(JRUBY_VERSION) end # protocol parsers -gem 'json', '>= 2.4.0', '<= 2.7.6' # due to load_file support and we use it for specs +gem 'json', '>= 2.4.0' # due to load_file support gem 'nokogiri', '>= 1.6.8.1' gem 'oga' gem 'rexml' From 3caae8900ff14d109f992e0fdb571ba438842aa6 Mon Sep 17 00:00:00 2001 From: Juli Tera Date: Tue, 19 Nov 2024 08:13:09 -0800 Subject: [PATCH 3/3] Update more specs from JSON.load to load_file --- gems/aws-eventstream/spec/spec_helper.rb | 2 +- .../spec/aws_partitions_spec.rb | 37 ++++++++++--------- gems/aws-sdk-core/spec/api_helper.rb | 23 ++++++------ .../spec/aws/xml/error_handler_spec.rb | 12 ++++-- gems/aws-sdk-s3/spec/encryptionV2/kat_spec.rb | 4 +- tasks/update-defaults-mode.rake | 2 +- 6 files changed, 44 insertions(+), 36 deletions(-) diff --git a/gems/aws-eventstream/spec/spec_helper.rb b/gems/aws-eventstream/spec/spec_helper.rb index 702a7c7a7c3..47f2110fbaf 100644 --- a/gems/aws-eventstream/spec/spec_helper.rb +++ b/gems/aws-eventstream/spec/spec_helper.rb @@ -28,7 +28,7 @@ def expected_decoded_error(path) end def convert_msg(path) - hash = JSON.load(File.read(path)) + hash = JSON.load_file(path) Aws::EventStream::Message.new( headers: build_headers(hash['headers']), payload: StringIO.new(Base64.decode64(hash['payload'])) diff --git a/gems/aws-partitions/spec/aws_partitions_spec.rb b/gems/aws-partitions/spec/aws_partitions_spec.rb index 17ac395df3f..027d42d6323 100644 --- a/gems/aws-partitions/spec/aws_partitions_spec.rb +++ b/gems/aws-partitions/spec/aws_partitions_spec.rb @@ -242,8 +242,9 @@ module Aws describe 'metadata' do let(:partition_metadata_json) do - path = File.expand_path('../test_partitions_metadata.json', __FILE__) - JSON.load(File.read(path)) + JSON.load_file( + File.expand_path('test_partitions_metadata.json', __dir__) + ) end before do @@ -267,13 +268,12 @@ module Aws end after do - path = File.expand_path('../../partitions.json', __FILE__) - original_json = JSON.load(File.read(path)) + original_json = + JSON.load_file(File.expand_path('../partitions.json', __dir__)) Partitions.clear Partitions.add(original_json) Partitions.merge_metadata( - JSON.load(File.read( - File.expand_path('../../partitions-metadata.json', __FILE__))) + JSON.load_file(File.expand_path('../partitions-metadata.json', __dir__)) ) end end @@ -281,8 +281,10 @@ module Aws # normal endpoint testing describe Partitions::EndpointProvider do let(:partition_json) do - path = File.expand_path('../test_partition.json', __FILE__) - JSON.load(File.read(path)) + JSON.load_file( + File.expand_path('test_partition.json', __dir__) + ) + end before { Partitions.add(partition_json) } @@ -428,8 +430,9 @@ module Aws # variants endpoints testing describe Partitions::EndpointProvider do let(:fips_partition_json) do - path = File.expand_path('../variant_test_partition.json', __FILE__) - JSON.load(File.read(path)) + JSON.load_file( + File.expand_path('variant_test_partition.json', __dir__) + ) end before do @@ -438,18 +441,19 @@ module Aws end after do - path = File.expand_path('../../partitions.json', __FILE__) - original_json = JSON.load(File.read(path)) + original_json = + JSON.load_file(File.expand_path('../partitions.json', __dir__)) Partitions.clear Partitions.add(original_json) Partitions.merge_metadata( - JSON.load(File.read( - File.expand_path('../../partitions-metadata.json', __FILE__))) + JSON.load_file( + File.expand_path('../partitions-metadata.json', __dir__) + ) ) end - path = File.expand_path('../variant_test_cases.json', __FILE__) - test_cases = JSON.load(File.read(path)) + test_cases = + JSON.load_file(File.expand_path('variant_test_cases.json', __dir__)) describe '.resolve' do test_cases.each_with_index do |test_case, index| @@ -503,6 +507,5 @@ module Aws end end end - end end diff --git a/gems/aws-sdk-core/spec/api_helper.rb b/gems/aws-sdk-core/spec/api_helper.rb index 61bc53601fd..ddf345eb357 100644 --- a/gems/aws-sdk-core/spec/api_helper.rb +++ b/gems/aws-sdk-core/spec/api_helper.rb @@ -7,48 +7,47 @@ class << self def sample_json # dynamodb @sample_json ||= begin - api = File.expand_path('../fixtures/apis/dynamodb.json', __FILE__) - api = JSON.load(File.read(api)) + api = + JSON.load_file(File.expand_path('fixtures/apis/dynamodb.json', __dir__)) sample_service(api: api) end end def sample_query # iam @sample_query ||= begin - api = File.expand_path('../fixtures/apis/iam.json', __FILE__) - api = JSON.load(File.read(api)) + api = + JSON.load_file(File.expand_path('fixtures/apis/iam.json', __dir__)) sample_service(api: api) end end def sample_rest_xml # s3 @sample_rest_xml ||= begin - api = File.expand_path('../fixtures/apis/s3.json', __FILE__) - api = JSON.load(File.read(api)) + api = + JSON.load_file(File.expand_path('fixtures/apis/s3.json', __dir__)) sample_service(api: api) end end def sample_rest_json # glacier @sample_rest_json ||= begin - api = File.expand_path('../fixtures/apis/glacier.json', __FILE__) - api = JSON.load(File.read(api)) + api = + JSON.load_file(File.expand_path('fixtures/apis/glacier.json', __dir__)) sample_service(api: api) end end def sample_ec2 # ec2 has its own protocol @sample_ec2 ||= begin - api = File.expand_path('../fixtures/apis/ec2.json', __FILE__) - api = JSON.load(File.read(api)) + api = JSON.load_file(File.expand_path('fixtures/apis/ec2.json', __dir__)) sample_service(api: api) end end def sample_rpcv2_cbor # cloudwatch logs changed to cbor @sample_rpcv2_cbor ||= begin - api = File.expand_path('../fixtures/apis/logs.json', __FILE__) - api = JSON.load(File.read(api)) + api = + JSON.load_file(File.expand_path('fixtures/apis/logs.json', __dir__)) sample_service(api: api) end end diff --git a/gems/aws-sdk-core/spec/aws/xml/error_handler_spec.rb b/gems/aws-sdk-core/spec/aws/xml/error_handler_spec.rb index af4e5320c0a..f0cd945301d 100644 --- a/gems/aws-sdk-core/spec/aws/xml/error_handler_spec.rb +++ b/gems/aws-sdk-core/spec/aws/xml/error_handler_spec.rb @@ -8,7 +8,9 @@ module Xml let(:cloudfront) { ApiHelper.sample_service( - api: JSON.load(File.read(File.expand_path('../../../fixtures/apis/cloudfront.json', __FILE__))) + api: JSON.load_file( + File.expand_path('../../fixtures/apis/cloudfront.json', __dir__) + ) )::Client.new( region: 'us-west-2', retry_limit: 0, @@ -19,7 +21,9 @@ module Xml let(:route53) { ApiHelper.sample_service( - api: JSON.load(File.read(File.expand_path('../../../fixtures/apis/route53.json', __FILE__))) + api: JSON.load_file( + File.expand_path('../../fixtures/apis/route53.json', __dir__) + ) )::Client.new( region: 'us-west-2', retry_limit: 0, @@ -39,7 +43,9 @@ module Xml let(:sns) { ApiHelper.sample_service( - api: JSON.load(File.read(File.expand_path('../../../fixtures/apis/sns.json', __FILE__))) + api: JSON.load_file( + File.expand_path('../../fixtures/apis/sns.json', __dir__) + ) )::Client.new( region: 'us-west-2', retry_limit: 0, diff --git a/gems/aws-sdk-s3/spec/encryptionV2/kat_spec.rb b/gems/aws-sdk-s3/spec/encryptionV2/kat_spec.rb index 0e8da29d3c7..10b24230189 100644 --- a/gems/aws-sdk-s3/spec/encryptionV2/kat_spec.rb +++ b/gems/aws-sdk-s3/spec/encryptionV2/kat_spec.rb @@ -27,8 +27,8 @@ def self.build_kat(raw_kat) ) end - fixture_path = File.expand_path('../../fixtures/encryption', __FILE__) - kats = JSON.load File.new(File.join(fixture_path, 'aes_gcm_kat.json')) + fixture_path = File.expand_path('../fixtures/encryption', __dir__) + kats = JSON.load_file(File.new(File.join(fixture_path, 'aes_gcm_kat.json'))) kats.each_with_index do |raw, i| kat = build_kat(raw) diff --git a/tasks/update-defaults-mode.rake b/tasks/update-defaults-mode.rake index 7e4fb9e3897..8892f113c26 100644 --- a/tasks/update-defaults-mode.rake +++ b/tasks/update-defaults-mode.rake @@ -10,7 +10,7 @@ task 'update-defaults-mode', [:defaults_file] do |t, args| end puts "Loading defaults from: #{defaults_file}" - defaults = JSON.load(File.read(defaults_file)) + defaults = JSON.load_file(defaults_file) default_mode_docs = ["

The following :default_mode values are supported:

"] default_mode_docs << "
    "