Skip to content

Commit

Permalink
Add encrypted databag options to chef-solo
Browse files Browse the repository at this point in the history
  • Loading branch information
Oakie3CR committed Mar 13, 2012
1 parent 05756cb commit b4e24c9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/vagrant/provisioners/chef_solo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class Config < Chef::Config
attr_accessor :data_bags_path
attr_accessor :recipe_url
attr_accessor :nfs
attr_accessor :encrypted_data_bag_secret_key_path
attr_accessor :encrypted_data_bag_secret

def encrypted_data_bag_secret; @encrypted_data_bag_secret || "/tmp/encrypted_data_bag_secret"; end

def initialize
super
Expand Down Expand Up @@ -86,6 +90,7 @@ def provision!

verify_binary(chef_binary_path("chef-solo"))
chown_provisioning_folder
upload_encrypted_data_bag_secret if config.encrypted_data_bag_secret_key_path
setup_json
setup_solo_config
run_chef_solo
Expand Down Expand Up @@ -155,6 +160,12 @@ def share_folders(prefix, folders)
end
end

def upload_encrypted_data_bag_secret
env[:ui].info I18n.t("vagrant.provisioners.chef.upload_encrypted_data_bag_secret_key")
env[:vm].channel.upload(encrypted_data_bag_secret_key_path,
config.encrypted_data_bag_secret)
end

def setup_solo_config
cookbooks_path = guest_paths(@cookbook_folders)
roles_path = guest_paths(@role_folders).first
Expand All @@ -167,6 +178,7 @@ def setup_solo_config
:recipe_url => config.recipe_url,
:roles_path => roles_path,
:data_bags_path => data_bags_path,
:encrypted_data_bag_secret => config.encrypted_data_bag_secret,
})
end

Expand Down Expand Up @@ -207,6 +219,10 @@ def verify_shared_folders(folders)
end
end

def encrypted_data_bag_secret_key_path
File.expand_path(config.encrypted_data_bag_secret_key_path, env[:root_path])
end

protected

# Extracts only the remote paths from a list of folders
Expand Down
2 changes: 2 additions & 0 deletions templates/provisioners/chef_solo/solo.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ cookbook_path <%= cookbooks_path.inspect %>
role_path <%= roles_path.inspect %>
log_level <%= log_level.inspect %>

encrypted_data_bag_secret "<%= encrypted_data_bag_secret %>"

<% if data_bags_path -%>
data_bag_path <%= data_bags_path.inspect %>
<% end %>
Expand Down
3 changes: 2 additions & 1 deletion test/unit_legacy/vagrant/provisioners/chef_solo_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
:cookbooks_path => @action.guest_paths(@action.cookbook_folders),
:recipe_url => @config.recipe_url,
:roles_path => @action.guest_paths(@action.role_folders).first,
:data_bags_path => @action.guest_paths(@action.data_bags_folders).first
:data_bags_path => @action.guest_paths(@action.data_bags_folders).first,
:encrypted_data_bag_secret => @config.encrypted_data_bag_secret
})

@action.setup_solo_config
Expand Down

0 comments on commit b4e24c9

Please sign in to comment.