summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@getchef.com>2015-01-22 17:53:40 -0800
committerdanielsdeleo <dan@getchef.com>2015-01-27 12:46:14 -0800
commitf86c252d761f34943da1df1b055c0b0994c0d0d9 (patch)
treeb5ceaf8a3c7502661204ed1a7e230370042076b2
parent9c6bd84af0262fa3bcc467500edb210fe9443b81 (diff)
downloadchef-f86c252d761f34943da1df1b055c0b0994c0d0d9.tar.gz
Add policy support to ChefFS configuration
-rw-r--r--lib/chef/chef_fs/config.rb29
-rw-r--r--spec/unit/chef_fs/config_spec.rb52
2 files changed, 77 insertions, 4 deletions
diff --git a/lib/chef/chef_fs/config.rb b/lib/chef/chef_fs/config.rb
index fcad6c919f..6666a3deee 100644
--- a/lib/chef/chef_fs/config.rb
+++ b/lib/chef/chef_fs/config.rb
@@ -26,6 +26,25 @@ class Chef
# objects representing the server and local repository, respectively).
#
class Config
+
+ # Not all of our object types pluralize by adding an 's', so we map them
+ # out here:
+ INFLECTIONS = {
+ "acls" => "acl",
+ "clients" => "client",
+ "cookbooks" => "cookbook",
+ "containers" => "container",
+ "data_bags" => "data_bag",
+ "environments" => "environment",
+ "groups" => "group",
+ "nodes" => "node",
+ "roles" => "role",
+ "users" => "user",
+ "policies" => "policy"
+ }
+ INFLECTIONS.each { |k,v| k.freeze; v.freeze }
+ INFLECTIONS.freeze
+
#
# Create a new Config object which can produce a chef_fs and local_fs.
#
@@ -215,14 +234,16 @@ class Chef
result = {}
case @chef_config[:repo_mode]
when 'static'
- object_names = %w(cookbooks data_bags environments roles)
+ object_names = %w(cookbooks data_bags environments roles policies)
when 'hosted_everything'
- object_names = %w(acls clients cookbooks containers data_bags environments groups nodes roles)
+ object_names = %w(acls clients cookbooks containers data_bags environments groups nodes roles policies)
else
- object_names = %w(clients cookbooks data_bags environments nodes roles users)
+ object_names = %w(clients cookbooks data_bags environments nodes roles users policies)
end
object_names.each do |object_name|
- variable_name = "#{object_name[0..-2]}_path" # cookbooks -> cookbook_path
+ # cookbooks -> cookbook_path
+ singular_name = INFLECTIONS[object_name] or raise "Unknown object name #{object_name}"
+ variable_name = "#{singular_name}_path"
paths = Array(@chef_config[variable_name]).flatten
result[object_name] = paths.map { |path| File.expand_path(path) }
end
diff --git a/spec/unit/chef_fs/config_spec.rb b/spec/unit/chef_fs/config_spec.rb
index 031da6c4b5..c7c47ad8ab 100644
--- a/spec/unit/chef_fs/config_spec.rb
+++ b/spec/unit/chef_fs/config_spec.rb
@@ -55,4 +55,56 @@ describe Chef::ChefFS::Config do
Chef::ChefFS::Config.new(base_config, Dir.pwd, {}, ui)
end
end
+
+ describe "local FS configuration" do
+
+ let(:chef_config) do
+ Mash.new({
+ client_path: "/base_path/clients",
+ cookbook_path: "/base_path/cookbooks",
+ data_bag_path: "/base_path/data_bags",
+ environment_path: "/base_path/environments",
+ node_path: "/base_path/nodes",
+ role_path: "/base_path/roles",
+ user_path: "/base_path/users",
+ policy_path: "/base_path/policies"
+ })
+ end
+
+ let(:chef_fs_config) { Chef::ChefFS::Config.new(chef_config, Dir.pwd) }
+
+ subject(:local_fs) { chef_fs_config.local_fs }
+
+ def platform_path(*args)
+ File.expand_path(*args)
+ end
+
+ it "sets the correct nodes path on the local FS object" do
+ expect(local_fs.child_paths["nodes"]).to eq([platform_path("/base_path/nodes")])
+ end
+
+ it "sets the correct cookbook path on the local FS object" do
+ expect(local_fs.child_paths["cookbooks"]).to eq([platform_path("/base_path/cookbooks")])
+ end
+
+ it "sets the correct data bag path on the local FS object" do
+ expect(local_fs.child_paths["data_bags"]).to eq([platform_path("/base_path/data_bags")])
+ end
+
+ it "sets the correct environment path on the local FS object" do
+ expect(local_fs.child_paths["environments"]).to eq([platform_path("/base_path/environments")])
+ end
+
+ it "sets the correct role path on the local FS object" do
+ expect(local_fs.child_paths["roles"]).to eq([platform_path("/base_path/roles")])
+ end
+
+ it "sets the correct user path on the local FS object" do
+ expect(local_fs.child_paths["users"]).to eq([platform_path("/base_path/users")])
+ end
+
+ it "sets the correct policy path on the local FS object" do
+ expect(local_fs.child_paths["policies"]).to eq([platform_path("/base_path/policies")])
+ end
+ end
end