stf-client-neofreko 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -5
- data/lib/stf/client.rb +30 -25
- data/lib/stf/interactor/start_debug_session_interactor.rb +26 -38
- data/lib/stf/interactor/user_interactor.rb +23 -0
- data/lib/stf/version.rb +1 -1
- data/lib/stf/view/cli.rb +23 -12
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2d1547cb516379f9794670327da1e61a4c38dda
|
4
|
+
data.tar.gz: c877f7b529fb3fe6dbafb672bc1c09f0448fdc34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e94a19593b4a94be969b7dc8ab8f4ad67b5c542989c9413cb921aef9451de5d13b9faf8e42577dc2b1d393cee3ee3d0c46f24d45e8ea496d5bf9d2042123ba7c
|
7
|
+
data.tar.gz: 235d8b26d77f34f1c686fc8595fd81c284a5c987617f8838424a8d93fdf14f7b8fbdab7c474c5ddf7f37112ddbbb85472cac281107b99198810b2d766db1454f
|
data/README.md
CHANGED
@@ -50,11 +50,6 @@ COMMANDS
|
|
50
50
|
ENVIRONMENT VARIABLES
|
51
51
|
STF_TOKEN - Authorization token
|
52
52
|
STF_URL - URL to STF
|
53
|
-
|
54
|
-
COMMAND OPTIONS
|
55
|
-
connect
|
56
|
-
-f - Filter devices in the form of "key:value". Use stf-client keys to list keys and stf-client values -k <key from prev command> to get list of applicable values
|
57
|
-
-d, --adb - Automatically execute adb connect command once device acquired. Default true
|
58
53
|
```
|
59
54
|
|
60
55
|
## Contributing
|
data/lib/stf/client.rb
CHANGED
@@ -17,52 +17,57 @@ module Stf
|
|
17
17
|
|
18
18
|
def get_devices
|
19
19
|
response = execute '/api/v1/devices', Net::HTTP::Get
|
20
|
-
|
20
|
+
response.devices
|
21
21
|
end
|
22
22
|
|
23
23
|
def get_device(serial)
|
24
24
|
response = execute "/api/v1/devices/#{serial}", Net::HTTP::Get
|
25
|
-
|
25
|
+
response.device
|
26
26
|
end
|
27
27
|
|
28
28
|
def get_user
|
29
29
|
response = execute '/api/v1/user', Net::HTTP::Get
|
30
|
-
|
30
|
+
response.user
|
31
31
|
end
|
32
32
|
|
33
33
|
def get_user_devices
|
34
34
|
response = execute '/api/v1/user/devices', Net::HTTP::Get
|
35
|
-
|
35
|
+
response.devices
|
36
36
|
end
|
37
37
|
|
38
38
|
def add_device(serial)
|
39
|
-
response = execute '/api/v1/user/devices', Net::HTTP::Post, {serial: serial}.to_json
|
40
|
-
|
39
|
+
response = execute '/api/v1/user/devices', Net::HTTP::Post, { serial: serial }.to_json
|
40
|
+
response.success
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_adb_public_key(adbkeypub)
|
44
|
+
response = execute '/api/v1/user/adbPublicKeys', Net::HTTP::Post, { publickey: adbkeypub }.to_json
|
45
|
+
response.success
|
41
46
|
end
|
42
47
|
|
43
48
|
def remove_device(serial)
|
44
49
|
response = execute "/api/v1/user/devices/#{serial}", Net::HTTP::Delete
|
45
|
-
|
50
|
+
response.success
|
46
51
|
end
|
47
52
|
|
48
53
|
def start_debug(serial)
|
49
54
|
response = execute "/api/v1/user/devices/#{serial}/remoteConnect", Net::HTTP::Post
|
50
|
-
|
55
|
+
response
|
51
56
|
end
|
52
57
|
|
53
58
|
def stop_debug(serial)
|
54
59
|
response = execute "/api/v1/user/devices/#{serial}/remoteConnect", Net::HTTP::Delete
|
55
|
-
|
60
|
+
response.success
|
56
61
|
end
|
57
62
|
|
58
63
|
private
|
59
64
|
|
60
|
-
def execute(relative_url, type, body='')
|
61
|
-
|
65
|
+
def execute(relative_url, type, body = '')
|
66
|
+
execute_absolute @base_url + relative_url, type, body
|
62
67
|
end
|
63
68
|
|
64
|
-
def execute_absolute(url, type, body='', limit = 10)
|
65
|
-
raise ArgumentError, 'too many HTTP redirects' if limit
|
69
|
+
def execute_absolute(url, type, body = '', limit = 10)
|
70
|
+
raise ArgumentError, 'too many HTTP redirects' if limit.zero?
|
66
71
|
|
67
72
|
uri = URI.parse(url)
|
68
73
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -72,19 +77,19 @@ module Stf
|
|
72
77
|
response = http.request(request)
|
73
78
|
|
74
79
|
case response
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
80
|
+
when Net::HTTPSuccess then
|
81
|
+
json = JSON.parse(response.body, object_class: OpenStruct)
|
82
|
+
|
83
|
+
logger.debug "API returned #{json}"
|
84
|
+
when Net::HTTPRedirection then
|
85
|
+
location = response['location']
|
86
|
+
logger.debug "redirected to #{location}"
|
87
|
+
return execute_absolute(location, type, body, limit - 1)
|
88
|
+
else
|
89
|
+
logger.error "API returned #{response.value}"
|
85
90
|
end
|
86
91
|
|
87
|
-
|
92
|
+
json
|
88
93
|
end
|
89
94
|
end
|
90
|
-
end
|
95
|
+
end
|
@@ -6,7 +6,6 @@ require 'stf/errors'
|
|
6
6
|
require 'stf/model/session'
|
7
7
|
|
8
8
|
class StartDebugSessionInteractor
|
9
|
-
|
10
9
|
include Log
|
11
10
|
include ADB
|
12
11
|
|
@@ -14,19 +13,19 @@ class StartDebugSessionInteractor
|
|
14
13
|
@stf = stf
|
15
14
|
end
|
16
15
|
|
17
|
-
def execute(wanted, all_flag, filter
|
16
|
+
def execute(wanted, all_flag, filter)
|
18
17
|
wanted = 1 if wanted.nil?
|
19
18
|
wanted = wanted.to_i
|
20
19
|
|
21
20
|
1..10.times do
|
22
|
-
wanted -= connect(wanted, all_flag, filter
|
21
|
+
wanted -= connect(wanted, all_flag, filter)
|
23
22
|
return if all_flag || wanted <= 0
|
24
23
|
logger.info 'We are still waiting for ' + wanted.to_s + ' device(s). Retrying'
|
25
24
|
sleep 5
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
|
-
def connect(wanted, all_flag, filter
|
28
|
+
def connect(wanted, all_flag, filter)
|
30
29
|
devices = @stf.get_devices
|
31
30
|
if devices.nil? || (devices.is_a?(Array) && devices.empty?)
|
32
31
|
logger.info 'No devices connected to STF'
|
@@ -34,8 +33,8 @@ class StartDebugSessionInteractor
|
|
34
33
|
end
|
35
34
|
|
36
35
|
usable_devices = devices
|
37
|
-
|
38
|
-
|
36
|
+
.map { |d| Device.new(d) }
|
37
|
+
.select do |d|
|
39
38
|
d.ready == true && d.present == true && d.using == false
|
40
39
|
end
|
41
40
|
|
@@ -59,47 +58,36 @@ class StartDebugSessionInteractor
|
|
59
58
|
|
60
59
|
n = 0
|
61
60
|
usable_devices.shuffle.each do |d|
|
62
|
-
n += 1 if connect_device(d
|
61
|
+
n += 1 if connect_device(d)
|
63
62
|
break if !all_flag && n >= wanted
|
64
63
|
end
|
65
64
|
|
66
65
|
n
|
67
66
|
end
|
68
67
|
|
69
|
-
def connect_device(device
|
70
|
-
|
71
|
-
return false if device.nil?
|
72
|
-
|
73
|
-
serial = device.serial
|
74
|
-
success = @stf.add_device serial
|
75
|
-
if success
|
76
|
-
logger.info "Device #{serial} added"
|
77
|
-
elsif logger.error "Can't add device #{serial}"
|
78
|
-
return false
|
79
|
-
end
|
80
|
-
|
81
|
-
result = @stf.start_debug serial
|
82
|
-
unless result.success
|
83
|
-
logger.error "Can't start debugging session for device #{serial}"
|
84
|
-
@stf.remove_device serial
|
85
|
-
return false
|
86
|
-
end
|
87
|
-
|
88
|
-
logger.info "remoteConnectUrl: #{result.remoteConnectUrl}"
|
68
|
+
def connect_device(device)
|
69
|
+
return false if device.nil?
|
89
70
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
71
|
+
serial = device.serial
|
72
|
+
success = @stf.add_device serial
|
73
|
+
if success
|
74
|
+
logger.info "Device #{serial} added"
|
75
|
+
elsif logger.error "Can't add device #{serial}"
|
76
|
+
return false
|
77
|
+
end
|
94
78
|
|
95
|
-
|
96
|
-
|
79
|
+
result = @stf.start_debug serial
|
80
|
+
unless result.success
|
81
|
+
logger.error "Can't start debugging session for device #{serial}"
|
82
|
+
@stf.remove_device serial
|
97
83
|
return false
|
98
84
|
end
|
99
|
-
end
|
100
85
|
|
101
|
-
|
102
|
-
|
103
|
-
end
|
86
|
+
execute_adb_with 30, "connect #{result.remoteConnectUrl}"
|
87
|
+
return true
|
104
88
|
|
105
|
-
|
89
|
+
rescue Net::HTTPFatalError
|
90
|
+
logger.error 'Failed to start debug session'
|
91
|
+
return false
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'ADB'
|
2
|
+
|
3
|
+
require 'stf/client'
|
4
|
+
require 'stf/log/log'
|
5
|
+
require 'stf/errors'
|
6
|
+
require 'stf/model/session'
|
7
|
+
|
8
|
+
class UserInteractor
|
9
|
+
include Log
|
10
|
+
def initialize(stf)
|
11
|
+
@stf = stf
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute(adb_public_key_location)
|
15
|
+
public_key = File.open(adb_public_key_location, 'rb', &:read)
|
16
|
+
success = @stf.add_adb_public_key public_key
|
17
|
+
if success
|
18
|
+
logger.info "adb public key from '#{adb_public_key_location}' has been added"
|
19
|
+
elsif logger.error "Can't add public key from '#{adb_public_key_location}'"
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/stf/version.rb
CHANGED
data/lib/stf/view/cli.rb
CHANGED
@@ -9,6 +9,7 @@ module Stf
|
|
9
9
|
require 'stf/interactor/remove_all_user_devices_interactor'
|
10
10
|
require 'stf/interactor/get_keys_interactor'
|
11
11
|
require 'stf/interactor/get_values_interactor'
|
12
|
+
require 'stf/interactor/user_interactor'
|
12
13
|
|
13
14
|
include GLI::App
|
14
15
|
extend self
|
@@ -24,15 +25,14 @@ module Stf
|
|
24
25
|
desc 'URL to STF, can also be set by environment variable STF_URL'
|
25
26
|
flag [:u, :url]
|
26
27
|
|
27
|
-
pre do |global_options,
|
28
|
-
|
28
|
+
pre do |global_options, _command, _options, _args|
|
29
29
|
global_options[:url] = ENV['STF_URL'] if global_options[:url].nil?
|
30
30
|
global_options[:token] = ENV['STF_TOKEN'] if global_options[:token].nil?
|
31
31
|
|
32
32
|
help_now!('STF url is required') if global_options[:url].nil?
|
33
33
|
help_now!('Authorization token is required') if global_options[:token].nil?
|
34
34
|
|
35
|
-
Log
|
35
|
+
Log.verbose(global_options[:verbose])
|
36
36
|
|
37
37
|
$stf = Stf::Client.new(global_options[:url], global_options[:token])
|
38
38
|
end
|
@@ -42,16 +42,15 @@ module Stf
|
|
42
42
|
c.switch [:all]
|
43
43
|
c.flag [:n, :number]
|
44
44
|
c.flag [:f, :filter]
|
45
|
-
c.switch :adb, default_value: true, desc: 'automatically execute adb connect'
|
46
45
|
|
47
|
-
c.action do |
|
48
|
-
StartDebugSessionInteractor.new($stf).execute(options[:number], options[:all], options[:filter]
|
46
|
+
c.action do |_global_options, options, _args|
|
47
|
+
StartDebugSessionInteractor.new($stf).execute(options[:number], options[:all], options[:filter])
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
52
|
-
desc 'Show
|
51
|
+
desc 'Show avaliable keys for filtering'
|
53
52
|
command :keys do |c|
|
54
|
-
c.action do |
|
53
|
+
c.action do |_global_options, _options, _args|
|
55
54
|
puts GetKeysInteractor.new($stf).execute
|
56
55
|
end
|
57
56
|
end
|
@@ -60,7 +59,7 @@ module Stf
|
|
60
59
|
command :values do |c|
|
61
60
|
c.flag [:k, :key]
|
62
61
|
|
63
|
-
c.action do |
|
62
|
+
c.action do |_global_options, options, _args|
|
64
63
|
if options[:key].nil?
|
65
64
|
help_now!('Please specify the key (--key)')
|
66
65
|
else
|
@@ -75,7 +74,7 @@ module Stf
|
|
75
74
|
c.flag [:d, :device]
|
76
75
|
c.switch [:all]
|
77
76
|
|
78
|
-
c.action do |
|
77
|
+
c.action do |_global_options, options, _args|
|
79
78
|
if options[:device].nil? && options[:all] == true
|
80
79
|
StopAllDebugSessionsInteractor.new($stf).execute
|
81
80
|
elsif !options[:device].nil? && options[:all] == false
|
@@ -87,12 +86,24 @@ module Stf
|
|
87
86
|
|
88
87
|
desc 'Frees all devices that are assigned to current user in STF. Doesn\'t modify local adb'
|
89
88
|
command :clean do |c|
|
90
|
-
c.action do |
|
89
|
+
c.action do |_global_options, _options, _args|
|
91
90
|
RemoveAllUserDevicesInteractor.new($stf).execute
|
92
91
|
end
|
93
92
|
end
|
94
93
|
|
94
|
+
desc 'Add current adb public key into STF (depends on https://github.com/openstf/stf/pull/770)'
|
95
|
+
command :trustme do |c|
|
96
|
+
c.flag [:k, :adb_public_key_location], desc: 'Location of adb public key', default_value: '~/.android/adbkey.pub'
|
97
|
+
c.action do |_global_options, options, _args|
|
98
|
+
options[:adb_public_key_location] = '~/.android/adbkey.pub' if options[:adb_public_key_location].nil?
|
99
|
+
filename = File.expand_path(options[:adb_public_key_location])
|
100
|
+
unless File.exist? filename
|
101
|
+
help_now!("File does not exist: '#{options[:adb_public_key_location]}'")
|
102
|
+
end
|
103
|
+
UserInteractor.new($stf).execute(options[:adb_public_key_location])
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
95
107
|
exit run(ARGV)
|
96
108
|
end
|
97
109
|
end
|
98
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stf-client-neofreko
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akhmad Fathonih
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/stf/interactor/start_debug_session_interactor.rb
|
135
135
|
- lib/stf/interactor/stop_all_debug_sessions_interactor.rb
|
136
136
|
- lib/stf/interactor/stop_debug_session_interactor.rb
|
137
|
+
- lib/stf/interactor/user_interactor.rb
|
137
138
|
- lib/stf/log/log.rb
|
138
139
|
- lib/stf/model/device.rb
|
139
140
|
- lib/stf/model/session.rb
|