Class: DPL::Provider::Heroku::Generic
Direct Known Subclasses
API, Git
Instance Attribute Summary collapse
#context, #options
Instance Method Summary
collapse
apt_get, #cleanup, #commit_msg, context, #create_key, #default_text_charset, #default_text_charset?, #deploy, deprecated, #detect_encoding?, #encoding_for, #error, experimental, #initialize, #log, new, npm_g, #option, pip, requires, #setup_git_credentials, #setup_git_ssh, #sha, shell, #uncleanup, #user_agent, #warn
Constructor Details
This class inherits a constructor from DPL::Provider
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
10
11
12
|
# File 'lib/dpl/provider/heroku/generic.rb', line 10
def app
@app
end
|
#user ⇒ Object
Returns the value of attribute user.
10
11
12
|
# File 'lib/dpl/provider/heroku/generic.rb', line 10
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
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 16
def faraday
return @conn if @conn
= { "Accept" => "application/vnd.heroku+json; version=3" }
if options[:user] and options[:password]
else
.merge!({ "Authorization" => "Bearer #{option(:api_key)}" })
end
@conn = Faraday.new( url: 'https://api.heroku.com', headers: ) do |faraday|
if options[:user] and options[:password]
faraday.basic_auth(options[:user], options[:password])
end
if log_level = options[: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
12
13
14
|
# File 'lib/dpl/provider/heroku/generic.rb', line 12
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.['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.['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
|