Skip to content

Instantly share code, notes, and snippets.

@Sillson
Created April 21, 2017 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sillson/21b7a583aaec685a362a242b97f6cb8f to your computer and use it in GitHub Desktop.
Save Sillson/21b7a583aaec685a362a242b97f6cb8f to your computer and use it in GitHub Desktop.
heroku pg creds
class CredFinder
attr_accessor :cred_hsh
def initialize(urn)
puts "***** \nSapSucking Creds For -- \n#{urn} \n*****"
@cms_urn = urn
@cred_hsh = {'dbname'=>'','host'=>'','port'=>'','user'=>'', 'password'=>''}
build_creds
end
def build_creds
# get credentials string from heroku
str = `heroku pg:credentials -a "#{@cms_urn}"`
# split string by spaces
str = str.split(' ')
# select only values that contain an equals symbol
creds = str.select {|substr| substr.include?('=')}
# for each key in the credentials hash, return the value from the creds array
@cred_hsh.keys.each do |key|
item_array = creds.select { |val| val.include?(key) }
item = item_array[0].split('=')
value = item.last
@cred_hsh[key] = value
end
return @cred_hsh
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment