Class: Gitlab::APIAuthentication::TokenLocator

Inherits:
Object
  • Object
show all
Includes:
ActionController::HttpAuthentication::Basic, ActiveModel::Validations
Defined in:
lib/gitlab/api_authentication/token_locator.rb

Defined Under Namespace

Classes: UsernameAndPassword

Constant Summary collapse

VALID_LOCATIONS =
%i[
  http_basic_auth
  http_token
  http_bearer_token
  http_deploy_token_header
  http_job_token_header
  http_private_token_header
  http_header
  token_param
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ TokenLocator

Returns a new instance of TokenLocator.



26
27
28
29
# File 'lib/gitlab/api_authentication/token_locator.rb', line 26

def initialize(location)
  @location = extract_location(location)
  validate!
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



22
23
24
# File 'lib/gitlab/api_authentication/token_locator.rb', line 22

def location
  @location
end

Instance Method Details

#extract(request) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gitlab/api_authentication/token_locator.rb', line 31

def extract(request)
  case @location
  when :http_basic_auth
    extract_from_http_basic_auth request
  when :http_token
    extract_from_http_token request
  when :http_bearer_token
    extract_from_http_bearer_token request
  when :http_deploy_token_header
    extract_from_http_deploy_token_header request
  when :http_job_token_header
    extract_from_http_job_token_header request
  when :http_private_token_header
    extract_from_http_private_token_header request
  when :http_header
    extract_from_http_header request
  when :token_param
    extract_from_token_param request
  end
end