<commit_before>require 'aws-sdk-s3'

module Fastlane
  module Helper
    class S3ClientHelper
      attr_reader :access_key
      attr_reader :region

      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

      def upload_file(bucket_name, file_name, file_data, acl)
        bucket = find_bucket!(bucket_name)
        details = {
          acl: acl,
          key: file_name,
          body: file_data
        }
        obj = bucket.put_object(details)

        # When you enable versioning on a S3 bucket,
        # writing to an object will create an object version
        # instead of replacing the existing object.
        # http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/ObjectVersion.html
        if obj.kind_of?(Aws::S3::ObjectVersion)
          obj = obj.object
        end

        # Return public url
        obj.public_url.to_s
      end

      def delete_file(bucket_name, file_name)
        bucket = find_bucket!(bucket_name)
        file = bucket.object(file_name)
        file.delete
      end

      def find_bucket!(bucket_name)
        bucket = Aws::S3::Bucket.new(bucket_name, client: client)
        raise "Bucket '#{bucket_name}' not found" unless bucket.exists?

        return bucket
      end

      private

      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.blank? || secret_access_key.blank?

        Aws::Credentials.new(
          access_key,<commit_msg>[fastlane] replace blank? with to_s.empty? (#16804)<commit_after>require 'aws-sdk-s3'

module Fastlane
  module Helper
    class S3ClientHelper
      attr_reader :access_key
      attr_reader :region

      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

      def upload_file(bucket_name, file_name, file_data, acl)
        bucket = find_bucket!(bucket_name)
        details = {
          acl: acl,
          key: file_name,
          body: file_data
        }
        obj = bucket.put_object(details)

        # When you enable versioning on a S3 bucket,
        # writing to an object will create an object version
        # instead of replacing the existing object.
        # http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/ObjectVersion.html
        if obj.kind_of?(Aws::S3::ObjectVersion)
          obj = obj.object
        end

        # Return public url
        obj.public_url.to_s
      end

      def delete_file(bucket_name, file_name)
        bucket = find_bucket!(bucket_name)
        file = bucket.object(file_name)
        file.delete
      end

      def find_bucket!(bucket_name)
        bucket = Aws::S3::Bucket.new(bucket_name, client: client)
        raise "Bucket '#{bucket_name}' not found" unless bucket.exists?

        return bucket
      end

      private

      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.to_s.empty? || secret_access_key.to_s.empty?

        Aws::Credentials.new(
          access_key,
{'fraction_non_alphanumeric': 0.07753164556962025, 'fraction_numerical': 0.006065400843881856, 'mean_word_length': 2.0613397901533497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2133648', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1111, 'n_words': 268}