class Chef::Config
Constants
- BACKSLASH
Public Class Methods
_this_file()
click to toggle source
Path to this file in the current install.
# File lib/chef/config.rb, line 606 def self._this_file File.expand_path(__FILE__) end
add_formatter(name, file_path=nil)
click to toggle source
# File lib/chef/config.rb, line 96 def self.add_formatter(name, file_path=nil) formatters << [name, file_path] end
derive_path_from_chef_repo_path(child_path)
click to toggle source
# File lib/chef/config.rb, line 165 def self.derive_path_from_chef_repo_path(child_path) if chef_repo_path.kind_of?(String) path_join(chef_repo_path, child_path) else chef_repo_path.map { |path| path_join(path, child_path)} end end
embedded_dir()
click to toggle source
If installed via an omnibus installer, this gives the path to the “embedded” directory which contains all of the software packaged with omnibus. This is used to locate the cacert.pem file on windows.
# File lib/chef/config.rb, line 595 def self.embedded_dir Pathname.new(_this_file).ascend do |path| if path.basename.to_s == "embedded" return path.to_s end end nil end
env()
click to toggle source
This provides a hook which rspec can stub so that we can avoid twiddling global state in tests.
# File lib/chef/config.rb, line 547 def self.env ENV end
find_chef_repo_path(cwd)
click to toggle source
# File lib/chef/config.rb, line 149 def self.find_chef_repo_path(cwd) # In local mode, we auto-discover the repo root by looking for a path with "cookbooks" under it. # This allows us to run config-free. path = cwd until File.directory?(path_join(path, "cookbooks")) new_path = File.expand_path('..', path) if new_path == path Chef::Log.warn("No cookbooks directory found at or above current directory. Assuming #{Dir.pwd}.") return Dir.pwd end path = new_path end Chef::Log.info("Auto-discovered chef repository at #{path}") path end
from_string(string, filename)
click to toggle source
Evaluates the given string as config.
filename
is used for context in stacktraces, but doesn't
need to be the name of an actual file.
# File lib/chef/config.rb, line 36 def self.from_string(string, filename) self.instance_eval(string, filename, 1) end
inspect()
click to toggle source
# File lib/chef/config.rb, line 57 def self.inspect configuration.inspect end
manage_secret_key()
click to toggle source
Manages the chef secret session key
Returns¶ ↑
- <newkey>
-
A new or retrieved session key
# File lib/chef/config.rb, line 44 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
on_windows?()
click to toggle source
# File lib/chef/config.rb, line 61 def self.on_windows? RUBY_PLATFORM =~ /mswin|mingw|windows/ end
path_accessible?(path)
click to toggle source
Returns true only if the path exists and is readable and writeable for the user.
# File lib/chef/config.rb, line 261 def self.path_accessible?(path) File.exists?(path) && File.readable?(path) && File.writable?(path) end
path_join(*args)
click to toggle source
# File lib/chef/config.rb, line 75 def self.path_join(*args) args = args.flatten args.inject do |joined_path, component| unless joined_path[-1,1] == platform_path_separator joined_path += platform_path_separator end joined_path += component end end
platform_path_separator()
click to toggle source
# File lib/chef/config.rb, line 67 def self.platform_path_separator if on_windows? File::ALT_SEPARATOR || BACKSLASH else File::SEPARATOR end end
platform_specific_path(path)
click to toggle source
# File lib/chef/config.rb, line 85 def self.platform_specific_path(path) if on_windows? # turns /etc/chef/client.rb into C:/chef/client.rb system_drive = env['SYSTEMDRIVE'] ? env['SYSTEMDRIVE'] : "" path = File.join(system_drive, path.split('/')[2..-1]) # ensure all forward slashes are backslashes path.gsub!(File::SEPARATOR, (File::ALT_SEPARATOR || '\')) end path end
set_defaults_for_nix()
click to toggle source
# File lib/chef/config.rb, line 525 def self.set_defaults_for_nix # Those lists of regular expressions define what chef considers a # valid user and group name # # user/group cannot start with '-', '+' or '~' # user/group cannot contain ':', ',' or non-space-whitespace or null byte # everything else is allowed (UTF-8, spaces, etc) and we delegate to your O/S useradd program to barf or not # copies: http://anonscm.debian.org/viewvc/pkg-shadow/debian/trunk/debian/patches/506_relaxed_usernames?view=markup default :user_valid_regex, [ /^[^-+~:,\t\r\n\f\0]+[^:,\t\r\n\f\0]*$/ ] default :group_valid_regex, [ /^[^-+~:,\t\r\n\f\0]+[^:,\t\r\n\f\0]*$/ ] end
set_defaults_for_windows()
click to toggle source
# File lib/chef/config.rb, line 514 def self.set_defaults_for_windows # Those lists of regular expressions define what chef considers a # valid user and group name # From http://technet.microsoft.com/en-us/library/cc776019(WS.10).aspx principal_valid_regex_part = '[^"\/\\\[\]\:;|=,+*?<>]+' default :user_valid_regex, [ /^(#{principal_valid_regex_part}\)?#{principal_valid_regex_part}$/ ] default :group_valid_regex, [ /^(#{principal_valid_regex_part}\)?#{principal_valid_regex_part}$/ ] default :fatal_windows_admin_check, false end
windows_home_path()
click to toggle source
# File lib/chef/config.rb, line 551 def self.windows_home_path windows_home_path = env['SYSTEMDRIVE'] + env['HOMEPATH'] if env['SYSTEMDRIVE'] && env['HOMEPATH'] end