module SolveBio::CLI::Credentials
Public Class Methods
get_credentials()
click to toggle source
# File lib/solvebio/cli/credentials.rb, line 30 def get_credentials begin n = Netrc.read(netrc_path) return n[api_host] rescue Netrc::Error => e raise CredentialsError, "Could not read credentials file: #{e}" end end
Public Instance Methods
api_host()
click to toggle source
# File lib/solvebio/cli/credentials.rb, line 11 def api_host Addressable::URI.parse(SolveBio.api_host).host end
delete_credentials()
click to toggle source
# File lib/solvebio/cli/credentials.rb, line 40 def delete_credentials n = Netrc.read(netrc_path) n.delete(api_host) n.save end
netrc_path()
click to toggle source
# File lib/solvebio/cli/credentials.rb, line 15 def netrc_path raise IOError, "$HOME is not set and is needed for SolveBio credentials" unless ENV['HOME'] path = File.join(ENV['HOME'], '.solvebio', 'credentials') dirname = File.dirname(path) FileUtils.mkdir_p(dirname) unless File.directory?(dirname) # create an empty credentials file if it doesn't exist FileUtils.touch path unless File.exist? path FileUtils.chmod 0600, path path end
save_credentials(email, api_key)
click to toggle source
# File lib/solvebio/cli/credentials.rb, line 46 def save_credentials(email, api_key) n = Netrc.read(netrc_path) # Overwrites any existing credentials n[api_host] = email, api_key n.save end
Private Instance Methods
get_credentials()
click to toggle source
# File lib/solvebio/cli/credentials.rb, line 30 def get_credentials begin n = Netrc.read(netrc_path) return n[api_host] rescue Netrc::Error => e raise CredentialsError, "Could not read credentials file: #{e}" end end