Class: Ecr::Auth

Inherits:
Object
  • Object
show all
Includes:
Ufo::AwsServices, Ufo::Utils::Logging
Defined in:
lib/ufo/ecr/auth.rb

Instance Method Summary collapse

Methods included from Ufo::Utils::Logging

#logger

Methods included from Ufo::AwsServices

#acm, #applicationautoscaling, #aws_options, #cfn, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #s3, #ssm_client, #waf_client

Methods included from Ufo::AwsServices::Concerns

#find_stack, #find_stack_resources, #stack_resources, #status, #task_definition_arns

Constructor Details

#initialize(docker_image) ⇒ Auth

Returns a new instance of Auth.



23
24
25
26
# File 'lib/ufo/ecr/auth.rb', line 23

def initialize(docker_image)
  @docker_image = docker_image
  @repo_domain = "#{docker_image.split('/').first}"
end

Instance Method Details

#ecr_image?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/ufo/ecr/auth.rb', line 44

def ecr_image?
  !!(@docker_image =~ /\.amazonaws\.com/)
end

#fetch_auth_tokenObject



48
49
50
# File 'lib/ufo/ecr/auth.rb', line 48

def fetch_auth_token
  ecr.get_authorization_token.authorization_data.first.authorization_token
end

#updateObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ufo/ecr/auth.rb', line 28

def update
  # wont update auth token unless the image being pushed in the ECR image format
  return unless ecr_image?

  auth_token = fetch_auth_token
  username, password = Base64.decode64(auth_token).split(':')

  command = "docker login -u #{username} --password-stdin #{@repo_domain}"
  logger.debug "=> #{command}".color(:green)
  *, status = Open3.capture3(command, stdin_data: password)
  unless status.success?
    logger.error "ERROR: The docker failed to login.".color(:red)
    exit 1
  end
end