Class: Ufo::EcrAuth
Instance Method Summary
collapse
#ecr, #ecs, #elb, #region
Constructor Details
#initialize(repo_domain) ⇒ EcrAuth
Returns a new instance of EcrAuth.
5
6
7
|
# File 'lib/ufo/ecr_auth.rb', line 5
def initialize(repo_domain)
@repo_domain = repo_domain
end
|
Instance Method Details
#docker_config ⇒ Object
25
26
27
|
# File 'lib/ufo/ecr_auth.rb', line 25
def docker_config
"#{ENV['HOME']}/.docker/config.json"
end
|
#ensure_dotdocker_exists ⇒ Object
29
30
31
32
|
# File 'lib/ufo/ecr_auth.rb', line 29
def ensure_dotdocker_exists
dirname = File.dirname(docker_config)
FileUtils.mkdir_p(dirname) unless File.exist?(dirname)
end
|
#fetch_auth_token ⇒ Object
21
22
23
|
# File 'lib/ufo/ecr_auth.rb', line 21
def fetch_auth_token
ecr.get_authorization_token.authorization_data.first.authorization_token
end
|
#update ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/ufo/ecr_auth.rb', line 9
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
|