Skip to content

Commit

Permalink
Instance plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp committed Jun 19, 2024
1 parent 03e4f2d commit d0d06db
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
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 - Support `:plugins` option on all Clients or using `Aws.config[:plugins]`.

3.197.0 (2024-06-05)
------------------

Expand Down
28 changes: 24 additions & 4 deletions gems/aws-sdk-core/lib/seahorse/client/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Base
# @api private
def initialize(plugins, options)
@config = build_config(plugins, options)
@handlers = build_handler_list(plugins)
after_initialize(plugins)
@handlers = build_handler_list(plugins + @config.plugins)
after_initialize(plugins + @config.plugins)
end

# @return [Configuration<Struct>]
Expand Down Expand Up @@ -60,10 +60,17 @@ def operation_names
def build_config(plugins, options)
config = Configuration.new
config.add_option(:api)
plugins.each do |plugin|
config.add_option(:plugins)
config_plugins = build_plugins(options.fetch(:plugins, []))
(plugins + config_plugins).each do |plugin|
plugin.add_options(config) if plugin.respond_to?(:add_options)
end
config.build!(options.merge(api: self.class.api))
config.build!(options.merge(api: self.class.api, plugins: config_plugins))
end

# Builds a list of plugins from a configured list of plugins
def build_plugins(plugins)
plugins.map { |plugin| plugin.is_a?(Class) ? plugin.new : plugin }
end

# Gives each plugin the opportunity to register handlers for this client.
Expand Down Expand Up @@ -220,10 +227,23 @@ def before_initialize(plugins, options)
end

def inherited(subclass)
super
subclass.instance_variable_set('@plugins', PluginList.new(@plugins))
end

end
end
end
end

class TestPlugin < Seahorse::Client::Plugin
option(:new_config, 'new_value')
class Handler < Seahorse::Client::Handler
def call(context)
puts "I was invoked! with #{context.config.new_config}"
@handler.call(context)
end
end

handler(Handler, step: :initialize)
end

0 comments on commit d0d06db

Please sign in to comment.