superbot-teleport 0.3.6 → 0.3.7
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 +3 -1
- data/lib/superbot/teleport/version.rb +1 -1
- data/lib/superbot/teleport/web.rb +52 -24
- 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: 5376f1fb8031a0517b62f61f005925b4c28aa53808a85278abf4eefdc38763ea
|
4
|
+
data.tar.gz: 1c8566752197cb1ef6d7eb78b902131585f7d1b8b2ed48596c3bf716848ff3db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55a7c5f1a1c8598b5862407a04428bc17056cd666e0ab33cc54c8703be8ffc764ebadf1b81b4601ce807daacca149413f637bef2b1d528571fbda050361df40f
|
7
|
+
data.tar.gz: 662acacf69bfbc574904fb6ed5142934e136fb586d6bbee203d3c8acf3b8923c2aea5db16ef2ac198ceb766931c5fdcbf9be4205b7f315fe127d04b892cddf67
|
data/Gemfile.lock
CHANGED
@@ -22,6 +22,7 @@ module Superbot
|
|
22
22
|
option ['--session'], 'SESSION', "Session to use in teleport"
|
23
23
|
option ['--base-url'], 'BASE_URL', "Base project URL"
|
24
24
|
option ['--tag'], 'TAG', "Deployment tag for webdriver session", environment_variable: "SUPERBOT_TAG"
|
25
|
+
option ['--acquire-session'], :flag, "Request session creation as soon as teleport open"
|
25
26
|
|
26
27
|
def execute
|
27
28
|
validate_teleport_options(browser, organization, session)
|
@@ -40,7 +41,8 @@ module Superbot
|
|
40
41
|
keep_session: session || keep_session?,
|
41
42
|
session: session,
|
42
43
|
base_url: base_url,
|
43
|
-
tag: tag
|
44
|
+
tag: tag,
|
45
|
+
acquire_session: acquire_session?
|
44
46
|
)
|
45
47
|
|
46
48
|
at_exit do
|
@@ -43,6 +43,31 @@ module Superbot
|
|
43
43
|
status upstream.status
|
44
44
|
upstream.body
|
45
45
|
end
|
46
|
+
|
47
|
+
def acquire_session(parsed_body: {}, headers: {})
|
48
|
+
assign_super_options(parsed_body)
|
49
|
+
proxy(
|
50
|
+
:post,
|
51
|
+
{ splat: ['session'] },
|
52
|
+
headers: headers.merge('Idempotency-Key' => SecureRandom.hex),
|
53
|
+
body: parsed_body.to_json,
|
54
|
+
retry_interval: 60
|
55
|
+
).tap do |session_response|
|
56
|
+
parsed_response = safe_parse_json session_response.body, on_error: {}
|
57
|
+
settings.teleport_options[:session] = parsed_response['sessionId']
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def assign_super_options(parsed_body)
|
62
|
+
parsed_body['organization_name'] = settings.teleport_options[:organization]
|
63
|
+
|
64
|
+
if settings.teleport_options.slice(:region, :tag).compact.any?
|
65
|
+
parsed_body['desiredCapabilities'] ||= { 'browserName' => 'chrome' }
|
66
|
+
parsed_body['desiredCapabilities']['superOptions'] ||= {}
|
67
|
+
parsed_body['desiredCapabilities']['superOptions']['region'] ||= settings.teleport_options[:region]
|
68
|
+
parsed_body['desiredCapabilities']['superOptions']['tag'] ||= settings.teleport_options[:tag]
|
69
|
+
end
|
70
|
+
end
|
46
71
|
end
|
47
72
|
|
48
73
|
sinatra.get "/wd/hub/*" do
|
@@ -58,28 +83,7 @@ module Superbot
|
|
58
83
|
return { 'sessionId': settings.teleport_options[:session] }.to_json
|
59
84
|
else
|
60
85
|
parsed_body = safe_parse_json request.body, on_error: {}
|
61
|
-
|
62
|
-
parsed_body['organization_name'] = settings.teleport_options[:organization]
|
63
|
-
|
64
|
-
if settings.teleport_options[:region] || settings.teleport_options[:tag]
|
65
|
-
parsed_body['desiredCapabilities'] ||= {}
|
66
|
-
parsed_body['desiredCapabilities']['superOptions'] ||= {}
|
67
|
-
parsed_body['desiredCapabilities']['superOptions']['region'] ||= settings.teleport_options[:region]
|
68
|
-
parsed_body['desiredCapabilities']['superOptions']['tag'] ||= settings.teleport_options[:tag]
|
69
|
-
end
|
70
|
-
|
71
|
-
session_response = proxy(
|
72
|
-
:post,
|
73
|
-
params,
|
74
|
-
headers: headers.merge('Idempotency-Key' => SecureRandom.hex),
|
75
|
-
body: parsed_body.to_json,
|
76
|
-
write_timeout: 500,
|
77
|
-
read_timeout: 500,
|
78
|
-
retry_interval: 60
|
79
|
-
)
|
80
|
-
settings.teleport_options[:session] = JSON.parse(session_response.body)['sessionId']
|
81
|
-
|
82
|
-
respond session_response
|
86
|
+
respond acquire_session(parsed_body: parsed_body, headers: headers)
|
83
87
|
end
|
84
88
|
else
|
85
89
|
parsed_body = safe_parse_json request.body, on_error: {}
|
@@ -117,11 +121,35 @@ module Superbot
|
|
117
121
|
end
|
118
122
|
end
|
119
123
|
|
124
|
+
if sinatra.teleport_options[:acquire_session]
|
125
|
+
sinatra.connection.request(
|
126
|
+
method: :post,
|
127
|
+
path: 'wd/hub/session',
|
128
|
+
headers: { 'Content-Type' => 'application/json', 'Idempotency-Key' => SecureRandom.hex },
|
129
|
+
body: {
|
130
|
+
organization_name: sinatra.teleport_options[:organization],
|
131
|
+
desiredCapabilities: {
|
132
|
+
browserName: 'chrome',
|
133
|
+
superOptions: {
|
134
|
+
tag: sinatra.teleport_options[:tag],
|
135
|
+
region: sinatra.teleport_options[:region],
|
136
|
+
}.compact
|
137
|
+
}
|
138
|
+
}.to_json,
|
139
|
+
idempotent: true,
|
140
|
+
retry_interval: 60
|
141
|
+
).tap do |session_response|
|
142
|
+
if session_response.status == 200
|
143
|
+
sinatra.teleport_options[:session] = JSON.parse(session_response.body)['sessionId']
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
120
148
|
at_exit do
|
121
|
-
return if sinatra.teleport_options[:session] && sinatra.
|
149
|
+
return if sinatra.teleport_options[:session] && sinatra.teleport_options[:keep_session]
|
122
150
|
|
123
151
|
puts nil, "Removing active session..."
|
124
|
-
sinatra.
|
152
|
+
sinatra.connection.request(
|
125
153
|
method: :delete,
|
126
154
|
path: "wd/hub/session/#{sinatra.teleport_options[:session]}",
|
127
155
|
headers: { 'Content-Type' => 'application/json' }
|
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.3.
|
4
|
+
version: 0.3.7
|
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-03-
|
11
|
+
date: 2019-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|