haproxy-tools 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b55425521f1c472fa1a0fcf14312fdee6d3543e6
4
+ data.tar.gz: a9e9263e329d00d7c158e2d20c118707b01599fd
5
+ SHA512:
6
+ metadata.gz: a7653024f2b7cc685ce732a1aa89be3a80686da0c34f2071b83deabe347d768b1a0d33f2629b24856c9250d1c563e25358e044de463162c5681c15bb3c62de88
7
+ data.tar.gz: b1d16f62e28dc60979b26fcdc0c5c5a34036c0b9fd3af4dd20e6282a7495a793e844bc0087f476b89e45ff4ee6d75de242a1cc4db602ca4d6c203068b8379ab3
@@ -0,0 +1,14 @@
1
+ coverage
2
+ rdoc
3
+ doc
4
+ .yardoc
5
+ pkg
6
+ .DS_Store
7
+ *.tmproj
8
+ tmtags
9
+ Gemfile.lock
10
+ *.swp
11
+ *~
12
+ tmp
13
+ *.orig
14
+ .bundle
data/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --format documentation
@@ -0,0 +1,13 @@
1
+ class SimpleCov::Formatter::QualityFormatter
2
+ def format(result)
3
+ SimpleCov::Formatter::HTMLFormatter.new.format(result)
4
+ File.open('coverage/covered_percent', 'w') do |f|
5
+ f.puts result.source_files.covered_percent.to_f
6
+ end
7
+ end
8
+ end
9
+ SimpleCov.formatter = SimpleCov::Formatter::QualityFormatter
10
+
11
+ SimpleCov.start do
12
+ add_filter '/spec/'
13
+ end
@@ -1,3 +1,10 @@
1
+ == 0.3.0
2
+
3
+ * Fixed: Handle server configurations that do not have any extra attributes (subakva)
4
+ * Fixed: Allow early blanks (jessekempf)
5
+ * Dev: Added cane and simplecov
6
+ * Dev: switched from jeweler to bundler gem management
7
+
1
8
  == 0.2.0
2
9
 
3
10
  * Switched to treetop grammer for parsing (subakva)
data/Gemfile CHANGED
@@ -1,12 +1,4 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- gem 'net-scp'
4
- gem 'orderedhash'
5
-
6
- group :development do
7
- gem "rspec", "~> 2.7.0"
8
- gem "yard", "~> 0.7.0"
9
- gem "jeweler", "~> 1.6.4"
10
- gem "rcov", ">= 0"
11
- gem "treetop"
12
- end
3
+ # Gem dependencies are defined in haproxy-tools.gemspec
4
+ gemspec
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Jason Wadsworth
1
+ Copyright (c) 2011-2013 Jason Wadsworth
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -8,7 +8,7 @@ Tools for managing HAProxy with Ruby.
8
8
 
9
9
  == Gemfile
10
10
 
11
- gem 'haproxy-tools', '~> 0.2.0'
11
+ gem 'haproxy-tools', '~> 0.3.0'
12
12
 
13
13
  == Basic Configuration File Parsing
14
14
 
@@ -55,6 +55,6 @@ Tools for managing HAProxy with Ruby.
55
55
 
56
56
  == Copyright
57
57
 
58
- Copyright (c) 2012 Jason Wadsworth. See LICENSE.txt for
58
+ Copyright (c) 2011-2013 Jason Wadsworth. See LICENSE.txt for
59
59
  further details.
60
60
 
