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.
- .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_join(*args) ⇒ Object
- .platform_path_separator ⇒ Object
- .platform_specific_path(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.
533 534 535 |
# File 'lib/chef/config.rb', line 533 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
185 186 187 188 189 190 191 |
# File 'lib/chef/config.rb', line 185 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.
522 523 524 525 526 527 528 529 530 |
# File 'lib/chef/config.rb', line 522 def self. Pathname.new(_this_file).ascend do |path| if path.basename.to_s == "embedded" return path.to_s end end nil end |
.find_chef_repo_path(cwd) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/chef/config.rb', line 169 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_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 |
Instance Method Details
#user ⇒ Object
Daemonization Settings ## What user should Chef run as?
285 |
# File 'lib/chef/config.rb', line 285 default :user, nil |