fastlane/lib/fastlane/helper/s3_client_helper.rb in fastlane-2.150.3 vs fastlane/lib/fastlane/helper/s3_client_helper.rb in fastlane-2.151.0

- old
+ new

@@ -1,18 +1,19 @@ require 'aws-sdk-s3' module Fastlane module Helper class S3ClientHelper - attr_reader :client + attr_reader :access_key + attr_reader :region - def initialize(access_key: nil, secret_access_key: nil, region: nil) - creds = Aws::Credentials.new(access_key, secret_access_key) - Aws.config.update( - region: region, - credentials: creds - ) + def initialize(access_key: nil, secret_access_key: nil, region: nil, s3_client: nil) + @access_key = access_key + @secret_access_key = secret_access_key + @region = region + + @client = s3_client end def list_buckets return client.list_buckets end @@ -48,14 +49,30 @@ bucket = Aws::S3::Bucket.new(bucket_name, client: client) raise "Bucket '#{bucket_name}' not found" unless bucket.exists? return bucket end - end - private + private - def client - @client ||= Aws::S3::Client.new + attr_reader :secret_access_key + + def client + @client ||= Aws::S3::Client.new( + { + region: region, + credentials: create_credentials + }.compact + ) + end + + def create_credentials + return nil if access_key.nil? || secret_access_key.nil? + + Aws::Credentials.new( + access_key, + secret_access_key + ) + end end end end