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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21608df2202349dc253a3a7d9bd7198e1a85a88adc34426e42f2c452bd577bb2
4
- data.tar.gz: 68f9315d65367edfa9064339ec0a29173ed6715e808e69da6cea758f6c7cb5f9
3
+ metadata.gz: 5376f1fb8031a0517b62f61f005925b4c28aa53808a85278abf4eefdc38763ea
4
+ data.tar.gz: 1c8566752197cb1ef6d7eb78b902131585f7d1b8b2ed48596c3bf716848ff3db
5
5
  SHA512:
6
- metadata.gz: 2493dd94547974cd299a55b2e9dffb1cb563b661362e6a6936140f2cbfd15acc80180e8bac7686b18180d83c2026d90b2e065e06efbf4908ba1c8d1c1927bc6a
7
- data.tar.gz: 373bf3c864187635acf664b30fe7f10c28421777f82d912f295ac8d2a2e2c2f5504361dc8ed7e47e41d92069fd9eb6bda2ff9ce955503b9ccec1c9a3586c743f
6
+ metadata.gz: 55a7c5f1a1c8598b5862407a04428bc17056cd666e0ab33cc54c8703be8ffc764ebadf1b81b4601ce807daacca149413f637bef2b1d528571fbda050361df40f
7
+ data.tar.gz: 662acacf69bfbc574904fb6ed5142934e136fb586d6bbee203d3c8acf3b8923c2aea5db16ef2ac198ceb766931c5fdcbf9be4205b7f315fe127d04b892cddf67
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superbot-teleport (0.3.6)
4
+ superbot-teleport (0.3.7)
5
5
  excon
6
6
 
7
7
  GEM
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Superbot
2
2
  module Teleport
3
- VERSION = "0.3.6"
3
+ VERSION = "0.3.7"
4
4
  end
5
5
  end
@@ -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.settings.teleport_options[:keep_session]
149
+ return if sinatra.teleport_options[:session] && sinatra.teleport_options[:keep_session]
122
150
 
123
151
  puts nil, "Removing active session..."
124
- sinatra.settings.connection.request(
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.6
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-07 00:00:00.000000000 Z
11
+ date: 2019-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon