superbot-teleport 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: 4cf993d114e2d4d467b2b14447bc00703fec337a3a3ed31493b276b9b497c8b0
4
- data.tar.gz: a5d01bc4e1ff057bdbabf44fe7f8442a179c51f39f1f52c1a8846a6461910ba8
3
+ metadata.gz: 2146506a6dfde333feb61b80b669a6d9119dd34c2462a7ac0ce0b684caf20987
4
+ data.tar.gz: 8b8feba60bdd91ccde2400260e8107e202ee3f41cb443b00f5bb62b88929ed21
5
5
  SHA512:
6
- metadata.gz: 0f05f544ed9c7b1953f287473deb3abe8d1946431cf148ea44f3c609d831c8da8307fd7fa8ae679c3ac7ce8c15fa38590e179090fb9a3f4b8019a6de8fc2704e
7
- data.tar.gz: 19be38e67e0bd137c11eeb887a521dd6ed5043e4087bad4ae5270c8be7055361b99ce2591578ef7b424bba4994ded339f114a9a6da01ce7ffbc4a7d7f66cf0af
6
+ metadata.gz: 0acda86612cd0aadd76051dbc94f7a042d4086eab42c3aaa954ce5c0bc16c51d14ed308af6428cc9ed85f73318302d81e10d56278bedf84d2ad7542b3a1b71d1
7
+ data.tar.gz: ee0c93403ff476339197e1c5f6a11aefc100d88c2ea74e616d48a16373b312cdfb0de5fac6e4c913d94d1e933b03c22ff626a2c117867bb0f17f75f81d18479d
@@ -1,13 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superbot-teleport (0.2.0)
4
+ superbot-teleport (0.2.1)
5
5
  excon
6
- sinatra
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
10
9
  specs:
10
+ addressable (2.5.2)
11
+ public_suffix (>= 2.0.2, < 4.0)
11
12
  archive-zip (0.11.0)
12
13
  io-like (~> 0.3.0)
13
14
  childprocess (0.9.0)
@@ -15,53 +16,32 @@ GEM
15
16
  chromedriver-helper (2.1.0)
16
17
  archive-zip (~> 0.10)
17
18
  nokogiri (~> 1.8)
19
+ clamp (1.2.1)
18
20
  coderay (1.1.2)
19
21
  diff-lcs (1.3)
20
22
  excon (0.62.0)
21
23
  ffi (1.9.25)
22
- formatador (0.2.5)
23
- guard (2.15.0)
24
- formatador (>= 0.2.4)
25
- listen (>= 2.7, < 4.0)
26
- lumberjack (>= 1.0.12, < 2.0)
27
- nenv (~> 0.1)
28
- notiffany (~> 0.0)
29
- pry (>= 0.9.12)
30
- shellany (~> 0.0)
31
- thor (>= 0.18.1)
32
- guard-bundler (2.1.0)
33
- bundler (~> 1.0)
34
- guard (~> 2.2)
35
- guard-compat (~> 1.1)
36
- guard-compat (1.2.1)
37
- guard-process (1.2.1)
38
- guard-compat (~> 1.2, >= 1.2.1)
39
- spoon (~> 0.0.1)
40
24
  io-like (0.3.0)
41
- listen (3.1.5)
42
- rb-fsevent (~> 0.9, >= 0.9.4)
43
- rb-inotify (~> 0.9, >= 0.9.7)
44
- ruby_dep (~> 1.2)
45
- lumberjack (1.0.13)
25
+ kommando (0.1.2)
26
+ launchy (2.4.3)
27
+ addressable (~> 2.3)
28
+ marcel (0.3.3)
29
+ mimemagic (~> 0.3.2)
46
30
  method_source (0.9.2)
31
+ mimemagic (0.3.2)
47
32
  mini_portile2 (2.3.0)
33
+ multipart-post (2.0.0)
48
34
  mustermann (1.0.3)
49
- nenv (0.3.0)
50
35
  nokogiri (1.8.5)
51
36
  mini_portile2 (~> 2.3.0)
52
- notiffany (0.1.1)
53
- nenv (~> 0.1)
54
- shellany (~> 0.0)
55
37
  pry (0.12.2)
56
38
  coderay (~> 1.1.0)
57
39
  method_source (~> 0.9.0)
40
+ public_suffix (3.0.3)
58
41
  rack (2.0.6)
59
42
  rack-protection (2.0.4)
60
43
  rack
61
44
  rake (11.3.0)
62
- rb-fsevent (0.10.3)
63
- rb-inotify (0.9.10)
64
- ffi (>= 0.5.0, < 2)
65
45
  rspec (3.8.0)
66
46
  rspec-core (~> 3.8.0)
67
47
  rspec-expectations (~> 3.8.0)
@@ -75,36 +55,44 @@ GEM
75
55
  diff-lcs (>= 1.2.0, < 2.0)
76
56
  rspec-support (~> 3.8.0)
77
57
  rspec-support (3.8.0)
78
- ruby_dep (1.5.0)
79
58
  rubyzip (1.2.2)
80
59
  selenium-webdriver (3.141.0)
81
60
  childprocess (~> 0.5)
82
61
  rubyzip (~> 1.2, >= 1.2.2)
83
- shellany (0.0.1)
84
62
  sinatra (2.0.4)
85
63
  mustermann (~> 1.0)
86
64
  rack (~> 2.0)
87
65
  rack-protection (= 2.0.4)
88
66
  tilt (~> 2.0)
89
- spoon (0.0.6)
90
- ffi
67
+ sinatra-silent (0.0.1)
68
+ superbot (0.1.28)
69
+ clamp (= 1.2.1)
70
+ kommando (~> 0.1)
71
+ launchy (= 2.4.3)
72
+ selenium-webdriver (~> 3.14, >= 3.14.0)
73
+ sinatra (= 2.0.4)
74
+ sinatra-silent (= 0.0.1)
75
+ superbot-cloud (~> 0.1.18)
76
+ superbot-teleport (~> 0.2.1)
77
+ zaru (= 0.2.0)
78
+ superbot-cloud (0.1.18)
79
+ marcel (= 0.3.3)
80
+ multipart-post (= 2.0.0)
91
81
  superbot-selenium-webdriver (1.0.0)
92
82
  chromedriver-helper (= 2.1.0)
93
83
  selenium-webdriver (= 3.141.0)
94
- thor (0.20.3)
95
84
  tilt (2.0.9)
85
+ zaru (0.2.0)
96
86
 
97
87
  PLATFORMS
98
88
  ruby
99
89
 
100
90
  DEPENDENCIES
101
91
  bundler (~> 1.17)
102
- guard
103
- guard-bundler
104
- guard-process
105
92
  pry
106
93
  rake (~> 11.2)
107
94
  rspec (~> 3.8)
95
+ superbot (~> 0.1.28)
108
96
  superbot-selenium-webdriver
109
97
  superbot-teleport!
110
98
 
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env sh
2
+
3
+ set -e
4
+
5
+ VERSION=$(superbot teleport --version)
6
+ GEM_FILE="superbot-teleport-$VERSION.gem"
7
+
8
+ gem uninstall -a -x superbot-teleport
9
+
10
+ [ -e "$GEM_FILE" ] && rm "$GEM_FILE"
11
+
12
+ gem build superbot-teleport
13
+ gem install superbot-teleport-$VERSION.gem
14
+ VERSION_INSTALLED=$(superbot teleport --version)
15
+
16
+ if [ "$VERSION" != "$VERSION_INSTALLED" ]; then
17
+ echo "!version"
18
+ exit 1
19
+ fi
20
+
21
+ echo "ok"
@@ -1,4 +1,5 @@
1
1
  require_relative "teleport/version"
2
+ require_relative "teleport/web"
2
3
  require_relative "teleport/cli"
3
4
 
4
5
  module Superbot
@@ -1,99 +1,10 @@
1
- require 'sinatra/base'
2
- require 'excon'
3
- require 'json'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'cli/root_command'
4
4
 
5
5
  module Superbot
6
6
  module Teleport
7
- class CLI
8
- def start!
9
- s = Sinatra.new
10
- s.set :raise_errors, false
11
- s.set :show_exceptions, false
12
-
13
- s.before do
14
- $__superbot_teleport_request_for_errors = request
15
- end
16
-
17
- s.set :connection, (
18
- Excon.new ENV.fetch("SUPERBOT_TELEPORT_UPSTREAM_URL"), {
19
- persistent: true,
20
- connect_timeout: 3,
21
- read_timeout: 5,
22
- write_timeout: 5,
23
- debug_request: (ENV["EXCON_DEBUG"] == "true"),
24
- debug_response: (ENV["EXCON_DEBUG"] == "true")
25
- }
26
- )
27
-
28
- s.helpers do
29
- def request_path(params)
30
- params[:splat].join("/")
31
- end
32
-
33
- def safe_parse_json(string_or_io, on_error: nil)
34
- JSON.parse (string_or_io.respond_to?(:read) ? string_or_io.read : string_or_io)
35
- rescue
36
- on_error
37
- end
38
-
39
- def proxy(method, params, opts={})
40
- raise "DELETE may not contain body" if method == :delete && opts[:body]
41
- opts[:headers] ||= {}
42
-
43
- unless ENV.fetch("SUPERBOT_TELEPORT_UPSTREAM_URL").include? "localhost"
44
- path = "wd/hub/#{request_path(params)}"
45
- headers["Content-Type"] = "application/json"
46
- else
47
- path = request_path
48
- end
49
-
50
- settings.connection.request({method: method, path: path}.merge(opts))
51
- end
52
-
53
- def respond(upstream)
54
- headers = upstream.headers
55
- status upstream.status
56
- upstream.body
57
- end
58
- end
59
-
60
- s.get "/wd/hub/*" do
61
- respond proxy(:get, params, {headers: headers, body: request.body})
62
- end
63
-
64
- s.post "/wd/hub/*" do
65
- case request_path(params)
66
- when "session"
67
- parsed_body = safe_parse_json request.body, on_error: {}
68
-
69
- if ENV['SUPERBOT_TELEPORT_REGION'] && parsed_body['desiredCapabilities']
70
- parsed_body['desiredCapabilities']['superOptions'] = { "region": ENV['SUPERBOT_TELEPORT_REGION'] }
71
- end
72
-
73
- respond proxy(:post, params, {headers: headers, body: parsed_body.to_json, read_timeout: 500})
74
- else
75
- respond proxy(:post, params, {headers: headers, body: request.body})
76
- end
77
- end
78
-
79
- s.delete "/wd/hub/*" do
80
- respond proxy(:delete, params, {headers: headers})
81
- end
82
-
83
- s.error Excon::Error::Socket do
84
- puts "="*30
85
- puts $__superbot_teleport_request_for_errors.path_info
86
-
87
- if $!.message.end_with? "(Errno::ECONNREFUSED)"
88
- status 500
89
- "upstream does not respond"
90
- else
91
- raise "unknown: #{$!.message}"
92
- end
93
- end
94
-
95
- s.run!
96
- end
7
+ module CLI
97
8
  end
98
9
  end
