Class: ChefConfig::Config
- Inherits:
-
Object
- Object
- ChefConfig::Config
- Extended by:
- Mixlib::Config
- Defined in:
- lib/chef-config/config.rb
Class Method Summary collapse
-
._this_file ⇒ Object
Path to this file in the current install.
- .add_event_logger(logger) ⇒ Object
- .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.
-
.guess_internal_locale ⇒ Object
Chef requires an English-language UTF-8 locale to function properly.
- .inspect ⇒ Object
-
.path_accessible?(path) ⇒ Boolean
Returns true only if the path exists and is readable and writeable for the user.
- .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
permalink ._this_file ⇒ Object
Path to this file in the current install.
737 738 739 |
# File 'lib/chef-config/config.rb', line 737 def self._this_file File.(__FILE__) end |
permalink .add_event_logger(logger) ⇒ Object
[View source]
62 63 64 |
# File 'lib/chef-config/config.rb', line 62 def self.add_event_logger(logger) event_handlers << logger end |
permalink .add_formatter(name, file_path = nil) ⇒ Object
[View source]
58 59 60 |
# File 'lib/chef-config/config.rb', line 58 def self.add_formatter(name, file_path=nil) formatters << [name, file_path] end |
permalink .derive_path_from_chef_repo_path(child_path) ⇒ Object
[View source]
127 128 129 130 131 132 133 |
# File 'lib/chef-config/config.rb', line 127 def self.derive_path_from_chef_repo_path(child_path) if chef_repo_path.kind_of?(String) PathHelper.join(chef_repo_path, child_path) else chef_repo_path.map { |path| PathHelper.join(path, child_path)} end end |
permalink .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.
726 727 728 729 730 731 732 733 734 |
# File 'lib/chef-config/config.rb', line 726 def self. Pathname.new(_this_file).ascend do |path| if path.basename.to_s == "embedded" return path.to_s end end nil end |
permalink .env ⇒ Object
This provides a hook which rspec can stub so that we can avoid twiddling global state in tests.
575 576 577 |
# File 'lib/chef-config/config.rb', line 575 def self.env ENV end |
permalink .find_chef_repo_path(cwd) ⇒ Object
[View source]
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/chef-config/config.rb', line 111 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?(PathHelper.join(path, "cookbooks")) new_path = File.('..', path) if new_path == path ChefConfig.logger.warn("No cookbooks directory found at or above current directory. Assuming #{Dir.pwd}.") return Dir.pwd end path = new_path end ChefConfig.logger.info("Auto-discovered chef repository at #{path}") path end |
permalink .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.
39 40 41 |
# File 'lib/chef-config/config.rb', line 39 def self.from_string(string, filename) self.instance_eval(string, filename, 1) end |
permalink .guess_internal_locale ⇒ Object
Chef requires an English-language UTF-8 locale to function properly. We attempt to use the ‘locale -a’ command and search through a list of preferences until we find one that we can use. On Ubuntu systems we should find ‘C.UTF-8’ and be able to use that even if there is no English locale on the server, but Mac, Solaris, AIX, etc do not have that locale. We then try to find an English locale and fall back to ‘C’ if we do not. The choice of fallback is pick-your-poison. If we try to do the work to return a non-US UTF-8 locale then we fail inside of providers when things like ‘svn info’ return Japanese and we can’t parse them. OTOH, if we pick ‘C’ then we will blow up on UTF-8 characters. Between the warn we throw and the Encoding exception that ruby will throw it is more obvious what is broken if we drop UTF-8 by default rather than drop English.
If there is no ‘locale -a’ then we return ‘en_US.UTF-8’ since that is the most commonly available English UTF-8 locale. However, all modern POSIXen should support ‘locale -a’.
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 |
# File 'lib/chef-config/config.rb', line 674 def self.guess_internal_locale # https://github.com/opscode/chef/issues/2181 # Some systems have the `locale -a` command, but the result has # invalid characters for the default encoding. # # For example, on CentOS 6 with ENV['LANG'] = "en_US.UTF-8", # `locale -a`.split fails with ArgumentError invalid UTF-8 encoding. cmd = Mixlib::ShellOut.new("locale -a").run_command cmd.error! locales = cmd.stdout.split case when locales.include?('C.UTF-8') 'C.UTF-8' when locales.include?('en_US.UTF-8'), locales.include?('en_US.utf8') 'en_US.UTF-8' when locales.include?('en.UTF-8') 'en.UTF-8' else # Will match en_ZZ.UTF-8, en_ZZ.utf-8, en_ZZ.UTF8, en_ZZ.utf8 guesses = locales.select { |l| l =~ /^en_.*UTF-?8$/i } unless guesses.empty? guessed_locale = guesses.first # Transform into the form en_ZZ.UTF-8 guessed_locale.gsub(/UTF-?8$/i, "UTF-8") else ChefConfig.logger.warn "Please install an English UTF-8 locale for Chef to use, falling back to C locale and disabling UTF-8 support." 'C' end end rescue if ChefConfig.windows? ChefConfig.logger.debug "Defaulting to locale en_US.UTF-8 on Windows, until it matters that we do something else." else ChefConfig.logger.debug "No usable locale -a command found, assuming you have en_US.UTF-8 installed." end 'en_US.UTF-8' end |
permalink .inspect ⇒ Object
[View source]
43 44 45 |
# File 'lib/chef-config/config.rb', line 43 def self.inspect configuration.inspect end |
permalink .path_accessible?(path) ⇒ Boolean
Returns true only if the path exists and is readable and writeable for the user.
226 227 228 |
# File 'lib/chef-config/config.rb', line 226 def self.path_accessible?(path) File.exists?(path) && File.readable?(path) && File.writable?(path) end |
permalink .platform_specific_path(path) ⇒ Object
[View source]
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/chef-config/config.rb', line 47 def self.platform_specific_path(path) path = PathHelper.cleanpath(path) if ChefConfig.windows? # turns \etc\chef\client.rb and \var\chef\client.rb into C:/chef/client.rb if env['SYSTEMDRIVE'] && path[0] == '\\' && path.split('\\')[2] == 'chef' path = PathHelper.join(env['SYSTEMDRIVE'], path.split('\\', 3)[2]) end end path end |
permalink .set_defaults_for_nix ⇒ Object
[View source]
553 554 555 556 557 558 559 560 561 562 563 |
# File 'lib/chef-config/config.rb', line 553 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 |
permalink .set_defaults_for_windows ⇒ Object
[View source]
542 543 544 545 546 547 548 549 550 551 |
# File 'lib/chef-config/config.rb', line 542 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 |
permalink .windows_home_path ⇒ Object
[View source]
579 580 581 582 |
# File 'lib/chef-config/config.rb', line 579 def self.windows_home_path ChefConfig.logger.deprecation("Chef::Config.windows_home_path is now deprecated. Consider using Chef::Util::PathHelper.home instead.") PathHelper.home end |
Instance Method Details
permalink #user ⇒ Object
Daemonization Settings ## What user should Chef run as?
248 |
# File 'lib/chef-config/config.rb', line 248 default :user, nil |