Class: HAProxy::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/haproxy/parser.rb

Overview

Responsible for reading an HAProxy config file and building an HAProxy::Config instance.

Constant Summary collapse

Error =

Raised when an error occurs during parsing.

Class.new(StandardError)
SERVER_ATTRIBUTE_NAMES_1_3 =

haproxy 1.3

%w{
  addr backup check cookie disabled fall id inter fastinter downinter
  maxconn maxqueue minconn port redir rise slowstart source track weight
}
SERVER_ATTRIBUTE_NAMES_1_4 =

Added in haproxy 1.4

%w{error-limit observe on-error}
SERVER_ATTRIBUTE_NAMES_1_5 =

Added in haproxy 1.5

%w{ 
  agent-check agent-inter agent-port ca-file check-send-proxy check-ssl
  ciphers crl-file crt error-limit force-sslv3 force-tlsv10 force-tlsv11
  force-tlsv12 no-sslv3 no-tls-tickets no-tlsv10 no-tlsv11 no-tlsv12 non-stick observe
  on-error on-marked-down on-marked-up send-proxy send-proxy-v2 send-proxy-v2-ssl
  send-proxy-v2-ssl-cn ssl verify verifyhost
}
SERVER_ATTRIBUTE_NAMES_1_6 =

Added in haproxy 1.6

%w{
  namespace no-ssl-reuse resolve-prefer resolvers sni tcp-ut
}
SERVER_ATTRIBUTE_NAMES_1_7 =

Added in haproxy 1.7

%w{
  agent-send init-addr resolve-net
}
SERVER_ATTRIBUTE_NAMES_1_8 =
%w{
  agent-addr check-sni enabled force-tlsv13 no-agent-check no-backup no-check no-check-ssl
  no-send-proxy no-send-proxy-v2 no-send-proxy-v2-ssl no-send-proxy-v2-ssl-cn no-ssl no-tlsv13 
  no-verifyhost ssl-max-ver ssl-min-ver ssl-reuse stick tls-tickets
}
SERVER_ATTRIBUTE_NAMES =

SERVER_ATTRIBUTE_NAMES_1_9 = %w{ } # as of 1/16/18 I do not see new server attributes in haproxy 1.9

SERVER_ATTRIBUTE_NAMES_1_3 + SERVER_ATTRIBUTE_NAMES_1_4 + SERVER_ATTRIBUTE_NAMES_1_5 \
+ SERVER_ATTRIBUTE_NAMES_1_6 + SERVER_ATTRIBUTE_NAMES_1_7 + SERVER_ATTRIBUTE_NAMES_1_8

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Parser

Returns a new instance of Parser.



41
42
43
44
45
46
47
# File 'lib/haproxy/parser.rb', line 41

def initialize(options = nil)
  options ||= {}
  options = { :verbose => false }.merge(options)

  self.options = options
  self.verbose = options[:verbose]
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



39
40
41
# File 'lib/haproxy/parser.rb', line 39

def options
  @options
end

#parse_resultObject

Returns the value of attribute parse_result.



39
40
41
# File 'lib/haproxy/parser.rb', line 39

def parse_result
  @parse_result
end

#verboseObject

Returns the value of attribute verbose.



39
40
41
# File 'lib/haproxy/parser.rb', line 39

def verbose
  @verbose
end

Instance Method Details

#parse(config_text) ⇒ Object



54
55
56
57
58
# File 'lib/haproxy/parser.rb', line 54

def parse(config_text)
  result = parse_config_text(config_text)
  self.parse_result = result
  build_config(result)
end

#parse_file(filename) ⇒ Object



49
50
51
52
# File 'lib/haproxy/parser.rb', line 49

def parse_file(filename)
  config_text = File.read(filename)
  self.parse(config_text)
end