99
10
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superbot
4
+ module Teleport
5
+ module CLI
6
+ class RootCommand < Clamp::Command
7
+ include Superbot::Validations
8
+ include Superbot::Cloud::Validations
9
+
10
+ option ['-v', '--version'], :flag, "Show version information" do
11
+ puts Superbot::Teleport::VERSION
12
+ exit 0
13
+ end
14
+
15
+ option ['--browser'], 'BROWSER', "Browser type to use. Can be either local or cloud", default: 'cloud' do |browser|
16
+ validates_browser_type browser
17
+ end
18
+ option ['--region'], 'REGION', 'Region for remote webdriver'
19
+
20
+ def execute
21
+ require_login unless browser == 'local'
22
+
23
+ puts 'Opening teleport...', ''
24
+ puts 'Configure your remote webdriver to http://localhost:4567/wd/hub', ''
25
+ puts 'Press [control+c] to exit', ''
26
+
27
+ @chromedriver = Kommando.run_async 'chromedriver-helper --silent --port=9515' if browser == 'local'
28
+
29
+ @web = Superbot::Web.run!(webdriver_type: browser, region: region)
30
+ ensure
31
+ close_teleport
32
+ end
33
+
34
+ def close_teleport
35
+ @web&.quit!
36
+ @chromedriver&.kill
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  module Superbot
2
2
  module Teleport
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -0,0 +1,100 @@
1
+ require 'excon'
2
+ require 'json'
3
+
4
+ module Superbot
5
+ module Teleport
6
+ module Web
7
+ def self.register(sinatra, webdriver_type: 'cloud', region: nil)
8
+ sinatra.before do
9
+ $__superbot_teleport_request_for_errors = request
10
+ end
11
+
12
+ user_auth_creds = Superbot::Cloud.credentials&.slice(:username, :token) || {}
13
+
14
+ sinatra.set :webdriver_type, webdriver_type
15
+ sinatra.set :webdriver_url, Superbot.webdriver_endpoint(webdriver_type)
16
+ sinatra.set :region, region
17
+
18
+ sinatra.set :connection, (
19
+ Excon.new sinatra.webdriver_url, {
20
+ user: user_auth_creds[:username],
21
+ password: user_auth_creds[:token],
22
+ persistent: true,
23
+ connect_timeout: 3,
24
+ read_timeout: 5,
25
+ write_timeout: 5,
26
+ }
27
+ )
28
+
29
+ sinatra.helpers do
30
+ def request_path(params)
31
+ params[:splat].join("/")
32
+ end
33
+
34
+ def safe_parse_json(string_or_io, on_error: nil)
35
+ JSON.parse (string_or_io.respond_to?(:read) ? string_or_io.read : string_or_io)
36
+ rescue
37
+ on_error
38
+ end
39
+
40
+ def proxy(method, params, opts={})
41
+ raise "DELETE may not contain body" if method == :delete && opts[:body]
42
+ opts[:headers] ||= {}
43
+
44
+ unless settings.webdriver_type == 'local'
45
+ path = "wd/hub/#{request_path(params)}"
46
+ headers["Content-Type"] = "application/json"
47
+ else
48
+ path = request_path
49
+ end
50
+
51
+ settings.connection.request({method: method, path: path}.merge(opts))
52
+ end
53
+
54
+ def respond(upstream)
55
+ headers = upstream.headers
56
+ status upstream.status
57
+ upstream.body
58
+ end
59
+ end
60
+
61
+ sinatra.get "/wd/hub/*" do
62
+ respond proxy(:get, params, {headers: headers, body: request.body})
63
+ end
64
+
65
+ sinatra.post "/wd/hub/*" do
66
+ case request_path(params)
67
+ when "session"
68
+ parsed_body = safe_parse_json request.body, on_error: {}
69
+
70
+ if settings.region && parsed_body.dig('desiredCapabilities', 'superOptions', 'region').nil?
71
+ parsed_body['desiredCapabilities'] ||= {}
72
+ parsed_body['desiredCapabilities']['superOptions'] ||= {}
73
+ parsed_body['desiredCapabilities']['superOptions']['region'] ||= settings.region
74
+ end
75
+
76
+ respond proxy(:post, params, {headers: headers, body: parsed_body.to_json, read_timeout: 500})
77
+ else
78
+ respond proxy(:post, params, {headers: headers, body: request.body})
79
+ end
80
+ end
81
+
82
+ sinatra.delete "/wd/hub/*" do
83
+ respond proxy(:delete, params, {headers: headers})
84
+ end
85
+
86
+ sinatra.error Excon::Error::Socket do
87
+ puts "="*30
88
+ puts $__superbot_teleport_request_for_errors.path_info
89
+
90
+ if $!.message.end_with? "(Errno::ECONNREFUSED)"
91
+ status 500
92
+ "upstream does not respond"
93
+ else
94
+ raise "unknown: #{$!.message}"
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -21,16 +21,13 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_runtime_dependency "sinatra"
25
24
  spec.add_runtime_dependency "excon"
26
25
 
27
26
  spec.add_development_dependency "bundler", "~> 1.17"
28
27
  spec.add_development_dependency "rake", "~> 11.2"
29
28
  spec.add_development_dependency "rspec", "~> 3.8"
30
- spec.add_development_dependency "guard"
31
- spec.add_development_dependency "guard-process"
32
- spec.add_development_dependency "guard-bundler"
33
29
  spec.add_development_dependency "pry"
34
30
 
31
+ spec.add_development_dependency "superbot", "~> 0.1.28"
35
32
  spec.add_development_dependency "superbot-selenium-webdriver"
