class Proxy::ContainerGateway::Api

Private Instance Methods

auth_header() click to toggle source
# File lib/smart_proxy_container_gateway/container_gateway_api.rb, line 233
def auth_header
  AuthorizationHeader.new(request.env['HTTP_AUTHORIZATION'])
end
handle_repo_auth(repository, auth_header, request) click to toggle source
# File lib/smart_proxy_container_gateway/container_gateway_api.rb, line 212
def handle_repo_auth(repository, auth_header, request)
  user_token_is_valid = false
  if auth_header.present? && auth_header.valid_user_token?
    user_token_is_valid = true
    username = auth_header.user[:name]
  end
  username = request.params['account'] if username.nil?

  return if container_gateway_main.authorized_for_repo?(repository, user_token_is_valid, username)

  redirect_authorization_headers
  halt 401, "unauthorized"
end
redirect_authorization_headers() click to toggle source
# File lib/smart_proxy_container_gateway/container_gateway_api.rb, line 226
def redirect_authorization_headers
  response.headers['Docker-Distribution-API-Version'] = 'registry/2.0'
  response.headers['Www-Authenticate'] = "Bearer realm=\"https://#{request.host}/v2/token\"," \
                                         "service=\"#{request.host}\"," \
                                         "scope=\"repository:registry:pull,push\""
end
translated_headers_for_proxy() click to toggle source
# File lib/smart_proxy_container_gateway/container_gateway_api.rb, line 201
def translated_headers_for_proxy
  current_headers = {}
  env = request.env.select do |key, _value|
    key.match("^HTTP_.*")
  end
  env.each do |header|
    current_headers[header[0].split('_')[1..].join('-')] = header[1]
  end
  current_headers
end