Permalink
Browse files

CHEF-448: Chef Server URL metaconfiguration option

  Adds -S to chef-client for chef-server-url
  Adds chef_server_url configuration option for client.rb to set the
  values of registration_url, openid_url, template_url, remotefile_url,
  search_url and role_url
  • Loading branch information...
fujin committed Jul 29, 2009
1 parent 94b6530 commit ff40456f566669df619ab8af5c381a2aa44d1630
Showing with 63 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +8 −0 chef/lib/chef/application/client.rb
  3. +19 −0 chef/lib/chef/config.rb
  4. +35 −0 chef/spec/unit/config_spec.rb
View
@@ -1,3 +1,4 @@
+.autotest
coverage
doc
.DS_Store
@@ -95,6 +95,12 @@ class Chef::Application::Client < Chef::Application
:description => "The splay time for running at intervals, in seconds",
:proc => lambda { |s| s.to_i }
+ option :chef_server_url,
+ :short => "-S CHEFSERVERURL",
+ :long => "--server CHEFSERVERURL",
+ :description => "The chef server URL",
+ :proc => nil
+
option :validation_token,
:short => "-t TOKEN",
:long => "--token TOKEN",
@@ -112,6 +118,8 @@ def initialize
# Re-open the JSON attributes and load them into the node
def reconfigure
super
+
+ Chef::Config[:chef_server_url] = config[:chef_server_url] if config.has_key? :chef_server_url
if Chef::Config[:daemonize]
Chef::Config[:interval] ||= 1800
View
@@ -41,6 +41,24 @@ def self.manage_secret_key
newkey
end
+
+ # Override the config dispatch to set the value of multiple server options simultaneously
+ #
+ # === Parameters
+ # url<String>:: String to be set for all of the chef-server-api URL's
+ #
+ def self.chef_server_url=(url)
+ configure do |c|
+ [ :registration_url,
+ :openid_url,
+ :template_url,
+ :remotefile_url,
+ :search_url,
+ :role_url ].each do |u|
+ c[u] = url
+ end
+ end
+ end
# Override the config dispatch to set the value of log_location configuration option
#
# === Parameters
@@ -61,6 +79,7 @@ def self.openid_providers=(providers)
authorized_openid_identifiers nil
authorized_openid_providers nil
+ chef_server_url nil
cookbook_path [ "/var/chef/site-cookbooks", "/var/chef/cookbooks" ]
couchdb_database "chef"
couchdb_url "http://localhost:5984"
@@ -19,6 +19,36 @@
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
describe Chef::Config do
+ describe "class method: chef_server_url" do
+ before do
+ Chef::Config.chef_server_url = "https://junglist.gen.nz"
+ end
+
+ it "should set the registration url" do
+ Chef::Config.registration_url.should == "https://junglist.gen.nz"
+ end
+
+ it "should set the openid url" do
+ Chef::Config.openid_url.should == "https://junglist.gen.nz"
+ end
+
+ it "should set the template url" do
+ Chef::Config.template_url.should == "https://junglist.gen.nz"
+ end
+
+ it "should set the remotefile url" do
+ Chef::Config.remotefile_url.should == "https://junglist.gen.nz"
+ end
+
+ it "should set the search url" do
+ Chef::Config.search_url.should == "https://junglist.gen.nz"
+ end
+
+ it "should set the role url" do
+ Chef::Config.role_url.should == "https://junglist.gen.nz"
+ end
+ end
+
describe "class method: manage_secret_key" do
before do
Chef::FileCache.stub!(:has_key?).with("chef_server_cookie_id").and_return(false)
@@ -33,6 +63,11 @@
before do
Chef::FileCache.stub!(:has_key?).with("chef_server_cookie_id").and_return(true)
end
+
+ it "should not generate and store a chef server cookie id" do
+ Chef::FileCache.should_not_receive(:store).with("chef_server_cookie_id", /\w{40}/).and_return(true)
+ Chef::Config.manage_secret_key
+ end
end
end

0 comments on commit ff40456

Please sign in to comment.