36
33
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superbot-teleport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Superbot HQ
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-05 00:00:00.000000000 Z
11
+ date: 2018-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: sinatra
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: excon
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -81,35 +67,7 @@ dependencies:
81
67
  - !ruby/object:Gem::Version
82
68
  version: '3.8'
83
69
  - !ruby/object:Gem::Dependency
84
- name: guard
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
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: guard-process
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: guard-bundler
70
+ name: pry
113
71
  requirement: !ruby/object:Gem::Requirement
114
72
  requirements:
115
73
  - - ">="
@@ -123,19 +81,19 @@ dependencies:
123
81
  - !ruby/object:Gem::Version
124
82
  version: '0'
125
83
  - !ruby/object:Gem::Dependency
126
- name: pry
84
+ name: superbot
127
85
  requirement: !ruby/object:Gem::Requirement
128
86
  requirements:
129
- - - ">="
87
+ - - "~>"
130
88
  - !ruby/object:Gem::Version
131
- version: '0'
89
+ version: 0.1.28
132
90
  type: :development
133
91
  prerelease: false
134
92
  version_requirements: !ruby/object:Gem::Requirement
135
93
  requirements:
136
- - - ">="
94
+ - - "~>"
137
95
  - !ruby/object:Gem::Version
138
- version: '0'
96
+ version: 0.1.28
139
97
  - !ruby/object:Gem::Dependency
140
98
  name: superbot-selenium-webdriver
141
99
  requirement: !ruby/object:Gem::Requirement
@@ -152,8 +110,7 @@ dependencies:
152
110
  version: '0'
153
111
  description:
154
112
  email:
155
- executables:
156
- - sb-teleport
113
+ executables: []
157
114
  extensions: []
158
115
  extra_rdoc_files: []
159
116
  files:
@@ -164,16 +121,17 @@ files:
164
121
  - ".travis.yml"
165
122
  - Gemfile
166
123
  - Gemfile.lock
167
- - Guardfile
168
124
  - LICENSE.txt
169
125
  - README.md
170
126
  - Rakefile
171
127
  - bin/console
128
+ - bin/release
172
129
  - bin/setup
173
- - exe/sb-teleport
174
130
  - lib/superbot/teleport.rb
175
131
  - lib/superbot/teleport/cli.rb
132
+ - lib/superbot/teleport/cli/root_command.rb
176
133
  - lib/superbot/teleport/version.rb
134
+ - lib/superbot/teleport/web.rb
177
135
  - superbot-teleport.gemspec
178
136
  homepage: https://github.com/superbothq/superbot-teleport
179
137
  licenses:
@@ -195,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
153
  version: '0'
196
154
  requirements: []
197
155
  rubyforge_project:
198
- rubygems_version: 2.7.7
156
+ rubygems_version: 2.7.6
199
157
  signing_key:
200
158
  specification_version: 4
201
159
  summary: superbot-teleport
data/Guardfile DELETED
@@ -1,35 +0,0 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
- ## Uncomment and set this to only include directories you want to watch
5
- # directories %w(app lib config test spec features) \
6
- # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
-
8
- ## Note: if you are using the `directories` clause above and you are not
9
- ## watching the project directory ('.'), then you will want to move
10
- ## the Guardfile to a watched dir and symlink it back, e.g.
11
- #
12
- # $ mkdir config
13
- # $ mv Guardfile config/
14
- # $ ln -s config/Guardfile .
15
- #
16
- # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
- guard 'process', name: 'sb-teleport', command: 'exe/sb-teleport' do
18
- watch(%r{^lib/(.+)\.rb})
19
- end
20
-
21
- guard 'process', name: 'chromedriver', command: 'chromedriver-helper' do
22
- end
23
-
24
-
25
- guard :bundler do
26
- require 'guard/bundler'
27
- require 'guard/bundler/verify'
28
- helper = Guard::Bundler::Verify.new
29
-
30
- files = ['Gemfile']
31
- files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
32
-
33
- # Assume files are symlinked from somewhere
34
- files.each { |file| watch(helper.real_path(file)) }
35
- end
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- STDOUT.sync = true
5
-
6
- require_relative "../lib/superbot/teleport"
7
-
8
- cli = Superbot::Teleport::CLI.new
9
- cli.start!