Forum: Ruby Retrieving Rubyforge login info on Mac Os X

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Stefano T. (Guest)
on 2006-04-21 14:25
(Received via mailing list)
Hi all,

On osx, I'm developing a small library hosted on rubyforge [1]. A
rakefile task takes care of  automatizing the release process.

The code snippet shown here allows the login information (username and
password) to be retrieved from osx's keychain [2]:

def keychain_login(domain)
  info = `security find-internet-password  -s '#{domain}' -g
2>&1`.split("\n")
  username = info.grep(/^\s*\"acct\"\<blob\>=\"(.*)\"$/){$1}.first
  password = info.grep(/^password: "(.*)"$/){$1}.first
  [username, password]
end

keychain_login('rubyforge.org')

This way, the username and password don't have to be hardcoded in the
script nor typed at run-time, nor set in the environment.

I hope this can make life slightly easier for my fellow developers on
osx.

Ciao
Stefano


[1] http://intervals.rubyforge.org/
[2] To have your username/password stored in the keychain, use Safari
to login on rubyforge at least once.
This topic is locked and can not be replied to.