# File lib/heroku/helpers/heroku_postgresql.rb, line 38 def primary_attachment! @primary_attachment = true end
class Heroku::Helpers::HerokuPostgresql::Attachment
Attributes
addon[R]
app[R]
bastion_key[R]
bastions[R]
config_var[R]
name[R]
plan[R]
resource_name[R]
url[R]
Public Class Methods
new(raw)
click to toggle source
# File lib/heroku/helpers/heroku_postgresql.rb, line 12 def initialize(raw) @raw = raw @app = raw['app']['name'] @name = raw['name'] || raw['config_var'].sub(/_URL\Z/, '') @config_var = raw['config_var'] @resource_name = raw['resource']['name'] @url = raw['resource']['value'] @addon, @plan = raw['resource']['type'].split(':') # Optional Bastion information for tunneling. if config = raw['config'] @bastions = if maybe_hosts = config[@name + '_BASTIONS'] maybe_hosts.split(',') end @bastion_key = config[@name + '_BASTION_KEY'] end end
Public Instance Methods
display_name()
click to toggle source
# File lib/heroku/helpers/heroku_postgresql.rb, line 34 def display_name config_var + (primary_attachment? ? " (DATABASE_URL)" : '') end
maybe_tunnel() { |uri| ... }
click to toggle source
# File lib/heroku/helpers/heroku_postgresql.rb, line 50 def maybe_tunnel require "net/ssh/gateway" uri = URI.parse(url) if uses_bastion? bastion_host = bastions.sample gateway = Net::SSH::Gateway.new(bastion_host, 'bastion', paranoid: false, timeout: 15, key_data: [bastion_key]) begin local_port = rand(65535 - 49152) + 49152 gateway.open(uri.host, uri.port, local_port) do |actual_local_port| uri.host = 'localhost' uri.port = actual_local_port yield uri end rescue Errno::EADDRINUSE # Get a new random port if a local binding was not possible. gateway && gateway.shutdown! gateway = nil retry ensure gateway && gateway.shutdown! end else yield uri end end
primary_attachment!()
click to toggle source
primary_attachment?()
click to toggle source
# File lib/heroku/helpers/heroku_postgresql.rb, line 42 def primary_attachment? @primary_attachment end
starter_plan?()
click to toggle source
# File lib/heroku/helpers/heroku_postgresql.rb, line 30 def starter_plan? plan =~ /dev|basic/ end
uses_bastion?()
click to toggle source
# File lib/heroku/helpers/heroku_postgresql.rb, line 46 def uses_bastion? !!(bastions && bastion_key) end