class Gitlab::QA::Runtime::TokenFinder

Attributes

suffix[R]
token[R]

Public Class Methods

find_token!(token, suffix: nil) click to toggle source
# File lib/gitlab/qa/runtime/token_finder.rb, line 7
def self.find_token!(token, suffix: nil)
  new(token, suffix).find_token!
end
new(token, suffix) click to toggle source
# File lib/gitlab/qa/runtime/token_finder.rb, line 13
def initialize(token, suffix)
  @token = token
  @suffix = suffix
end

Public Instance Methods

find_token!() click to toggle source
# 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_attrs() click to toggle source
# File lib/gitlab/qa/runtime/token_finder.rb, line 22
def find_token_from_attrs
  token
end
find_token_from_env() click to toggle source
# File lib/gitlab/qa/runtime/token_finder.rb, line 26
def find_token_from_env
  Env.qa_access_token
end
find_token_from_file() click to toggle source
# 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

Private Instance Methods

token_file_path() click to toggle source
# File lib/gitlab/qa/runtime/token_finder.rb, line 38
def token_file_path
  @token_file_path ||= File.expand_path("../api_token#{"_#{suffix}" if suffix}", __dir__)
end