Class: DPL::Provider::Heroku::Generic
- Inherits:
-
DPL::Provider
- Object
- DPL::Provider
- DPL::Provider::Heroku::Generic
- Defined in:
- lib/dpl/provider/heroku/generic.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #check_app ⇒ Object
- #check_auth ⇒ Object
- #faraday ⇒ Object
- #handle_error_response(response) ⇒ Object
- #needs_key? ⇒ Boolean
- #restart ⇒ Object
- #run(command) ⇒ Object
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
7 8 9 |
# File 'lib/dpl/provider/heroku/generic.rb', line 7 def app @app end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
7 8 9 |
# File 'lib/dpl/provider/heroku/generic.rb', line 7 def user @user end |
Instance Method Details
#check_app ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/dpl/provider/heroku/generic.rb', line 59 def check_app log "checking for app #{option(:app)}" response = faraday.get("/apps/#{option(:app)}") if response.success? @app = JSON.parse(response.body) log "found app #{@app["name"]}" else handle_error_response(response) end end |
#check_auth ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dpl/provider/heroku/generic.rb', line 42 def check_auth response = faraday.get('/account') if response.success? email = JSON.parse(response.body)["email"] @user = email log "authentication succeeded" else handle_error_response(response) end end |
#faraday ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dpl/provider/heroku/generic.rb', line 13 def faraday return @conn if @conn headers = { "Accept" => "application/vnd.heroku+json; version=3", "User-Agent" => user_agent, } if [:user] and [:password] # no-op else headers.merge!({ "Authorization" => "Bearer #{option(:api_key)}" }) end @conn = Faraday.new( url: 'https://api.heroku.com', headers: headers ) do |faraday| if [:user] and [:password] faraday.basic_auth([:user], [:password]) end if log_level = [:log_level] logger = Logger.new($stderr) logger.level = Logger.const_get(log_level.upcase) faraday.response :logger, logger do | logger | logger.filter(/(.*Authorization: ).*/,'\1[REDACTED]') end end faraday.adapter Faraday.default_adapter end end |
#handle_error_response(response) ⇒ Object
54 55 56 57 |
# File 'lib/dpl/provider/heroku/generic.rb', line 54 def handle_error_response(response) error_response = JSON.parse(response.body) error "API request failed.\nMessage: #{error_response["message"]}\nReference: #{error_response["url"]}" end |
#needs_key? ⇒ Boolean
9 10 11 |
# File 'lib/dpl/provider/heroku/generic.rb', line 9 def needs_key? false end |
#restart ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/dpl/provider/heroku/generic.rb', line 70 def restart response = faraday.delete "/apps/#{option(:app)}/dynos" do |req| req.headers['Content-Type'] = 'application/json' end unless response.success? handle_error_response(response) end end |
#run(command) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/dpl/provider/heroku/generic.rb', line 79 def run(command) response = faraday.post "/apps/#{option(:app)}/dynos" do |req| req.headers['Content-Type'] = 'application/json' req.body = {"command" => command, "attach" => true}.to_json end if response.success? rendezvous_url = JSON.parse(response.body)["attach_url"] Rendezvous.start(url: rendezvous_url) else handle_error_response(response) end end |