# # Author:: Adam Jacob () # Author:: Christopher Brown () # Author:: AJ Christensen () # Copyright:: Copyright (c) 2008 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'chef/log' require 'mixlib/config' class Chef class Config extend Mixlib::Config # Manages the chef secret session key # === Returns # :: A new or retrieved session key # def self.manage_secret_key newkey = nil if Chef::FileCache.has_key?("chef_server_cookie_id") newkey = Chef::FileCache.load("chef_server_cookie_id") else chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a newkey = "" 40.times { |i| newkey << chars[rand(chars.size-1)] } Chef::FileCache.store("chef_server_cookie_id", newkey) end newkey end def self.inspect configuration.inspect end # Override the config dispatch to set the value of multiple server options simultaneously # # === Parameters # url:: String to be set for all of the chef-server-api URL's # config_attr_writer :chef_server_url do |url| configure do |c| [ :registration_url, :template_url, :remotefile_url, :search_url, :chef_server_url, :role_url ].each do |u| c[u] = url end end url end # Override the config dispatch to set the value of log_location configuration option # # === Parameters # location:: Logging location as either an IO stream or string representing log file path # config_attr_writer :log_location do |location| if location.respond_to? :sync= location.sync = true location elsif location.respond_to? :to_str f = File.new(location.to_str, "a") f.sync = true f end end # Turn on "path sanity" by default. See also: http://wiki.opscode.com/display/chef/User+Environment+PATH+Sanity enforce_path_sanity(true) # The number of times the client should retry when registering with the server client_registration_retries 5 # Where the cookbooks are located. Meaning is somewhat context dependent between # chef-client, and chef-solo. cookbook_path [ "/var/chef/cookbooks", "/var/chef/site-cookbooks" ] # Where cookbook files are stored on the server (by content checksum) checksum_path "/var/chef/checksums" # Where chef's cache files should be stored file_cache_path "/var/chef/cache" # Where backups of chef-managed files should go file_backup_path "/var/chef/backup" http_retry_count 5 http_retry_delay 5 interval nil log_level :info log_location STDOUT verbose_logging nil node_name nil node_path "/var/chef/node" pid_file nil rest_timeout 300 run_command_stderr_timeout 120 run_command_stdout_timeout 120 solo false splay nil # Set these to enable SSL authentication / mutual-authentication # with the server ssl_client_cert nil ssl_client_key nil ssl_verify_mode :verify_none ssl_ca_path nil ssl_ca_file nil # Where should chef-solo look for role files? role_path "/var/chef/roles" # Report Handlers report_handlers [] # Exception Handlers exception_handlers [] # Checksum Cache # Uses Moneta on the back-end cache_type "BasicFile" cache_options({ :path => "/var/chef/cache/checksums", :skip_expires => true }) # Those lists of regular expressions define what chef considers a # valid user and group name user_valid_regex [ /^([-a-zA-Z0-9_.]+)$/, /^\d+$/ ] group_valid_regex [ /^([-a-zA-Z0-9_.\\ ]+)$/, /^\d+$/ ] end end