Class: Kubes::Auth::Gcr

Inherits:
Base
  • Object
show all
Defined in:
lib/kubes/auth/gcr.rb

Instance Method Summary collapse

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

#authorize!Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/kubes/auth/gcr.rb', line 7

def authorize!
  command = "gcloud auth configure-docker"
  logger.debug "Authorizing GCR with: #{command}"
  success = system(command)
  unless success
    logger.error "ERROR: running #{command}".color(:red)
    exit $?.exitstatus if exit_on_fail
  end
  success
end

#authorized?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/kubes/auth/gcr.rb', line 18

def authorized?
  return false unless File.exist?(docker_config)
  data = JSON.load(IO.read(docker_config))
  !!data.dig('credHelpers', 'gcr.io')
end

#runObject



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

def run
  authorize! unless authorized?
end