vagrant-dnsmasq 0.0.9 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b75455201bfb6befe1e758adbc39e12fc285499
4
- data.tar.gz: 533a9dba6753b9f00fed10706b995f983e87c57a
3
+ metadata.gz: 32fa6a951824651c68fc45260332a031c5cac985
4
+ data.tar.gz: 1dc26c7cf06d98bd76d5a56713a2abac4242be2e
5
5
  SHA512:
6
- metadata.gz: 7453f930a999bba5635ba38e20175ba4668cbd9bd1e765f229b38678b7741a81ca5b1acebf72d717af931edf525b2d200e614470a6be1ef2d0401150e81f3644
7
- data.tar.gz: ba5e5c725f7f2c3ea2b67602c390c30ac66ca280a2a72d4dd306485f57ce852987302167ee415a4edd045308e04327bb01d03aee684ddd6cc8d1809f0964e999
6
+ metadata.gz: d9abe56b4521cd162621b34c409daa324406bb1619322a050aa1fd5a76a3607fdb417374c11513512bec0edbdaf884dc056c0939c3493718e2ee982eca9c474a
7
+ data.tar.gz: b45905b0a184b75100758da736c46d0e8a220bac5c9e379f9918a1f173e59698da9a104070a481bf48e34b72c1e4e7f65a310c8fb03bdc7a8d4ae4e4adc5640e
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.3
data/.travis.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
- script: "rspec test/*.spec.rb"
4
+ script: "bundle exec rspec test/*.spec.rb"
data/Gemfile.lock CHANGED
@@ -15,31 +15,35 @@ GIT
15
15
  PATH
16
16
  remote: .
17
17
  specs:
18
- vagrant-dnsmasq (0.0.9)
18
+ vagrant-dnsmasq (0.1.1)
19
19
 
20
20
  GEM
21
21
  remote: https://rubygems.org/
22
22
  specs:
23
23
  childprocess (0.3.9)
24
24
  ffi (~> 1.0, >= 1.0.11)
25
- diff-lcs (1.2.4)
25
+ diff-lcs (1.2.5)
26
26
  erubis (2.7.0)
27
- ffi (1.9.0)
28
- i18n (0.6.4)
27
+ ffi (1.9.3)
28
+ i18n (0.6.11)
29
29
  json (1.7.7)
30
30
  log4r (1.1.10)
31
- net-scp (1.1.1)
31
+ net-scp (1.1.2)
32
32
  net-ssh (>= 2.6.5)
33
- net-ssh (2.6.7)
34
- rake (10.1.0)
35
- rspec (2.13.0)
36
- rspec-core (~> 2.13.0)
37
- rspec-expectations (~> 2.13.0)
38
- rspec-mocks (~> 2.13.0)
39
- rspec-core (2.13.1)
40
- rspec-expectations (2.13.0)
41
- diff-lcs (>= 1.1.3, < 2.0)
42
- rspec-mocks (2.13.1)
33
+ net-ssh (2.6.8)
34
+ rake (10.3.2)
35
+ rspec (3.1.0)
36
+ rspec-core (~> 3.1.0)
37
+ rspec-expectations (~> 3.1.0)
38
+ rspec-mocks (~> 3.1.0)
39
+ rspec-core (3.1.4)
40
+ rspec-support (~> 3.1.0)
41
+ rspec-expectations (3.1.1)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.1.0)
44
+ rspec-mocks (3.1.1)
45
+ rspec-support (~> 3.1.0)
46
+ rspec-support (3.1.0)
43
47
 
44
48
  PLATFORMS
45
49
  ruby
data/README.md CHANGED
@@ -48,6 +48,9 @@ config.dnsmasq.domain = '.dev'
48
48
  brew_prefix = `brew --prefix`.strip
49
49
  config.dnsmasq.dnsmasqconf = brew_prefix + '/etc/dnsmasq.conf'
50
50
 
51
+ # command for reloading dnsmasq after config changes
52
+ config.dnsmasq.reload_command = 'sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist; sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist'
53
+
51
54
  # disable dnsmasq handling
52
55
  # config.dnsmasq.disable = true
