Automating Credentials in Capistrano

Posted by Vincent Woo Wed, 13 Jun 2007 20:40:00 GMT

Here’s a small tip that’s working well for me. If the user and password variables are set in the capistrano deployment scripts, then capistrano won’t prompt for the credentials anymore. It’s best to store them in ~/.caprc so you don’t commit your credentials to your SCM for all to see.

I’ve accumulated several different sets of credentials now that I’ve been working on several rails projects with different teams with their own login naming conventions. The simple assignment in .caprc just won’t do anymore.

Well, .caprc is just ruby code. Additionally, proc’s can be assigned to values to defer code execution until the value is first accessed. That way, the proc will have access to the application value in it’s local scope. Then we could do something like the following in .caprc:

set :user, Proc.new {
                case application
                   when 'project1': 'user1'
                   when 'project2': 'user2'
                 end
}

set :password, Proc.new {
                 case application
                   when 'project1': 'pass1'
                   when 'project2': 'pass2'
                 end
}

set :svn_username, Proc.new {
                 case application
                   when 'project1': 'svn_user1'
                   when 'project2': 'svn_user2'
                 end
}

Posted in  | Tags , , ,  | no comments | no trackbacks

Comments

Trackbacks

Use the following link to trackback from your own site:
http://www.undefinedrange.com/trackbacks?article_id=automating-credentials-in-capistrano&day=13&month=06&year=2007

Comments are disabled