diff --git a/gems/aws-sdk-core/CHANGELOG.md b/gems/aws-sdk-core/CHANGELOG.md index 1b02a061255..74c50ec1b82 100644 --- a/gems/aws-sdk-core/CHANGELOG.md +++ b/gems/aws-sdk-core/CHANGELOG.md @@ -1,6 +1,8 @@ Unreleased Changes ------------------ +* Feature - Seahorse::Client::Configuration no longer generate real Ruby Struct at runtime. + 3.269.0 (2026-11-16) ------------------ diff --git a/gems/aws-sdk-core/lib/seahorse/client/configuration.rb b/gems/aws-sdk-core/lib/seahorse/client/configuration.rb index 683a053d26d..f94bc2b446a 100644 --- a/gems/aws-sdk-core/lib/seahorse/client/configuration.rb +++ b/gems/aws-sdk-core/lib/seahorse/client/configuration.rb @@ -73,6 +73,73 @@ def call(*args) end end + # @api private + class DynamicStruct + attr_reader :members + + def initialize(members) + @members = members.map(&:to_sym).to_set + @attributes = {} + end + + def [](name) + name = name.to_sym + unless @members.include?(name) + raise NameError, "No member #{name} in Struct" + end + + @attributes[name] + end + + def []=(name, value) + name = name.to_sym + unless @members.include?(name) + raise NameError, "No member #{name} in Struct" + end + + @attributes[name] = value + end + + def each_pair + return enum_for(:each_pair) unless block_given? + + @members.each do |member| + yield(member, @attributes[member]) + end + self + end + + def initialize_copy(source) + super + @members = @members.dup + @attributes = @attributes.dup + end + + private + + alias_method :write_attribute, :[]= + alias_method :read_attribute, :[] + + def method_missing(name, *args, **kwargs, &block) + if name.end_with?('=') + attr_name = name[0..-2].to_sym + if @members.include?(attr_name) + write_attribute(attr_name, *args, **kwargs, &block) + else + super + end + elsif @members.include?(name) + read_attribute(name, *args, **kwargs, &block) + else + super + end + end + + def respond_to_missing?(name, include_private = false) + @members.include?(name) || (name.end_with?('=') && @members.include?(name[0..-2].to_sym)) || super + end + end + # @api private def initialize @defaults = Hash.new { |h,k| h[k] = Defaults.new } @@ -156,7 +223,7 @@ def build!(options = {}) private def empty_struct - Struct.new(*@defaults.keys.sort).new + DynamicStruct.new(@defaults.keys.sort) end def apply_options(struct, options) diff --git a/gems/aws-sdk-core/spec/aws/plugins/global_configuration_spec.rb b/gems/aws-sdk-core/spec/aws/plugins/global_configuration_spec.rb index 6c349f18120..35dc557c8d7 100644 --- a/gems/aws-sdk-core/spec/aws/plugins/global_configuration_spec.rb +++ b/gems/aws-sdk-core/spec/aws/plugins/global_configuration_spec.rb @@ -71,7 +71,10 @@ module Plugins it 'instructs plugins to #add_handlers' do expect(plugin).to receive(:add_handlers). - with(kind_of(Seahorse::Client::HandlerList), kind_of(Struct)) + with( + kind_of(Seahorse::Client::HandlerList), + kind_of(Seahorse::Client::Configuration::DynamicStruct) + ) GlobalConfigClient.new end diff --git a/gems/aws-sdk-core/spec/seahorse/client/base_spec.rb b/gems/aws-sdk-core/spec/seahorse/client/base_spec.rb index f500163c256..d897f7720e6 100644 --- a/gems/aws-sdk-core/spec/seahorse/client/base_spec.rb +++ b/gems/aws-sdk-core/spec/seahorse/client/base_spec.rb @@ -24,7 +24,7 @@ module Client describe '#config' do it 'returns a Configuration struct' do - expect(client.config).to be_kind_of(Struct) + expect(client.config).to be_kind_of(Configuration::DynamicStruct) end it 'contains the client api' do @@ -277,7 +277,10 @@ module Client it 'instructs plugins to #add_handlers' do expect(plugin).to receive(:add_handlers). - with(kind_of(HandlerList), kind_of(Struct)) + with( + kind_of(HandlerList), + kind_of(Configuration::DynamicStruct) + ) client_class.add_plugin(plugin) client_class.new(endpoint: 'http://foo.com') end @@ -321,7 +324,10 @@ module Client it 'instructs plugins to #add_handlers' do expect(plugin).to receive(:add_handlers). - with(kind_of(HandlerList), kind_of(Struct)) + with( + kind_of(HandlerList), + kind_of(Configuration::DynamicStruct) + ) client_class.new(endpoint: 'http://foo.com', plugins: [plugin]) end diff --git a/gems/aws-sdk-core/spec/seahorse/client/configuration_spec.rb b/gems/aws-sdk-core/spec/seahorse/client/configuration_spec.rb index 37842a70436..f2884d2b504 100644 --- a/gems/aws-sdk-core/spec/seahorse/client/configuration_spec.rb +++ b/gems/aws-sdk-core/spec/seahorse/client/configuration_spec.rb @@ -66,7 +66,7 @@ module Client it 'returns self so it can be chained' do c = config.add_option(:name).add_option(:color) expect(c).to be(config) - expect(c.build!.members).to eq([:color, :name]) + expect(c.build!.members).to eq(Set[:color, :name]) end end @@ -74,7 +74,7 @@ module Client describe '#build!' do it 'returns a Struct' do - expect(config.add_option(:opt).build!).to be_kind_of(Struct) + expect(config.add_option(:opt).build!).to be_kind_of(Configuration::DynamicStruct) end it 'accepts a hash of options' do @@ -105,6 +105,26 @@ module Client expect(config.build!.proc).to be(value) end + it 'enumerates configuration members and values' do + config.add_option(:name, 'John Doe') + config.add_option(:color, 'red') + + expect(config.build!.each_pair.to_a).to eq( + [[:color, 'red'], [:name, 'John Doe']] + ) + end + + it 'duplicates configuration attributes independently' do + config.add_option(:name, 'John Doe') + original = config.build! + copy = original.dup + + copy.name = 'Jane Doe' + + expect(original.name).to eq('John Doe') + expect(copy.name).to eq('Jane Doe') + end + it 'resolves defaults in LIFO order until a non-nil value is found' do # default cost is 10 config.add_option(:cost) { 10 } diff --git a/gems/aws-sdk-s3/spec/object_copier_spec.rb b/gems/aws-sdk-s3/spec/object_copier_spec.rb index 5f4b57655ce..32291260085 100644 --- a/gems/aws-sdk-s3/spec/object_copier_spec.rb +++ b/gems/aws-sdk-s3/spec/object_copier_spec.rb @@ -92,6 +92,26 @@ def request_params(operation_name) expect(api_requests(:create_multipart_upload).size).to eq(1) expect(api_requests(:complete_multipart_upload).size).to eq(1) end + + it 'uses a source client in copy_source_region' do + client + source_client = instance_double(S3::Client) + multipart_copier = instance_double(ObjectMultipartCopier) + + expect(S3::Client).to receive(:new).with( + hash_including(region: 'us-west-2', stub_responses: true) + ).and_return(source_client) + allow(ObjectMultipartCopier).to receive(:new).and_return(multipart_copier) + expect(multipart_copier).to receive(:copy).with( + hash_including(copy_source_client: source_client) + ) + + copier.copy_from( + 'source-bucket/source-key', + multipart_copy: true, + copy_source_region: 'us-west-2' + ) + end end end diff --git a/gems/aws-sdk-swf/spec/plugins/read_timeouts_spec.rb b/gems/aws-sdk-swf/spec/plugins/read_timeouts_spec.rb new file mode 100644 index 00000000000..cc1dde1f7d5 --- /dev/null +++ b/gems/aws-sdk-swf/spec/plugins/read_timeouts_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require_relative '../spec_helper' +require 'aws-sdk-swf/client' + +module Aws + module SWF + describe Plugins::ReadTimeouts do + let(:client) do + Client.new(stub_responses: true, http_read_timeout: 60) + end + + it 'uses a request-local read timeout for poll_for_activity_task' do + client.poll_for_activity_task( + domain: 'domain', + task_list: { name: 'task-list' } + ) + + request = client.api_requests.last + expect(request[:context].config.http_read_timeout).to eq(90) + expect(client.config.http_read_timeout).to eq(60) + end + + it 'uses a request-local read timeout for poll_for_decision_task' do + client.poll_for_decision_task( + domain: 'domain', + task_list: { name: 'task-list' } + ) + + request = client.api_requests.last + expect(request[:context].config.http_read_timeout).to eq(90) + expect(client.config.http_read_timeout).to eq(60) + end + end + end +end