vagrant-reverse-proxy 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d2bade0a1a9fa80664838bddeeea6372d6d9270
4
- data.tar.gz: 183513ca7e4df37802e84df2d342f512fc0483fe
3
+ metadata.gz: 26d9391f462c1912d503f0fc872ad82f1171bf26
4
+ data.tar.gz: 31b74fb24938a8ad11f549bf0750900b1ecef175
5
5
  SHA512:
6
- metadata.gz: dec9e1ad3abb232431b6264587f692d710509f6a9403199aaf295fc6a0409fd443f5596d50f35784e414c629ec51e0f65d0d44a7b78c3df712be0071689d1ccf
7
- data.tar.gz: 7cda2ec9d2dd2c264a3c8d57655e943afeaf7ccd212acf67e6caf14881b0e36da07b658ea079297689d82fd2bf43d3eebf0775bbbeea48b0a2d7f8e7caaf5d4b
6
+ metadata.gz: 10f1d65e39fcfd7877ecdaf91a8d47708179eb9e5cd32e2e73be19ca559e749d475f5edebaa87d6a442e9ccd32b52baec142fbdb7ef100b7ad2c46247a006174
7
+ data.tar.gz: ecaec449938977b8555bc5811bac8ac1eba378804119a6809cf75df5775a6d0ff103cdcc9f1c591b2c470ab23d0acf9c83385f02f995113b26cbae6fe8b5aa5f
@@ -2,11 +2,12 @@ module VagrantPlugins
2
2
  module ReverseProxy
3
3
  module Action
4
4
  class WriteNginxConfig
5
- def initialize(app, env)
5
+ def initialize(app, env, action)
6
6
  @app = app
7
7
  @global_env = env[:machine].env
8
8
  @provider = env[:machine].provider_name
9
9
  @config = @global_env.vagrantfile.config
10
+ @action = action
10
11
  end
11
12
 
12
13
  def call(env)
@@ -25,9 +26,28 @@ module VagrantPlugins
25
26
 
26
27
  env[:ui].info('Updating nginx configuration. Administrator privileges will be required...')
27
28
 
28
- File.open(tmp_file, 'w') do |f|
29
- get_machines().each do |m|
30
- f.write(server_block(m))
29
+ machines = get_machines()
30
+ # This code is so stupid
31
+ File.open(nginx_site, 'r') do |old|
32
+ File.open(tmp_file, 'w') do |new|
33
+ sm = machines.map {|m| start_marker(m) }
34
+ em = machines.map {|m| end_marker(m) }
35
+
36
+ while ln = old.gets() do
37
+ if sm.member?(ln.chomp)
38
+ until !ln || em.member?(ln.chomp) do
39
+ ln = old.gets()
40
+ end
41
+ else
42
+ new.puts(ln)
43
+ end
44
+ end
45
+
46
+ if @action == :add
47
+ machines.each do |m|
48
+ new.write(start_marker(m)+"\n"+server_block(m)+end_marker(m)+"\n")
49
+ end
50
+ end
31
51
  end
32
52
  end
33
53
 
@@ -57,14 +77,21 @@ EOF
57
77
  end.join("\n")
58
78
  end
59
79
 
80
+ def start_marker(m)
81
+ "# BEGIN #{m.id} #"
82
+ end
83
+
84
+ def end_marker(m)
85
+ "# END #{m.id} #"
86
+ end
87
+
60
88
  # Machine-finding code stolen from vagrant-hostmanager :)
61
89
  def get_machines()
62
90
  # Collect only machines that exist for the current provider
63
91
  @global_env.active_machines.collect do |name, provider|
64
92
  if provider == @provider
65
93
  begin
66
- m = @global_env.machine(name, @provider)
67
- m.state.id == :running ? m : nil
94
+ @global_env.machine(name, @provider)
68
95
  rescue Vagrant::Errors::MachineNotFound
69
96
  nil #ignore
70
97
  end
@@ -9,15 +9,15 @@ module VagrantPlugins
9
9
  # machine; we always write a complete config with all machines.
10
10
  def self.add_machine
11
11
  Vagrant::Action::Builder.new.tap do |builder|
12
- builder.use ConfigValidate
13
- builder.use WriteNginxConfig
12
+ builder.use(ConfigValidate)
13
+ builder.use(WriteNginxConfig, :add)
14
14
  end
15
15
  end
16
16
 
17
17
  def self.remove_machine
18
18
  Vagrant::Action::Builder.new.tap do |builder|
19
- builder.use ConfigValidate
20
- builder.use WriteNginxConfig
19
+ builder.use(ConfigValidate)
20
+ builder.use(WriteNginxConfig, :remove)
21
21
  end
22
22
  end
23
23
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module ReverseProxy
3
- VERSION = "0.0.4"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-reverse-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bex
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-16 00:00:00.000000000 Z
11
+ date: 2016-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler