superbot-cloud 0.2.6 → 0.2.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: b7cf9f4ebda39c246a90a762bf76cb9101fa8f0a34abb8b4c87586fd77b09305
4
- data.tar.gz: 3cf214ca9a1215afd9c76f87305da9ec7e647da163330d7a8fe447cd73d2fec6
3
+ metadata.gz: e4dbcec81d287ce7f963412a81a3061645dd519fe8951919b1bcabc870007857
4
+ data.tar.gz: aeafad6a71e729648875cbf35e7052864e7e09bf3ed9cc6c3966db0c93e19006
5
5
  SHA512:
6
- metadata.gz: 9516b4f2711a3b345b3e89707407653b0215edaf22f1f49507d1cb078f6d1ad68f8df0c58f524feeb7235757657d3c0739abc27550675e9ae97cc0e7db647554
7
- data.tar.gz: 01a28235edf1bc534f1704bf6f142bf78b012b25c404ca639c481d3e69cc4ea6b78c4cd277e680c0419144813167cb06adb83bcc91f97b625aa36fd23f19e8ed
6
+ metadata.gz: aa8790116ed3dd57d05b8b89760bd0e9ea2c38122cfa35b74c8ec0c2050828da54c6b3f26595830810a21fab989b9052d6fa0a4a9b8b1f3b85ea0646d24a89e2
7
+ data.tar.gz: 1b3544b4cc35c66cb80f63e645d78f69d3f2ec65d54aa86d2a7fb4c08a849ab31a9fddb890e1f8cec05c2492b37eec80e6718a0e38410ef28ce23d1533dbaa92
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superbot-cloud (0.2.6)
4
+ superbot-cloud (0.2.7)
5
5
  marcel (= 0.3.3)
6
6
  multipart-post (= 2.0.0)
7
7
 
@@ -18,6 +18,7 @@ module Superbot
18
18
  cancel_schedule: { method: :delete, endpoint: 'schedules', required_param: :id },
19
19
  webdriver_session_list: { method: :get, endpoint: 'webdriver_sessions' },
20
20
  delete_webdriver_session: { method: :delete, endpoint: 'webdriver_sessions', required_param: :session_id },
21
+ get_webdriver_session: { method: :get, endpoint: 'webdriver_sessions', required_param: :session_id },
21
22
  member_list: { method: :get, endpoint: 'members' },
22
23
  add_member: { method: :post, endpoint: 'members' },
23
24
  remove_member: { method: :delete, endpoint: 'members', required_param: :username },
@@ -25,7 +26,10 @@ module Superbot
25
26
  abort_interactive_run: { method: :delete, endpoint: 'interactive_runs', required_param: :id },
26
27
  update_interactive_run: { method: :patch, endpoint: 'interactive_runs', required_param: :id },
27
28
  show_interactive_run: { method: :get, endpoint: 'interactive_runs', required_param: :id },
28
- interactive_run_list: { method: :get, endpoint: 'interactive_runs' }
29
+ interactive_run_list: { method: :get, endpoint: 'interactive_runs' },
30
+ access_token_list: { method: :get, endpoint: 'access_tokens' },
31
+ create_access_token: { method: :post, endpoint: 'access_tokens' },
32
+ revoke_access_token: { method: :delete, endpoint: 'access_tokens', required_param: :token }
29
33
  }.freeze
30
34
 
31
35
  def self.request(type, params: {})
@@ -46,11 +50,10 @@ module Superbot
46
50
  request_class.new(uri).tap { |r| r.set_form_data(params) }
47
51
  end
48
52
 
49
- if Superbot::Cloud.credentials
50
- req['Authorization'] = format(
51
- 'Token token="%<token>s", email="%<email>s"',
52
- **Superbot::Cloud.credentials.slice(:email, :token)
53
- )
53
+ auth_token = ENV['SUPERBOT_TOKEN'] || Superbot::Cloud.credentials&.slice(:username, :token)&.values&.join(':')
54
+ if auth_token
55
+ auth_type = ENV['SUPERBOT_TOKEN'] ? 'Bearer' : 'Basic'
56
+ req['Authorization'] = "#{auth_type} #{Base64.urlsafe_encode64(auth_token)}"
54
57
  end
55
58
 
56
59
  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
@@ -4,7 +4,7 @@ module Superbot
4
4
  module Cloud
5
5
  module CLI
6
6
  class OrganizationBasedCommand < LoginRequiredCommand
7
- option ["--org"], "ORGANIZATION", "Name of organization to take action on", required: true, attribute_name: :organization
7
+ option ["--org"], "ORGANIZATION", "Name of organization to take action on", environment_variable: "SUPERBOT_ORG", required: ENV['SUPERBOT_TOKEN'].to_s.empty?, attribute_name: :organization
8
8
  end
9
9
  end
10
10
  end
@@ -12,6 +12,7 @@ require_relative 'webdriver_command'
12
12
  require_relative 'member_command'
13
13
  require_relative 'schedule_command'
14
14
  require_relative 'run_command'
15
+ require_relative 'token_command'
15
16
 
16
17
  module Superbot
17
18
  module Cloud
