Class: Bolt::Config
- Inherits:
-
Struct
- Object
- Struct
- Bolt::Config
- Defined in:
- lib/bolt/config.rb
Constant Summary collapse
- DEFAULTS =
{ concurrency: 100, transport: 'ssh', format: 'human', modulepath: [], puppetdb: {} }.freeze
- TRANSPORT_OPTIONS =
%i[password run-as sudo-password extensions private-key tty tmpdir user connect-timeout cacert token-file service-url].freeze
- TRANSPORT_DEFAULTS =
{ 'connect-timeout' => 10, 'tty' => false }.freeze
- TRANSPORT_SPECIFIC_DEFAULTS =
{ ssh: { 'host-key-check' => true }, winrm: { 'ssl' => true, 'ssl-verify' => true }, pcp: { 'task-environment' => 'production', 'local-validation' => false }, local: {} }.freeze
Instance Attribute Summary collapse
-
#concurrency ⇒ Object
Returns the value of attribute concurrency.
-
#format ⇒ Object
Returns the value of attribute format.
-
#inventoryfile ⇒ Object
Returns the value of attribute inventoryfile.
-
#log ⇒ Object
Returns the value of attribute log.
-
#modulepath ⇒ Object
Returns the value of attribute modulepath.
-
#puppetdb ⇒ Object
Returns the value of attribute puppetdb.
-
#transport ⇒ Object
Returns the value of attribute transport.
-
#transports ⇒ Object
Returns the value of attribute transports.
Instance Method Summary collapse
- #deep_clone ⇒ Object
- #default_paths ⇒ Object
-
#initialize(**kwargs) ⇒ Config
constructor
A new instance of Config.
- #load_file(path) ⇒ Object
- #normalize_log(target) ⇒ Object
- #transport_conf ⇒ Object
- #update_from_cli(options) ⇒ Object
- #update_from_inventory(data) ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(**kwargs) ⇒ Config
Returns a new instance of Config.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/bolt/config.rb', line 69 def initialize(**kwargs) super() @logger = Logging.logger[self] DEFAULTS.merge(kwargs).each { |k, v| self[k] = v } # add an entry for the default console logger self[:log] ||= {} self[:log]['console'] ||= {} self[:transports] ||= {} TRANSPORTS.each_key do |transport| self[:transports][transport] ||= {} TRANSPORT_DEFAULTS.each do |k, v| unless self[:transports][transport][k] self[:transports][transport][k] = v end end TRANSPORT_SPECIFIC_DEFAULTS[transport].each do |k, v| unless self[:transports][transport].key? k self[:transports][transport][k] = v end end end end |
Instance Attribute Details
#concurrency ⇒ Object
Returns the value of attribute concurrency
26 27 28 |
# File 'lib/bolt/config.rb', line 26 def concurrency @concurrency end |
#format ⇒ Object
Returns the value of attribute format
26 27 28 |
# File 'lib/bolt/config.rb', line 26 def format @format end |
#inventoryfile ⇒ Object
Returns the value of attribute inventoryfile
26 27 28 |
# File 'lib/bolt/config.rb', line 26 def inventoryfile @inventoryfile end |
#log ⇒ Object
Returns the value of attribute log
26 27 28 |
# File 'lib/bolt/config.rb', line 26 def log @log end |
#modulepath ⇒ Object
Returns the value of attribute modulepath
26 27 28 |
# File 'lib/bolt/config.rb', line 26 def modulepath @modulepath end |
#puppetdb ⇒ Object
Returns the value of attribute puppetdb
26 27 28 |
# File 'lib/bolt/config.rb', line 26 def puppetdb @puppetdb end |
#transport ⇒ Object
Returns the value of attribute transport
26 27 28 |
# File 'lib/bolt/config.rb', line 26 def transport @transport end |
#transports ⇒ Object
Returns the value of attribute transports
26 27 28 |
# File 'lib/bolt/config.rb', line 26 def transports @transports end |
Instance Method Details
#deep_clone ⇒ Object
96 97 98 |
# File 'lib/bolt/config.rb', line 96 def deep_clone Bolt::Util.deep_clone(self) end |
#default_paths ⇒ Object
100 101 102 103 |
# File 'lib/bolt/config.rb', line 100 def default_paths root_path = File.(File.join('~', '.puppetlabs')) [File.join(root_path, 'bolt.yaml'), File.join(root_path, 'bolt.yml')] end |
#load_file(path) ⇒ Object
147 148 149 150 |
# File 'lib/bolt/config.rb', line 147 def load_file(path) data = Bolt::Util.read_config_file(path, default_paths, 'config') update_from_file(data) if data end |
#normalize_log(target) ⇒ Object
105 106 107 108 109 |
# File 'lib/bolt/config.rb', line 105 def normalize_log(target) return target if target == 'console' target = target[5..-1] if target.start_with?('file:') 'file:' + File.(target) end |
#transport_conf ⇒ Object
193 194 195 196 |
# File 'lib/bolt/config.rb', line 193 def transport_conf { transport: self[:transport], transports: self[:transports] } end |
#update_from_cli(options) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/bolt/config.rb', line 152 def update_from_cli() %i[concurrency transport format modulepath inventoryfile].each do |key| self[key] = [key] if [key] end if [:debug] self[:log]['console'][:level] = :debug elsif [:verbose] self[:log]['console'][:level] = :info end TRANSPORTS.each_key do |transport| transport = self[:transports][transport] TRANSPORT_OPTIONS.each do |key| if [key] transport[key.to_s] = Bolt::Util.walk_keys([key], &:to_s) end end end if .key?(:ssl) # this defaults to true so we need to check the presence of the key self[:transports][:winrm]['ssl'] = [:ssl] end if .key?(:'ssl-verify') # this defaults to true so we need to check the presence of the key self[:transports][:winrm]['ssl-verify'] = [:'ssl-verify'] end if .key?(:'host-key-check') # this defaults to true so we need to check the presence of the key self[:transports][:ssh]['host-key-check'] = [:'host-key-check'] end end |
#update_from_inventory(data) ⇒ Object
185 186 187 188 189 190 191 |
# File 'lib/bolt/config.rb', line 185 def update_from_inventory(data) update_from_file(data) if data['transport'] self[:transport] = data['transport'] end end |
#validate ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/bolt/config.rb', line 198 def validate self[:log].each_pair do |name, params| if params.key?(:level) && !Bolt::Logger.valid_level?(params[:level]) raise Bolt::CLIError, "level of log #{name} must be one of: #{Bolt::Logger.levels.join(', ')}; received #{params[:level]}" end if params.key?(:append) && params[:append] != true && params[:append] != false raise Bolt::CLIError, "append flag of log #{name} must be a Boolean, received #{params[:append]}" end end unless %w[human json].include? self[:format] raise Bolt::CLIError, "Unsupported format: '#{self[:format]}'" end unless self[:transport].nil? || Bolt::TRANSPORTS.include?(self[:transport].to_sym) raise UnknownTransportError, self[:transport] end TRANSPORTS.each do |transport, impl| impl.validate(self[:transports][transport]) end end |