Class: ChefConfig::WorkstationConfigLoader
- Inherits:
-
Object
- Object
- ChefConfig::WorkstationConfigLoader
- Includes:
- Mixin::Credentials, Mixin::DotD
- Defined in:
- lib/chef-config/workstation_config_loader.rb
Instance Attribute Summary collapse
-
#credentials_found ⇒ Object
readonly
Returns the value of attribute credentials_found.
-
#explicit_config_file ⇒ Object
Path to a config file requested by user, (e.g., via command line option).
-
#profile ⇒ Object
The name of a credentials profile.
Instance Method Summary collapse
- #chef_config_dir ⇒ Object
- #config_location ⇒ Object
-
#env ⇒ Object
(Private API, public for test purposes).
-
#initialize(explicit_config_file, logger = nil, profile: nil) ⇒ WorkstationConfigLoader
constructor
TODO: initialize this with a logger for Chef and Knife.
- #load ⇒ Object
- #no_config_found? ⇒ Boolean
-
#path_exists?(path) ⇒ Boolean
(Private API, public for test purposes).
Methods included from Mixin::Credentials
#credentials_file_path, #credentials_profile, #load_credentials, #parse_credentials_file
Methods included from Mixin::DotD
Constructor Details
#initialize(explicit_config_file, logger = nil, profile: nil) ⇒ WorkstationConfigLoader
TODO: initialize this with a logger for Chef and Knife
41 42 43 44 45 46 47 48 |
# File 'lib/chef-config/workstation_config_loader.rb', line 41 def initialize(explicit_config_file, logger = nil, profile: nil) @explicit_config_file = explicit_config_file @chef_config_dir = nil @config_location = nil @profile = profile @logger = logger || NullLogger.new @credentials_found = false end |
Instance Attribute Details
#credentials_found ⇒ Object (readonly)
Returns the value of attribute credentials_found.
38 39 40 |
# File 'lib/chef-config/workstation_config_loader.rb', line 38 def credentials_found @credentials_found end |
#explicit_config_file ⇒ Object
Path to a config file requested by user, (e.g., via command line option). Can be nil
35 36 37 |
# File 'lib/chef-config/workstation_config_loader.rb', line 35 def explicit_config_file @explicit_config_file end |
#profile ⇒ Object
The name of a credentials profile. Can be nil
37 38 39 |
# File 'lib/chef-config/workstation_config_loader.rb', line 37 def profile @profile end |
Instance Method Details
#chef_config_dir ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/chef-config/workstation_config_loader.rb', line 58 def chef_config_dir if @chef_config_dir.nil? @chef_config_dir = false full_path = working_directory.split(File::SEPARATOR) (full_path.length - 1).downto(0) do |i| candidate_directory = File.join(full_path[0..i] + [ChefUtils::Dist::Infra::USER_CONF_DIR]) if File.exist?(candidate_directory) && File.directory?(candidate_directory) @chef_config_dir = candidate_directory break end end end @chef_config_dir end |
#config_location ⇒ Object
54 55 56 |
# File 'lib/chef-config/workstation_config_loader.rb', line 54 def config_location @config_location ||= (explicit_config_file || locate_local_config) end |
#env ⇒ Object
(Private API, public for test purposes)
93 94 95 |
# File 'lib/chef-config/workstation_config_loader.rb', line 93 def env ENV end |
#load ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/chef-config/workstation_config_loader.rb', line 73 def load load_credentials(profile) # Ignore it if there's no explicit_config_file and can't find one at a # default path. unless config_location.nil? if explicit_config_file && !path_exists?(config_location) raise ChefConfig::ConfigurationError, "Specified config file #{config_location} does not exist" end # Have to set Config.config_file b/c other config is derived from it. Config.config_file = config_location apply_config(IO.read(config_location), config_location) end load_dot_d(Config[:config_d_dir]) if Config[:config_d_dir] apply_defaults end |
#no_config_found? ⇒ Boolean
50 51 52 |
# File 'lib/chef-config/workstation_config_loader.rb', line 50 def no_config_found? config_location.nil? && !credentials_found end |
#path_exists?(path) ⇒ Boolean
(Private API, public for test purposes)
98 99 100 |
# File 'lib/chef-config/workstation_config_loader.rb', line 98 def path_exists?(path) Pathname.new(path)..exist? end |