@@ -25,7 +26,8 @@ module Superbot
25
26
  subcommand ['webdriver'], "Manage your webdriver sessions", WebdriverCommand
26
27
  subcommand ['member'], "Manage your organization members", MemberCommand
27
28
  subcommand ['schedule'], "Manage your schedules", ScheduleCommand
28
- subcommand(['run'], "Schedule a cloud run", RunCommand) if ENV['SUPERBOT_FEAT_CLOUD_RUNS'] == 'true'
29
+ subcommand(['run'], "Manage your interactive cloud runs", RunCommand) if ENV['SUPERBOT_FEAT_CLOUD_RUNS'] == 'true'
30
+ subcommand ['token'], "Manage your organization tokens", TokenCommand
29
31
 
30
32
  option ['-v', '--version'], :flag, "Show version information" do
31
33
  puts Superbot::Cloud::VERSION
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superbot
4
+ module Cloud
5
+ module CLI
6
+ module Token
7
+ class BaseCommand < OrganizationBasedCommand
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superbot
4
+ module Cloud
5
+ module CLI
6
+ module Token
7
+ class GenerateCommand < BaseCommand
8
+ parameter "NAME", "Token title", required: true
9
+
10
+ def execute
11
+ generate_token
12
+ end
13
+
14
+ def generate_token
15
+ api_response = Superbot::Cloud::Api.request(:create_access_token, params: { organization_name: organization, name: name })
16
+ puts api_response[:token]
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superbot
4
+ module Cloud
5
+ module CLI
6
+ module Token
7
+ class ListCommand < BaseCommand
8
+ OUTPUT_HEADERS = {
9
+ name: "Title",
10
+ token: "Token",
11
+ scope: "API scope"
12
+ }.freeze
13
+
14
+ def execute
15
+ list_tokens
16
+ end
17
+
18
+ def list_tokens
19
+ api_response = Superbot::Cloud::Api.request(:access_token_list, params: { organization_name: organization })
20
+ puts "Organization: #{api_response[:organization]}"
21
+ puts "Access Tokens:"
22
+ puts(api_response[:access_tokens].map { |m| m[:username] })
23
+
24
+ puts "Organization: #{api_response[:organization]}"
25
+ puts OUTPUT_HEADERS.values.map { |header| header.ljust(35) }.join
26
+ puts ''.ljust(35 * OUTPUT_HEADERS.length, '-')
27
+ api_response[:access_tokens].each do |webdriver_session|
28
+ puts webdriver_session.slice(*OUTPUT_HEADERS.keys).values.map { |v| v.to_s.ljust(35) }.join
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superbot
4
+ module Cloud
5
+ module CLI
6
+ module Token
7
+ class RevokeCommand < BaseCommand
8
+ parameter "TOKEN", "Access token to remove"
9
+
10
+ def execute
11
+ revoke_token
12
+ end
13
+
14
+ def revoke_token
15
+ api_response = Superbot::Cloud::Api.request(:revoke_access_token, params: { organization_name: organization, token: token })
16
+ puts "Token was successfully revoked"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'token/base_command'
4
+ require_relative 'token/generate_command'
5
+ require_relative 'token/revoke_command'
6
+ require_relative 'token/list_command'
7
+
8
+ module Superbot
9
+ module Cloud
10
+ module CLI
11
+ class TokenCommand < LoginRequiredCommand
12
+ subcommand ['generate'], "Generate new access token", Token::GenerateCommand
13
+ subcommand ['revoke'], "Revoke token", Token::RevokeCommand
14
+ subcommand ['list'], "List your organization access tokens", Token::ListCommand
15
+ end
16
+ end
17
+ end
18
+ end
@@ -21,8 +21,6 @@ module Superbot
21
21
  def list_sessions
22
22
  states = all? ? nil : %w[idle proxying]
23
23
  api_response = Superbot::Cloud::Api.request(:webdriver_session_list, params: { organization_name: organization, 'aasm_state[]': states })
24
- abort api_response[:error] if api_response[:error]
25
-
26
24
  abort "No active sessions found for #{api_response[:organization]} organization" if api_response[:webdriver_sessions].empty?
27
25
 
28
26
  if quiet?
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Superbot
4
4
  module Cloud
5
- VERSION = "0.2.6"
5
+ VERSION = "0.2.7"
6
6
  end
7
7
  end
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.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Superbots
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-17 00:00:00.000000000 Z
11
+ date: 2019-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post
@@ -166,6 +166,11 @@ files:
166
166
  - lib/superbot/cloud/cli/test/list_command.rb
167
167
  - lib/superbot/cloud/cli/test/upload_command.rb
168
168
  - lib/superbot/cloud/cli/test_command.rb
169
+ - lib/superbot/cloud/cli/token/base_command.rb
170
+ - lib/superbot/cloud/cli/token/generate_command.rb
171
+ - lib/superbot/cloud/cli/token/list_command.rb
172
+ - lib/superbot/cloud/cli/token/revoke_command.rb
173
+ - lib/superbot/cloud/cli/token_command.rb
169
174
  - lib/superbot/cloud/cli/validations.rb
170
175
  - lib/superbot/cloud/cli/version_command.rb
171
176
  - lib/superbot/cloud/cli/webdriver/base_command.rb