Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gems/aws-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Feature - Seahorse::Client::Configuration no longer generate real Ruby Struct at runtime.

3.269.0 (2026-11-16)
------------------

Expand Down
69 changes: 68 additions & 1 deletion gems/aws-sdk-core/lib/seahorse/client/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 9 additions & 3 deletions gems/aws-sdk-core/spec/seahorse/client/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
24 changes: 22 additions & 2 deletions gems/aws-sdk-core/spec/seahorse/client/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ 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

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
Expand Down Expand Up @@ -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 }
Expand Down
20 changes: 20 additions & 0 deletions gems/aws-sdk-s3/spec/object_copier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 36 additions & 0 deletions gems/aws-sdk-swf/spec/plugins/read_timeouts_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading