Sha256: ac216bf8e390311fb4830131fd97af95b8b42ebf5c4ee1f69a880146eb4e8e99

Contents?: true

Size: 1.86 KB

Versions: 6

Compression:

Stored size: 1.86 KB

Contents

module DPL
  class Provider
    module Heroku
      class Generic < Provider
        requires 'heroku-api'
        requires 'rendezvous'

        def needs_key?
          false
        end

        def api
          @api ||= ::Heroku::API.new(api_options)
        end

        def api_options
          api_options = { headers: { 'User-Agent' => user_agent(::Heroku::API::HEADERS.fetch('User-Agent')) } }
          if options[:user] and options[:password]
            api_options[:user]     = options[:user]
            api_options[:password] = options[:password]
          else
            api_options[:api_key]  = option(:api_key)
          end
          api_options
        end

        def user
          @user ||= api.get_user.body["email"]
        end

        def check_auth
          log "authenticated as %s" % user
        end

        def check_app
          log "checking for app '#{option(:app)}'"
          info = api.get_app(option(:app)).body
          log "found app '#{info['name']}'"
        rescue ::Heroku::API::Errors::Forbidden => error
          raise Error, "#{error.message} (does the app '#{option(:app)}' exist and does your account have access to it?)", error.backtrace
        end

        def run(command)
          data           = api.post_ps(option(:app), command, :attach => true).body
          rendezvous_url = data['rendezvous_url']
          Rendezvous.start(:url => rendezvous_url) unless rendezvous_url.nil?
        end

        def restart
          api.post_ps_restart option(:app)
        end

        def deploy
          super
        rescue ::Heroku::API::Errors::NotFound => error
          raise Error, "#{error.message} (wrong app #{options[:app].inspect}?)", error.backtrace
        rescue ::Heroku::API::Errors::Unauthorized => error
          raise Error, "#{error.message} (wrong API key?)", error.backtrace
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dpl-1.7.6.travis.623.1 lib/dpl/provider/heroku/generic.rb
dpl-1.7.5.travis.622.1 lib/dpl/provider/heroku/generic.rb
dpl-1.7.5 lib/dpl/provider/heroku/generic.rb
dpl-1.7.5.travis.620.1 lib/dpl/provider/heroku/generic.rb
dpl-1.7.4 lib/dpl/provider/heroku/generic.rb
dpl-1.7.4.travis.619.1 lib/dpl/provider/heroku/generic.rb