Class: TransportConfig
- Inherits:
-
Object
- Object
- TransportConfig
- Defined in:
- lib/bolt_ext/server_config.rb
Instance Attribute Summary collapse
-
#concurrency ⇒ Object
Returns the value of attribute concurrency.
-
#host ⇒ Object
Returns the value of attribute host.
-
#logfile ⇒ Object
Returns the value of attribute logfile.
-
#loglevel ⇒ Object
Returns the value of attribute loglevel.
-
#port ⇒ Object
Returns the value of attribute port.
-
#ssl_ca_cert ⇒ Object
Returns the value of attribute ssl_ca_cert.
-
#ssl_cert ⇒ Object
Returns the value of attribute ssl_cert.
-
#ssl_cipher_suites ⇒ Object
Returns the value of attribute ssl_cipher_suites.
-
#ssl_key ⇒ Object
Returns the value of attribute ssl_key.
-
#whitelist ⇒ Object
Returns the value of attribute whitelist.
Instance Method Summary collapse
-
#initialize(global = nil, local = nil) ⇒ TransportConfig
constructor
A new instance of TransportConfig.
- #load_config(path) ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(global = nil, local = nil) ⇒ TransportConfig
Returns a new instance of TransportConfig.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bolt_ext/server_config.rb', line 9 def initialize(global = nil, local = nil) @host = '127.0.0.1' @port = 62658 @ssl_cert = nil @ssl_key = nil @ssl_ca_cert = nil @ssl_cipher_suites = ['ECDHE-ECDSA-AES256-GCM-SHA384', 'ECDHE-RSA-AES256-GCM-SHA384', 'ECDHE-ECDSA-CHACHA20-POLY1305', 'ECDHE-RSA-CHACHA20-POLY1305', 'ECDHE-ECDSA-AES128-GCM-SHA256', 'ECDHE-RSA-AES128-GCM-SHA256', 'ECDHE-ECDSA-AES256-SHA384', 'ECDHE-RSA-AES256-SHA384', 'ECDHE-ECDSA-AES128-SHA256', 'ECDHE-RSA-AES128-SHA256'] @loglevel = 'notice' @logfile = nil @whitelist = nil @concurrency = 100 global_path = global || '/etc/puppetlabs/bolt-server/conf.d/bolt-server.conf' local_path = local || File.join(ENV['HOME'].to_s, ".puppetlabs", "bolt-server.conf") load_config(global_path) load_config(local_path) validate end |
Instance Attribute Details
#concurrency ⇒ Object
Returns the value of attribute concurrency.
6 7 8 |
# File 'lib/bolt_ext/server_config.rb', line 6 def concurrency @concurrency end |
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/bolt_ext/server_config.rb', line 6 def host @host end |
#logfile ⇒ Object
Returns the value of attribute logfile.
6 7 8 |
# File 'lib/bolt_ext/server_config.rb', line 6 def logfile @logfile end |
#loglevel ⇒ Object
Returns the value of attribute loglevel.
6 7 8 |
# File 'lib/bolt_ext/server_config.rb', line 6 def loglevel @loglevel end |
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/bolt_ext/server_config.rb', line 6 def port @port end |
#ssl_ca_cert ⇒ Object
Returns the value of attribute ssl_ca_cert.
6 7 8 |
# File 'lib/bolt_ext/server_config.rb', line 6 def ssl_ca_cert @ssl_ca_cert end |
#ssl_cert ⇒ Object
Returns the value of attribute ssl_cert.
6 7 8 |
# File 'lib/bolt_ext/server_config.rb', line 6 def ssl_cert @ssl_cert end |
#ssl_cipher_suites ⇒ Object
Returns the value of attribute ssl_cipher_suites.
6 7 8 |
# File 'lib/bolt_ext/server_config.rb', line 6 def ssl_cipher_suites @ssl_cipher_suites end |
#ssl_key ⇒ Object
Returns the value of attribute ssl_key.
6 7 8 |
# File 'lib/bolt_ext/server_config.rb', line 6 def ssl_key @ssl_key end |
#whitelist ⇒ Object
Returns the value of attribute whitelist.
6 7 8 |
# File 'lib/bolt_ext/server_config.rb', line 6 def whitelist @whitelist end |
Instance Method Details
#load_config(path) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/bolt_ext/server_config.rb', line 39 def load_config(path) begin parsed_hocon = Hocon.load(path)['bolt-server'] rescue Hocon::ConfigError => e raise "Hocon data in '#{path}' failed to load.\n Error: '#{e.}'" rescue Errno::EACCES raise "Your user doesn't have permission to read #{path}" end unless parsed_hocon.nil? %w[host port ssl-cert ssl-key ssl-ca-cert ssl-cipher-suites loglevel logfile whitelist concurrency].each do |key| varname = '@' + key.tr('-', '_') instance_variable_set(varname, parsed_hocon[key]) if parsed_hocon.key?(key) end end end |
#validate ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/bolt_ext/server_config.rb', line 56 def validate required_keys = %w[ssl_cert ssl_key ssl_ca_cert] ssl_keys = %w[ssl_cert ssl_key ssl_ca_cert] required_keys.each do |k| next unless send(k).nil? raise Bolt::ValidationError, <<-MSG You must configure #{k} in either /etc/puppetlabs/bolt-server/conf.d/bolt-server.conf or ~/.puppetlabs/bolt-server.conf MSG end unless @port.is_a?(Integer) && @port > 0 raise Bolt::ValidationError, "Configured 'port' must be a valid integer greater than 0" end ssl_keys.each do |sk| unless File.file?(send(sk)) && File.readable?(send(sk)) raise Bolt::ValidationError, "Configured #{sk} must be a valid filepath" end end unless @ssl_cipher_suites.is_a?(Array) raise Bolt::ValidationError, "Configured 'ssl-cipher-suites' must be an array of cipher suite names" end unless @whitelist.nil? || @whitelist.is_a?(Array) raise Bolt::ValidationError, "Configured 'whitelist' must be an array of names" end unless @concurrency.is_a?(Integer) && @concurrency.positive? raise Bolt::ValidationError, "Configured 'concurrency' must be a positive integer" end end |