Sha256: 82cb5a6b731a75f138ae9d54374910e5618e0728205591c7b5f2127c9e338495

Contents?: true

Size: 1.57 KB

Versions: 28

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

module Aws
  module S3
    # @api private
    def self.express_credentials_cache
      @express_credentials_cache ||= LRUCache.new(max_entries: 100)
    end

    # Returns Credentials class for S3 Express. Accepts CreateSession
    # params as options. See {Client#create_session} for details.
    class ExpressCredentialsProvider
      # @param [Hash] options
      # @option options [Client] :client The S3 client used to create the
      #  session.
      # @option options [String] :session_mode (see: {Client#create_session})
      # @option options [Boolean] :caching (true) When true, credentials will
      #  be cached.
      # @option options [Callable] :before_refresh Proc called before
      #   credentials are refreshed.
      def initialize(options = {})
        @client = options.delete(:client)
        @caching = options.delete(:caching) != false
        @options = options
        return unless @caching

        @cache = Aws::S3.express_credentials_cache
      end

      def express_credentials_for(bucket)
        if @caching
          cached_credentials_for(bucket)
        else
          new_credentials_for(bucket)
        end
      end

      attr_accessor :client

      private

      def cached_credentials_for(bucket)
        if @cache.key?(bucket)
          @cache[bucket]
        else
          @cache[bucket] = new_credentials_for(bucket)
        end
      end

      def new_credentials_for(bucket)
        ExpressCredentials.new(
          bucket: bucket,
          client: @client,
          **@options
        )
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
aws-sdk-s3-1.173.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.172.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.171.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.170.1 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.170.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.169.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.168.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.167.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.166.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.165.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.164.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.163.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.162.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.161.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.160.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.159.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.158.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.157.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.156.0 lib/aws-sdk-s3/express_credentials_provider.rb
aws-sdk-s3-1.155.0 lib/aws-sdk-s3/express_credentials_provider.rb