superbot-teleport 0.2.7 → 0.2.8
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/superbot/teleport/cli/root_command.rb +14 -7
- data/lib/superbot/teleport/version.rb +1 -1
- data/lib/superbot/teleport/web.rb +49 -18
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b274c26142be5c2dc8b56512ce30742f6707868ef8a767b4fa2fa2dde664e6a
|
4
|
+
data.tar.gz: 4aae54f1e4ca46467c11c0427730ef588a6a4a44286941ceda53afecee3d0749
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f6b4ecf86782e3706254290d899f38f08dcea71f09081eae6781a1a96ce33979f546ad7d416f326bc622920e63b6cec300cc483a8439f5dd413a62bf1549183
|
7
|
+
data.tar.gz: f6f03e163930c425ac56d25574d7d7c1aa634e4dbda493bf5ae3af95d3e40e6db9b59aaa12f89adffa4dc3841db5b651e556ea6a0a98bf8bedb9142277fe64fa
|
data/Gemfile.lock
CHANGED
@@ -16,6 +16,7 @@ module Superbot
|
|
16
16
|
option ['--browser'], 'BROWSER', "Browser type to use. Can be either local or cloud", default: 'cloud'
|
17
17
|
option ['--region'], 'REGION', 'Region for remote webdriver'
|
18
18
|
option ['--org'], 'ORGANIZATION', 'Name of organization to take action', attribute_name: :organization
|
19
|
+
option ['--reuse'], :flag, "Reuse existing session"
|
19
20
|
|
20
21
|
def execute
|
21
22
|
validate_teleport_options(browser, organization)
|
@@ -26,19 +27,25 @@ module Superbot
|
|
26
27
|
puts 'Configure your remote webdriver to http://localhost:4567/wd/hub', ''
|
27
28
|
puts 'Press [control+c] to exit', ''
|
28
29
|
|
29
|
-
@web = Superbot::Web.run!(
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
@web = Superbot::Web.run!(
|
31
|
+
webdriver_type: browser,
|
32
|
+
region: region,
|
33
|
+
organization: organization,
|
34
|
+
reuse: reuse?
|
35
|
+
)
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
+
at_exit do
|
38
|
+
@web&.quit!
|
39
|
+
end
|
37
40
|
end
|
38
41
|
|
39
42
|
def run_local_chromedriver
|
40
43
|
chromedriver_path = Chromedriver::Helper.new.binary_path
|
41
44
|
@chromedriver = Kommando.run_async "#{chromedriver_path} --silent --port=9515 --url-base=wd/hub"
|
45
|
+
|
46
|
+
at_exit do
|
47
|
+
@chromedriver&.kill
|
48
|
+
end
|
42
49
|
end
|
43
50
|
end
|
44
51
|
end
|
@@ -11,16 +11,16 @@ module Superbot
|
|
11
11
|
|
12
12
|
user_auth_creds = Superbot::Cloud.credentials&.slice(:username, :token) || {}
|
13
13
|
|
14
|
-
sinatra.set :connection, (
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
}
|
14
|
+
sinatra.set :connection, Excon.new(
|
15
|
+
sinatra.webdriver_url,
|
16
|
+
user: user_auth_creds[:username],
|
17
|
+
password: user_auth_creds[:token],
|
18
|
+
persistent: true,
|
19
|
+
connect_timeout: 3,
|
20
|
+
read_timeout: 500,
|
21
|
+
write_timeout: 500
|
23
22
|
)
|
23
|
+
sinatra.set :current_session, nil
|
24
24
|
|
25
25
|
sinatra.helpers do
|
26
26
|
def request_path(params)
|
@@ -39,18 +39,18 @@ module Superbot
|
|
39
39
|
path = "wd/hub/#{request_path(params)}"
|
40
40
|
headers["Content-Type"] = "application/json"
|
41
41
|
|
42
|
-
settings.connection.request({method: method, path: path}.merge(opts))
|
42
|
+
settings.connection.request({ method: method, path: path }.merge(opts))
|
43
43
|
end
|
44
44
|
|
45
45
|
def respond(upstream)
|
46
|
-
headers
|
46
|
+
headers upstream.headers
|
47
47
|
status upstream.status
|
48
48
|
upstream.body
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
sinatra.get "/wd/hub/*" do
|
53
|
-
respond proxy(:get, params,
|
53
|
+
respond proxy(:get, params, headers: headers, body: request.body)
|
54
54
|
end
|
55
55
|
|
56
56
|
sinatra.post "/wd/hub/*" do
|
@@ -58,22 +58,39 @@ module Superbot
|
|
58
58
|
when "session"
|
59
59
|
parsed_body = safe_parse_json request.body, on_error: {}
|
60
60
|
|
61
|
-
parsed_body['organization_name'] = settings.organization
|
61
|
+
parsed_body['organization_name'] = settings.teleport_options[:organization]
|
62
62
|
|
63
|
-
if settings.region && parsed_body.dig('desiredCapabilities', 'superOptions', 'region').nil?
|
63
|
+
if settings.teleport_options[:region] && parsed_body.dig('desiredCapabilities', 'superOptions', 'region').nil?
|
64
64
|
parsed_body['desiredCapabilities'] ||= {}
|
65
65
|
parsed_body['desiredCapabilities']['superOptions'] ||= {}
|
66
|
-
parsed_body['desiredCapabilities']['superOptions']['region'] ||= settings.region
|
66
|
+
parsed_body['desiredCapabilities']['superOptions']['region'] ||= settings.teleport_options[:region]
|
67
67
|
end
|
68
68
|
|
69
|
-
|
69
|
+
unless settings.teleport_options[:reuse] && settings.current_session
|
70
|
+
settings.current_session = proxy(
|
71
|
+
:post,
|
72
|
+
params,
|
73
|
+
headers: headers,
|
74
|
+
body: parsed_body.to_json,
|
75
|
+
write_timeout: 500,
|
76
|
+
read_timeout: 500
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
respond settings.current_session
|
70
81
|
else
|
71
|
-
respond proxy(:post, params,
|
82
|
+
respond proxy(:post, params, headers: headers, body: request.body)
|
72
83
|
end
|
73
84
|
end
|
74
85
|
|
75
86
|
sinatra.delete "/wd/hub/*" do
|
76
|
-
|
87
|
+
if settings.teleport_options[:reuse]
|
88
|
+
puts "Skipping DELETE, keep session open"
|
89
|
+
halt 204
|
90
|
+
else
|
91
|
+
settings.current_session = nil
|
92
|
+
respond proxy(:delete, params, headers: headers)
|
93
|
+
end
|
77
94
|
end
|
78
95
|
|
79
96
|
sinatra.error Excon::Error::Socket do
|
@@ -87,6 +104,20 @@ module Superbot
|
|
87
104
|
raise "unknown: #{$!.message}"
|
88
105
|
end
|
89
106
|
end
|
107
|
+
|
108
|
+
at_exit do
|
109
|
+
return unless sinatra.settings.current_session
|
110
|
+
|
111
|
+
puts nil, "Removing active session..."
|
112
|
+
session_id = JSON.parse(sinatra.settings.current_session.body)['sessionId']
|
113
|
+
sinatra.settings.connection.request(
|
114
|
+
method: :delete,
|
115
|
+
path: "wd/hub/session/#{session_id}",
|
116
|
+
headers: { 'Content-Type' => 'application/json' }
|
117
|
+
)
|
118
|
+
rescue => e
|
119
|
+
puts e.message
|
120
|
+
end
|
90
121
|
end
|
91
122
|
end
|
92
123
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: superbot-teleport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Superbot HQ
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01
|
11
|
+
date: 2019-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|