53
56
  ```
@@ -48,7 +48,7 @@ module Vagrant
48
48
  # use ip to update dnsmasq.conf and /etc/resolver
49
49
 
50
50
  # update dnsmasq.conf
51
- dnsmasq = DnsmasqConf.new(@machine.config.dnsmasq.dnsmasqconf)
51
+ dnsmasq = DnsmasqConf.new(@machine.config.dnsmasq.dnsmasqconf, @machine.config.dnsmasq.reload_command)
52
52
  dnsmasq.insert(@machine.config.dnsmasq.domain, use_ip)
53
53
 
54
54
  # update /etc/resolver
@@ -79,7 +79,7 @@ module Vagrant
79
79
  # remove records from dnsmasq.conf and /etc/resolver
80
80
 
81
81
  # update dnsmasq.conf
82
- dnsmasq = DnsmasqConf.new(@machine.config.dnsmasq.dnsmasqconf)
82
+ dnsmasq = DnsmasqConf.new(@machine.config.dnsmasq.dnsmasqconf, @machine.config.dnsmasq.reload_command)
83
83
  dnsmasq.delete(@machine.config.dnsmasq.domain)
84
84
 
85
85
  # update /etc/resolver
@@ -7,6 +7,7 @@ module Vagrant
7
7
  attr_accessor :resolver
8
8
  attr_accessor :keep_resolver_on_destroy
9
9
  attr_accessor :dnsmasqconf
10
+ attr_accessor :reload_command
10
11
  attr_accessor :disable
11
12
 
12
13
  def initialize
@@ -15,14 +16,22 @@ module Vagrant
15
16
  @resolver = UNSET_VALUE
16
17
  @keep_resolver_on_destroy = UNSET_VALUE
17
18
  @dnsmasqconf = UNSET_VALUE
19
+ @reload_command = UNSET_VALUE
18
20
  @disable = UNSET_VALUE
19
21
  end
20
22
 
21
23
  def finalize!
22
- @domain = nil if @domain == UNSET_VALUE
24
+
25
+ if @domain == UNSET_VALUE
26
+ @domain = nil
27
+ elsif !@domain.is_a?(Domain)
28
+ @domain = Domain.new @domain;
29
+ end
30
+
23
31
  @keep_resolver_on_destroy = false if @keep_resolver_on_destroy == UNSET_VALUE
24
32
  @resolver = '/etc/resolver' if @resolver == UNSET_VALUE
25
33
  @dnsmasqconf = "/etc/dnsmasq.conf" if @dnsmasqconf == UNSET_VALUE
34
+ @reload_command = nil if @reload_command == UNSET_VALUE
26
35
  @disable = false if @disable == UNSET_VALUE
27
36
 
28
37
  # default way to obtain ip address
@@ -1,28 +1,24 @@
1
1
  class DnsmasqConf
2
2
 
3
3
  attr_reader :filename
4
+ attr_reader :reload_command
4
5
 
5
- def initialize(filename)
6
+ def initialize(filename, reload_command)
6
7
  raise ArgumentError, 'wrong filename' if filename.blank?
7
8
  raise IOError unless File.exists? filename
8
9
  @filename = filename
10
+ @reload_command = reload_command
9
11
  end
10
12
 
11
- def self.flush_cache!
12
- begin
13
- # restart dnsmasq (if installed with homebrew)
14
-
15
-
16
- # hmm ... this seems to be useless?!
17
- # puts "You might be asked for your password to restart the dnsmasq daemon."
18
- # system "sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist"
19
- # system "sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist"
20
-
21
-
22
- # @todo: call proc or try other fancy things to reload dnsmasq
23
-
24
- rescue => e
25
- # hmm ... i dont care
13
+ def reload
14
+ if @reload_command
15
+ begin
16
+ # reload dnsmasq config if command specified
17
+ puts "You might be asked for your password to restart the dnsmasq daemon."
18
+ system @reload_command
19
+ rescue => e
20
+ # hmm ... i dont care
21
+ end
26
22
  end
27
23
  end
28
24
 
@@ -34,7 +30,7 @@ class DnsmasqConf
34
30
  File.open(@filename, 'a') { |file|
35
31
  file.write "\naddress=/#{domain.dotted}/#{ip.v4}"
36
32
  }
37
- DnsmasqConf::flush_cache!
33
+ reload
38
34
  end
39
35
  end
40
36
 
@@ -51,7 +47,7 @@ class DnsmasqConf
51
47
  raise ArgumentError, 'invalid domain instance' unless domain.is_a? Domain
52
48
 
53
49
  delete_line_from_file(@filename, Regexp.new("address=/\.#{domain.name}"))
54
- DnsmasqConf::flush_cache!
50
+ reload
55
51
  end
56
52
 
57
53
 
@@ -1,6 +1,6 @@
1
1
  class Domain
2
2
 
3
- MATCH = /^\.?[a-z]*$/
3
+ MATCH = /^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*$/
4
4
 
5
5
  def initialize(name)
6
6
  @name = nil
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module Dnsmasq
3
- VERSION = "0.0.9"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -7,7 +7,7 @@ random = (0...50).map{ ('a'..'z').to_a[rand(26)] }.join
7
7
  describe "At first" do
8
8
  it "should fail if there is no conf file" do
9
9
  expect {
10
- DnsmasqConf.new("/tmp/some-non-existing-file-#{random}-h25hch345b3k5")
10
+ DnsmasqConf.new("/tmp/some-non-existing-file-#{random}-h25hch345b3k5", nil)
11
11
  }.to raise_error IOError
12
12
  end
13
13
  end
@@ -16,7 +16,7 @@ end
16
16
  describe DnsmasqConf do
17
17
  before(:each) do
18
18
  system "touch /tmp/dnsmasq-conf-#{random}"
19
- @dnsm = DnsmasqConf.new("/tmp/dnsmasq-conf-#{random}")
19
+ @dnsm = DnsmasqConf.new("/tmp/dnsmasq-conf-#{random}", nil)
20
20
  @domain = Domain.new('.foobar')
21
21
  @ip = Ip.new('10.10.10.10')
22
22
  end
@@ -5,11 +5,25 @@ describe Domain do
5
5
  it "should return normal domain" do
6
6
  Domain.new('foobar').name.should eq('foobar')
7
7
  Domain.new('.foobar').name.should eq('foobar')
8
+ Domain.new('foo.bar').name.should eq('foo.bar')
9
+ Domain.new('.foo.bar').name.should eq('foo.bar')
10
+ Domain.new('foo8ar').name.should eq('foo8ar')
11
+ Domain.new('.foo8ar').name.should eq('foo8ar')
12
+ Domain.new('foo.8ar').name.should eq('foo.8ar')
13
+ Domain.new('.foo.8ar').name.should eq('foo.8ar')
14
+ Domain.new('foo-bar').name.should eq('foo-bar')
8
15
  end
9
16
 
10
17
  it "should return dotted domain" do
11
18
  Domain.new('foobar').dotted.should eq('.foobar')
12
19
  Domain.new('.foobar').dotted.should eq('.foobar')
20
+ Domain.new('foo.bar').dotted.should eq('.foo.bar')
21
+ Domain.new('.foo.bar').dotted.should eq('.foo.bar')
22
+ Domain.new('foo8ar').dotted.should eq('.foo8ar')
23
+ Domain.new('.foo8ar').dotted.should eq('.foo8ar')
24
+ Domain.new('foo.8ar').dotted.should eq('.foo.8ar')
25
+ Domain.new('.foo.8ar').dotted.should eq('.foo.8ar')
26
+ Domain.new('foo-bar').dotted.should eq('.foo-bar')
13
27
  end
14
28
 
15
29
  it "should return valid domain if domain is passed" do
@@ -17,6 +31,19 @@ describe Domain do
17
31
  Domain.new(Domain.new('.foobar')).name.should eq('foobar')
18
32
  Domain.new(Domain.new('foobar')).dotted.should eq('.foobar')
19
33
  Domain.new(Domain.new('.foobar')).dotted.should eq('.foobar')
34
+ Domain.new(Domain.new('foo.bar')).name.should eq('foo.bar')
35
+ Domain.new(Domain.new('.foo.bar')).name.should eq('foo.bar')
36
+ Domain.new(Domain.new('foo.bar')).dotted.should eq('.foo.bar')
37
+ Domain.new(Domain.new('.foo.bar')).dotted.should eq('.foo.bar')
38
+ Domain.new(Domain.new('foo8ar')).name.should eq('foo8ar')
39
+ Domain.new(Domain.new('.foo8ar')).name.should eq('foo8ar')
40
+ Domain.new(Domain.new('foo8ar')).dotted.should eq('.foo8ar')
41
+ Domain.new(Domain.new('.foo8ar')).dotted.should eq('.foo8ar')
42
+ Domain.new(Domain.new('foo.8ar')).name.should eq('foo.8ar')
43
+ Domain.new(Domain.new('.foo.8ar')).name.should eq('foo.8ar')
44
+ Domain.new(Domain.new('foo.8ar')).dotted.should eq('.foo.8ar')
45
+ Domain.new(Domain.new('.foo.8ar')).dotted.should eq('.foo.8ar')
46
+ Domain.new(Domain.new('foo-bar')).name.should eq('foo-bar')
20
47
  end
21
48
 
22
49
  it "should make the domain lowercase" do
@@ -25,7 +52,15 @@ describe Domain do
25
52
 
26
53
  it "should fail for invalid domains" do
27
54
  expect {
28
- Domain.new('foo1')
55
+ Domain.new('foo*')
56
+ }.to raise_error ArgumentError
57
+
58
+ expect {
59
+ Domain.new('.')
60
+ }.to raise_error ArgumentError
61
+
62
+ expect {
63
+ Domain.new('foo..bar')
29
64
  }.to raise_error ArgumentError
30
65
 
31
66
  expect {
@@ -36,6 +71,10 @@ describe Domain do
36
71
  Domain.new('foo.')
37
72
  }.to raise_error ArgumentError
38
73
 
74
+ expect {
75
+ Domain.new('-foo')
76
+ }.to raise_error ArgumentError
77
+
39
78
  expect {
40
79
  Domain.new('foo-')
41
80
  }.to raise_error ArgumentError
@@ -50,9 +89,12 @@ describe Domain do
50
89
  end
51
90
 
52
91
  it "#valid? should fail for invalid domains" do
53
- Domain::valid?('foo1').should eq(false)
92
+ Domain::valid?('foo*').should eq(false)
93
+ Domain::valid?('.').should eq(false)
94
+ Domain::valid?('foo..bar').should eq(false)
54
95
  Domain::valid?('foo_').should eq(false)
55
96
  Domain::valid?('foo.').should eq(false)
97
+ Domain::valid?('-foo').should eq(false)
56
98
  Domain::valid?('foo-').should eq(false)
57
99
  Domain::valid?('').should eq(false)
58
100
  Domain::valid?(nil).should eq(false)
data/test/Vagrantfile CHANGED
@@ -41,6 +41,9 @@ Vagrant.configure('2') do |config|
41
41
  brew_prefix = `brew --prefix`.strip
42
42
  config.dnsmasq.dnsmasqconf = brew_prefix + '/etc/dnsmasq.conf'
43
43
 
44
+ # specify command to reload dnsmasq
45
+ config.dnsmasq.reload_command = 'sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist; sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist'
46
+
44
47
  # disable dnsmasq handling
45
48
  # config.dnsmasq.disable = true
46
49
 
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-dnsmasq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - mattes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-27 00:00:00.000000000 Z
11
+ date: 2014-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: A Dnsmasq Vagrant plugin that manages the dnsmasq.conf file and /etc/resolver
@@ -60,8 +60,9 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - .gitignore
64
- - .travis.yml
63
+ - ".gitignore"
64
+ - ".ruby-version"
65
+ - ".travis.yml"
65
66
  - Gemfile
66
67
  - Gemfile.lock
67
68
  - LICENSE.txt
@@ -94,17 +95,17 @@ require_paths:
94
95
  - lib
95
96
  required_ruby_version: !ruby/object:Gem::Requirement
96
97
  requirements:
97
- - - '>='
98
+ - - ">="
98
99
  - !ruby/object:Gem::Version
99
100
  version: '0'
100
101
  required_rubygems_version: !ruby/object:Gem::Requirement
101
102
  requirements:
102
- - - '>='
103
+ - - ">="
103
104
  - !ruby/object:Gem::Version
104
105
  version: '0'
105
106
  requirements: []
106
107
  rubyforge_project:
107
- rubygems_version: 2.0.3
108
+ rubygems_version: 2.2.2
108
109
  signing_key:
109
110
  specification_version: 4
110
111
  summary: A Dnsmasq Vagrant plugin that manages the dnsmasq.conf file and /etc/resolver