superbot-teleport 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/superbot/teleport/cli/root_command.rb +9 -5
- data/lib/superbot/teleport/cli/validations.rb +6 -2
- data/lib/superbot/teleport/version.rb +1 -1
- data/lib/superbot/teleport/web.rb +23 -20
- 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: 49234eaa577cc8d0b36d1170229022d765603222b842f9a5191192b32aa4d0af
|
4
|
+
data.tar.gz: 6f38f0ced550f0ebb8d400218c6687a94b8ae4e25b6511958b16e611927f5501
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f26e286bc638cd4a905caf05ea5950cdb4c078e0860937ea3610d1f346fad2184f3ac6ffe4cf6a7c81d93a59cd886f88bb3d3b98ae95cb221ced8e36eb1436aa
|
7
|
+
data.tar.gz: 3e578db0b76f1fe09f7c72236a2e7fc8ad66da483614dd5b6a57ec41adefd1d10abb41114e153f94f9699a5ced0ebab762449deec60d4baf3fb55b8b6935fbff
|
data/Gemfile.lock
CHANGED
@@ -14,12 +14,14 @@ module Superbot
|
|
14
14
|
end
|
15
15
|
|
16
16
|
option ['--browser'], 'BROWSER', "Browser type to use. Can be either local or cloud", default: 'cloud'
|
17
|
-
option ['--region'], 'REGION',
|
18
|
-
option ['--org'], 'ORGANIZATION',
|
19
|
-
option ['--
|
17
|
+
option ['--region'], 'REGION', "Region for remote webdriver"
|
18
|
+
option ['--org'], 'ORGANIZATION', "Name of organization to take action on", environment_variable: "SUPERBOT_ORG", attribute_name: :organization
|
19
|
+
option ['--ignore-delete'], :flag, "Reuse existing session"
|
20
|
+
option ['--keep-session'], :flag, "Keep session when teleport closing"
|
21
|
+
option ['--session'], 'SESSION', "Session to use in teleport"
|
20
22
|
|
21
23
|
def execute
|
22
|
-
validate_teleport_options(browser, organization)
|
24
|
+
validate_teleport_options(browser, organization, session)
|
23
25
|
|
24
26
|
run_local_chromedriver if browser == 'local'
|
25
27
|
|
@@ -31,7 +33,9 @@ module Superbot
|
|
31
33
|
webdriver_type: browser,
|
32
34
|
region: region,
|
33
35
|
organization: organization,
|
34
|
-
|
36
|
+
ignore_delete: session || ignore_delete?,
|
37
|
+
keep_session: session || keep_session?,
|
38
|
+
session: session
|
35
39
|
)
|
36
40
|
|
37
41
|
at_exit do
|
@@ -5,16 +5,20 @@ module Superbot
|
|
5
5
|
module Validations
|
6
6
|
include Superbot::Cloud::Validations
|
7
7
|
|
8
|
-
def validate_teleport_options(browser, organization)
|
8
|
+
def validate_teleport_options(browser, organization, session = nil)
|
9
9
|
return if browser == 'local'
|
10
10
|
|
11
11
|
unless %w[local cloud local_cloud].include?(browser)
|
12
12
|
signal_usage_error "The --browser=#{browser} browser option is not allowed. Should be either 'local' or 'cloud'."
|
13
13
|
end
|
14
14
|
|
15
|
-
signal_usage_error '--org option is required for cloud teleport' unless organization
|
15
|
+
signal_usage_error '--org option is required for cloud teleport' unless organization || ENV['SUPERBOT_TOKEN']
|
16
16
|
|
17
17
|
require_login
|
18
|
+
|
19
|
+
return unless session
|
20
|
+
|
21
|
+
Superbot::Cloud::Api.request(:get_webdriver_session, params: {session_id: session, organization_name: organization})
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
@@ -20,7 +20,6 @@ module Superbot
|
|
20
20
|
read_timeout: 500,
|
21
21
|
write_timeout: 500
|
22
22
|
)
|
23
|
-
sinatra.set :current_session, nil
|
24
23
|
|
25
24
|
sinatra.helpers do
|
26
25
|
def request_path(params)
|
@@ -56,18 +55,22 @@ module Superbot
|
|
56
55
|
sinatra.post "/wd/hub/*" do
|
57
56
|
case request_path(params)
|
58
57
|
when "session"
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
parsed_body
|
65
|
-
|
66
|
-
parsed_body['
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
58
|
+
if settings.teleport_options[:session]
|
59
|
+
status 200
|
60
|
+
headers 'Content-Type' => 'application/json'
|
61
|
+
return { 'sessionId': settings.teleport_options[:session] }.to_json
|
62
|
+
else
|
63
|
+
parsed_body = safe_parse_json request.body, on_error: {}
|
64
|
+
|
65
|
+
parsed_body['organization_name'] = settings.teleport_options[:organization]
|
66
|
+
|
67
|
+
if settings.teleport_options[:region] && parsed_body.dig('desiredCapabilities', 'superOptions', 'region').nil?
|
68
|
+
parsed_body['desiredCapabilities'] ||= {}
|
69
|
+
parsed_body['desiredCapabilities']['superOptions'] ||= {}
|
70
|
+
parsed_body['desiredCapabilities']['superOptions']['region'] ||= settings.teleport_options[:region]
|
71
|
+
end
|
72
|
+
|
73
|
+
session_response = proxy(
|
71
74
|
:post,
|
72
75
|
params,
|
73
76
|
headers: headers,
|
@@ -75,20 +78,21 @@ module Superbot
|
|
75
78
|
write_timeout: 500,
|
76
79
|
read_timeout: 500
|
77
80
|
)
|
78
|
-
|
81
|
+
settings.teleport_options[:session] = JSON.parse(session_response.body)['sessionId']
|
79
82
|
|
80
|
-
|
83
|
+
respond session_response
|
84
|
+
end
|
81
85
|
else
|
82
86
|
respond proxy(:post, params, headers: headers, body: request.body)
|
83
87
|
end
|
84
88
|
end
|
85
89
|
|
86
90
|
sinatra.delete "/wd/hub/*" do
|
87
|
-
if settings.teleport_options[:
|
91
|
+
if settings.teleport_options[:ignore_delete]
|
88
92
|
puts "Skipping DELETE, keep session open"
|
89
93
|
halt 204
|
90
94
|
else
|
91
|
-
settings.
|
95
|
+
settings.teleport_options[:session] = nil
|
92
96
|
respond proxy(:delete, params, headers: headers)
|
93
97
|
end
|
94
98
|
end
|
@@ -106,13 +110,12 @@ module Superbot
|
|
106
110
|
end
|
107
111
|
|
108
112
|
at_exit do
|
109
|
-
return
|
113
|
+
return if sinatra.teleport_options[:session] && sinatra.settings.teleport_options[:keep_session]
|
110
114
|
|
111
115
|
puts nil, "Removing active session..."
|
112
|
-
session_id = JSON.parse(sinatra.settings.current_session.body)['sessionId']
|
113
116
|
sinatra.settings.connection.request(
|
114
117
|
method: :delete,
|
115
|
-
path: "wd/hub/session/#{
|
118
|
+
path: "wd/hub/session/#{sinatra.teleport_options[:session]}",
|
116
119
|
headers: { 'Content-Type' => 'application/json' }
|
117
120
|
)
|
118
121
|
rescue => e
|
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.9
|
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-02-
|
11
|
+
date: 2019-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|