class Tagfish::APICall

Attributes

debug[RW]
http[RW]
http_auth[RW]
request[RW]
uri[RW]

Public Class Methods

new(debug = false) click to toggle source
# File lib/tagfish/api_call.rb, line 14
def initialize (debug = false)
  @debug = debug
  @auth = nil
end

Public Instance Methods

auth(registry) click to toggle source
# File lib/tagfish/api_call.rb, line 40
def auth(registry)
  begin
    file_path = ENV.fetch('DOCKER_CONFIG', '~/.docker/config.json')
    docker_config_data = JSON.parse(File.read(File.expand_path(file_path)))
  rescue Exception => e
    abort("Tried to get username/password but the file #{file_path} does not exist")
  end

  cs = CredentialStore.new(docker_config_data)
  @http_auth = cs.credentials_for(registry)
end
get(uri_string) click to toggle source
# File lib/tagfish/api_call.rb, line 19
def get(uri_string)
  @uri = URI.parse(uri_string)
  @http = Net::HTTP.new(uri.host, uri.port)
  @http.use_ssl = true if uri.port == 443
  @http.set_debug_output($stderr) if debug
  @request = Net::HTTP::Get.new(uri.request_uri)
  if http_auth
    @request.basic_auth(http_auth.username, http_auth.password)
  end
  http_response = http.request(request)
  APIResponse.new(http_response)
end
get!(uri_string) click to toggle source
# File lib/tagfish/api_call.rb, line 32
def get!(uri_string)
  response = get(uri_string)
  if response.code != 200
    raise APIError, "call to '#{uri_string}' failed with #{response.code}"
  end
  response
end