data/Rakefile CHANGED
@@ -1,43 +1,25 @@
1
- # encoding: utf-8
1
+ #!/usr/bin/env rake
2
2
 
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "haproxy-tools"
18
- gem.homepage = "http://github.com/subakva/haproxy-tools"
19
- gem.license = "MIT"
20
- gem.summary = %Q{HAProxy Tools for Ruby}
21
- gem.description = %Q{Ruby tools for HAProxy, including config file management.}
22
- gem.email = "jdwadsworth@gmail.com"
23
- gem.authors = ["Jason Wadsworth"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
3
+ require 'bundler/gem_tasks'
27
4
 
28
- require 'rspec/core'
29
5
  require 'rspec/core/rake_task'
30
- RSpec::Core::RakeTask.new(:spec) do |spec|
31
- spec.pattern = FileList['spec/**/*_spec.rb']
32
- end
33
-
34
- RSpec::Core::RakeTask.new(:rcov) do |spec|
35
- spec.pattern = 'spec/**/*_spec.rb'
36
- spec.rcov = true
37
- end
38
-
39
- task :default => :spec
6
+ RSpec::Core::RakeTask.new(:spec)
40
7
 
41
8
  require 'yard'
42
9
  YARD::Rake::YardocTask.new
43
10
 
11
+ begin
12
+ require 'cane/rake_task'
13
+
14
+ desc "Run cane to check quality metrics"
15
+ Cane::RakeTask.new(:cane) do |cane|
16
+ cane.abc_max = 15
17
+ cane.style_measure = 100
18
+ cane.style_glob = '{lib}/**/*.rb'
19
+ cane.gte = {'coverage/covered_percent' => 95}
20
+ end
21
+ rescue LoadError
22
+ warn "cane not available, quality task not provided."
23
+ end
24
+
25
+ task :default => [:spec, :cane]
@@ -1,83 +1,28 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'haproxy/version'
5
5
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{haproxy-tools}
8
- s.version = "0.2.0"
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'haproxy-tools'
8
+ gem.version = HAProxy::VERSION
9
+ gem.authors = ['Jason Wadsworth']
10
+ gem.email = ['jdwadsworth@gmail.com']
11
+ gem.description = %q{Ruby tools for HAProxy, including config file management.}
12
+ gem.summary = %q{HAProxy Tools for Ruby}
13
+ gem.homepage = 'https://github.com/subakva/haproxy-tools'
9
14
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Jason Wadsworth"]
12
- s.date = %q{2012-04-24}
13
- s.description = %q{Ruby tools for HAProxy, including config file management.}
14
- s.email = %q{jdwadsworth@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.rdoc",
18
- "TODO"
19
- ]
20
- s.files = [
21
- ".document",
22
- ".rspec",
23
- "CHANGES.rdoc",
24
- "Gemfile",
25
- "LICENSE.txt",
26
- "README.rdoc",
27
- "Rakefile",
28
- "TODO",
29
- "VERSION",
30
- "docs/haproxy-1.3-configuration.txt",
31
- "docs/haproxy-1.4-configuration.txt",
32
- "haproxy-tools.gemspec",
33
- "lib/haproxy-tools.rb",
34
- "lib/haproxy/config.rb",
35
- "lib/haproxy/parser.rb",
36
- "lib/haproxy/renderer.rb",
37
- "lib/haproxy/treetop/config.treetop",
38
- "lib/haproxy/treetop/nodes.rb",
39
- "lib/haproxy_tools.rb",
40
- "spec/fixtures/multi-pool.haproxy.cfg",
41
- "spec/fixtures/simple.haproxy.cfg",
42
- "spec/haproxy/config_spec.rb",
43
- "spec/haproxy/parser_spec.rb",
44
- "spec/haproxy/treetop/config_parser_spec.rb",
45
- "spec/spec_helper.rb"
46
- ]
47
- s.homepage = %q{http://github.com/subakva/haproxy-tools}
48
- s.licenses = ["MIT"]
49
- s.require_paths = ["lib"]
50
- s.rubygems_version = %q{1.4.2}
51
- s.summary = %q{HAProxy Tools for Ruby}
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
52
19
 
53
- if s.respond_to? :specification_version then
54
- s.specification_version = 3
55
-
56
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
- s.add_runtime_dependency(%q<net-scp>, [">= 0"])
58
- s.add_runtime_dependency(%q<orderedhash>, [">= 0"])
59
- s.add_development_dependency(%q<rspec>, ["~> 2.7.0"])
60
- s.add_development_dependency(%q<yard>, ["~> 0.7.0"])
61
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
62
- s.add_development_dependency(%q<rcov>, [">= 0"])
63
- s.add_development_dependency(%q<treetop>, [">= 0"])
64
- else
65
- s.add_dependency(%q<net-scp>, [">= 0"])
66
- s.add_dependency(%q<orderedhash>, [">= 0"])
67
- s.add_dependency(%q<rspec>, ["~> 2.7.0"])
68
- s.add_dependency(%q<yard>, ["~> 0.7.0"])
69
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
70
- s.add_dependency(%q<rcov>, [">= 0"])
71
- s.add_dependency(%q<treetop>, [">= 0"])
72
- end
73
- else
74
- s.add_dependency(%q<net-scp>, [">= 0"])
75
- s.add_dependency(%q<orderedhash>, [">= 0"])
76
- s.add_dependency(%q<rspec>, ["~> 2.7.0"])
77
- s.add_dependency(%q<yard>, ["~> 0.7.0"])
78
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
79
- s.add_dependency(%q<rcov>, [">= 0"])
80
- s.add_dependency(%q<treetop>, [">= 0"])
81
- end
20
+ gem.add_dependency('net-scp')
21
+ gem.add_dependency("treetop")
22
+ gem.add_development_dependency("rake")
23
+ gem.add_development_dependency("rspec")
24
+ gem.add_development_dependency("yard")
25
+ gem.add_development_dependency('simplecov')
26
+ gem.add_development_dependency('cane')
27
+ gem.add_development_dependency('pry-debugger')
82
28
  end
83
-
@@ -5,6 +5,9 @@ module HAProxy
5
5
  Frontend = Struct.new(:name, :host, :port, :options, :config)
6
6
  Server = Struct.new(:name, :host, :port, :attributes)
7
7
 
8
+ # Contains shared methods for config objects that contain a list of servers. The including class
9
+ # is expected to have an instance variable called :servers that contains a hash of server
10
+ # configurations.
8
11
  module ServerList
9
12
  def add_server(name, host, options)
10
13
  options ||= {}
@@ -18,17 +21,21 @@ module HAProxy
18
21
  end
19
22
  end
20
23
 
24
+
25
+ # Represents a listener configuration block.
21
26
  class Listener
22
27
  include ServerList
23
28
  end
24
29
 
30
+ # Represents a backend configuration block.
25
31
  class Backend
26
32
  include ServerList
27
33
  end
28
34
 
35
+ # Represents an haproxy configuration file.
29
36
  class Config
30
37
  attr_accessor :original_parse_tree, :listeners, :backends, :frontends, :global, :defaults
31
-
38
+
32
39
  def initialize(parse_tree)
33
40
  self.original_parse_tree = parse_tree
34
41
  self.backends = []
@@ -1,14 +1,17 @@
1
1
  module HAProxy
2
- class Parser
3
- class Error < Exception; end
2
+ # Responsible for reading an HAProxy config file and building an HAProxy::Config instance.
3
+ class Parser
4
+ # Raised when an error occurs during parsing.
5
+ Error = Class.new(StandardError)
4
6
 
5
7
  # haproxy 1.3
6
- SERVER_ATTRIBUTE_NAMES = %w{
8
+ SERVER_ATTRIBUTE_NAMES_1_3 = %w{
7
9
  addr backup check cookie disabled fall id inter fastinter downinter
8
10
  maxconn maxqueue minconn port redir rise slowstart source track weight
9
11
  }
10
12
  # Added in haproxy 1.4
11
- SERVER_ATTRIBUTE_NAMES += %w{error-limit observe on-error}
13
+ SERVER_ATTRIBUTE_NAMES_1_4 = %w{error-limit observe on-error}
14
+ SERVER_ATTRIBUTE_NAMES = SERVER_ATTRIBUTE_NAMES_1_3 + SERVER_ATTRIBUTE_NAMES_1_4
12
15
 
13
16
  attr_accessor :verbose, :options, :parse_result
14
17
 
@@ -26,62 +29,91 @@ module HAProxy
26
29
  end
27
30
 
28
31
  def parse(config_text)
32
+ result = parse_config_text(config_text)
33
+ self.parse_result = result
34
+ build_config(result)
35
+ end
36
+
37
+ protected
38
+
39
+ def parse_config_text(config_text)
29
40
  parser = HAProxy::Treetop::ConfigParser.new
30
41
  result = parser.parse(config_text)
31
42
  raise HAProxy::Parser::Error.new(parser.failure_reason) if result.nil?
43
+ result
44
+ end
32
45
 
33
- config = HAProxy::Config.new(result)
34
- config.global = config_hash_from_config_section(result.global)
46
+ def build_config(result)
47
+ HAProxy::Config.new(result).tap do |config|
48
+ config.global = config_hash_from_config_section(result.global)
35
49
 
36
- result.frontends.each do |fs|
37
- f = Frontend.new
38
- f.name = try(fs.frontend_header, :proxy_name, :content)
39
- f.host = try(fs.frontend_header, :service_address, :host, :content)
40
- f.port = try(fs.frontend_header, :service_address, :port, :content)
50
+ config.frontends += collect_frontends(result)
51
+ config.backends += collect_backends(result)
52
+ config.listeners += collect_listeners(result)
53
+ config.defaults += collect_defaults(result)
54
+ end
55
+ end
56
+
57
+ def build_frontend(fs)
58
+ Frontend.new.tap do |f|
59
+ f.name = try_send(fs.frontend_header, :proxy_name, :content)
60
+ f.host = try_send(fs.frontend_header, :service_address, :host, :content)
61
+ f.port = try_send(fs.frontend_header, :service_address, :port, :content)
41
62
  f.options = options_hash_from_config_section(fs)
42
63
  f.config = config_hash_from_config_section(fs)
43
- config.frontends << f
44
64
  end
65
+ end
45
66
 
46
- result.backends.each do |bs|
47
- b = Backend.new
48
- b.name = try(bs.backend_header, :proxy_name, :content)
67
+ def build_backend(bs)
68
+ Backend.new.tap do |b|
69
+ b.name = try_send(bs.backend_header, :proxy_name, :content)
49
70
  b.options = options_hash_from_config_section(bs)
50
71
  b.config = config_hash_from_config_section(bs)
51
72
  b.servers = server_hash_from_config_section(bs)
52
- config.backends << b
53
73
  end
74
+ end
54
75
 
55
- result.listeners.each do |ls|
56
- l = Listener.new
57
- l.name = try(ls.listen_header, :proxy_name, :content)
58
- l.host = try(ls.listen_header, :service_address, :host, :content)
59
- l.port = try(ls.listen_header, :service_address, :port, :content)
76
+ def build_listener(ls)
77
+ Listener.new.tap do |l|
78
+ l.name = try_send(ls.listen_header, :proxy_name, :content)
79
+ l.host = try_send(ls.listen_header, :service_address, :host, :content)
80
+ l.port = try_send(ls.listen_header, :service_address, :port, :content)
60
81
  l.options = options_hash_from_config_section(ls)
61
82
  l.config = config_hash_from_config_section(ls)
62
83
  l.servers = server_hash_from_config_section(ls)
63
- config.listeners << l
64
84
  end
85
+ end
65
86
 
66
- result.defaults.each do |ds|
67
- d = Default.new
68
- d.name = try(ds.defaults_header, :proxy_name, :content)
87
+ def build_default(ds)
88
+ Default.new.tap do |d|
89
+ d.name = try_send(ds.defaults_header, :proxy_name, :content)
69
90
  d.options = options_hash_from_config_section(ds)
70
91
  d.config = config_hash_from_config_section(ds)
71
- config.defaults << d
72
92
  end
93
+ end
73
94
 
74
- self.parse_result = result
75
- config
95
+ def collect_frontends(result)
96
+ result.frontends.map { |fs| build_frontend(fs) }
76
97
  end
77
98
 
78
- protected
99
+ def collect_backends(result)
100
+ result.backends.map { |bs| build_backend(bs) }
101
+ end
79
102
 
80
- def try(node, *method_names)
103
+ def collect_listeners(result)
104
+ result.listeners.map { |ls| build_listener(ls) }
105
+ end
106
+
107
+ def collect_defaults(result)
108
+ result.defaults.map { |ds| build_default(ds) }
109
+ end
110
+
111
+
112
+ def try_send(node, *method_names)
81
113
  method_name = method_names.shift
82
114
  if node.respond_to?(method_name)
83
115
  next_node = node.send(method_name)
84
- method_names.empty? ? next_node : try(next_node, *method_names)
116
+ method_names.empty? ? next_node : try_send(next_node, *method_names)
85
117
  else
86
118
  nil
87
119
  end
@@ -89,23 +121,24 @@ module HAProxy
89
121
 
90
122
  def server_hash_from_config_section(cs)
91
123
  cs.servers.inject({}) do |ch, s|
92
- value = try(s, :value, :content)
124
+ value = try_send(s, :value, :content)
93
125
  ch[s.name] = Server.new(s.name, s.host, s.port, parse_server_attributes(value))
94
126
  ch
95
127
  end
96
128
  end
97
129
 
98
- # Parses server attributes from the server value. I couldn't get manage to get treetop to do this.
99
- #
130
+ # Parses server attributes from the server value. I couldn't manage to get treetop to do
131
+ # this.
132
+ #
100
133
  # Types of server attributes to support:
101
134
  # ipv4, boolean, string, integer, time (us, ms, s, m, h, d), url, source attributes
102
- #
103
- # BUG: If an attribute value matches an attribute name, the parser will assume that a new attribute value
104
- # has started. I don't know how haproxy itself handles that situation.
135
+ #
136
+ # BUG: If an attribute value matches an attribute name, the parser will assume that a new
137
+ # attribute value has started. I don't know how haproxy itself handles that situation.
105
138
  def parse_server_attributes(value)
106
- parts = value.split(/\s/)
139
+ parts = value.to_s.split(/\s/)
107
140
  current_name = nil
108
- pairs = parts.inject(OrderedHash.new) do |pairs, part|
141
+ pairs = parts.inject({}) do |pairs, part|
109
142
  if SERVER_ATTRIBUTE_NAMES.include?(part)
110
143
  current_name = part
111
144
  pairs[current_name] = []
@@ -120,7 +153,8 @@ module HAProxy
120
153
  return clean_parsed_server_attributes(pairs)
121
154
  end
122
155
 
123
- # Converts attributes with no values to true, and combines everything else into space-separated strings.
156
+ # Converts attributes with no values to true, and combines everything else into space-
157
+ # separated strings.
124
158
  def clean_parsed_server_attributes(pairs)
125
159
  pairs.each do |k,v|
126
160
  if v.empty?
@@ -147,4 +181,3 @@ module HAProxy
147
181
 
148
182
  end
149
183
  end
150
-
@@ -1,4 +1,5 @@
1
1
  module HAProxy
2
+ # Responsible for rendering an HAProxy::Config instance to a string.
2
3
  class Renderer
3
4
 
4
5
  attr_accessor :config, :source_tree
@@ -32,7 +33,8 @@ module HAProxy
32
33
  end
33
34
 
34
35
  if e.class == HAProxy::Treetop::ServerLine
35
- # Use a custom rendering method for servers, since we allow them to be added/removed/changed.
36
+ # Use a custom rendering method for servers, since we allow them to be
37
+ # added/removed/changed.
36
38
  render_server_element(e)
37
39
  elsif e.elements && e.elements.size > 0
38
40
  render_node(e)
@@ -4,7 +4,7 @@ module HAProxy::Treetop
4
4
 
5
5
  grammar Config
6
6
  rule configuration
7
- (comment_line / global_section / defaults_section / userlist_section / listen_section / frontend_section / backend_section)* <ConfigurationFile>
7
+ (comment_line / blank_line / global_section / defaults_section / userlist_section / listen_section / frontend_section / backend_section)* <ConfigurationFile>
8
8
  end
9
9
 
10
10
  rule global_section
@@ -2,12 +2,14 @@ module HAProxy
2
2
  module Treetop
3
3
  extend self
4
4
 
5
+ # Include this module to always strip whitespace from the text_value
5
6
  module StrippedTextContent
6
7
  def content
7
8
  self.text_value.strip
8
9
  end
9
10
  end
10
11
 
12
+ # Include this module if the node contains a config element.
11
13
  module ConfigBlockContainer
12
14
  def option_lines
13
15
  self.config_block.elements.select {|e| e.class == OptionLine}
@@ -18,6 +20,7 @@ module HAProxy
18
20
  end
19
21
  end
20
22
 
23
+ # Include this module if the node contains a service address element.
21
24
  module ServiceAddressContainer
22
25
  def service_address
23
26
  self.elements.find {|e| e.class == ServiceAddress }
@@ -32,12 +35,14 @@ module HAProxy
32
35
  end
33
36
  end
34
37
 
38
+ # Include this module if the node contains a server elements.
35
39
  module ServerContainer
36
40
  def servers
37
- self.config_block.elements.select {|e| e.class == ServerLine}
41
+ self.config_block.elements.select {|e| e.class == ServerLine}
38
42
  end
39
43
  end
40
44
 
45
+ # Include this module if the value is optional for the node.
41
46
  module OptionalValueElement
42
47
  def value
43
48
  self.elements.find {|e| e.class == Value}
@@ -49,22 +54,54 @@ module HAProxy
49
54
  self.text_value
50
55
  end
51
56
  end
52
- class LineBreak < ::Treetop::Runtime::SyntaxNode; end
53
- class Char < ::Treetop::Runtime::SyntaxNode; include StrippedTextContent; end
54
- class Keyword < ::Treetop::Runtime::SyntaxNode; include StrippedTextContent; end
55
- class ProxyName < ::Treetop::Runtime::SyntaxNode; include StrippedTextContent; end
56
- class ServerName < ::Treetop::Runtime::SyntaxNode; include StrippedTextContent; end
57
- class Host < ::Treetop::Runtime::SyntaxNode; include StrippedTextContent; end
58
- class Port < ::Treetop::Runtime::SyntaxNode; include StrippedTextContent; end
59
- class Value < ::Treetop::Runtime::SyntaxNode; include StrippedTextContent; end
60
- class CommentText < ::Treetop::Runtime::SyntaxNode; include StrippedTextContent; end
57
+
58
+ class LineBreak < ::Treetop::Runtime::SyntaxNode
59
+ end
60
+
61
+ class Char < ::Treetop::Runtime::SyntaxNode
62
+ include StrippedTextContent
63
+ end
64
+
65
+ class Keyword < ::Treetop::Runtime::SyntaxNode
66
+ include StrippedTextContent
67
+ end
68
+
69
+ class ProxyName < ::Treetop::Runtime::SyntaxNode
70
+ include StrippedTextContent
71
+ end
72
+
73
+ class ServerName < ::Treetop::Runtime::SyntaxNode
74
+ include StrippedTextContent
75
+ end
76
+
77
+ class Host < ::Treetop::Runtime::SyntaxNode
78
+ include StrippedTextContent
79
+ end
80
+
81
+ class Port < ::Treetop::Runtime::SyntaxNode
82
+ include StrippedTextContent
83
+ end
84
+
85
+ class Value < ::Treetop::Runtime::SyntaxNode
86
+ include StrippedTextContent
87
+ end
88
+
89
+ class CommentText < ::Treetop::Runtime::SyntaxNode
90
+ include StrippedTextContent
91
+ end
61
92
 
62
93
  class ServiceAddress < ::Treetop::Runtime::SyntaxNode
63
94
  include StrippedTextContent
64
95
  end
65
96
 
66
- class CommentLine < ::Treetop::Runtime::SyntaxNode; include StrippedTextContent; end
67
- class BlankLine < ::Treetop::Runtime::SyntaxNode; include StrippedTextContent; end
97
+ class CommentLine < ::Treetop::Runtime::SyntaxNode
98
+ include StrippedTextContent
99
+ end
100
+
101
+ class BlankLine < ::Treetop::Runtime::SyntaxNode
102
+ include StrippedTextContent
103
+ end
104
+
68
105
  class ConfigLine < ::Treetop::Runtime::SyntaxNode
69
106
  include StrippedTextContent
70
107
  include OptionalValueElement
@@ -85,7 +122,9 @@ module HAProxy
85
122
  end
86
123
  end
87
124
 
88
- class GlobalHeader < ::Treetop::Runtime::SyntaxNode; include StrippedTextContent; end
125
+ class GlobalHeader < ::Treetop::Runtime::SyntaxNode
126
+ include StrippedTextContent
127
+ end
89
128
 
90
129
  class DefaultsHeader < ::Treetop::Runtime::SyntaxNode
91
130
  include StrippedTextContent
@@ -94,8 +133,13 @@ module HAProxy
94
133
  end
95
134
  end
96
135
 
97
- class UserlistHeader < ::Treetop::Runtime::SyntaxNode; include StrippedTextContent; end
98
- class BackendHeader < ::Treetop::Runtime::SyntaxNode; include StrippedTextContent; end
136
+ class UserlistHeader < ::Treetop::Runtime::SyntaxNode
137
+ include StrippedTextContent
138
+ end
139
+
140
+ class BackendHeader < ::Treetop::Runtime::SyntaxNode
141
+ include StrippedTextContent
142
+ end
99
143
 
100
144
  class FrontendHeader < ::Treetop::Runtime::SyntaxNode
101
145
  include ServiceAddressContainer
@@ -105,7 +149,8 @@ module HAProxy
105
149
  include ServiceAddressContainer
106
150
  end
107
151
 
108
- class ConfigBlock < ::Treetop::Runtime::SyntaxNode; end
152
+ class ConfigBlock < ::Treetop::Runtime::SyntaxNode
153
+ end
109
154
 
110
155
  class DefaultsSection < ::Treetop::Runtime::SyntaxNode
111
156
  include ConfigBlockContainer
@@ -141,7 +186,7 @@ module HAProxy
141
186
  def defaults
142
187
  self.elements.select {|e| e.class == DefaultsSection}
143
188
  end
144
-
189
+
145
190
  def listeners
146
191
  self.elements.select {|e| e.class == ListenSection}
147
192
  end
@@ -171,4 +216,3 @@ module HAProxy
171
216
  end
172
217
  end
173
218
  end
174
-
@@ -0,0 +1,3 @@
1
+ module HAProxy
2
+ VERSION = "0.3.0"
3
+ end
@@ -1,12 +1,5 @@
1
- require 'polyglot'
2
1
  require 'treetop'
3
- require 'orderedhash'
4
2
  require 'haproxy/treetop/config'
5
3
  require 'haproxy/config'
6
4
  require 'haproxy/renderer'
7
5
  require 'haproxy/parser'
8
-
9
- module HAProxy
10
- VERSION = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION')).strip
11
- end
12
-
@@ -1,4 +1,5 @@
1
1
  # This is a top-level comment. It should be allowed.
2
+
2
3
  global
3
4
  maxconn 4096 # Total Max Connections. This is dependent on ulimit
4
5
  daemon
@@ -19,4 +20,4 @@ listen http_proxy 55.55.55.55:80
19
20
  ## Define your servers to balance
20
21
  server web1 66.66.66.66:80 weight 1 maxconn 512 check
21
22
  server web2 77.77.77.77:80 weight 1 maxconn 512 check
22
- server web3 88.88.88.88:80 weight 1 maxconn 512 check
23
+ server web3 88.88.88.88:80
@@ -57,7 +57,7 @@ describe "HAProxy::Parser" do
57
57
  defaults.options.should include('httpclose')
58
58
  end
59
59
 
60
- it 'parses a listener from a config file' do
60
+ it 'parses a listener from a config file' do
61
61
  @config.listeners.size.should == 1
62
62
 
63
63
  listener = @config.listener('http_proxy')
@@ -92,9 +92,7 @@ describe "HAProxy::Parser" do
92
92
  server3.name.should == 'web3'
93
93
  server3.host.should == '88.88.88.88'
94
94
  server3.port.should == '80'
95
- server3.attributes['weight'].should == '1'
96
- server3.attributes['maxconn'].should == '512'
97
- server3.attributes['check'].should == true
95
+ server3.attributes.should be_empty
98
96
  end
99
97
  end
100
98
  end
@@ -52,17 +52,21 @@ describe HAProxy::Treetop::ConfigParser do
52
52
  it 'can parse a file with a listen section' do
53
53
  parse_single_pool
54
54
 
55
+ @result.elements
55
56
  @result.class.should == HAProxy::Treetop::ConfigurationFile
56
- @result.elements.size.should == 4
57
+ @result.elements.size.should == 5
58
+
59
+ @result.elements[0].class.should == HAProxy::Treetop::CommentLine
60
+ @result.elements[1].class.should == HAProxy::Treetop::BlankLine
57
61
 
58
- @result.global.should == @result.elements[1]
59
- @result.elements[1].class.should == HAProxy::Treetop::GlobalSection
62
+ @result.global.should == @result.elements[2]
63
+ @result.elements[2].class.should == HAProxy::Treetop::GlobalSection
60
64
 
61
- @result.defaults[0].should == @result.elements[2]
62
- @result.elements[2].class.should == HAProxy::Treetop::DefaultsSection
65
+ @result.defaults[0].should == @result.elements[3]
66
+ @result.elements[3].class.should == HAProxy::Treetop::DefaultsSection
63
67
 
64
- @result.listeners[0].should == @result.elements[3]
65
- @result.elements[3].class.should == HAProxy::Treetop::ListenSection
68
+ @result.listeners[0].should == @result.elements[4]
69
+ @result.elements[4].class.should == HAProxy::Treetop::ListenSection
66
70
  end
67
71
 
68
72
  it 'can parse a file with frontend/backend sections' do
@@ -1,12 +1,24 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
- require 'rspec'
4
- require 'haproxy-tools'
3
+
4
+ require 'bundler'
5
+ Bundler.require(:default, :development)
6
+
7
+ require 'haproxy_tools'
5
8
 
6
9
  # Requires supporting files with custom matchers and macros, etc,
7
10
  # in ./support/ and its subdirectories.
8
11
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
12
 
10
13
  RSpec.configure do |config|
11
-
14
+ config.treat_symbols_as_metadata_keys_with_true_values = true
15
+ config.run_all_when_everything_filtered = true
16
+ config.filter_run :focus
17
+
18
+ # Run specs in random order to surface order dependencies. If you find an
19
+ # order dependency and want to debug it, you can fix the order by providing
20
+ # the seed, which is printed after each run.
21
+ # --seed 1234
22
+ config.order = 'random'
23
+
12
24
  end
metadata CHANGED
@@ -1,147 +1,144 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: haproxy-tools
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Jason Wadsworth
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-04-24 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- prerelease: false
11
+ date: 2013-08-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
23
14
  name: net-scp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
24
20
  type: :runtime
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- hash: 3
31
- segments:
32
- - 0
33
- version: "0"
34
- requirement: *id001
35
- - !ruby/object:Gem::Dependency
36
21
  prerelease: false
37
- name: orderedhash
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: treetop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
38
34
  type: :runtime
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
48
- requirement: *id002
49
- - !ruby/object:Gem::Dependency
50
35
  prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
51
56
  name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
52
62
  type: :development
53
- version_requirements: &id003 !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
56
- - - ~>
57
- - !ruby/object:Gem::Version
58
- hash: 19
59
- segments:
60
- - 2
61
- - 7
62
- - 0
63
- version: 2.7.0
64
- requirement: *id003
65
- - !ruby/object:Gem::Dependency
66
63
  prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
67
70
  name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
68
76
  type: :development
69
- version_requirements: &id004 !ruby/object:Gem::Requirement
70
- none: false
71
- requirements:
72
- - - ~>
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- - 7
78
- - 0
79
- version: 0.7.0
80
- requirement: *id004
81
- - !ruby/object:Gem::Dependency
82
77
  prerelease: false
83
- name: jeweler
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
84
90
  type: :development
85
- version_requirements: &id005 !ruby/object:Gem::Requirement
86
- none: false
87
- requirements:
88
- - - ~>
89
- - !ruby/object:Gem::Version
90
- hash: 7
91
- segments:
92
- - 1
93
- - 6
94
- - 4
95
- version: 1.6.4
96
- requirement: *id005
97
- - !ruby/object:Gem::Dependency
98
91
  prerelease: false
99
- name: rcov
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: cane
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
100
104
  type: :development
101
- version_requirements: &id006 !ruby/object:Gem::Requirement
102
- none: false
103
- requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- hash: 3
107
- segments:
108
- - 0
109
- version: "0"
110
- requirement: *id006
111
- - !ruby/object:Gem::Dependency
112
105
  prerelease: false
113
- name: treetop
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-debugger
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
114
118
  type: :development
115
- version_requirements: &id007 !ruby/object:Gem::Requirement
116
- none: false
117
- requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- hash: 3
121
- segments:
122
- - 0
123
- version: "0"
124
- requirement: *id007
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
125
  description: Ruby tools for HAProxy, including config file management.
126
- email: jdwadsworth@gmail.com
126
+ email:
127
+ - jdwadsworth@gmail.com
127
128
  executables: []
128
-
129
129
  extensions: []
130
-
131
- extra_rdoc_files:
132
- - LICENSE.txt
133
- - README.rdoc
134
- - TODO
135
- files:
130
+ extra_rdoc_files: []
131
+ files:
136
132
  - .document
133
+ - .gitignore
137
134
  - .rspec
135
+ - .simplecov
138
136
  - CHANGES.rdoc
139
137
  - Gemfile
140
138
  - LICENSE.txt
141
139
  - README.rdoc
142
140
  - Rakefile
143
141
  - TODO
144
- - VERSION
145
142
  - docs/haproxy-1.3-configuration.txt
146
143
  - docs/haproxy-1.4-configuration.txt
147
144
  - haproxy-tools.gemspec
@@ -151,6 +148,7 @@ files:
151
148
  - lib/haproxy/renderer.rb
152
149
  - lib/haproxy/treetop/config.treetop
153
150
  - lib/haproxy/treetop/nodes.rb
151
+ - lib/haproxy/version.rb
154
152
  - lib/haproxy_tools.rb
155
153
  - spec/fixtures/multi-pool.haproxy.cfg
156
154
  - spec/fixtures/simple.haproxy.cfg
@@ -158,39 +156,34 @@ files:
158
156
  - spec/haproxy/parser_spec.rb
159
157
  - spec/haproxy/treetop/config_parser_spec.rb
160
158
  - spec/spec_helper.rb
161
- has_rdoc: true
162
- homepage: http://github.com/subakva/haproxy-tools
163
- licenses:
164
- - MIT
159
+ homepage: https://github.com/subakva/haproxy-tools
160
+ licenses: []
161
+ metadata: {}
165
162
  post_install_message:
166
163
  rdoc_options: []
167
-
168
- require_paths:
164
+ require_paths:
169
165
  - lib
170
- required_ruby_version: !ruby/object:Gem::Requirement
171
- none: false
172
- requirements:
173
- - - ">="
174
- - !ruby/object:Gem::Version
175
- hash: 3
176
- segments:
177
- - 0
178
- version: "0"
179
- required_rubygems_version: !ruby/object:Gem::Requirement
180
- none: false
181
- requirements:
182
- - - ">="
183
- - !ruby/object:Gem::Version
184
- hash: 3
185
- segments:
186
- - 0
187
- version: "0"
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
188
176
  requirements: []
189
-
190
177
  rubyforge_project:
191
- rubygems_version: 1.4.2
178
+ rubygems_version: 2.0.3
192
179
  signing_key:
193
- specification_version: 3
180
+ specification_version: 4
194
181
  summary: HAProxy Tools for Ruby
195
- test_files: []
196
-
182
+ test_files:
183
+ - spec/fixtures/multi-pool.haproxy.cfg
184
+ - spec/fixtures/simple.haproxy.cfg
185
+ - spec/haproxy/config_spec.rb
186
+ - spec/haproxy/parser_spec.rb
187
+ - spec/haproxy/treetop/config_parser_spec.rb
188
+ - spec/spec_helper.rb
189
+ has_rdoc:
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.0