Class: S3ClientFactory
- Inherits:
-
Object
- Object
- S3ClientFactory
- Defined in:
- lib/logstash/inputs/s3/client_factory.rb
Overview
not needed - Mutex is part of core lib: require ‘thread’
Instance Method Summary collapse
- #get_s3_client(bucket_name) {|| ... } ⇒ Object
-
#initialize(logger, options, aws_options_hash) ⇒ S3ClientFactory
constructor
A new instance of S3ClientFactory.
Constructor Details
#initialize(logger, options, aws_options_hash) ⇒ S3ClientFactory
Returns a new instance of S3ClientFactory.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/logstash/inputs/s3/client_factory.rb', line 6 def initialize(logger, , ) @logger = logger @aws_options_hash = @s3_default_options = Hash[[:s3_default_options].map { |k, v| [k.to_sym, v] }] @aws_options_hash.merge!(@s3_default_options) unless @s3_default_options.empty? @sts_client = Aws::STS::Client.new(region: [:aws_region]) @credentials_by_bucket = [:s3_credentials_by_bucket] @region_by_bucket = [:s3_region_by_bucket] @logger.debug("Credentials by Bucket", :credentials => @credentials_by_bucket) @default_session_name = [:s3_role_session_name] @clients_by_bucket = {} @creation_mutex = Mutex.new end |
Instance Method Details
#get_s3_client(bucket_name) {|| ... } ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/logstash/inputs/s3/client_factory.rb', line 20 def get_s3_client(bucket_name) bucket_symbol = bucket_name.to_sym @creation_mutex.synchronize do if @clients_by_bucket[bucket_symbol].nil? = @aws_options_hash.clone unless @credentials_by_bucket[bucket_name].nil? .merge!(credentials: get_s3_auth(@credentials_by_bucket[bucket_name])) end unless @region_by_bucket[bucket_name].nil? .merge!(region: @region_by_bucket[bucket_name]) end @clients_by_bucket[bucket_symbol] = Aws::S3::Client.new() @logger.debug("Created a new S3 Client", :bucket_name => bucket_name, :client => @clients_by_bucket[bucket_symbol], :used_options => ) end end # to be thread-safe, one uses this method like this: # s3_client_factory.get_s3_client(my_s3_bucket) do # ... do stuff ... # end yield @clients_by_bucket[bucket_symbol] end |