Created
April 21, 2017 20:44
-
-
Save Sillson/21b7a583aaec685a362a242b97f6cb8f to your computer and use it in GitHub Desktop.
heroku pg creds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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