Class: Escobar::Heroku::App

Inherits:
Object
  • Object
show all
Defined in:
lib/escobar/heroku/app.rb

Overview

Class representing a heroku application

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, id) ⇒ App

Returns a new instance of App.



6
7
8
9
# File 'lib/escobar/heroku/app.rb', line 6

def initialize(client, id)
  @id     = id
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/escobar/heroku/app.rb', line 5

def client
  @client
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/escobar/heroku/app.rb', line 5

def id
  @id
end

Instance Method Details

#build_request_for(pipeline) ⇒ Object



80
81
82
# File 'lib/escobar/heroku/app.rb', line 80

def build_request_for(pipeline)
  Escobar::Heroku::BuildRequest.new(pipeline, id)
end

#cache_keyObject



51
52
53
# File 'lib/escobar/heroku/app.rb', line 51

def cache_key
  "escobar-app-#{id}"
end

#config_varsObject



39
40
41
# File 'lib/escobar/heroku/app.rb', line 39

def config_vars
  @config_vars ||= Escobar::Heroku::ConfigVars.new(client, id)
end

#current_release_refObject



31
32
33
# File 'lib/escobar/heroku/app.rb', line 31

def current_release_ref
  releases.first.ref
end

#dashboard_urlObject



47
48
49
# File 'lib/escobar/heroku/app.rb', line 47

def dashboard_url
  "https://dashboard.heroku.com/apps/#{name}"
end

#direct_to_drain?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/escobar/heroku/app.rb', line 68

def direct_to_drain?
  !log_drains.is_a?(Array)
end

#drainObject



84
85
86
87
88
# File 'lib/escobar/heroku/app.rb', line 84

def drain
  @drain ||= log_drains.find do |drain|
    drain["url"].match(heroku_drain_url_pattern)
  end
end

#drain_tokenObject



72
73
74
# File 'lib/escobar/heroku/app.rb', line 72

def drain_token
  @drain_token ||= drain && drain["token"]
end

#dynosObject



35
36
37
# File 'lib/escobar/heroku/app.rb', line 35

def dynos
  @dynos ||= Escobar::Heroku::Dynos.new(client, id)
end

#heroku_drain_url_patternObject



90
91
92
# File 'lib/escobar/heroku/app.rb', line 90

def heroku_drain_url_pattern
  %r{forward\.log\.herokai\.com:9999|logs\.herokai\.com\/logs}
end

#infoObject



15
16
17
# File 'lib/escobar/heroku/app.rb', line 15

def info
  @info ||= heroku.get("/apps/#{id}")
end

#locked?Boolean

Returns:

  • (Boolean)


60
61
62
63
64
65
66
# File 'lib/escobar/heroku/app.rb', line 60

def locked?
  response = heroku.get("/apps/#{id}/config-vars")
  response["id"] == "two_factor"
rescue Escobar::Client::HTTPError => e
  response = JSON.parse(e.response.body)
  response["id"] == "two_factor"
end

#log_drainsObject



43
44
45
# File 'lib/escobar/heroku/app.rb', line 43

def log_drains
  @log_drains ||= heroku.get("/apps/#{id}/log-drains")
end

#log_urlObject



76
77
78
# File 'lib/escobar/heroku/app.rb', line 76

def log_url
  @log_url ||= "#{dashboard_url}/logs"
end

#nameObject



11
12
13
# File 'lib/escobar/heroku/app.rb', line 11

def name
  info["name"]
end

#preauth(second_factor) ⇒ Object

Accepts either google authenticator or yubikey second_factor formatting



56
57
58
# File 'lib/escobar/heroku/app.rb', line 56

def preauth(second_factor)
  heroku.put("/apps/#{id}/pre-authorizations", {}, second_factor).none?
end

#releasesObject



25
26
27
28
29
# File 'lib/escobar/heroku/app.rb', line 25

def releases
  @releases ||= releases_json.map do |release|
    Escobar::Heroku::Release.new(client, id, nil, release["id"])
  end
end

#releases_jsonObject



19
20
21
22
23
# File 'lib/escobar/heroku/app.rb', line 19

def releases_json
  @releases_json ||= heroku.get_range(
    "/apps/#{id}/releases", "version; order=desc,max=25;"
  )
end