# 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 543
    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 532
    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

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_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