Class: Kubes::Auth::Ecr

Inherits:
Base
  • Object
show all
Includes:
Kubes::AwsServices
Defined in:
lib/kubes/auth/ecr.rb

Instance Method Summary collapse

Methods included from Kubes::AwsServices

#ecr

Methods inherited from Base

#docker_config, #ensure_dotdocker_exists, #initialize

Methods included from Logging

#logger

Constructor Details

This class inherits a constructor from Kubes::Auth::Base

Instance Method Details

#fetch_auth_tokenObject



37
38
39
# File 'lib/kubes/auth/ecr.rb', line 37

def fetch_auth_token
  ecr.get_authorization_token.authorization_data.first.authorization_token
end

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kubes/auth/ecr.rb', line 20

def run
  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

  # Handle legacy docker clients that still have old format with https://
  legacy_entry = "https://#{@repo_domain}"
  data["auths"][legacy_entry] = {auth: auth_token}

  ensure_dotdocker_exists
  IO.write(docker_config, JSON.pretty_generate(data))
end