Class: Ufo::Ecr::Auth
Instance Method Summary
collapse
Methods included from AwsService
#cloudwatchlogs, #ecr, #ecs, #elb
Constructor Details
#initialize(full_image_name) ⇒ Auth
Returns a new instance of Auth.
20
21
22
23
|
# File 'lib/ufo/ecr/auth.rb', line 20
def initialize(full_image_name)
@full_image_name = full_image_name
@repo_domain = "#{full_image_name.split('/').first}"
end
|
Instance Method Details
#docker_config ⇒ Object
45
46
47
|
# File 'lib/ufo/ecr/auth.rb', line 45
def docker_config
"#{ENV['HOME']}/.docker/config.json"
end
|
#ecr_image? ⇒ Boolean
37
38
39
|
# File 'lib/ufo/ecr/auth.rb', line 37
def ecr_image?
!!(@full_image_name =~ /\.amazonaws\.com/)
end
|
#ensure_dotdocker_exists ⇒ Object
49
50
51
52
|
# File 'lib/ufo/ecr/auth.rb', line 49
def ensure_dotdocker_exists
dirname = File.dirname(docker_config)
FileUtils.mkdir_p(dirname) unless File.exist?(dirname)
end
|
#fetch_auth_token ⇒ Object
41
42
43
|
# File 'lib/ufo/ecr/auth.rb', line 41
def fetch_auth_token
ecr.get_authorization_token.authorization_data.first.authorization_token
end
|
#update ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/ufo/ecr/auth.rb', line 25
def update
auth_token = fetch_auth_token
if File.exist?(docker_config)
data = JSON.load(IO.read(docker_config))
data["auths"][@repo_domain] = {auth: auth_token}
else
data = {auths: {@repo_domain => {auth: auth_token}}}
end
ensure_dotdocker_exists
IO.write(docker_config, JSON.pretty_generate(data))
end
|