Class: Ecr::Auth
Instance Method Summary
collapse
#logger
#acm, #applicationautoscaling, #aws_options, #cloudformation, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #find_stack, #ssm_client, #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
44
45
46
|
# File 'lib/ufo/ecr/auth.rb', line 44
def ecr_image?
!!(@docker_image =~ /\.amazonaws\.com/)
end
|
#fetch_auth_token ⇒ Object
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
|
#update ⇒ Object
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
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
|