Class: Ecr::Auth
Instance Method Summary
collapse
#cloudformation, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb
Constructor Details
#initialize(full_image_name) ⇒ Auth
Returns a new instance of Auth.
22
23
24
25
|
# File 'lib/ufo/ecr/auth.rb', line 22
def initialize(full_image_name)
@full_image_name = full_image_name
@repo_domain = "#{full_image_name.split('/').first}"
end
|
Instance Method Details
#ecr_image? ⇒ Boolean
43
44
45
|
# File 'lib/ufo/ecr/auth.rb', line 43
def ecr_image?
!!(@full_image_name =~ /\.amazonaws\.com/)
end
|
#fetch_auth_token ⇒ Object
47
48
49
|
# File 'lib/ufo/ecr/auth.rb', line 47
def fetch_auth_token
ecr.get_authorization_token.authorization_data.first.authorization_token
end
|
#update ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/ufo/ecr/auth.rb', line 27
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}"
puts "=> #{command}".color(:green)
*, status = Open3.capture3(command, stdin_data: password)
unless status.success?
puts "ERROR: The docker failed to login.".color(:red)
exit 1
end
end
|