class Proxy::ContainerGateway::Api::AuthorizationHeader

Constants

UNAUTHORIZED_TOKEN

Public Class Methods

new(value) click to toggle source
# File lib/smart_proxy_container_gateway/container_gateway_api.rb, line 244
def initialize(value)
  @value = value || ''
end

Public Instance Methods

basic_auth?() click to toggle source
# File lib/smart_proxy_container_gateway/container_gateway_api.rb, line 272
def basic_auth?
  @value.split(' ')[0] == 'Basic'
end
blank?() click to toggle source
# File lib/smart_proxy_container_gateway/container_gateway_api.rb, line 276
def blank?
  Base64.decode64(@value.split(' ')[1]) == ':'
end
present?() click to toggle source
# File lib/smart_proxy_container_gateway/container_gateway_api.rb, line 260
def present?
  !@value.nil? && @value != ""
end
raw_header() click to toggle source
# File lib/smart_proxy_container_gateway/container_gateway_api.rb, line 256
def raw_header
  @value
end
token_auth?() click to toggle source
# File lib/smart_proxy_container_gateway/container_gateway_api.rb, line 268
def token_auth?
  @value.split(' ')[0] == 'Bearer'
end
unauthorized_token?() click to toggle source
# File lib/smart_proxy_container_gateway/container_gateway_api.rb, line 264
def unauthorized_token?
  @value.split(' ')[1] == UNAUTHORIZED_TOKEN
end
user() click to toggle source
# File lib/smart_proxy_container_gateway/container_gateway_api.rb, line 248
def user
  container_gateway_main.token_user(@value.split(' ')[1])
end
v1_foreman_authorized_username() click to toggle source

A special case for the V1 API. Defer authentication to Foreman and return the username. `nil` if not authorized.

# File lib/smart_proxy_container_gateway/container_gateway_api.rb, line 281
def v1_foreman_authorized_username
  username = Base64.decode64(@value.split(' ')[1]).split(':')[0]
  auth_response = ForemanApi.new.fetch_token(raw_header, { 'account' => username })
  return username if auth_response.code.to_i == 200 && (JSON.parse(auth_response.body)['token'] != 'unauthenticated')

  nil
end
valid_user_token?() click to toggle source
# File lib/smart_proxy_container_gateway/container_gateway_api.rb, line 252
def valid_user_token?
  token_auth? && container_gateway_main.valid_token?(@value.split(' ')[1])
end