superbot-cloud 0.2.7 → 0.3.0

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: e4dbcec81d287ce7f963412a81a3061645dd519fe8951919b1bcabc870007857
4
- data.tar.gz: aeafad6a71e729648875cbf35e7052864e7e09bf3ed9cc6c3966db0c93e19006
3
+ metadata.gz: db593e16a528d6b2d3962fc3cbf698c371c33ab782f7a4c466863655e06779eb
4
+ data.tar.gz: 4852ae8c8b4edb93faecdc2fc90e58eeaab958ce66e42f04df7f45496f426789
5
5
  SHA512:
6
- metadata.gz: aa8790116ed3dd57d05b8b89760bd0e9ea2c38122cfa35b74c8ec0c2050828da54c6b3f26595830810a21fab989b9052d6fa0a4a9b8b1f3b85ea0646d24a89e2
7
- data.tar.gz: 1b3544b4cc35c66cb80f63e645d78f69d3f2ec65d54aa86d2a7fb4c08a849ab31a9fddb890e1f8cec05c2492b37eec80e6718a0e38410ef28ce23d1533dbaa92
6
+ metadata.gz: 83306afd7af5b132ff46d96be8b3e4fe5c1fc3f52c5836b7fa8a6a41e2a130dfe1ff08cb6d5a337da96e978861a02227f4ac06bcf8cf5bce7ffe7f367e75cfb6
7
+ data.tar.gz: 9ab8d305a398c82d6cf8e24c774466940fb6f036a301d7d72ef74b37f506a7186415eac68dd8cdf483a76c2b8ba1208067b0138e81584e6378f65733ffded570
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superbot-cloud (0.2.7)
4
+ superbot-cloud (0.3.0)
5
5
  marcel (= 0.3.3)
6
6
  multipart-post (= 2.0.0)
7
7
 
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superbot
4
+ module Cloud
5
+ module CLI
6
+ module Webdriver
7
+ class CreateCommand < BaseCommand
8
+ option ['--region'], 'REGION', 'Region for remote webdriver'
9
+ option ['--local'], :flag, "Local dev webdriver environment", hidden: true
10
+
11
+ def execute
12
+ create_webdriver
13
+ end
14
+
15
+ def create_webdriver
16
+ request_body = {
17
+ organization_name: organization,
18
+ desiredCapabilities: {
19
+ browserName: 'chrome',
20
+ superOptions: {}
21
+ }
22
+ }
23
+ request_body[:desiredCapabilities][:superOptions][:region] = region if region
24
+ puts "Creating webdriver session..."
25
+ puts "Please wait for Session ID or press [ctrl/cmd + c] to exit"
26
+ session = Excon.post(
27
+ [Superbot.webdriver_endpoint(local? ? 'local_cloud' : 'cloud'), 'wd/hub/session'].join('/'),
28
+ persistent: true,
29
+ headers: { 'Authorization' => Superbot::Cloud.authorization_header, 'Content-Type' => 'application/json' },
30
+ body: request_body.to_json,
31
+ connect_timeout: 3,
32
+ read_timeout: 500,
33
+ write_timeout: 500
34
+ )
35
+ parsed_response = JSON.parse(session.body)
36
+ puts parsed_response['error'] || parsed_response['sessionId']
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -5,13 +5,27 @@ module Superbot
5
5
  module CLI
6
6
  module Webdriver
7
7
  class DeleteCommand < BaseCommand
8
- parameter "SESSION_ID ...", "webdriver session ID", required: true
8
+ option ['--all'], :flag, "Delete all active sessions"
9
+ parameter "SESSION_ID ...", "webdriver session ID", required: false
9
10
 
10
11
  def execute
11
12
  delete_session
12
13
  end
13
14
 
14
15
  def delete_session
16
+ if all?
17
+ webdriver_sessions = Superbot::Cloud::Api.request(
18
+ :webdriver_session_list,
19
+ params: { organization_name: organization, 'aasm_state[]': %w[idle proxying] }
20
+ ).fetch(:webdriver_sessions, [])
21
+
22
+ abort "All sessions are finished" if webdriver_sessions.empty?
23
+
24
+ @session_id_list = webdriver_sessions&.map { |session| session[:session_id] }
25
+ elsif session_id_list.empty?
26
+ signal_usage_error "parameter SESSION_ID is required"
27
+ end
28
+
15
29
  session_id_list.each do |session_id|
16
30
  Superbot::Cloud::Api.request(
17
31
  :delete_webdriver_session,
@@ -3,6 +3,7 @@
3
3
  require_relative 'webdriver/base_command'
4
4
  require_relative 'webdriver/list_command'
5
5
  require_relative 'webdriver/delete_command'
6
+ require_relative 'webdriver/create_command'
6
7
 
7
8
  module Superbot
8
9
  module Cloud
@@ -10,6 +11,7 @@ module Superbot
10
11
  class WebdriverCommand < LoginRequiredCommand
11
12
  subcommand ['list'], "List all webdriver sessions", Webdriver::ListCommand
12
13
  subcommand ['delete'], "Terminate and finish specific session", Webdriver::DeleteCommand
14
+ subcommand ['create'], "Create active webdriver session", Webdriver::CreateCommand
13
15
  end
14
16
  end
15
17
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Superbot
4
4
  module Cloud
5
- VERSION = "0.2.7"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
@@ -34,6 +34,19 @@ module Superbot
34
34
  all_credentials.delete(Superbot::DOMAIN.to_sym)
35
35
  File.write CREDENTIALS_FILE_PATH, all_credentials.to_json
36
36
  end
37
+
38
+ def self.authorization_header
39
+ @authorization_header ||= format(
40
+ '%<auth_type>s %<auth_token>s',
41
+ auth_type: ENV['SUPERBOT_TOKEN'] ? 'Bearer' : 'Basic',
42
+ auth_token: Base64.urlsafe_encode64(
43
+ ENV.fetch(
44
+ 'SUPERBOT_TOKEN',
45
+ credentials&.values_at(:username, :token)&.join(':').to_s
46
+ )
47
+ )
48
+ )
49
+ end
37
50
  end
38
51
  end
39
52
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superbot-cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Superbots
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-08 00:00:00.000000000 Z
11
+ date: 2019-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post
@@ -174,6 +174,7 @@ files:
174
174
  - lib/superbot/cloud/cli/validations.rb
175
175
  - lib/superbot/cloud/cli/version_command.rb
176
176
  - lib/superbot/cloud/cli/webdriver/base_command.rb
177
+ - lib/superbot/cloud/cli/webdriver/create_command.rb
177
178
  - lib/superbot/cloud/cli/webdriver/delete_command.rb
178
179
  - lib/superbot/cloud/cli/webdriver/list_command.rb
179
180
  - lib/superbot/cloud/cli/webdriver_command.rb