Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 21st, 2012  |  syntax: None  |  size: 0.96 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ##
  2. # HTTP Authentification deployment Recipe
  3. # => Add htaccess password protection when deploying, with the correct htpassword file for the passed users
  4. ##
  5. _cset (:http_auth_users) {[
  6.         ["admin", "password"]
  7. ]}
  8. _cset (:http_auth_path) { "" } # Path of the directory to add http auth, from the release root
  9.  
  10. namespace :httpAuth do
  11.  
  12.         desc <<-DESC
  13.                 Generates / updates .htaccess and .htpasswd files with the credentials passed in parameter
  14.                 Inspired from: https://gist.github.com/805879
  15.         DESC
  16.         task :protect do
  17.                 htpasswdFile = "#{current_release}#{http_auth_path}/.htpasswd"
  18.                 htpasswdContent = http_auth_users.inject("") { |content, user|
  19.                         content = content + user[0] + ":" + user[1].crypt("httpauth") + "\n"
  20.                 }
  21.                 put htpasswdContent, htpasswdFile, :mode => 0644
  22.  
  23.                 [
  24.                         '',
  25.                         'AuthType Basic',
  26.                         'AuthName "Restricted"',
  27.                         "AuthUserFile \"#{htpasswdFile}\"",
  28.                         'Require valid-user'
  29.                 ].each { |line| run "echo '#{line}' >> #{current_release}#{http_auth_path}/.htaccess" }
  30.         end
  31. end