Class: Kubes::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/kubes/auth/ecr.rb,
lib/kubes/auth.rb,
lib/kubes/auth/gcr.rb,
lib/kubes/auth/base.rb

Overview

Normally, you must authorized to AWS ECR to push to their registry with:

eval $(aws ecr get-login --no-include-email)

If you haven’t ever ran the ecr get-login command before then you’ll get this error:

no basic auth credentials

If you have ran it before but the auto token has expired you’ll get this message:

denied: Your Authorization Token has expired. Please run 'aws ecr get-login' to fetch a new one.

This class updates the ~/.docker/config.json file which is an internal docker file to automatically update the auto token for you. If that format changes, the update will need to be updated.

Defined Under Namespace

Classes: Base, Ecr, Gcr

Instance Method Summary collapse

Constructor Details

#initialize(image) ⇒ Auth

Returns a new instance of Auth.



3
4
5
# File 'lib/kubes/auth.rb', line 3

def initialize(image)
  @image = image
end

Instance Method Details

#auth?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
# File 'lib/kubes/auth.rb', line 25

def auth?
  if ENV['KUBES_REPO_AUTO_AUTH'].nil?
    Kubes.config.repo_auto_auth
  else
    %w[1 true].include?(ENV['KUBES_REPO_AUTO_AUTH'])
  end
end

#runObject



7
8
9
10
11
# File 'lib/kubes/auth.rb', line 7

def run
  klass = strategy_class
  return unless klass
  klass.new(@image).run
end

#strategy_classObject

Currently only support ECR and GCR TODO: consider moving this to plugin gems



15
16
17
18
19
20
21
22
23
# File 'lib/kubes/auth.rb', line 15

def strategy_class
  return unless auth?
  case @image
  when /\.amazonaws\.com/ # IE: 112233445566.dkr.ecr.us-west-2.amazonaws.com/demo/sinatra
    Ecr
  when /gcr\.io/
    Gcr
  end
end