Class: Gitlab::QA::Runtime::TokenFinder
- Inherits:
-
Object
- Object
- Gitlab::QA::Runtime::TokenFinder
- Defined in:
- lib/gitlab/qa/runtime/token_finder.rb
Instance Attribute Summary collapse
-
#suffix ⇒ Object
readonly
Returns the value of attribute suffix.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #find_token! ⇒ Object
- #find_token_from_attrs ⇒ Object
- #find_token_from_env ⇒ Object
- #find_token_from_file ⇒ Object
-
#initialize(token, suffix) ⇒ TokenFinder
constructor
A new instance of TokenFinder.
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
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
11 12 13 |
# File 'lib/gitlab/qa/runtime/token_finder.rb', line 11 def suffix @suffix end |
#token ⇒ Object (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_attrs ⇒ Object
22 23 24 |
# File 'lib/gitlab/qa/runtime/token_finder.rb', line 22 def find_token_from_attrs token end |
#find_token_from_env ⇒ Object
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_file ⇒ Object
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 |