Module: Onair::Auth::Netrc

Defined in:
lib/onair/auth/netrc.rb

Overview

Minimal ~/.netrc reader — just enough to pull the token the Heroku CLI stores under machine api.heroku.com. Handles both same-line and multi-line entry styles (the format is whitespace-token based).

Class Method Summary collapse

Class Method Details

.token(host, path: File.join(Dir.home, ".netrc")) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/onair/auth/netrc.rb', line 9

def self.token(host, path: File.join(Dir.home, ".netrc"))
  return nil unless File.readable?(path)

  tokens = File.read(path).split(/\s+/)
  tokens.each_with_index do |word, index|
    return password_after(tokens, index + 2) if word == "machine" && tokens[index + 1] == host
  end
  nil
end