Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate a dedicated token for heroku deployments #785

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions lib/travis/cli/setup/heroku.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,33 @@ class Heroku < Service

def run
deploy 'heroku' do |config|
config['api_key'] = `heroku auth:token 2>/dev/null`.strip
config['api_key'] = ask("Heroku API token: ") { |q| q.echo = "*" }.to_s if config['api_key'].empty?
config['api_key'] = get_token
config['api_key'] = ask("Heroku API token: ") { |q| q.echo = "*" }.to_s if config['api_key'].to_s.empty?
config['app'] = `heroku apps:info 2>/dev/null`.scan(/^=== (.+)$/).flatten.first
config['app'] = ask("Heroku application name: ") { |q| q.default = repository.name }.to_s if config['app'].nil?
end
end

def get_token
return unless Tools::System.has? 'heroku'
say "Generating Heroku token - "
system "heroku auth:whoami"
unless debug_run 'heroku authorizations'
say "Installing Heroku OAuth plugin"
debug_run 'heroku plugins:install https://github.com/heroku/heroku-oauth'
end
`heroku authorizations:create --description "Travis CI (#{repository.slug})"`[/Token:\s+(\S+)/, 1]
end

def debug_run(cmd)
command.debug "$ #{cmd}"
IO.popen(cmd, :err=>[:child, :out]) do |io|
command.debug("> #{io.gets.sub(/(\S)\s*\n|\n/, '\1')}") until io.eof?
end
result = $?.success?
command.debug "#{cmd} - #{result ? "succeeded" : "failed"}"
result
end
end
end
end
Expand Down