typhoon 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: 729c44cc7816f616756d4d25525faedb00465d34fe57c46769555e7b5f55fe76
4
+ data.tar.gz: 2351de94633c2a1df90f981b8543c280df9a5a6fe5609df99bca721ff41ea2d6
5
+ SHA512:
6
+ metadata.gz: e1aac1364a9a9460e36d905fda5ef2eac0b11588ea1e2b8faf58233acfa9c28f5ce70d7d90d9af38f7e89061f2b2e80c027956ad0adfd3e4e85715d66086a321
7
+ data.tar.gz: e4c436987936d4d72ab0270b2c348599d7ec8a77e497b557505e4901598d8c4d66de24be30fa75c25a19030208974574722f36aa4faa3ee591bb372a48c7e37e
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 2.6
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in typhoon.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Gary Tou
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,35 @@
1
+ # Typhoon
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/typhoon`. 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
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add typhoon
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install typhoon
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ https://bundler.io/guides/creating_gem.html
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/typhoon.
32
+
33
+ ## License
34
+
35
+ 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,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: %i[spec]
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typhoon::Cloudflared
4
+ class Configuration
5
+ attr_accessor :tunnel_cert_path
6
+
7
+ def initialize
8
+ @tunnel_cert_path = nil
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mkmf'
4
+ require 'typhoon/concerns/configurable'
5
+ require 'typhoon/cloudflared/configuration'
6
+
7
+ module Typhoon
8
+ module Cloudflared
9
+ include Concerns::Configurable
10
+ configure_with Cloudflared::Configuration
11
+
12
+ class << self
13
+ def run!(command = nil)
14
+ raise MissingCloudflared unless installed?
15
+
16
+ run(command || yeild)
17
+ end
18
+
19
+ def logged_in?
20
+ # TODO
21
+ run!('tunnel login')
22
+ end
23
+
24
+ def version
25
+ @version ||= installed? && run('-v').split[2]
26
+ end
27
+
28
+ def installed?
29
+ @installed ||= !!path && run('-v').start_with?('cloudflared version')
30
+ end
31
+
32
+ def path
33
+ # The `find_executable0` method doesn't polute the stdout with messages
34
+ @path ||= find_executable0 'cloudflared'
35
+ end
36
+
37
+ private
38
+
39
+ def run(command = nil)
40
+ command ||= yeild
41
+ cmd = path
42
+
43
+ # Global options
44
+ cmd += " --credentials-file #{configuration.tunnel_cert_path}" if configuration.tunnel_cert_path
45
+
46
+ `#{cmd} #{command}`.strip
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/concern'
4
+ require 'active_support/inflector'
5
+
6
+ module Typhoon::Concerns
7
+ module Configurable
8
+ extend ActiveSupport::Concern
9
+
10
+ class_methods do
11
+ attr_reader :configurator
12
+ attr_writer :configuration
13
+
14
+ def configuration
15
+ @configuration ||= reset
16
+ end
17
+
18
+ def reset
19
+ @configuration = configurator.new
20
+ end
21
+
22
+ def configure
23
+ yield configuration
24
+ end
25
+
26
+ def configurator
27
+ raise Typhoon::MissingConfigurator unless @configurator
28
+
29
+ @configurator
30
+ end
31
+
32
+ private
33
+
34
+ def configurator=(value)
35
+ @configurator = value
36
+ end
37
+
38
+ def configure_with(value)
39
+ self.configurator = value
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typhoon
4
+ class Configuration
5
+ attr_accessor :default_port
6
+
7
+ def cloudflared_configuration
8
+ ::Typhoon::Cloudflared.configuration
9
+ end
10
+
11
+ def cloudflared_configuration=(value)
12
+ ::Typhoon::Cloudflared.configuration = value
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'typhoon/cloudflared'
4
+ require 'typhoon/configuration'
5
+ require 'socket'
6
+
7
+ module Typhoon
8
+ # This class could really use a better name
9
+ class Typhoon
10
+ include Concerns::Configurable
11
+ configure_with ::Typhoon::Configuration
12
+
13
+ def initialize(name)
14
+ @name = name
15
+ raise NotFound unless self.class.exists? name
16
+ end
17
+
18
+ def self.find(name)
19
+ new(name)
20
+ end
21
+
22
+ def self.list
23
+ out = Cloudflared.run!('tunnel list')
24
+ lines = out.split("\n")
25
+ lines.shift # remove message
26
+ headers = lines.shift.split
27
+
28
+ lines.map do |l|
29
+ id, name, created, conn = l.split
30
+
31
+ conn = conn&.split(',')&.map do |c|
32
+ num, loc = c.split('x')
33
+ { location: loc, quantity: num.to_i }
34
+ end
35
+
36
+ { id: id, name: name, created: created, connections: conn }
37
+ end
38
+ end
39
+
40
+ def self.create(name: nil, hostname:, force: false)
41
+ name ||= hostname.split('.').first
42
+ raise AlreadyExists if exists? name && !force
43
+
44
+ # Create tunnel
45
+ Cloudflared.run!("tunnel create #{name}")
46
+
47
+ # Map DNS name to tunnel
48
+ cmd = "tunnel route dns #{name} #{hostname}"
49
+ cmd += ' -f' if force
50
+ Cloudflared.run!(cmd)
51
+ end
52
+
53
+ def info
54
+ Cloudflared.run!("tunnel info #{@name}")
55
+ end
56
+
57
+ def start(port: nil, hostname: 'localhost')
58
+ port ||= self.class.find_port
59
+ Cloudflared.run!("tunnel run --url #{hostname}:#{port} #{@name}")
60
+ end
61
+
62
+ def delete(force: false)
63
+ cleanup
64
+
65
+ cmd = "tunnel delete #{@name}"
66
+ cmd += ' -f' if force
67
+ Cloudflared.run!(cmd)
68
+
69
+ # The DNS record still lingers. The cloudflared CLI doesn't provide a way
70
+ # to delete it :(
71
+ end
72
+
73
+ def cleanup
74
+ Cloudflared.run! "tunnel cleanup #{@name}"
75
+ end
76
+
77
+ def self.version
78
+ ::Typhoon::VERSION
79
+ end
80
+
81
+ def self.exists?(name)
82
+ list.find { |t| t[:name] == name }
83
+ end
84
+
85
+ private
86
+
87
+ def self.find_port(hostname: 'localhost')
88
+ # TODO: try to find a reasonable open (used) port
89
+ configuration.default_port || 3000
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Typhoon
4
+ VERSION = "0.1.0"
5
+ end
data/lib/typhoon.rb ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'typhoon/version'
4
+ require 'typhoon/typhoon'
5
+ require 'typhoon/concerns/configurable'
6
+ require 'typhoon/configuration'
7
+
8
+ module Typhoon
9
+ class TyphoonError < StandardError; end
10
+
11
+ class AlreadyExists < TyphoonError; end
12
+
13
+ class NotFound < TyphoonError; end
14
+
15
+ class MissingCloudflared < TyphoonError; end
16
+
17
+ class MissingConfigurator < TyphoonError; end
18
+
19
+ (Typhoon.public_methods - Object.public_methods).each do |m|
20
+ # Send all methods to Typhoon class
21
+ define_singleton_method m do |*args, **kwargs, &block|
22
+ Typhoon.send(m, *args, **kwargs, &block)
23
+ end
24
+ end
25
+
26
+ end
data/sig/typhoon.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Typhoon
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/terms.md ADDED
@@ -0,0 +1,20 @@
1
+ # Typhoon-related Terminology
2
+
3
+ - convection
4
+ - cyclone
5
+ - eye
6
+ - gale
7
+ - gust
8
+ - hurricane
9
+ - hurricane season
10
+ - landfall
11
+ - monsoon
12
+ - storm surge
13
+ - surge
14
+ - swell
15
+ - thunderstorm
16
+ - tide
17
+ - vortex
18
+ - weather alert/warning
19
+ - weather watch
20
+ - wind
data/typhoon.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/typhoon/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "typhoon"
7
+ spec.version = Typhoon::VERSION
8
+ spec.authors = ["Gary Tou"]
9
+ spec.email = ["gary@garytou.com"]
10
+
11
+ spec.summary = "An inclement tunnel through the clouds"
12
+ spec.description = "Expose your local development servers with the help of a typhoon (via cloudflared tunnels)"
13
+ spec.homepage = "https://github.com/garyhtou/typhoon"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = spec.homepage
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Dependencies
33
+ spec.add_runtime_dependency "rake", "~> 13.0"
34
+ spec.add_runtime_dependency "activesupport", "~> 7.0"
35
+
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+
38
+ # For more information and examples about making a new gem, check out our
39
+ # guide at: https://bundler.io/guides/creating_gem.html
40
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: typhoon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gary Tou
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '13.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '7.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '7.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Expose your local development servers with the help of a typhoon (via
56
+ cloudflared tunnels)
57
+ email:
58
+ - gary@garytou.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".rspec"
64
+ - ".standard.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/typhoon.rb
70
+ - lib/typhoon/cloudflared.rb
71
+ - lib/typhoon/cloudflared/configuration.rb
72
+ - lib/typhoon/concerns/configurable.rb
73
+ - lib/typhoon/configuration.rb
74
+ - lib/typhoon/typhoon.rb
75
+ - lib/typhoon/version.rb
76
+ - sig/typhoon.rbs
77
+ - terms.md
78
+ - typhoon.gemspec
79
+ homepage: https://github.com/garyhtou/typhoon
80
+ licenses:
81
+ - MIT
82
+ metadata:
83
+ homepage_uri: https://github.com/garyhtou/typhoon
84
+ source_code_uri: https://github.com/garyhtou/typhoon
85
+ changelog_uri: https://github.com/garyhtou/typhoon
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.6.0
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubygems_version: 3.3.7
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: An inclement tunnel through the clouds
105
+ test_files: []