Sha256: de8603ab5aa90e5abf452995ecf1c06b5976e1eefb8a82055a906f664294ee56

Contents?: true

Size: 961 Bytes

Versions: 1

Compression:

Stored size: 961 Bytes

Contents

require 'aws-sdk'
require 'ostruct'

module RakeDocker
  module Authentication
    class ECR < Proc
      def initialize &block
        config = OpenStruct.new(
            region: nil,
            registry_id: nil)
        block.call(config)

        @ecr_client = Aws::ECR::Client.new(region: config.region)

        @registry_id = config.registry_id.respond_to?(:call) ?
            config.registry_id.call :
            config.registry_id
      end

      def call
        token_response = @ecr_client.get_authorization_token(
            registry_ids: [@registry_id])
        token_data = token_response.authorization_data[0]
        proxy_endpoint = token_data.proxy_endpoint
        email = 'none'
        username, password =
            Base64.decode64(token_data.authorization_token).split(':')

        {
            username: username, password: password, email: email,
            serveraddress: proxy_endpoint
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rake_docker-0.7.2 lib/rake_docker/authentication/ecr.rb