Skip to content

Commit

Permalink
Defer evaluation of the Heroku auth token
Browse files Browse the repository at this point in the history
- HerokuSan::API was trying to evaluate the auth token at construction time, instead of waiting until it was actually needed, if ever.
- Fixes #156
  • Loading branch information
kmayer committed Oct 28, 2013
1 parent 2a04ecc commit a96ce5e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/heroku_san/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module HerokuSan
class API
def initialize(options = {})
@options = options
@options[:api_key] ||= auth_token
@heroku_api = Heroku::API.new(@options)
end

def sh(app, *command)
Expand All @@ -23,7 +21,7 @@ def sh(app, *command)
end

def method_missing(name, *args)
@heroku_api.send(name, *args)
heroku_api.send(name, *args)
rescue Heroku::API::Errors::ErrorWithResponse => error
status = error.response.headers["Status"]
msg = JSON.parse(error.response.body)['error'] rescue '???'
Expand All @@ -34,6 +32,13 @@ def method_missing(name, *args)

private

def heroku_api
@heroku_api ||= begin
@options[:api_key] ||= auth_token
Heroku::API.new(@options)
end
end

def auth_token
ENV['HEROKU_API_KEY'] || Bundler.with_clean_env { `heroku auth:token`.chomp }
rescue Errno::ENOENT
Expand Down

0 comments on commit a96ce5e

Please sign in to comment.