Class: Ufo::EcrAuth

Inherits:
Object
  • Object
show all
Includes:
AwsServices
Defined in:
lib/ufo/ecr_auth.rb

Instance Method Summary collapse

Methods included from AwsServices

#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_configObject



25
26
27
# File 'lib/ufo/ecr_auth.rb', line 25

def docker_config
  "#{ENV['HOME']}/.docker/config.json"
end

#ensure_dotdocker_existsObject



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_tokenObject



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

#updateObject



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