vagrant-foodshow 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +10 -0
- data/MIT-LICENSE +22 -0
- data/README.md +123 -0
- data/Rakefile +1 -0
- data/lib/vagrant-foodshow/action/start.rb +50 -0
- data/lib/vagrant-foodshow/action/stop.rb +30 -0
- data/lib/vagrant-foodshow/config.rb +97 -0
- data/lib/vagrant-foodshow/plugin.rb +36 -0
- data/lib/vagrant-foodshow/util/ngrok.rb +94 -0
- data/lib/vagrant-foodshow/util/ngrok_config.rb +46 -0
- data/lib/vagrant-foodshow/version.rb +5 -0
- data/lib/vagrant-foodshow.rb +6 -0
- data/vagrant-foodshow.gemspec +24 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 88f6cec9d2f7c57b8a2e92e0bec90135fab7e9a1
|
4
|
+
data.tar.gz: 30e62916d8ec460e30e4cdb16b7dd0752be5cc54
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 374c1b799cc844e393271ac642e34f64dbe48faeb8c3bf4e23d313eeda4f4e45f030e760386e5784eba77bb963e54c323d93de3fbc8dd761fcea8a804c6410df
|
7
|
+
data.tar.gz: 5098467446f496b68312946dc81d077b1ca768c7331cc75ec33246bf6d777e88e0dfb47835d51ae6f359fdb0c79a144d52baa5f4099e62ef5291fa7085e4a31e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Nikita Borzykh
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# Foodshow: Share your [Vagrant](http://vagrantup.com) virtual machine
|
2
|
+
|
3
|
+
Vagrant-Foodshow plugin allows you to share tcp ports of your virtual machine via the Internet.
|
4
|
+
|
5
|
+
With Vagrant You may show your web application to your colleague, present new feature for your customer and give ssh access to your ops guy.
|
6
|
+
|
7
|
+
All tunneling job performed by [Ngrok](http://ngrok.com) backend.
|
8
|
+
Ngrok tunnel operates in TCP and HTTP mode. In HTTP tunnel mode ngrok provides access to HTTP requests and server answers, so you can analyze your traffic. TCP mode allows you tunnel any binary protocol like a `ssh` or `postgresql` or whatever you want, but there is no introspection in TCP tunnel.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
To install this plugin just execute:
|
13
|
+
|
14
|
+
```bash
|
15
|
+
vagrant plugin install vagrant-foodshow
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage&Configuration
|
19
|
+
|
20
|
+
First of all you should enable plugin in your `Vagrantfile`:
|
21
|
+
```ruby
|
22
|
+
config.foodshow.enabled = true
|
23
|
+
```
|
24
|
+
|
25
|
+
### There are two ways to create a tunnel
|
26
|
+
|
27
|
+
##### Call method `foodshow.tunnel` :
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
...
|
31
|
+
config.foodshow.tunnel <host_port>, <protocol>, [options hash]
|
32
|
+
...
|
33
|
+
```
|
34
|
+
|
35
|
+
##### Add `ngrok_proto` parameter to `vm.network` :
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
...
|
39
|
+
config.vm.network :forwarded_port, guest: <guest_port>, host: <host_port>, ngrok_proto: "<protocol>"
|
40
|
+
...
|
41
|
+
```
|
42
|
+
|
43
|
+
Default tunnel protocol is `http+https`. Ngrok supports `http`, `https`, `http+https` and `tcp`. For tcp protocol authtoken is required.
|
44
|
+
|
45
|
+
### Simple tunnel example
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
Vagrant.configure("2") do |config|
|
49
|
+
#Enable foodshow
|
50
|
+
config.foodshow.enabled = true
|
51
|
+
...
|
52
|
+
# Define vm
|
53
|
+
config.vm.define :web01 do |conf|
|
54
|
+
...
|
55
|
+
#Just add ngrok_proto parameter to your port forwarding entry
|
56
|
+
conf.vm.network :forwarded_port, guest: 80, host: 8080, ngrok_proto: "http+https"
|
57
|
+
...
|
58
|
+
end
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
### Advanced tunnel example
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
Vagrant.configure("2") do |config|
|
66
|
+
#Enable foodshow
|
67
|
+
config.foodshow.enabled = true
|
68
|
+
config.foodshow.forward_ssh = true
|
69
|
+
...
|
70
|
+
# Define vms
|
71
|
+
config.vm.define :web01 do |conf|
|
72
|
+
...
|
73
|
+
conf.vm.network :forwarded_port, guest: 80, host: 8080, ngrok_proto: "http+https"
|
74
|
+
# Don't tunnel ssh for this vm
|
75
|
+
config.foodshow.forward_ssh = false
|
76
|
+
# For this vm we use another token
|
77
|
+
conf.foodshow.authtoken = <sometoken_2>
|
78
|
+
...
|
79
|
+
end
|
80
|
+
config.vm.define :web02 do |conf|
|
81
|
+
...
|
82
|
+
conf.vm.network :forwarded_port, guest: 80, host: 8081
|
83
|
+
conf.vm.network :forwarded_port, guest: 389, host: 3389
|
84
|
+
# You may pass some params as tunnel options
|
85
|
+
# This code creates a tunnel http://mycopmanyllc.ngrok.com with basic auth
|
86
|
+
conf.foodshow.tunnel 8081, "http", :httpauth => "foodshow:ngrok" :subdomain => "mycopmanyllc"
|
87
|
+
# And sure you may tunnel any tcp port
|
88
|
+
conf.foodshow.tunnel 3389, "tcp"
|
89
|
+
...
|
90
|
+
end
|
91
|
+
end
|
92
|
+
```
|
93
|
+
### Options
|
94
|
+
|
95
|
+
- Scope *config* means that this option can be set only via `foodshow.<options>`
|
96
|
+
- Scope *config+tunnel* means that this option can be set via `foodshow.<options>` and can be can be passed to the `foodshow.tunnel` method as options hash.
|
97
|
+
- Scope *tunnel* means that this option can be passed to the `foodshow.tunnel` method
|
98
|
+
|
99
|
+
Option | Default | Scope | Purpose
|
100
|
+
-------|---------|---------|--------
|
101
|
+
`enabled` | `false` | config | Enable foodshow plugin
|
102
|
+
`ngrok_bin` | `~/bin/ngrok` | config+tunnel | Ngrok binary location (you should put a binary file at this location)
|
103
|
+
`forward_ssh` | `false` | config | Automatically search and forward vagrant ssh guest port (authtoken required)
|
104
|
+
`timeout` | `10` | config | Max waiting time for establishing tunnel
|
105
|
+
`authtoken` | `nil` | config+tunnel | Auth token. Required for TCP tunnels and some functions (Go to [ngrok.com](http://ngrok.com) to get authkey)
|
106
|
+
`httpauth` | `nil` | config+tunnel | You may set basic auth for http/https tunnel. Format: `user:password`
|
107
|
+
`subdomain` | `nil` | config+tunnel | Custom subdomain for http/https tunnel. URL will be like a http://\<subdomain\>.ngrok.com
|
108
|
+
`hostname` | `nil` | config+tunnel | Custom domain for http/https tunnel (Paid feature, see [Pricing & Features](http://ngrok.com/features) on ngrok website )
|
109
|
+
`host_ip` | `127.0.0.1` | tunnel | Custom destination ip for tunnel
|
110
|
+
`inspect_addr` | `127.0.0.1` | config | Address for traffic inspection
|
111
|
+
`inspect_pbase` | `4040` | config | Base port for traffic inspection, other ngrok processes will use the next available port
|
112
|
+
|
113
|
+
# Authors
|
114
|
+
|
115
|
+
* Nikita Borzykh (<sample.n@gmail.com>)
|
116
|
+
|
117
|
+
## Contributing
|
118
|
+
|
119
|
+
1. Fork it ( http://github.com/express42/vagrant-foodshow/fork )
|
120
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
121
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
122
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
123
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Foodshow
|
3
|
+
module Action
|
4
|
+
class Start
|
5
|
+
def initialize(app,env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
@app.call(env)
|
11
|
+
|
12
|
+
return unless env[:machine].config.foodshow.enabled?
|
13
|
+
env[:machine].config.vm.networks.each do |network|
|
14
|
+
if network[0] == :forwarded_port
|
15
|
+
if network[1][:ngrok_proto] or (network[1][:id] == "ssh" && env[:machine].config.foodshow.forward_ssh?)
|
16
|
+
|
17
|
+
if network[1][:id] == "ssh"
|
18
|
+
network[1][:ngrok_proto] = "tcp"
|
19
|
+
end
|
20
|
+
|
21
|
+
if network[1][:protocol] != "tcp"
|
22
|
+
env[:ui].error "Can't tunnel port #{network[1][:host]}, only tcp protocol supported. Skipping."
|
23
|
+
next
|
24
|
+
end
|
25
|
+
|
26
|
+
env[:machine].config.foodshow.tunnel(
|
27
|
+
network[1][:host],
|
28
|
+
network[1][:ngrok_proto],
|
29
|
+
:host => network[1][:host_ip] || "127.0.0.1",
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
env[:machine].config.foodshow.tunnels.each do |tunnel|
|
35
|
+
status, message, debug_output = VagrantPlugins::Foodshow::Util::Ngrok.start(env, tunnel)
|
36
|
+
|
37
|
+
if status == 0
|
38
|
+
env[:ui].success "Tunnel from " + message + " to " + tunnel[:host] + ":" + tunnel[:port].to_s
|
39
|
+
elsif status == 1
|
40
|
+
env[:ui].error "Ngrok failed: " + message
|
41
|
+
elsif status == -1
|
42
|
+
env[:ui].error message
|
43
|
+
env[:ui].error "Ngrok output: " + debug_output.join()
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Foodshow
|
3
|
+
module Action
|
4
|
+
class Stop
|
5
|
+
def initialize(app,env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
|
11
|
+
Dir.glob("#{env[:tmp_path] || '/tmp'}/ngrok-#{env[:machine].id}-*.pid") do |pid_file|
|
12
|
+
::File.open(pid_file, "r") do |f|
|
13
|
+
begin
|
14
|
+
pid = f.readline().to_i
|
15
|
+
::Process.kill("TERM",pid)
|
16
|
+
::File.delete(pid_file)
|
17
|
+
rescue Errno::ESRCH
|
18
|
+
::File.delete(pid_file)
|
19
|
+
ensure
|
20
|
+
env[:ui].info("ngrok terminated")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
@app.call(env)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Foodshow
|
3
|
+
class Config < Vagrant.plugin(2, :config)
|
4
|
+
|
5
|
+
attr_accessor :timeout
|
6
|
+
attr_accessor :enabled
|
7
|
+
attr_accessor :forward_ssh
|
8
|
+
|
9
|
+
attr_accessor :authtoken
|
10
|
+
attr_accessor :hostname
|
11
|
+
attr_accessor :httpauth
|
12
|
+
attr_accessor :subdomain
|
13
|
+
attr_accessor :inspect_addr
|
14
|
+
attr_accessor :inspect_pbase
|
15
|
+
|
16
|
+
attr_reader :tunnels
|
17
|
+
attr_reader :ngrok_bin
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@forward_ssh = UNSET_VALUE
|
21
|
+
@enabled = UNSET_VALUE
|
22
|
+
@timeout = UNSET_VALUE
|
23
|
+
@ngrok_bin = UNSET_VALUE
|
24
|
+
@inspect_addr = UNSET_VALUE
|
25
|
+
@inspect_port = UNSET_VALUE
|
26
|
+
@tunnels = []
|
27
|
+
|
28
|
+
#ngrok params
|
29
|
+
@authtoken = UNSET_VALUE
|
30
|
+
@hostname = UNSET_VALUE
|
31
|
+
@httpauth = UNSET_VALUE
|
32
|
+
@subdomain = UNSET_VALUE
|
33
|
+
end
|
34
|
+
|
35
|
+
def tunnel(port, proto = "http+https", options={})
|
36
|
+
host_hash = {:host => options[:host] || "127.0.0.1"}
|
37
|
+
@tunnels << options.merge(:port => port).merge( :proto => proto).merge(host_hash)
|
38
|
+
end
|
39
|
+
|
40
|
+
def forward_ssh?
|
41
|
+
@forward_ssh
|
42
|
+
end
|
43
|
+
|
44
|
+
def enabled?
|
45
|
+
@enabled
|
46
|
+
end
|
47
|
+
|
48
|
+
def ngrok_bin=(path)
|
49
|
+
@ngrok_bin = ::File.expand_path(path)
|
50
|
+
end
|
51
|
+
|
52
|
+
def validate(machine)
|
53
|
+
errors = _detected_errors
|
54
|
+
unless ::File.executable? @ngrok_bin
|
55
|
+
errors << "You must put ngrok binary to #{@ngrok_bin}.\n"\
|
56
|
+
" Go to http://ngrok.com and download ngrok binary.\n"\
|
57
|
+
" You can change binary location by changing option foodshow.ngrok_bin.\n\n"\
|
58
|
+
" EXAMPLE. Download and unpack ngrok to ~/bin on Mac OS x86_64:\n"\
|
59
|
+
" curl -O https://dl.ngrok.com/darwin_amd64/ngrok.zip && unzip ngrok.zip && mkdir -p ~/bin && mv ngrok ~/bin\n\n"\
|
60
|
+
" You can read docs at http://github.com/express42/vagrant-foodshow\n"
|
61
|
+
end
|
62
|
+
|
63
|
+
unless @authtoken
|
64
|
+
if @subdomain || @forward_ssh || @hostname
|
65
|
+
errors << "You should set authtoken if you use subdomain/forward_ssh/hostname options"
|
66
|
+
end
|
67
|
+
|
68
|
+
@tunnels.each do |tunnel|
|
69
|
+
|
70
|
+
unless tunnel[:authtoken]
|
71
|
+
if tunnel[:hostname] || tunnel[:subdomain] || tunnel[:proto] == "tcp"
|
72
|
+
errors << "You should set authtoken if you call foodshow.tunnel with subdomain/hostname/proto=tcp options"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
{ "foodshow" => errors }
|
80
|
+
end
|
81
|
+
|
82
|
+
def finalize!
|
83
|
+
@ngrok_bin = ::File.expand_path('~/bin/ngrok') if @ngrok_bin == UNSET_VALUE
|
84
|
+
|
85
|
+
@enabled = false if @enabled == UNSET_VALUE
|
86
|
+
@forward_ssh = false if @forward_ssh == UNSET_VALUE
|
87
|
+
@timeout = 10 if @timeout == UNSET_VALUE
|
88
|
+
@authtoken = nil if @authtoken == UNSET_VALUE
|
89
|
+
@hostname = nil if @hostname == UNSET_VALUE
|
90
|
+
@httpauth = nil if @httpauth == UNSET_VALUE
|
91
|
+
@subdomain = nil if @subdomain == UNSET_VALUE
|
92
|
+
@inspect_addr = "127.0.0.1" if @inspect_addr == UNSET_VALUE
|
93
|
+
@inspect_pbase = 4040 if @inspect_port == UNSET_VALUE
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "vagrant-foodshow/action/start.rb"
|
2
|
+
require "vagrant-foodshow/action/stop.rb"
|
3
|
+
require "vagrant-foodshow/util/ngrok.rb"
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module Foodshow
|
7
|
+
class Plugin < Vagrant.plugin("2")
|
8
|
+
name "foodshow"
|
9
|
+
config 'foodshow' do
|
10
|
+
require_relative "config"
|
11
|
+
Config
|
12
|
+
end
|
13
|
+
action_hook :ngrok_start_handler, :machine_action_up do |hook|
|
14
|
+
hook.append(Action::Start)
|
15
|
+
end
|
16
|
+
|
17
|
+
action_hook :ngrok_start_handler, :machine_action_halt do |hook|
|
18
|
+
hook.prepend(Action::Stop)
|
19
|
+
end
|
20
|
+
|
21
|
+
action_hook :ngrok_start_handler, :machine_action_reload do |hook|
|
22
|
+
hook.prepend(Action::Stop)
|
23
|
+
hook.append(Action::Start)
|
24
|
+
end
|
25
|
+
|
26
|
+
action_hook :ngrok_start_handler, :machine_action_suspend do |hook|
|
27
|
+
hook.prepend(Action::Stop)
|
28
|
+
end
|
29
|
+
|
30
|
+
action_hook :ngrok_start_handler, :machine_action_resume do |hook|
|
31
|
+
hook.append(Action::Start)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'timeout'
|
3
|
+
require "vagrant-foodshow/util/ngrok_config.rb"
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module Foodshow
|
7
|
+
module Util
|
8
|
+
class Ngrok
|
9
|
+
def self.start(env, tunnel)
|
10
|
+
if defined?(@@counter)
|
11
|
+
@@counter += 1
|
12
|
+
else
|
13
|
+
@@counter = 0
|
14
|
+
end
|
15
|
+
|
16
|
+
config = VagrantPlugins::Foodshow::Util::NgrokConfig.merge_config(env, tunnel)
|
17
|
+
timeout = config.delete(:timeout)
|
18
|
+
log_file = config.delete(:log_file)
|
19
|
+
pid_file = config.delete(:pid_file)
|
20
|
+
inspect_addr = config.delete(:inspect_addr)
|
21
|
+
authtoken = config.delete(:authtoken)
|
22
|
+
inspect_pbase = config.delete(:inspect_pbase)
|
23
|
+
config_file = config[:config]
|
24
|
+
|
25
|
+
cmd = VagrantPlugins::Foodshow::Util::NgrokConfig.build_cmd(config)
|
26
|
+
|
27
|
+
begin
|
28
|
+
current_pid=-1
|
29
|
+
::File.open(pid_file) { |pid| current_pid = pid.readline(); }
|
30
|
+
Process.getpgid(current_pid.to_i)
|
31
|
+
return 0, "Ngrok already running at pid #{current_pid}. Skipping tunnel", ""
|
32
|
+
rescue
|
33
|
+
end
|
34
|
+
|
35
|
+
::File.open(config_file, "w") do |conf_h|
|
36
|
+
|
37
|
+
conf_h.write("inspect_addr: #{inspect_addr.to_s}:#{inspect_pbase.to_i + @@counter}\n")
|
38
|
+
|
39
|
+
if authtoken
|
40
|
+
conf_h.write("auth_token: #{authtoken}\n")
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
pid = spawn(cmd, :out => log_file.to_s)
|
46
|
+
|
47
|
+
::File.open(pid_file, "w") { |pid_h| pid_h.write(pid) }
|
48
|
+
|
49
|
+
log_h = ::File.open(log_file, "r")
|
50
|
+
status, message, debug_output = parse_log(log_h, timeout)
|
51
|
+
log_h.close
|
52
|
+
|
53
|
+
unless status == 0
|
54
|
+
begin
|
55
|
+
::File.delete(pid_file)
|
56
|
+
::Process.kill("TERM", pid)
|
57
|
+
rescue
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
return status, message, debug_output
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def self.parse_log(log_h, timeout)
|
67
|
+
debug_output = []
|
68
|
+
begin
|
69
|
+
timeout(timeout.to_i) do
|
70
|
+
while true do
|
71
|
+
begin
|
72
|
+
stdout_str = log_h.readline()
|
73
|
+
rescue
|
74
|
+
next
|
75
|
+
end
|
76
|
+
debug_output << stdout_str
|
77
|
+
|
78
|
+
if stdout_str.include? "[INFO] [client] Tunnel established at"
|
79
|
+
return 0, stdout_str[/(http\:\/\/|https\:\/\/|tcp\:\/\/).+/], debug_output
|
80
|
+
end
|
81
|
+
|
82
|
+
if stdout_str.include? "[EROR]"
|
83
|
+
return 1, stdout_str, debug_output
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
rescue ::Timeout::Error
|
88
|
+
return -1, "Ngrok wait timeout. See ngrok output:", debug_output
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Foodshow
|
3
|
+
module Util
|
4
|
+
class NgrokConfig
|
5
|
+
NGROK_ALLOWED_OPTIONS = %w(authtoken hostname httpauth proto subdomain host port)
|
6
|
+
|
7
|
+
def self.build_cmd(config)
|
8
|
+
cmd = config.delete(:ngrok_bin) + " -log=stdout"
|
9
|
+
host = config.delete(:host)
|
10
|
+
port = config.delete(:port)
|
11
|
+
|
12
|
+
config.each_pair do |opt, val|
|
13
|
+
cmd = cmd + " -" + opt.to_s + "=" + val.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
cmd = cmd + " " + host + ":" + port.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.merge_config(env, tunnel)
|
20
|
+
config = {}
|
21
|
+
foodshow_config = env[:machine].config.foodshow
|
22
|
+
|
23
|
+
config[:ngrok_bin] = foodshow_config.ngrok_bin if foodshow_config.ngrok_bin
|
24
|
+
config[:timeout] = foodshow_config.timeout if foodshow_config.timeout
|
25
|
+
|
26
|
+
config[:authtoken] = foodshow_config.authtoken if foodshow_config.authtoken
|
27
|
+
config[:hostname] = foodshow_config.hostname if foodshow_config.hostname
|
28
|
+
config[:httpauth] = foodshow_config.httpauth if foodshow_config.httpauth
|
29
|
+
config[:subdomain] = foodshow_config.subdomain if foodshow_config.subdomain
|
30
|
+
config[:inspect_addr] = foodshow_config.inspect_addr if foodshow_config.inspect_addr
|
31
|
+
config[:inspect_pbase] = foodshow_config.inspect_pbase if foodshow_config.inspect_pbase
|
32
|
+
|
33
|
+
tunnel.keys.each do |key|
|
34
|
+
raise unless NGROK_ALLOWED_OPTIONS.include? key.to_s
|
35
|
+
end
|
36
|
+
config.merge!(tunnel)
|
37
|
+
|
38
|
+
config[:config] = (env[:tmp_path] || "/tmp") + ("ngrok-" + env[:machine].id + "-" + config[:port].to_s + ".cfg")
|
39
|
+
config[:log_file] = (env[:tmp_path] || "/tmp") + ("ngrok-" + env[:machine].id + "-" + config[:port].to_s + ".log")
|
40
|
+
config[:pid_file] = (env[:tmp_path] || "/tmp") + ("ngrok-" + env[:machine].id + "-" + config[:port].to_s + ".pid")
|
41
|
+
config
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant-foodshow/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vagrant-foodshow"
|
8
|
+
spec.version = Vagrant::Foodshow::VERSION
|
9
|
+
spec.authors = ["Nikita Borzykh"]
|
10
|
+
spec.email = ["sample.n@gmail.com"]
|
11
|
+
spec.summary = %q{You can share your vagrant vm with your colleagues easily by using vagrant-foodshow}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/express42/vagrant-foodshow"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.rubyforge_project = "vagrant-foodshow"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-foodshow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nikita Borzykh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
description: You can share your vagrant vm with your colleagues easily by using vagrant-foodshow
|
28
|
+
email:
|
29
|
+
- sample.n@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- Gemfile
|
36
|
+
- MIT-LICENSE
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- lib/vagrant-foodshow.rb
|
40
|
+
- lib/vagrant-foodshow/action/start.rb
|
41
|
+
- lib/vagrant-foodshow/action/stop.rb
|
42
|
+
- lib/vagrant-foodshow/config.rb
|
43
|
+
- lib/vagrant-foodshow/plugin.rb
|
44
|
+
- lib/vagrant-foodshow/util/ngrok.rb
|
45
|
+
- lib/vagrant-foodshow/util/ngrok_config.rb
|
46
|
+
- lib/vagrant-foodshow/version.rb
|
47
|
+
- vagrant-foodshow.gemspec
|
48
|
+
homepage: https://github.com/express42/vagrant-foodshow
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project: vagrant-foodshow
|
68
|
+
rubygems_version: 2.2.1
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: You can share your vagrant vm with your colleagues easily by using vagrant-foodshow
|
72
|
+
test_files: []
|