haveapi-client 0.20.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/Rakefile +0 -1
- data/haveapi-client.gemspec +7 -10
- data/lib/haveapi/cli/action_state.rb +50 -51
- data/lib/haveapi/cli/authentication/base.rb +4 -9
- data/lib/haveapi/cli/authentication/basic.rb +3 -1
- data/lib/haveapi/cli/authentication/token.rb +7 -8
- data/lib/haveapi/cli/cli.rb +115 -127
- data/lib/haveapi/cli/command.rb +2 -4
- data/lib/haveapi/cli/commands/action_state_wait.rb +9 -9
- data/lib/haveapi/cli/example_formatter.rb +8 -8
- data/lib/haveapi/cli/output_formatter.rb +39 -36
- data/lib/haveapi/cli/utils.rb +5 -5
- data/lib/haveapi/cli.rb +1 -1
- data/lib/haveapi/client/action.rb +17 -20
- data/lib/haveapi/client/action_state.rb +3 -7
- data/lib/haveapi/client/authentication/base.rb +4 -7
- data/lib/haveapi/client/authentication/basic.rb +2 -2
- data/lib/haveapi/client/authentication/noauth.rb +0 -1
- data/lib/haveapi/client/authentication/token.rb +28 -27
- data/lib/haveapi/client/client.rb +12 -6
- data/lib/haveapi/client/communicator.rb +33 -35
- data/lib/haveapi/client/exceptions.rb +5 -9
- data/lib/haveapi/client/parameters/resource.rb +1 -0
- data/lib/haveapi/client/parameters/typed.rb +3 -5
- data/lib/haveapi/client/params.rb +8 -8
- data/lib/haveapi/client/resource.rb +12 -13
- data/lib/haveapi/client/resource_instance.rb +71 -72
- data/lib/haveapi/client/resource_instance_list.rb +2 -1
- data/lib/haveapi/client/response.rb +8 -8
- data/lib/haveapi/client/validator.rb +7 -8
- data/lib/haveapi/client/validators/confirmation.rb +1 -0
- data/lib/haveapi/client/validators/length.rb +1 -0
- data/lib/haveapi/client/validators/numericality.rb +2 -1
- data/lib/haveapi/client/validators/presence.rb +1 -0
- data/lib/haveapi/client/version.rb +2 -2
- data/lib/haveapi/client.rb +2 -2
- data/lib/restclient_ext/resource.rb +5 -5
- data/shell.nix +1 -1
- metadata +15 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a10ca3718864bd73e33c306e4c9d0b01627f60bf43352adc88a48fd14164aef
|
4
|
+
data.tar.gz: 2344875dcded9d82436b0d7a10935ffba00eeb07cebcd6aebb1f45a35e0561fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 389f8ae1e086215dab9d62cdf642b1cb47bb1608e40dab3be0a7415696a19a9bb235d87cbe37b02f69941740b6d4daa34ab2080ac8d6cc981964d0c655021bf6
|
7
|
+
data.tar.gz: f7be612fbc40e3cd2d47e4507cb4ae3c34706086fcae5a2a65740ae5d90a5e5922f584ae561f5c2a8c51f4eeedbec2b2814ff97485126a909b9f9564fa698e26
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/haveapi-client.gemspec
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
|
2
|
-
lib
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$:.unshift(lib) unless $:.include?(lib)
|
4
3
|
require 'haveapi/client/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
@@ -9,22 +8,20 @@ Gem::Specification.new do |spec|
|
|
9
8
|
spec.authors = ['Jakub Skokan']
|
10
9
|
spec.email = ['jakub.skokan@vpsfree.cz']
|
11
10
|
spec.summary =
|
12
|
-
|
11
|
+
spec.description = 'Ruby API and CLI for HaveAPI'
|
13
12
|
spec.homepage = ''
|
14
13
|
spec.license = 'MIT'
|
15
14
|
|
15
|
+
spec.required_ruby_version = ">= #{File.read('../../.ruby-version').strip}"
|
16
|
+
|
16
17
|
spec.files = `git ls-files -z`.split("\x0")
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency 'bundler'
|
22
|
-
spec.add_development_dependency 'rake'
|
23
|
-
|
24
21
|
spec.add_runtime_dependency 'activesupport', '>= 7.0'
|
22
|
+
spec.add_runtime_dependency 'highline', '~> 2.1.0'
|
23
|
+
spec.add_runtime_dependency 'json'
|
25
24
|
spec.add_runtime_dependency 'require_all', '~> 2.0.0'
|
26
25
|
spec.add_runtime_dependency 'rest-client', '~> 2.1.0'
|
27
|
-
spec.add_runtime_dependency 'json'
|
28
|
-
spec.add_runtime_dependency 'highline', '~> 2.1.0'
|
29
26
|
spec.add_runtime_dependency 'ruby-progressbar', '~> 1.13.0'
|
30
27
|
end
|
@@ -26,31 +26,30 @@ module HaveAPI::CLI
|
|
26
26
|
id ||= @id
|
27
27
|
|
28
28
|
if cancel
|
29
|
-
puts
|
29
|
+
puts 'Waiting for the action to cancel (hit Ctrl+C to skip)...'
|
30
30
|
else
|
31
|
-
puts
|
31
|
+
puts 'Waiting for the action to complete (hit Ctrl+C to skip)...'
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
last_status = false
|
35
35
|
can_cancel = false
|
36
|
-
|
36
|
+
|
37
37
|
begin
|
38
38
|
ret = HaveAPI::Client::Action.wait_for_completion(
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
@client,
|
40
|
+
id,
|
41
|
+
timeout:
|
42
42
|
) do |state|
|
43
43
|
last_status = state.status
|
44
44
|
can_cancel = state.can_cancel?
|
45
|
-
|
45
|
+
|
46
46
|
update_progress(state, cancel)
|
47
47
|
end
|
48
|
-
|
49
48
|
rescue Interrupt
|
50
49
|
@pb && @pb.stop
|
51
50
|
puts
|
52
51
|
|
53
|
-
cancel_action(timeout:
|
52
|
+
cancel_action(timeout:) if can_cancel && !cancel && last_status
|
54
53
|
|
55
54
|
puts
|
56
55
|
print_help(id)
|
@@ -70,67 +69,67 @@ module HaveAPI::CLI
|
|
70
69
|
# and call self.wait_for_completion on the cancellation, if it is blocking
|
71
70
|
# operation.
|
72
71
|
def cancel_action(timeout: nil)
|
73
|
-
|
74
|
-
|
72
|
+
$stdout.write('Do you wish to cancel the action? [y/N]: ')
|
73
|
+
$stdout.flush
|
75
74
|
|
76
|
-
|
77
|
-
begin
|
78
|
-
res = HaveAPI::Client::Action.cancel(@client, @id)
|
75
|
+
return unless $stdin.readline.strip.downcase == 'y'
|
79
76
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
puts "Cancelled"
|
86
|
-
exit
|
87
|
-
|
88
|
-
elsif res
|
89
|
-
@pb.resume
|
90
|
-
|
91
|
-
wait_for_completion(
|
92
|
-
id: res,
|
93
|
-
timeout: timeout,
|
94
|
-
cancel: true,
|
95
|
-
)
|
96
|
-
exit
|
97
|
-
end
|
77
|
+
begin
|
78
|
+
res = HaveAPI::Client::Action.cancel(@client, @id)
|
79
|
+
rescue HaveAPI::Client::ActionFailed => e
|
80
|
+
res = e.response
|
81
|
+
end
|
98
82
|
|
99
|
-
|
100
|
-
|
83
|
+
if res.is_a?(HaveAPI::Client::Response) && res.ok?
|
84
|
+
puts 'Cancelled'
|
85
|
+
exit
|
86
|
+
|
87
|
+
elsif res
|
88
|
+
@pb.resume
|
89
|
+
|
90
|
+
wait_for_completion(
|
91
|
+
id: res,
|
92
|
+
timeout:,
|
93
|
+
cancel: true
|
94
|
+
)
|
95
|
+
exit
|
101
96
|
end
|
97
|
+
|
98
|
+
warn "Cancel failed: #{res.message}"
|
99
|
+
exit(false)
|
102
100
|
end
|
103
101
|
|
104
102
|
def print_help(id = nil)
|
105
103
|
id ||= @id
|
106
104
|
|
107
|
-
puts
|
105
|
+
puts 'Run'
|
108
106
|
puts " #{$0} action_state show #{id}"
|
109
|
-
puts
|
107
|
+
puts 'or'
|
110
108
|
puts " #{$0} action_state wait #{id}"
|
111
109
|
puts "to check the action's progress."
|
112
110
|
end
|
113
111
|
|
114
112
|
protected
|
113
|
+
|
115
114
|
def update_progress(state, cancel)
|
116
115
|
@pb ||= ProgressBar.create(
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
116
|
+
title: cancel ? 'Cancelling' : 'Executing',
|
117
|
+
total: state.progress.total,
|
118
|
+
format: if state.progress.total && state.progress.total > 0
|
119
|
+
"%t: [%B] %c/%C #{state.progress.unit}"
|
120
|
+
else
|
121
|
+
'%t: [%B]'
|
122
|
+
end,
|
123
|
+
starting_at: state.progress.current,
|
124
|
+
autofinish: false
|
126
125
|
)
|
127
126
|
|
128
|
-
if state.status
|
129
|
-
|
127
|
+
@pb.title = if state.status
|
128
|
+
cancel ? 'Cancelling' : 'Executing'
|
130
129
|
|
131
|
-
|
132
|
-
|
133
|
-
|
130
|
+
else
|
131
|
+
'Failing'
|
132
|
+
end
|
134
133
|
|
135
134
|
if state.progress.total && state.progress.total > 0
|
136
135
|
@pb.progress = state.progress.current
|
@@ -27,28 +27,23 @@ module HaveAPI::CLI
|
|
27
27
|
# This method is NOT called if the auth provider has been loaded
|
28
28
|
# from the config and wasn't specified as a command line option
|
29
29
|
# and therefore all necessary information must be stored in the config.
|
30
|
-
def options(opts)
|
31
|
-
|
32
|
-
end
|
30
|
+
def options(opts); end
|
33
31
|
|
34
32
|
# Implement this method to check if all needed information
|
35
33
|
# for successful authentication are provided.
|
36
34
|
# Ask the user on stdin if something is missing.
|
37
|
-
def validate
|
38
|
-
|
39
|
-
end
|
35
|
+
def validate; end
|
40
36
|
|
41
37
|
# This method should call HaveAPI::Client::Communicator#authenticate
|
42
38
|
# with arguments specific for this authentication provider.
|
43
|
-
def authenticate
|
44
|
-
|
45
|
-
end
|
39
|
+
def authenticate; end
|
46
40
|
|
47
41
|
def save
|
48
42
|
@communicator.auth_save
|
49
43
|
end
|
50
44
|
|
51
45
|
protected
|
46
|
+
|
52
47
|
attr_reader :communicator, :desc
|
53
48
|
end
|
54
49
|
end
|
@@ -21,10 +21,12 @@ module HaveAPI::CLI::Authentication
|
|
21
21
|
q.default = nil
|
22
22
|
q.echo = false
|
23
23
|
end.to_s
|
24
|
+
|
25
|
+
nil
|
24
26
|
end
|
25
27
|
|
26
28
|
def authenticate
|
27
|
-
@communicator.authenticate(:basic, {user: @user, password: @password})
|
29
|
+
@communicator.authenticate(:basic, { user: @user, password: @password })
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
@@ -22,7 +22,7 @@ module HaveAPI::CLI::Authentication
|
|
22
22
|
end
|
23
23
|
|
24
24
|
opts.on('--token-lifetime LIFETIME',
|
25
|
-
%i
|
25
|
+
%i[fixed renewable_manual renewable_auto permanent],
|
26
26
|
'Token lifetime, defaults to renewable_auto') do |l|
|
27
27
|
@lifetime = l
|
28
28
|
end
|
@@ -36,7 +36,7 @@ module HaveAPI::CLI::Authentication
|
|
36
36
|
@token = nil
|
37
37
|
end
|
38
38
|
|
39
|
-
via = %i
|
39
|
+
via = %i[query_param header]
|
40
40
|
|
41
41
|
opts.on('--token-via VIA', via,
|
42
42
|
'Send token as a query parameter or in HTTP header',
|
@@ -61,12 +61,12 @@ module HaveAPI::CLI::Authentication
|
|
61
61
|
lifetime: @lifetime || :renewable_auto,
|
62
62
|
interval: @interval,
|
63
63
|
valid_to: @valid_to,
|
64
|
-
via: @via
|
64
|
+
via: @via
|
65
65
|
}
|
66
66
|
|
67
67
|
opts.update(@credentials) if @credentials
|
68
68
|
|
69
|
-
@communicator.authenticate(:token, opts) do |
|
69
|
+
@communicator.authenticate(:token, opts) do |_action, params|
|
70
70
|
ret = {}
|
71
71
|
|
72
72
|
params.each do |name, desc|
|
@@ -78,14 +78,13 @@ module HaveAPI::CLI::Authentication
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def save
|
81
|
-
super.update({via: @via, interval: @interval})
|
81
|
+
super.update({ via: @via, interval: @interval })
|
82
82
|
end
|
83
83
|
|
84
84
|
protected
|
85
|
+
|
85
86
|
def request_credentials
|
86
|
-
desc[:resources][:token][:actions][:request][:input][:parameters].
|
87
|
-
%i(lifetime interval).include?(name)
|
88
|
-
end
|
87
|
+
desc[:resources][:token][:actions][:request][:input][:parameters].except(:lifetime, :interval)
|
89
88
|
end
|
90
89
|
end
|
91
90
|
end
|