class Paratrooper::LocalApiKeyExtractor

Attributes

file_path[R]
netrc_klass[R]

Public Class Methods

get_credentials() click to toggle source
# File lib/paratrooper/local_api_key_extractor.rb, line 10
def self.get_credentials
  new.read_credentials
end
new(options = {}) click to toggle source
# File lib/paratrooper/local_api_key_extractor.rb, line 14
def initialize(options = {})
  @netrc_klass = options[:netrc_klass] || Netrc
  @file_path   = options[:file_path] || netrc_klass.default_path
end

Public Instance Methods

read_credentials() click to toggle source
# File lib/paratrooper/local_api_key_extractor.rb, line 19
def read_credentials
  ENV['HEROKU_API_KEY'] || read_credentials_for('api.heroku.com')
end

Private Instance Methods

netrc() click to toggle source
# File lib/paratrooper/local_api_key_extractor.rb, line 24
def netrc
  unless netrc_present?
    raise NetrcFileDoesNotExist, netrc_file_missing_message
  end
  @netrc ||= Netrc.read(file_path)
end
netrc_file_missing_message() click to toggle source
# File lib/paratrooper/local_api_key_extractor.rb, line 35
def netrc_file_missing_message
  "Unable to find netrc file. Expected location: #{netrc_klass.default_path}."
end
netrc_present?() click to toggle source
# File lib/paratrooper/local_api_key_extractor.rb, line 39
def netrc_present?
  File.exists?(file_path)
end
read_credentials_for(domain) click to toggle source
# File lib/paratrooper/local_api_key_extractor.rb, line 31
def read_credentials_for(domain)
  netrc[domain][1]
end