Class: RakeDocker::Authentication::ECR

Inherits:
Object
  • Object
show all
Defined in:
lib/rake_docker/authentication/ecr.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ ECR

Returns a new instance of ECR.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rake_docker/authentication/ecr.rb', line 7

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

Instance Method Details

#callObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rake_docker/authentication/ecr.rb', line 20

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