diff options
author | sawanoboly <sawanoboriyu@higanworks.com> | 2014-09-12 13:01:48 +0900 |
---|---|---|
committer | sawanoboly <sawanoboriyu@higanworks.com> | 2014-09-12 13:01:48 +0900 |
commit | 1ab9ae58068da346bf2262cb0b8acc14a72d9f2b (patch) | |
tree | 4bb2f07e095d0653a0fe67374c843e130c704d1b /lib/chef/knife | |
parent | 5c94009b6053e7ae71d528485f3560e2bf8a7851 (diff) | |
parent | 34d956c6b96087e6ca4bfbc9080037ded481709d (diff) | |
download | chef-1ab9ae58068da346bf2262cb0b8acc14a72d9f2b.tar.gz |
Merge remote-tracking branch 'upstream/master' into prevew_archive_before_site_share
Diffstat (limited to 'lib/chef/knife')
-rw-r--r-- | lib/chef/knife/bootstrap.rb | 122 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/archlinux-gems.erb | 2 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/centos5-gems.erb | 62 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/chef-full.erb | 1 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/fedora13-gems.erb | 44 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/ubuntu10.04-apt.erb | 53 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/ubuntu10.04-gems.erb | 48 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/ubuntu12.04-gems.erb | 46 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_site_download.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_site_list.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_site_search.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_site_share.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_site_show.rb | 6 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_site_unshare.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/core/bootstrap_context.rb | 79 | ||||
-rw-r--r-- | lib/chef/knife/core/node_editor.rb | 5 | ||||
-rw-r--r-- | lib/chef/knife/core/ui.rb | 4 | ||||
-rw-r--r-- | lib/chef/knife/search.rb | 68 | ||||
-rw-r--r-- | lib/chef/knife/serve.rb | 2 |
19 files changed, 188 insertions, 364 deletions
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index d3d45bad4b..36a0fc1e47 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -94,11 +94,20 @@ class Chef :description => "Do not proxy locations for the node being bootstrapped; this option is used internally by Opscode", :proc => Proc.new { |np| Chef::Config[:knife][:bootstrap_no_proxy] = np } + # DEPR: Remove this option in Chef 13 option :distro, :short => "-d DISTRO", :long => "--distro DISTRO", - :description => "Bootstrap a distro using a template", - :default => "chef-full" + :description => "Bootstrap a distro using a template. [DEPRECATED] Use -t / --bootstrap-template option instead.", + :proc => Proc.new { |v| + Chef::Log.warn("[DEPRECATED] -d / --distro option is deprecated. Use -t / --bootstrap-template option instead.") + v + } + + option :bootstrap_template, + :short => "-t TEMPLATE", + :long => "--bootstrap-template TEMPLATE", + :description => "Bootstrap Chef using a built-in or custom template. Set to the full path of an erb template or use one of the built-in templates." option :use_sudo, :long => "--sudo", @@ -110,10 +119,14 @@ class Chef :description => "Execute the bootstrap via sudo with password", :boolean => false + # DEPR: Remove this option in Chef 13 option :template_file, :long => "--template-file TEMPLATE", - :description => "Full path to location of template to use", - :default => false + :description => "Full path to location of template to use. [DEPRECATED] Use -t / --bootstrap-template option instead.", + :proc => Proc.new { |v| + Chef::Log.warn("[DEPRECATED] --template-file option is deprecated. Use -t / --bootstrap-template option instead.") + v + } option :run_list, :short => "-r RUN_LIST", @@ -141,7 +154,8 @@ class Chef :proc => Proc.new { |h| Chef::Config[:knife][:hints] ||= Hash.new name, path = h.split("=") - Chef::Config[:knife][:hints][name] = path ? Chef::JSONCompat.parse(::File.read(path)) : Hash.new } + Chef::Config[:knife][:hints][name] = path ? Chef::JSONCompat.parse(::File.read(path)) : Hash.new + } option :secret, :short => "-s SECRET", @@ -174,53 +188,75 @@ class Chef :description => "Add options to curl when install chef-client", :proc => Proc.new { |co| Chef::Config[:knife][:bootstrap_curl_options] = co } - def find_template(template=nil) - # Are we bootstrapping using an already shipped template? - if config[:template_file] - bootstrap_files = config[:template_file] - else - bootstrap_files = [] - bootstrap_files << File.join(File.dirname(__FILE__), 'bootstrap', "#{config[:distro]}.erb") - bootstrap_files << File.join(Knife.chef_config_dir, "bootstrap", "#{config[:distro]}.erb") if Knife.chef_config_dir - bootstrap_files << File.join(ENV['HOME'], '.chef', 'bootstrap', "#{config[:distro]}.erb") if ENV['HOME'] - bootstrap_files << Gem.find_files(File.join("chef","knife","bootstrap","#{config[:distro]}.erb")) - bootstrap_files.flatten! + option :node_ssl_verify_mode, + :long => "--node-ssl-verify-mode [peer|none]", + :description => "Whether or not to verify the SSL cert for all HTTPS requests.", + :proc => Proc.new { |v| + valid_values = ["none", "peer"] + unless valid_values.include?(v) + raise "Invalid value '#{v}' for --node-ssl-verify-mode. Valid values are: #{valid_values.join(", ")}" + end + } + + option :node_verify_api_cert, + :long => "--[no-]node-verify-api-cert", + :description => "Verify the SSL cert for HTTPS requests to the Chef server API.", + :boolean => true + + def bootstrap_template + # For some reason knife.merge_configs doesn't pick up the default values from + # Chef::Config[:knife][:bootstrap_template] unless Chef::Config[:knife][:bootstrap_template] + # is forced to pick up the values before calling merge_configs. + # We therefore have Chef::Config[:knife][:bootstrap_template] to pick up the defaults + # if no option is specified. + config[:bootstrap_template] || config[:distro] || config[:template_file] || Chef::Config[:knife][:bootstrap_template] + end + + def find_template + template = bootstrap_template + + # Use the template directly if it's a path to an actual file + if File.exists?(template) + Chef::Log.debug("Using the specified bootstrap template: #{File.dirname(template)}") + return template + end - template = Array(bootstrap_files).find do |bootstrap_template| + # Otherwise search the template directories until we find the right one + bootstrap_files = [] + bootstrap_files << File.join(File.dirname(__FILE__), 'bootstrap', "#{template}.erb") + bootstrap_files << File.join(Knife.chef_config_dir, "bootstrap", "#{template}.erb") if Chef::Knife.chef_config_dir + bootstrap_files << File.join(ENV['HOME'], '.chef', 'bootstrap', "#{template}.erb") if ENV['HOME'] + bootstrap_files << Gem.find_files(File.join("chef","knife","bootstrap","#{template}.erb")) + bootstrap_files.flatten! + + template_file = Array(bootstrap_files).find do |bootstrap_template| Chef::Log.debug("Looking for bootstrap template in #{File.dirname(bootstrap_template)}") File.exists?(bootstrap_template) end - unless template - ui.info("Can not find bootstrap definition for #{config[:distro]}") + unless template_file + ui.info("Can not find bootstrap definition for #{template}") raise Errno::ENOENT end - Chef::Log.debug("Found bootstrap template in #{File.dirname(template)}") + Chef::Log.debug("Found bootstrap template in #{File.dirname(template_file)}") - template + template_file end - def render_template(template=nil) + def render_template + template_file = find_template + template = IO.read(template_file).chomp context = Knife::Core::BootstrapContext.new(config, config[:run_list], Chef::Config) Erubis::Eruby.new(template).evaluate(context) end - def read_template - IO.read(@template_file).chomp - end - def run validate_name_args! - warn_chef_config_secret_key - @template_file = find_template(config[:bootstrap_template]) @node_name = Array(@name_args).first - # back compat--templates may use this setting: - config[:server_name] = @node_name $stdout.sync = true - ui.info("Connecting to #{ui.color(@node_name, :bold)}") begin @@ -272,7 +308,7 @@ class Chef end def ssh_command - command = render_template(read_template) + command = render_template if config[:use_sudo] command = config[:use_sudo_password] ? "echo '#{config[:ssh_password]}' | sudo -S #{command}" : "sudo #{command}" @@ -281,28 +317,6 @@ class Chef command end - def warn_chef_config_secret_key - unless Chef::Config[:encrypted_data_bag_secret].nil? - ui.warn "* " * 40 - ui.warn(<<-WARNING) -Specifying the encrypted data bag secret key using an 'encrypted_data_bag_secret' -entry in 'knife.rb' is deprecated. Please see CHEF-4011 for more details. You -can supress this warning and still distribute the secret key to all bootstrapped -machines by adding the following to your 'knife.rb' file: - - knife[:secret_file] = "/path/to/your/secret" - -If you would like to selectively distribute a secret key during bootstrap -please use the '--secret' or '--secret-file' options of this command instead. - -#{ui.color('IMPORTANT:', :red, :bold)} In a future version of Chef, this -behavior will be removed and any 'encrypted_data_bag_secret' entries in -'knife.rb' will be ignored completely. -WARNING - ui.warn "* " * 40 - end - end - end end end diff --git a/lib/chef/knife/bootstrap/archlinux-gems.erb b/lib/chef/knife/bootstrap/archlinux-gems.erb index ab2aa7a7f1..bb84340c05 100644 --- a/lib/chef/knife/bootstrap/archlinux-gems.erb +++ b/lib/chef/knife/bootstrap/archlinux-gems.erb @@ -6,7 +6,7 @@ if [ ! -f /usr/bin/chef-client ]; then pacman -S --noconfirm ruby ntp base-devel ntpdate -u pool.ntp.org gem install ohai --no-user-install --no-document --verbose - gem install chef --no-user-install --no-document --verbose <%= bootstrap_version_string %> + gem install chef --no-user-install --no-document --verbose <%= Chef::VERSION %> fi mkdir -p /etc/chef diff --git a/lib/chef/knife/bootstrap/centos5-gems.erb b/lib/chef/knife/bootstrap/centos5-gems.erb deleted file mode 100644 index 6aacc47179..0000000000 --- a/lib/chef/knife/bootstrap/centos5-gems.erb +++ /dev/null @@ -1,62 +0,0 @@ -bash -c ' -<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%> - -if [ ! -f /usr/bin/chef-client ]; then - tmp_dir=$(mktemp -d) || exit 1 - pushd "$tmp_dir" - - yum install -y wget - - wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm - rpm -Uvh epel-release-5-4.noarch.rpm - wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>http://rpm.aegisco.com/aegisco/rhel/aegisco-rhel.rpm - rpm -Uvh aegisco-rhel.rpm - - yum install -y ruby ruby-devel gcc gcc-c++ automake autoconf make - - wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>http://production.cf.rubygems.org/rubygems/rubygems-1.6.2.tgz -O - | tar zxf - - (cd rubygems-1.6.2 && ruby setup.rb --no-format-executable) - - popd - rm -r "$tmp_dir" -fi - -gem update --system -gem update -gem install ohai --no-rdoc --no-ri --verbose -gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %> - -mkdir -p /etc/chef - -cat > /etc/chef/validation.pem <<'EOP' -<%= validation_key %> -EOP -chmod 0600 /etc/chef/validation.pem - -<% if encrypted_data_bag_secret -%> -cat > /etc/chef/encrypted_data_bag_secret <<'EOP' -<%= encrypted_data_bag_secret %> -EOP -chmod 0600 /etc/chef/encrypted_data_bag_secret -<% end -%> - -<%# Generate Ohai Hints -%> -<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%> -mkdir -p /etc/chef/ohai/hints - -<% @chef_config[:knife][:hints].each do |name, hash| -%> -cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' -<%= hash.to_json %> -EOP -<% end -%> -<% end -%> - -cat > /etc/chef/client.rb <<'EOP' -<%= config_content %> -EOP - -cat > /etc/chef/first-boot.json <<'EOP' -<%= first_boot.to_json %> -EOP - -<%= start_chef %>' diff --git a/lib/chef/knife/bootstrap/chef-full.erb b/lib/chef/knife/bootstrap/chef-full.erb index c953a7e433..a4e85b9d67 100644 --- a/lib/chef/knife/bootstrap/chef-full.erb +++ b/lib/chef/knife/bootstrap/chef-full.erb @@ -23,7 +23,6 @@ exists() { <%= knife_config[:bootstrap_install_command] %> <% else %> install_sh="<%= knife_config[:bootstrap_url] ? knife_config[:bootstrap_url] : "https://www.opscode.com/chef/install.sh" %>" - version_string="-v <%= chef_version %>" if ! exists /usr/bin/chef-client; then echo "Installing Chef Client..." if exists wget; then diff --git a/lib/chef/knife/bootstrap/fedora13-gems.erb b/lib/chef/knife/bootstrap/fedora13-gems.erb deleted file mode 100644 index 0aabc31085..0000000000 --- a/lib/chef/knife/bootstrap/fedora13-gems.erb +++ /dev/null @@ -1,44 +0,0 @@ -bash -c ' -<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%> - -yum install -y ruby ruby-devel gcc gcc-c++ automake autoconf rubygems make - -gem update --system -gem update -gem install ohai --no-rdoc --no-ri --verbose -gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %> - -mkdir -p /etc/chef - -cat > /etc/chef/validation.pem <<'EOP' -<%= validation_key %> -EOP -chmod 0600 /etc/chef/validation.pem - -<% if encrypted_data_bag_secret -%> -cat > /etc/chef/encrypted_data_bag_secret <<'EOP' -<%= encrypted_data_bag_secret %> -EOP -chmod 0600 /etc/chef/encrypted_data_bag_secret -<% end -%> - -<%# Generate Ohai Hints -%> -<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%> -mkdir -p /etc/chef/ohai/hints - -<% @chef_config[:knife][:hints].each do |name, hash| -%> -cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' -<%= hash.to_json %> -EOP -<% end -%> -<% end -%> - -cat > /etc/chef/client.rb <<'EOP' -<%= config_content %> -EOP - -cat > /etc/chef/first-boot.json <<'EOP' -<%= first_boot.to_json %> -EOP - -<%= start_chef %>' diff --git a/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb b/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb deleted file mode 100644 index 4549b94d2b..0000000000 --- a/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +++ /dev/null @@ -1,53 +0,0 @@ -bash -c ' -<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%> - -if [ ! -f /usr/bin/chef-client ]; then - apt-get install -y wget - echo "chef chef/chef_server_url string <%= @chef_config[:chef_server_url] %>" | debconf-set-selections - [ -f /etc/apt/sources.list.d/opscode.list ] || echo "deb http://apt.opscode.com <%= chef_version.to_f == 0.10 ? "lucid-0.10" : "lucid" %> main" > /etc/apt/sources.list.d/opscode.list - wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>-O- http://apt.opscode.com/packages@opscode.com.gpg.key | apt-key add - -fi -apt-get update -apt-get install -y chef - -cat > /etc/chef/validation.pem <<'EOP' -<%= validation_key %> -EOP -chmod 0600 /etc/chef/validation.pem - -<% if encrypted_data_bag_secret -%> -cat > /etc/chef/encrypted_data_bag_secret <<'EOP' -<%= encrypted_data_bag_secret %> -EOP -chmod 0600 /etc/chef/encrypted_data_bag_secret -<% end -%> - -<%# Generate Ohai Hints -%> -<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%> -mkdir -p /etc/chef/ohai/hints - -<% @chef_config[:knife][:hints].each do |name, hash| -%> -cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' -<%= hash.to_json %> -EOP -<% end -%> -<% end -%> - -<% unless @chef_config[:validation_client_name] == "chef-validator" -%> -[ `grep -qx "validation_client_name \"<%= @chef_config[:validation_client_name] %>\"" /etc/chef/client.rb` ] || echo "validation_client_name \"<%= @chef_config[:validation_client_name] %>\"" >> /etc/chef/client.rb -<% end -%> - -<% if @config[:chef_node_name] %> -[ `grep -qx "node_name \"<%= @config[:chef_node_name] %>\"" /etc/chef/client.rb` ] || echo "node_name \"<%= @config[:chef_node_name] %>\"" >> /etc/chef/client.rb -<% end -%> - -<% if knife_config[:bootstrap_proxy] %> -echo 'http_proxy "knife_config[:bootstrap_proxy]"' >> /etc/chef/client.rb -echo 'https_proxy "knife_config[:bootstrap_proxy]"' >> /etc/chef/client.rb -<% end -%> - -cat > /etc/chef/first-boot.json <<'EOP' -<%= first_boot.to_json %> -EOP - -<%= start_chef %>' diff --git a/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb b/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb deleted file mode 100644 index 62ff7c857e..0000000000 --- a/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +++ /dev/null @@ -1,48 +0,0 @@ -bash -c ' -<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%> - -if [ ! -f /usr/bin/chef-client ]; then - apt-get update - apt-get install -y ruby ruby1.8-dev build-essential wget libruby-extras libruby1.8-extras - wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>http://production.cf.rubygems.org/rubygems/rubygems-1.6.2.tgz -O - | tar zxf - - (cd rubygems-1.6.2 && ruby setup.rb --no-format-executable) -fi - -gem update --no-rdoc --no-ri -gem install ohai --no-rdoc --no-ri --verbose -gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %> - -mkdir -p /etc/chef - -cat > /etc/chef/validation.pem <<'EOP' -<%= validation_key %> -EOP -chmod 0600 /etc/chef/validation.pem - -<% if encrypted_data_bag_secret -%> -cat > /etc/chef/encrypted_data_bag_secret <<'EOP' -<%= encrypted_data_bag_secret %> -EOP -chmod 0600 /etc/chef/encrypted_data_bag_secret -<% end -%> - -<%# Generate Ohai Hints -%> -<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%> -mkdir -p /etc/chef/ohai/hints - -<% @chef_config[:knife][:hints].each do |name, hash| -%> -cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' -<%= hash.to_json %> -EOP -<% end -%> -<% end -%> - -cat > /etc/chef/client.rb <<'EOP' -<%= config_content %> -EOP - -cat > /etc/chef/first-boot.json <<'EOP' -<%= first_boot.to_json %> -EOP - -<%= start_chef %>' diff --git a/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb b/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb deleted file mode 100644 index 8e9c6583d0..0000000000 --- a/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +++ /dev/null @@ -1,46 +0,0 @@ -bash -c ' -<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%> - -if [ ! -f /usr/bin/chef-client ]; then - aptitude update - aptitude install -y ruby ruby1.8-dev build-essential wget libruby1.8 rubygems -fi - -gem update --no-rdoc --no-ri -gem install ohai --no-rdoc --no-ri --verbose -gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %> - -mkdir -p /etc/chef - -cat > /etc/chef/validation.pem <<'EOP' -<%= validation_key %> -EOP -chmod 0600 /etc/chef/validation.pem - -<% if encrypted_data_bag_secret -%> -cat > /etc/chef/encrypted_data_bag_secret <<'EOP' -<%= encrypted_data_bag_secret %> -EOP -chmod 0600 /etc/chef/encrypted_data_bag_secret -<% end -%> - -<%# Generate Ohai Hints -%> -<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%> -mkdir -p /etc/chef/ohai/hints - -<% @chef_config[:knife][:hints].each do |name, hash| -%> -cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' -<%= hash.to_json %> -EOP -<% end -%> -<% end -%> - -cat > /etc/chef/client.rb <<'EOP' -<%= config_content %> -EOP - -cat > /etc/chef/first-boot.json <<'EOP' -<%= first_boot.to_json %> -EOP - -<%= start_chef %>' diff --git a/lib/chef/knife/cookbook_site_download.rb b/lib/chef/knife/cookbook_site_download.rb index 645b1728e6..de6e21d0d2 100644 --- a/lib/chef/knife/cookbook_site_download.rb +++ b/lib/chef/knife/cookbook_site_download.rb @@ -58,7 +58,7 @@ class Chef private def cookbooks_api_url - 'http://cookbooks.opscode.com/api/v1/cookbooks' + 'https://supermarket.getchef.com/api/v1/cookbooks' end def current_cookbook_data diff --git a/lib/chef/knife/cookbook_site_list.rb b/lib/chef/knife/cookbook_site_list.rb index fe83b71388..6fcf7e6064 100644 --- a/lib/chef/knife/cookbook_site_list.rb +++ b/lib/chef/knife/cookbook_site_list.rb @@ -41,7 +41,7 @@ class Chef end def get_cookbook_list(items=10, start=0, cookbook_collection={}) - cookbooks_url = "http://cookbooks.opscode.com/api/v1/cookbooks?items=#{items}&start=#{start}" + cookbooks_url = "https://supermarket.getchef.com/api/v1/cookbooks?items=#{items}&start=#{start}" cr = noauth_rest.get_rest(cookbooks_url) cr["items"].each do |cookbook| cookbook_collection[cookbook["cookbook_name"]] = cookbook diff --git a/lib/chef/knife/cookbook_site_search.rb b/lib/chef/knife/cookbook_site_search.rb index b636276cba..ec4d196ee3 100644 --- a/lib/chef/knife/cookbook_site_search.rb +++ b/lib/chef/knife/cookbook_site_search.rb @@ -29,7 +29,7 @@ class Chef end def search_cookbook(query, items=10, start=0, cookbook_collection={}) - cookbooks_url = "http://cookbooks.opscode.com/api/v1/search?q=#{query}&items=#{items}&start=#{start}" + cookbooks_url = "https://supermarket.getchef.com/api/v1/search?q=#{query}&items=#{items}&start=#{start}" cr = noauth_rest.get_rest(cookbooks_url) cr["items"].each do |cookbook| cookbook_collection[cookbook["cookbook_name"]] = cookbook diff --git a/lib/chef/knife/cookbook_site_share.rb b/lib/chef/knife/cookbook_site_share.rb index 71bbb00abc..e5c56f654d 100644 --- a/lib/chef/knife/cookbook_site_share.rb +++ b/lib/chef/knife/cookbook_site_share.rb @@ -99,7 +99,7 @@ class Chef end def do_upload(cookbook_filename, cookbook_category, user_id, user_secret_filename) - uri = "http://cookbooks.opscode.com/api/v1/cookbooks" + uri = "https://supermarket.getchef.com/api/v1/cookbooks" category_string = Chef::JSONCompat.to_json({ 'category'=>cookbook_category }) diff --git a/lib/chef/knife/cookbook_site_show.rb b/lib/chef/knife/cookbook_site_show.rb index d15098e915..c520c00621 100644 --- a/lib/chef/knife/cookbook_site_show.rb +++ b/lib/chef/knife/cookbook_site_show.rb @@ -31,14 +31,14 @@ class Chef def get_cookbook_data case @name_args.length when 1 - noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{@name_args[0]}") + noauth_rest.get_rest("https://supermarket.getchef.com/api/v1/cookbooks/#{@name_args[0]}") when 2 - noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{@name_args[0]}/versions/#{name_args[1].gsub('.', '_')}") + noauth_rest.get_rest("https://supermarket.getchef.com/api/v1/cookbooks/#{@name_args[0]}/versions/#{name_args[1].gsub('.', '_')}") end end def get_cookbook_list(items=10, start=0, cookbook_collection={}) - cookbooks_url = "http://cookbooks.opscode.com/api/v1/cookbooks?items=#{items}&start=#{start}" + cookbooks_url = "https://supermarket.getchef.com/api/v1/cookbooks?items=#{items}&start=#{start}" cr = noauth_rest.get_rest(cookbooks_url) cr["items"].each do |cookbook| cookbook_collection[cookbook["cookbook_name"]] = cookbook diff --git a/lib/chef/knife/cookbook_site_unshare.rb b/lib/chef/knife/cookbook_site_unshare.rb index a2828549a0..f095885f15 100644 --- a/lib/chef/knife/cookbook_site_unshare.rb +++ b/lib/chef/knife/cookbook_site_unshare.rb @@ -41,7 +41,7 @@ class Chef confirm "Do you really want to unshare the cookbook #{@cookbook_name}" begin - rest.delete_rest "http://cookbooks.opscode.com/api/v1/cookbooks/#{@name_args[0]}" + rest.delete_rest "https://supermarket.getchef.com/api/v1/cookbooks/#{@name_args[0]}" rescue Net::HTTPServerException => e raise e unless e.message =~ /Forbidden/ ui.error "Forbidden: You must be the maintainer of #{@cookbook_name} to unshare it." diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb index 742ef226a3..9fa6dcc46f 100644 --- a/lib/chef/knife/core/bootstrap_context.rb +++ b/lib/chef/knife/core/bootstrap_context.rb @@ -34,14 +34,6 @@ class Chef @chef_config = chef_config end - def bootstrap_version_string - if @config[:prerelease] - "--prerelease" - else - "--version #{chef_version}" - end - end - def bootstrap_environment @chef_config[:environment] || '_default' end @@ -52,10 +44,12 @@ class Chef def encrypted_data_bag_secret knife_config[:secret] || begin - if knife_config[:secret_file] && File.exist?(knife_config[:secret_file]) - IO.read(File.expand_path(knife_config[:secret_file])) - elsif @chef_config[:encrypted_data_bag_secret] && File.exist?(@chef_config[:encrypted_data_bag_secret]) - IO.read(File.expand_path(@chef_config[:encrypted_data_bag_secret])) + secret_file_path = knife_config[:secret_file] + expanded_secret_file_path = File.expand_path(secret_file_path.to_s) + if secret_file_path && File.exist?(expanded_secret_file_path) + IO.read(expanded_secret_file_path) + else + nil end end end @@ -72,6 +66,36 @@ CONFIG client_rb << "# Using default node name (fqdn)\n" end + # We configure :verify_api_cert only when it's overridden on the CLI + # or when specified in the knife config. + if !@config[:node_verify_api_cert].nil? || knife_config.has_key?(:verify_api_cert) + value = @config[:node_verify_api_cert].nil? ? knife_config[:verify_api_cert] : @config[:node_verify_api_cert] + client_rb << %Q{verify_api_cert #{value}\n} + end + + # We configure :ssl_verify_mode only when it's overridden on the CLI + # or when specified in the knife config. + if @config[:node_ssl_verify_mode] || knife_config.has_key?(:ssl_verify_mode) + value = case @config[:node_ssl_verify_mode] + when "peer" + :verify_peer + when "none" + :verify_none + when nil + knife_config[:ssl_verify_mode] + else + nil + end + + if value + client_rb << %Q{ssl_verify_mode :#{value}\n} + end + end + + if @config[:ssl_verify_mode] + client_rb << %Q{ssl_verify_mode :#{knife_config[:ssl_verify_mode]}\n} + end + if knife_config[:bootstrap_proxy] client_rb << %Q{http_proxy "#{knife_config[:bootstrap_proxy]}"\n} client_rb << %Q{https_proxy "#{knife_config[:bootstrap_proxy]}"\n} @@ -93,7 +117,7 @@ CONFIG client_path = @chef_config[:chef_client_path] || 'chef-client' s = "#{client_path} -j /etc/chef/first-boot.json" s << ' -l debug' if @config[:verbosity] and @config[:verbosity] >= 2 - s << " -E #{bootstrap_environment}" if chef_version.to_f != 0.9 # only use the -E option on Chef 0.10+ + s << " -E #{bootstrap_environment}" s end @@ -102,29 +126,26 @@ CONFIG end # - # This function is used by older bootstrap templates other than chef-full - # and potentially by custom templates as well hence it's logic needs to be - # preserved for backwards compatibility reasons until we hit Chef 12. - def chef_version - knife_config[:bootstrap_version] || Chef::VERSION - end - - # # chef version string to fetch the latest current version from omnitruck # If user is on X.Y.Z bootstrap will use the latest X release # X here can be 10 or 11 def latest_current_chef_version_string - chef_version_string = if knife_config[:bootstrap_version] - knife_config[:bootstrap_version] + installer_version_string = nil + if @config[:prerelease] + installer_version_string = "-p" else - Chef::VERSION.split(".").first - end + chef_version_string = if knife_config[:bootstrap_version] + knife_config[:bootstrap_version] + else + Chef::VERSION.split(".").first + end - installer_version_string = ["-v", chef_version_string] + installer_version_string = ["-v", chef_version_string] - # If bootstrapping a pre-release version add -p to the installer string - if chef_version_string.split(".").length > 3 - installer_version_string << "-p" + # If bootstrapping a pre-release version add -p to the installer string + if chef_version_string.split(".").length > 3 + installer_version_string << "-p" + end end installer_version_string.join(" ") diff --git a/lib/chef/knife/core/node_editor.rb b/lib/chef/knife/core/node_editor.rb index 073492197c..fe14e18d9d 100644 --- a/lib/chef/knife/core/node_editor.rb +++ b/lib/chef/knife/core/node_editor.rb @@ -42,8 +42,8 @@ class Chef end def updated? - pristine_copy = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(node), :create_additions => false) - updated_copy = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(@updated_node), :create_additions => false) + pristine_copy = Chef::JSONCompat.parse(Chef::JSONCompat.to_json(node)) + updated_copy = Chef::JSONCompat.parse(Chef::JSONCompat.to_json(@updated_node)) unless pristine_copy == updated_copy updated_properties = %w{name normal chef_environment run_list default override automatic}.reject do |key| pristine_copy[key] == updated_copy[key] @@ -107,4 +107,3 @@ class Chef end end end - diff --git a/lib/chef/knife/core/ui.rb b/lib/chef/knife/core/ui.rb index c4d7d73b00..0007480ea2 100644 --- a/lib/chef/knife/core/ui.rb +++ b/lib/chef/knife/core/ui.rb @@ -195,8 +195,8 @@ class Chef # We wouldn't have to do these shenanigans if all the editable objects # implemented to_hash, or if to_json against a hash returned a string # with stable key order. - object_parsed_again = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(object), :create_additions => false) - output_parsed_again = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(output), :create_additions => false) + object_parsed_again = Chef::JSONCompat.parse(Chef::JSONCompat.to_json(object)) + output_parsed_again = Chef::JSONCompat.parse(Chef::JSONCompat.to_json(output)) if object_parsed_again != output_parsed_again output.save self.msg("Saved #{output}") diff --git a/lib/chef/knife/search.rb b/lib/chef/knife/search.rb index bc020c0445..34d12168b6 100644 --- a/lib/chef/knife/search.rb +++ b/lib/chef/knife/search.rb @@ -71,6 +71,11 @@ class Chef :long => "--query QUERY", :description => "The search query; useful to protect queries starting with -" + option :filter_result, + :short => "-f FILTER", + :long => "--filter-result FILTER", + :description => "Only bring back specific attributes of the matching objects; for example: \"ServerName=name, Kernel=kernel.version\"" + def run read_cli_args fuzzify_query @@ -79,7 +84,6 @@ class Chef ui.use_presenter Knife::Core::NodePresenter end - q = Chef::Search::Query.new escaped_query = URI.escape(@query, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) @@ -87,14 +91,26 @@ class Chef result_items = [] result_count = 0 - rows = config[:rows] - start = config[:start] + search_args = Hash.new + search_args[:sort] = config[:sort] + search_args[:start] = config[:start] + search_args[:rows] = config[:rows] + if config[:filter_result] + search_args[:filter_result] = create_result_filter(config[:filter_result]) + elsif (not ui.config[:attribute].nil?) && (not ui.config[:attribute].empty?) + search_args[:filter_result] = create_result_filter_from_attributes(ui.config[:attribute]) + end + begin - q.search(@type, escaped_query, config[:sort], start, rows) do |item| - formatted_item = format_for_display(item) - # if formatted_item.respond_to?(:has_key?) && !formatted_item.has_key?('id') - # formatted_item['id'] = item.has_key?('id') ? item['id'] : item.name - # end + q.search(@type, escaped_query, search_args) do |item| + formatted_item = Hash.new + if item.is_a?(Hash) + # doing a little magic here to set the correct name + formatted_item[item["data"]["__display_name"]] = item["data"] + formatted_item[item["data"]["__display_name"]].delete("__display_name") + else + formatted_item = format_for_display(item) + end result_items << formatted_item result_count += 1 end @@ -149,10 +165,38 @@ class Chef end end + # This method turns a set of key value pairs in a string into the appropriate data structure that the + # chef-server search api is expecting. + # expected input is in the form of: + # -f "return_var1=path.to.attribute, return_var2=shorter.path" + # + # a more concrete example might be: + # -f "env=chef_environment, ruby_platform=languages.ruby.platform" + # + # The end result is a hash where the key is a symbol in the hash (the return variable) + # and the path is an array with the path elements as strings (in order) + # See lib/chef/search/query.rb for more examples of this. + def create_result_filter(filter_string) + final_filter = Hash.new + filter_string.gsub!(" ", "") + filters = filter_string.split(",") + filters.each do |f| + return_id, attr_path = f.split("=") + final_filter[return_id.to_sym] = attr_path.split(".") + end + return final_filter + end + + def create_result_filter_from_attributes(filter_array) + final_filter = Hash.new + filter_array.each do |f| + final_filter[f] = f.split(".") + end + # adding magic filter so we can actually pull the name as before + final_filter["__display_name"] = [ "name" ] + return final_filter + end + end end end - - - - diff --git a/lib/chef/knife/serve.rb b/lib/chef/knife/serve.rb index 15994590cd..870177e0be 100644 --- a/lib/chef/knife/serve.rb +++ b/lib/chef/knife/serve.rb @@ -33,7 +33,7 @@ class Chef def run server = Chef::LocalMode.chef_zero_server begin - output "Serving files from:\n#{server.options[:data_store].chef_fs.fs_description}" + output "Serving files from:\n#{Chef::LocalMode.chef_fs.fs_description}" server.stop server.start(stdout) # to print header ensure |