Class: Soba::Infrastructure::GitHubTokenProvider
- Inherits:
-
Object
- Object
- Soba::Infrastructure::GitHubTokenProvider
- Defined in:
- lib/soba/infrastructure/github_token_provider.rb
Overview
rubocop:disable Airbnb/ModuleMethodInWrongFile
Defined Under Namespace
Classes: TokenFetchError
Instance Method Summary collapse
Instance Method Details
#detect_best_method ⇒ Object
31 32 33 34 35 36 |
# File 'lib/soba/infrastructure/github_token_provider.rb', line 31 def detect_best_method return 'gh' if gh_available? return 'env' if ENV['GITHUB_TOKEN'] nil end |
#fetch(auth_method: nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/soba/infrastructure/github_token_provider.rb', line 11 def fetch(auth_method: nil) case auth_method when 'gh' fetch_from_gh when 'env' fetch_from_env when nil fetch_auto else raise TokenFetchError, "Invalid auth_method: #{auth_method}" end end |
#gh_available? ⇒ Boolean
24 25 26 27 28 29 |
# File 'lib/soba/infrastructure/github_token_provider.rb', line 24 def gh_available? return false unless system('which gh > /dev/null 2>&1') output = `gh auth token 2>/dev/null` last_command_status.success? && !output.strip.empty? end |