diff options
author | Noah Kantrowitz <noah@coderanger.net> | 2018-06-23 18:38:56 -0700 |
---|---|---|
committer | Noah Kantrowitz <noah@coderanger.net> | 2018-06-23 18:38:56 -0700 |
commit | cc7608f7a9eb1e7c4f4cd490c8762c8a391d7a6a (patch) | |
tree | 0bb3c2ef947b9d8186419ded159a77abde891511 | |
parent | dce10ada511109e9b62093dc5101e1303a40f660 (diff) | |
download | chef-cc7608f7a9eb1e7c4f4cd490c8762c8a391d7a6a.tar.gz |
Make the default validation client name more likely to be correct.
Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
-rw-r--r-- | chef-config/lib/chef-config/config.rb | 10 | ||||
-rw-r--r-- | chef-config/spec/unit/config_spec.rb | 18 |
2 files changed, 27 insertions, 1 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb index bd47ab509e..1f98936188 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -656,7 +656,15 @@ module ChefConfig # # If chef-zero is enabled, this defaults to nil (no authentication). default(:validation_key) { chef_zero.enabled ? nil : platform_specific_path("/etc/chef/validation.pem") } - default :validation_client_name, "chef-validator" + default :validation_client_name do + # If the URL is set and looks like a normal Chef Server URL, extract the + # org name and use that as part of the default. + if chef_server_url.to_s =~ %r{/organizations/(.*)$} + "#{$1}-validator" + else + "chef-validator" + end + end default :validation_key_contents, nil # When creating a new client via the validation_client account, Chef 11 diff --git a/chef-config/spec/unit/config_spec.rb b/chef-config/spec/unit/config_spec.rb index 71ea158840..7e32a1e742 100644 --- a/chef-config/spec/unit/config_spec.rb +++ b/chef-config/spec/unit/config_spec.rb @@ -1191,4 +1191,22 @@ RSpec.describe ChefConfig::Config do end + describe "validation_client_name" do + context "with a normal server URL" do + before { ChefConfig::Config[:chef_server_url] = "https://chef.example/organizations/myorg" } + + it "sets the validation client to myorg-validator" do + expect(ChefConfig::Config[:validation_client_name]).to eq "myorg-validator" + end + end + + context "with an unusual server URL" do + before { ChefConfig::Config[:chef_server_url] = "https://chef.example/myorg" } + + it "sets the validation client to chef-validator" do + expect(ChefConfig::Config[:validation_client_name]).to eq "chef-validator" + end + end + end + end |