ensure_ngrok_tunnel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b2931e7c38d85022b0b5815e48da8d78c97fc224f5ebe849d5fbe13d6948c104
4
+ data.tar.gz: 4ce0716280a2584eb065aa79b11def5612107d948b7a684a887ac657bc4e0b31
5
+ SHA512:
6
+ metadata.gz: 79b4fe7d512dd8361afbcf93e43aff0f64ed0d73315d402c52dd94154a499dd6e7d04094278cf651f6adc63bda88305fc04b37af61d2cca3f33e8eb2e256dca2
7
+ data.tar.gz: 370c80d3e42c43913acd13abf1022c04638a583e8728bad90525ab779c85299e60e04d6b81cac272e3327e7a35c58e5b475c6b43e64a4f0e7ee1a194ce962c97
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ensure_ngrok_tunnel.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ensure_ngrok_tunnel (0.1.0)
5
+ json
6
+ rest-client
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ domain_name (0.5.20170404)
12
+ unf (>= 0.0.5, < 1.0.0)
13
+ http-cookie (1.0.3)
14
+ domain_name (~> 0.5)
15
+ json (2.1.0)
16
+ mime-types (3.1)
17
+ mime-types-data (~> 3.2015)
18
+ mime-types-data (3.2016.0521)
19
+ netrc (0.11.0)
20
+ rake (10.4.2)
21
+ rest-client (2.0.2)
22
+ http-cookie (>= 1.0.2, < 2.0)
23
+ mime-types (>= 1.16, < 4.0)
24
+ netrc (~> 0.8)
25
+ unf (0.1.4)
26
+ unf_ext
27
+ unf_ext (0.0.7.5)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 1.16)
34
+ ensure_ngrok_tunnel!
35
+ rake (~> 10.0)
36
+
37
+ BUNDLED WITH
38
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Michael Johnston
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # EnsureNgrokTunnel
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ensure_ngrok_tunnel`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ensure_ngrok_tunnel'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ensure_ngrok_tunnel
22
+
23
+ ## Usage
24
+
25
+ In your development.rb, call `EnsureNgrokTunnel.start` with a [valid ngrok config](https://ngrok.com/docs#config). If you have tunnels defined in your global ngrok config, this could just be `{name: 'name-of-my-tunnel'}`.
26
+
27
+ To determine whether the tunnel already exists, `EnsureNgrokTunnel` just looks for any tunnel bound to the port specified by `addr` in the config, or if not set, in `ENV['PORT']`. If you are using a config that just specifies a tunnel by name, you can optionally pass the port as `port: XXXX`.
28
+
29
+ `EnsureNgrokTunnel` returns the tunnel url.
30
+
31
+ Example:
32
+ ```ruby
33
+ server_port = ENV.fetch('PORT')
34
+ ngrok_url = EnsureNgrokTunnel.start(
35
+ config: {
36
+ name: Rails.application.class.parent.name.underscore,
37
+ addr: server_port,
38
+ proto: 'tls',
39
+ hostname: ENV.fetch('API_DOMAIN'),
40
+ key: Rails.root.join('certificates', 'development-key.pem').to_s,
41
+ crt: Rails.root.join('certificates', 'development-cert.pem').to_s
42
+ },
43
+ port: server_port
44
+ )
45
+
46
+ puts "[NGROK] tunneling at " + ngrok_url
47
+ ```
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/lastobelus/ensure_ngrok_tunnel.
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ensure_ngrok_tunnel"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ensure_ngrok_tunnel/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ensure_ngrok_tunnel"
8
+ spec.version = EnsureNgrokTunnel::VERSION
9
+ spec.authors = ["Michael Johnston"]
10
+ spec.email = ["lastobelus@mac.com"]
11
+
12
+ spec.summary = %q{Ensure an ngrok tunnel is started}
13
+ spec.description = %q{This tiny gem has a singular tunnel: ensure there is an ngrok tunnel running for the specified port.}
14
+ spec.homepage = "https://github.com/lastobelus/ensure_ngrok_tunnel"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+
27
+ spec.add_dependency "rest-client"
28
+ spec.add_dependency "json"
29
+ end
@@ -0,0 +1,3 @@
1
+ module EnsureNgrokTunnel
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,58 @@
1
+ require "ensure_ngrok_tunnel/version"
2
+
3
+ module EnsureNgrokTunnel
4
+ def self.start(config:, port: nil)
5
+ require 'json'
6
+ require 'open-uri'
7
+
8
+ port ||= config['addr'] || config[:addr] || ENV.fetch("PORT")
9
+
10
+ puts "setting up ngrok"
11
+ ngrok_url = false
12
+ ngrok_process = nil
13
+ ngrok = nil
14
+ ngrok_url = 'http://localhost:4040/api/tunnels'
15
+
16
+ begin
17
+ puts "checking ngrok for tunnels"
18
+ ngrok = open(ngrok_url).read
19
+ rescue
20
+ if ngrok_process
21
+ puts "waiting for ngrok..."
22
+ sleep 0.5
23
+ else
24
+ puts "starting ngrok..."
25
+ ngrok_process = spawn('ngrok start --none')
26
+ Process.detach(ngrok_process)
27
+ end
28
+ retry
29
+ end
30
+
31
+ retries = 0
32
+ begin
33
+ ngrok = JSON.parse(ngrok)
34
+ tunnel = ngrok['tunnels'].detect{|t| t['config']['addr'].split(':').last.to_s == port.to_s}
35
+ if tunnel
36
+ ngrok_url = tunnel.fetch('public_url')
37
+ else
38
+ puts "could not find tunnel..."
39
+ raise "not found"
40
+ end
41
+ rescue
42
+ retries += 1
43
+ name = config['name'] || config['hostname'] || config['subdomain'] || ENV.fetch('DOMAIN', '????')
44
+ puts "starting ngrok tunnel for #{name}"
45
+ begin
46
+ response = RestClient.post ngrok_url, config.to_json, {content_type: :json, accept: :json}
47
+ rescue => e
48
+ puts "error starting tunnel: #{e.inspect}\n#{e.response.body.inspect}"
49
+ end
50
+ sleep 0.5
51
+ puts "retrying"
52
+ ngrok = open(ngrok_url).read
53
+ retry unless retries > 5
54
+ end
55
+
56
+ ngrok_url
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ensure_ngrok_tunnel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Johnston
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-22 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: 'This tiny gem has a singular tunnel: ensure there is an ngrok tunnel
70
+ running for the specified port.'
71
+ email:
72
+ - lastobelus@mac.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - ensure_ngrok_tunnel.gemspec
86
+ - lib/ensure_ngrok_tunnel.rb
87
+ - lib/ensure_ngrok_tunnel/version.rb
88
+ homepage: https://github.com/lastobelus/ensure_ngrok_tunnel
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.7.6
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Ensure an ngrok tunnel is started
112
+ test_files: []