Class: Chef::Config
- Extended by:
- Mixlib::Config
- Defined in:
- lib/chef/config.rb
Constant Summary collapse
- BACKSLASH =
'\\'.freeze
Class Method Summary collapse
-
._this_file ⇒ Object
Path to this file in the current install.
- .add_formatter(name, file_path = nil) ⇒ Object
- .derive_path_from_chef_repo_path(child_path) ⇒ Object
-
.embedded_dir ⇒ Object
If installed via an omnibus installer, this gives the path to the “embedded” directory which contains all of the software packaged with omnibus.
-
.env ⇒ Object
This provides a hook which rspec can stub so that we can avoid twiddling global state in tests.
- .find_chef_repo_path(cwd) ⇒ Object
-
.from_string(string, filename) ⇒ Object
Evaluates the given string as config.
- .inspect ⇒ Object
-
.manage_secret_key ⇒ Object
- Manages the chef secret session key === Returns <newkey>
-
A new or retrieved session key.
- .on_windows? ⇒ Boolean
-
.path_accessible?(path) ⇒ Boolean
Returns true only if the path exists and is readable and writeable for the user.
- .path_join(*args) ⇒ Object
- .platform_path_separator ⇒ Object
- .platform_specific_path(path) ⇒ Object
- .set_defaults_for_nix ⇒ Object
- .set_defaults_for_windows ⇒ Object
- .windows_home_path ⇒ Object
Instance Method Summary collapse
-
#user ⇒ Object
Daemonization Settings ## What user should Chef run as?.
Class Method Details
._this_file ⇒ Object
Path to this file in the current install.
606 607 608 |
# File 'lib/chef/config.rb', line 606 def self._this_file File.(__FILE__) end |
.add_formatter(name, file_path = nil) ⇒ Object
96 97 98 |
# 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) ⇒ Object
165 166 167 168 169 170 171 |
# 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 ⇒ Object
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.
595 596 597 598 599 600 601 602 603 |
# File 'lib/chef/config.rb', line 595 def self. Pathname.new(_this_file).ascend do |path| if path.basename.to_s == "embedded" return path.to_s end end nil end |
.env ⇒ Object
This provides a hook which rspec can stub so that we can avoid twiddling global state in tests.
547 548 549 |
# File 'lib/chef/config.rb', line 547 def self.env ENV end |
.find_chef_repo_path(cwd) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# 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.('..', 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) ⇒ Object
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.
36 37 38 |
# File 'lib/chef/config.rb', line 36 def self.from_string(string, filename) self.instance_eval(string, filename, 1) end |
.inspect ⇒ Object
57 58 59 |
# File 'lib/chef/config.rb', line 57 def self.inspect configuration.inspect end |
.manage_secret_key ⇒ Object
Manages the chef secret session key
Returns
- <newkey>
-
A new or retrieved session key
44 45 46 47 48 49 50 51 52 53 54 55 |
# 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? ⇒ Boolean
61 62 63 |
# File 'lib/chef/config.rb', line 61 def self.on_windows? RUBY_PLATFORM =~ /mswin|mingw|windows/ end |
.path_accessible?(path) ⇒ Boolean
Returns true only if the path exists and is readable and writeable for the user.
261 262 263 |
# 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) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# 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 ⇒ Object
67 68 69 70 71 72 73 |
# 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) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# 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 ⇒ Object
525 526 527 528 529 530 531 532 533 534 535 |
# 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 ⇒ Object
514 515 516 517 518 519 520 521 522 523 |
# 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 ⇒ Object
551 552 553 |
# 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 |
Instance Method Details
#user ⇒ Object
Daemonization Settings ## What user should Chef run as?
283 |
# File 'lib/chef/config.rb', line 283 default :user, nil |