Skip to content

Commit

Permalink
Filter sensitive settings, like password
Browse files Browse the repository at this point in the history
  • Loading branch information
iain committed May 15, 2012
1 parent 8b32b1a commit ea6b0c9
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions lib/roundsman/capistrano.rb
Expand Up @@ -173,6 +173,7 @@ def install_ruby?
set_default :chef_version, "~> 0.10.8"
set_default :cookbooks_directory, ["config/cookbooks"]
set_default :copyfile_disable, false
set_default :filter_sensitive_settings, [ /password/, /filter_sensitive_settings/ ]

task :default, :except => { :no_release => true } do
ensure_cookbooks_exists
Expand Down Expand Up @@ -220,11 +221,11 @@ def install_chef?
def generate_config
cookbook_string = cookbooks_paths.map { |c| "File.join(root, #{c.to_s.inspect})" }.join(', ')
solo_rb = <<-RUBY
root = File.expand_path(File.dirname(__FILE__))
file_cache_path File.join(root, "cache")
cookbook_path [ #{cookbook_string} ]
RUBY
put solo_rb, roundsman_working_dir("solo.rb"), :via => :scp
root = File.expand_path(File.dirname(__FILE__))
file_cache_path File.join(root, "cache")
cookbook_path [ #{cookbook_string} ]
RUBY
put solo_rb, roundsman_working_dir("solo.rb"), :via => :scp
end

def generate_attributes
Expand All @@ -238,22 +239,22 @@ def generate_attributes
def remove_procs_from_hash(hash)
new_hash = {}
hash.each do |key, value|
next if fetch(:filter_sensitive_settings).find { |regex| regex.match(key) }
real_value = if value.respond_to?(:call)
next if key == :password # do not prompt user for password, when they opt not to provide one it is usually because keys are being used, instead
begin
value.call
rescue ::Capistrano::CommandError => e
logger.debug "Could not get the value of #{key}: #{e.message}"
nil
end
else
value
end
begin
value.call
rescue ::Capistrano::CommandError => e
logger.debug "Could not get the value of #{key}: #{e.message}"
nil
end
else
value
end

if real_value.is_a?(Hash)
real_value = remove_procs_from_hash(real_value)
end
unless real_value.class.to_s.include?("Capistrano") # skip capistrano tasks
if real_value && !real_value.class.to_s.include?("Capistrano") # skip capistrano tasks
new_hash[key] = real_value
end
end
Expand Down

2 comments on commit ea6b0c9

@mikesmullin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iain this commit broke something for me. i can't seem to set any node['mysql'] attributes for my mysql::server recipe. i forked and removed from my branch and it started working again. not sure exactly what about it tho.

@antono
Copy link

@antono antono commented on ea6b0c9 Feb 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can easily use upstream version, just add this to your deploy.rb:

set :filter_sensitive_settings, []

Just remember to drop /tmp/roundsman/node.json if you care about plain text passwords.

Please sign in to comment.