flaun 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cb30e318296711bb1b206dcb1c07addb2763ade6
4
+ data.tar.gz: eeffd3bb2e90b4cbd2debce8fd18bd6f8546ed57
5
+ SHA512:
6
+ metadata.gz: 6bb7b3dbff5e1affc56c6090422fdb64d5358af27bd858d2e180645abcacccb77fdb7c945754e1163030cebd414b21a184c88d89d2395319879d7656bb127b27
7
+ data.tar.gz: 3dcbeb919eeaf0a4c92b2f0de1d4a140ab5751bc454cb3f9af0133eb24983930a77837a889635c08dc34df650a8cf9db459cf2f9086a619f418667e5138f5d06
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ features/fixture/config.flaun
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flaun.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tomohiko Himura
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.
@@ -0,0 +1,60 @@
1
+ # Flaun
2
+
3
+ TODO 英語で書きなおす。
4
+
5
+ リモートのサーバからブラウザでアクセスすることを再現できます。
6
+ もっと詳しく言うとは ssh でポートフォワード して ブラウザでひらきます。
7
+ アクセス制御したいるが、固定IPがない時に便利かもしれません。
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'flaun'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install flaun
22
+
23
+ ## Usage
24
+
25
+ もし eiel.info というマシンから http://localhost/foo にアクセスしたいとする。
26
+ この情報を `sample` とすると、以下のコマンドでブラウザでひらけるようにします。
27
+
28
+ ```bash
29
+ $ flaun sample
30
+ ```
31
+
32
+ これをできるようにするには `~/.flaun` を作成します。
33
+
34
+ ```ruby
35
+ port 8010
36
+
37
+ target :sample do
38
+ host 'eiel.info'
39
+ path 'foo'
40
+ end
41
+ ```
42
+
43
+ ### 具体的には
44
+
45
+ 以下のコマンドを実行した状態で、
46
+
47
+ ```
48
+ ssh eiel.info -L 8010:eiel.info:80
49
+ ```
50
+
51
+ `http://localhost:8010/foo` へブラウザで表示します。
52
+
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'flaun'
3
+
4
+ Flaun.run *ARGV
File without changes
@@ -0,0 +1,15 @@
1
+ Feature: hoge
2
+
3
+ Scenario: Open remote host
4
+ Given config file:
5
+ """
6
+ port 8010
7
+
8
+ target :sample do
9
+ host 'eiel.info'
10
+ path 'foo'
11
+ end
12
+ """
13
+ Given should open "http://localhost:8010/foo"
14
+ Given should ssh "eiel.info"
15
+ When I run "sample"
@@ -0,0 +1,31 @@
1
+ def filename
2
+ File.join(File.dirname(__FILE__), '..', 'fixture','config.flaun')
3
+ end
4
+
5
+ Given(/^should open "(.*?)"$/) do |uri|
6
+ Launchy.should_receive(:open).with(uri) { puts "open browser #{uri}" }
7
+ end
8
+
9
+ Given(/^should ssh "(.*?)"$/) do |host|
10
+ Net::SSH.should_receive(:start).with(host, ENV['USER']) do |a,b, &block|
11
+ ssh = double
12
+
13
+ h = 'localhost'
14
+ ssh.should_receive(:forward) { ssh }
15
+ ssh.should_receive(:local).with(8010, h, 80) do |port, host, remote|
16
+ puts "local fowarad #{port}:#{host}:#{remote}"
17
+ end
18
+ ssh.should_receive(:loop) { sleep 1 }
19
+
20
+ block.call ssh
21
+ end
22
+ end
23
+
24
+
25
+ When(/^I run "(.*?)"$/) do |target|
26
+ Flaun.start target, filename
27
+ end
28
+
29
+ Given(/^config file:$/) do |string|
30
+ open(filename,'w') { |io| io.write string }
31
+ end
@@ -0,0 +1,4 @@
1
+ require 'bundler/setup'
2
+ require 'pry-byebug'
3
+ require 'cucumber/rspec/doubles'
4
+ require 'flaun'
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'flaun/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "flaun"
8
+ spec.version = Flaun::VERSION
9
+ spec.authors = ["Tomohiko Himura"]
10
+ spec.email = ["eiel.hal@gmail.com"]
11
+ spec.description = %q{launch browser after ssh local forward}
12
+ spec.summary = %q{launchBrowesr after ssh local forward}
13
+ spec.homepage = "https://github.com/eiel/flaun"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "cucumber"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "pry-byebug"
26
+ spec.add_dependency "launchy"
27
+ spec.add_dependency "net-ssh"
28
+ end
@@ -0,0 +1,55 @@
1
+ require 'flaun/version'
2
+ require 'flaun/dsl'
3
+ require 'launchy'
4
+ require 'net/ssh'
5
+
6
+ module Flaun
7
+ extend self
8
+
9
+ def run(*argv)
10
+ Thread.abort_on_exception = true
11
+ thread = Thread.new do
12
+ start *argv
13
+ end
14
+
15
+ loop do
16
+ puts 'quit? (y/N)'
17
+ break if $stdin.gets.chomp == 'y'
18
+ end
19
+ thread.kill
20
+ end
21
+
22
+ def config_load(text, filename)
23
+ dsl = Flaun::DSL.new
24
+ dsl.instance_eval text, filename
25
+ dsl.config
26
+ end
27
+
28
+ def start(target_name = nil, config_file = nil)
29
+ config_file ||= Pathname.new("~/.flaun").expand_path.to_s
30
+ unless File.exist? config_file
31
+ $stderr.puts 'Plaese, create file ~/.flaun'
32
+ exit 1
33
+ end
34
+ config = config_load(open(config_file).read, config_file)
35
+
36
+ if target_name.nil?
37
+ $stderr.puts 'select target:'
38
+ puts config.targets.keys
39
+ exit 1
40
+ end
41
+
42
+ target = config[target_name.to_sym]
43
+
44
+ Net::SSH.start(target.host, target.user ) do |ssh|
45
+ ssh.forward.local(
46
+ target.forward_port,
47
+ target.forward_host,
48
+ target.forward_host_port)
49
+
50
+ Launchy.open( target.access_url )
51
+
52
+ ssh.loop { true }
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,39 @@
1
+ module Flaun
2
+ class Config
3
+ attr_accessor :port, :targets
4
+
5
+ def initialize
6
+ @targets = {}
7
+ @port = 3000
8
+ end
9
+
10
+ def [](name)
11
+ @targets[name]
12
+ end
13
+ end
14
+
15
+ class TargetConfig
16
+ attr_accessor :forward_host_port, :host, :path
17
+
18
+ def initialize(config)
19
+ @config = config
20
+ @forward_host_port = 80
21
+ end
22
+
23
+ def user
24
+ ENV['USER']
25
+ end
26
+
27
+ def forward_port
28
+ @config.port
29
+ end
30
+
31
+ def forward_host
32
+ 'localhost'
33
+ end
34
+
35
+ def access_url
36
+ "http://localhost:#{@config.port}/#{path}"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,41 @@
1
+ require 'flaun/config'
2
+
3
+ module Flaun
4
+ class DSL < BasicObject
5
+ attr_reader :config
6
+
7
+ def initialize
8
+ @config = ::Flaun::Config.new
9
+ end
10
+
11
+ def port(port)
12
+ @config.port = port
13
+ end
14
+
15
+ def target(name, &block)
16
+ target = DSLTarget.new(@config)
17
+ target.instance_exec &block
18
+ @config.targets[name] = target.config
19
+ end
20
+ end
21
+
22
+ class DSLTarget < BasicObject
23
+ attr_reader :config
24
+
25
+ def initialize(config)
26
+ @config = ::Flaun::TargetConfig.new(config)
27
+ end
28
+
29
+ def port(port)
30
+ @config.forward_host_port = port
31
+ end
32
+
33
+ def host(host)
34
+ @config.host = host
35
+ end
36
+
37
+ def path(path)
38
+ @config.path = path
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module Flaun
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flaun
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tomohiko Himura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-09 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cucumber
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: launchy
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: net-ssh
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: launch browser after ssh local forward
112
+ email:
113
+ - eiel.hal@gmail.com
114
+ executables:
115
+ - flaun
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bin/flaun
125
+ - features/fixture/.keep
126
+ - features/flaun.feature
127
+ - features/step_definit/flaun_steps.rb
128
+ - features/support/env.rb
129
+ - flaun.gemspec
130
+ - lib/flaun.rb
131
+ - lib/flaun/config.rb
132
+ - lib/flaun/dsl.rb
133
+ - lib/flaun/version.rb
134
+ homepage: https://github.com/eiel/flaun
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.0.3
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: launchBrowesr after ssh local forward
158
+ test_files:
159
+ - features/fixture/.keep
160
+ - features/flaun.feature
161
+ - features/step_definit/flaun_steps.rb
162
+ - features/support/env.rb
163
+ has_rdoc: