Class: Gitlab::QA::Runtime::TokenFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/qa/runtime/token_finder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, suffix) ⇒ TokenFinder

Returns a new instance of TokenFinder.



13
14
15
16
# File 'lib/gitlab/qa/runtime/token_finder.rb', line 13

def initialize(token, suffix)
  @token = token
  @suffix = suffix
end

Instance Attribute Details

#suffixObject (readonly)

Returns the value of attribute suffix.



11
12
13
# File 'lib/gitlab/qa/runtime/token_finder.rb', line 11

def suffix
  @suffix
end

#tokenObject (readonly)

Returns the value of attribute token.



11
12
13
# File 'lib/gitlab/qa/runtime/token_finder.rb', line 11

def token
  @token
end

Class Method Details

.find_token!(token, suffix: nil) ⇒ Object



7
8
9
# File 'lib/gitlab/qa/runtime/token_finder.rb', line 7

def self.find_token!(token, suffix: nil)
  new(token, suffix).find_token!
end

Instance Method Details

#find_token!Object



18
19
20
# File 'lib/gitlab/qa/runtime/token_finder.rb', line 18

def find_token!
  find_token_from_attrs || find_token_from_env || find_token_from_file
end

#find_token_from_attrsObject



22
23
24
# File 'lib/gitlab/qa/runtime/token_finder.rb', line 22

def find_token_from_attrs
  token
end

#find_token_from_envObject



26
27
28
# File 'lib/gitlab/qa/runtime/token_finder.rb', line 26

def find_token_from_env
  Env.qa_access_token
end

#find_token_from_fileObject



30
31
32
33
34
# File 'lib/gitlab/qa/runtime/token_finder.rb', line 30

def find_token_from_file
  @token_from_file ||= File.read(token_file_path).strip
rescue Errno::ENOENT
  fail "Please provide a valid access token with the `-t/--token` option, the `GITLAB_QA_ACCESS_TOKEN` environment variable, or in the `#{token_file_path}` file!"
end