haveapi-client 0.25.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27e77fcc6b09abb1256fc690f810b3a2b2e6414f7c05b1700fba1c1265b740a3
4
- data.tar.gz: d5b67f3dfa43b10abc7f19ce949db3848d6dd498a768ac115209a155baae9bde
3
+ metadata.gz: 05b1882ec03471aaac2e24887a5d8e79566790d4320c8325407a8317c3e18a16
4
+ data.tar.gz: a741e6ceacd43b667325dc7e857c19b0df5b913a08b0574b15a9233ec697d867
5
5
  SHA512:
6
- metadata.gz: 305088bba08a3dd5eb76ee4e9efd8206b07a30a2ebeb8fb5aab456142bb9ae10770a1f5eff0b5cae4465a1a1f19dd06918a10a7b87942eea5b5eea28be1fc742
7
- data.tar.gz: 16b373b4ca92362e161db123500e0c306d5b50e37d8d424b246985e3547ae1ad91d2e89a27094c9e280dbb8998858f79887ce4b77787c54e186c4960cc897d9c
6
+ metadata.gz: bfbb1976f6269371c4bdb63bd3f47d608f97abf1c055b6bfc2c437dbb838a83b0dc29bb1a9a00d082f102e66833f5dd59fb04b7f22d3d09814f02791632704ec
7
+ data.tar.gz: ac3faa2328d45ef0986e98001a8fd046632c24c32614f9003912b6f8e59a3e9fa395459cd53d4b83047715c676fa0b4811b5b5a94f93a9798d1778bcd85563df
@@ -160,6 +160,7 @@ module HaveAPI::CLI
160
160
  def options
161
161
  options = {
162
162
  client: default_url,
163
+ raw_values: false,
163
164
  block: true,
164
165
  verbose: false
165
166
  }
@@ -173,7 +174,7 @@ module HaveAPI::CLI
173
174
 
174
175
  opts.on('-a', '--auth METHOD', Cli.auth_methods.keys, 'Authentication method') do |m|
175
176
  options[:auth] = m
176
- connect_api(url: options[:client], version: options[:version])
177
+ connect_api(url: options[:client], version: options[:version], verify_ssl: options[:verify_ssl])
177
178
 
178
179
  @auth = Cli.auth_methods[m].new(
179
180
  @api,
@@ -237,6 +238,10 @@ module HaveAPI::CLI
237
238
  options[:raw] = true
238
239
  end
239
240
 
241
+ opts.on('--[no-]raw-values', 'Toggle parameter processing') do |v|
242
+ options[:raw_values] = v
243
+ end
244
+
240
245
  opts.on('--timestamp', 'Display Datetime parameters as timestamp') do
241
246
  options[:datetime] = :timestamp
242
247
  end
@@ -281,6 +286,10 @@ module HaveAPI::CLI
281
286
  @action = [:check_compat]
282
287
  end
283
288
 
289
+ opts.on('--[no-]verify-ssl', 'Toggle SSL peer verification') do |v|
290
+ options[:verify_ssl] = v
291
+ end
292
+
284
293
  opts.on('-h', '--help', 'Show this message') do
285
294
  options[:help] = true
286
295
  end
@@ -298,7 +307,10 @@ module HaveAPI::CLI
298
307
 
299
308
  unless options[:auth]
300
309
  cfg = server_config(options[:client])
301
- connect_api(url: options[:client], version: options[:version]) unless @api
310
+
311
+ unless @api
312
+ connect_api(url: options[:client], version: options[:version], verify_ssl: options[:verify_ssl])
313
+ end
302
314
 
303
315
  if (m = cfg[:last_auth])
304
316
  @auth = Cli.auth_methods[m].new(
@@ -326,9 +338,8 @@ module HaveAPI::CLI
326
338
 
327
339
  options[name] = if arg.nil?
328
340
  read_param(name, p)
329
-
330
341
  else
331
- args.first
342
+ parse_action_param(name, args.first)
332
343
  end
333
344
  end
334
345
  end
@@ -652,14 +663,33 @@ module HaveAPI::CLI
652
663
  @config[:servers].last
653
664
  end
654
665
 
655
- def connect_api(url: nil, version: nil)
666
+ def connect_api(url: nil, version: nil, verify_ssl: nil)
667
+ verify_ssl = @opts && @opts[:verify_ssl] if verify_ssl.nil?
668
+
656
669
  @api = HaveAPI::Client::Communicator.new(
657
670
  url || api_url,
658
- version || (@opts && @opts[:version])
671
+ version || (@opts && @opts[:version]),
672
+ verify_ssl: verify_ssl
659
673
  )
660
674
  @api.identity = $0.split('/').last
661
675
  end
662
676
 
677
+ def parse_action_param(name, value)
678
+ if @opts[:raw_values] || !value.start_with?('@')
679
+ value
680
+ elsif value.start_with?('@@')
681
+ value[1..]
682
+ else
683
+ file_path = value[1..]
684
+
685
+ begin
686
+ File.read(file_path)
687
+ rescue SystemCallError => e
688
+ raise "Unable to read parameter #{name} from file '#{file_path}': #{e.message}"
689
+ end
690
+ end
691
+ end
692
+
663
693
  def format_errors(action, msg, errors)
664
694
  warn "Action failed: #{msg}"
665
695
 
@@ -137,9 +137,7 @@ module HaveAPI::CLI
137
137
  v = o[i]
138
138
  end
139
139
 
140
- # rubocop:disable Lint/FormatParameterMismatch
141
140
  line format("%#{w}s: %s", c[:label], v)
142
- # rubocop:enable Lint/FormatParameterMismatch
143
141
  end
144
142
 
145
143
  line
@@ -5,7 +5,12 @@ module HaveAPI::Client::Authentication
5
5
  register :basic
6
6
 
7
7
  def resource
8
- RestClient::Resource.new(@communicator.url, @opts[:user], @opts[:password])
8
+ RestClient::Resource.new(
9
+ @communicator.url,
10
+ user: @opts[:user],
11
+ password: @opts[:password],
12
+ verify_ssl: @communicator.verify_ssl
13
+ )
9
14
  end
10
15
 
11
16
  def user = @opts.[](:user)
@@ -14,6 +14,7 @@ class HaveAPI::Client::Client
14
14
  # @option opts [Boolean] block
15
15
  # @option opts [Integer] block_interval
16
16
  # @option opts [Integer] block_timeout
17
+ # @option opts [Boolean] verify_ssl
17
18
  def initialize(url, opts = {})
18
19
  @setup = false
19
20
  @opts = opts
@@ -25,7 +26,11 @@ class HaveAPI::Client::Client
25
26
  @api = @opts[:communicator]
26
27
 
27
28
  else
28
- @api = HaveAPI::Client::Communicator.new(url, @version)
29
+ @api = HaveAPI::Client::Communicator.new(
30
+ url,
31
+ @version,
32
+ **{ verify_ssl: opts[:verify_ssl] }.compact
33
+ )
29
34
  @api.identity = @opts[:identity]
30
35
  end
31
36
  end
@@ -80,7 +85,7 @@ class HaveAPI::Client::Client
80
85
 
81
86
  # @return [Hash] client options
82
87
  def opts(*keys)
83
- keys.empty? ? @opts.clone : @opts.select { |k, _| keys.include?(k) }
88
+ keys.empty? ? @opts.clone : @opts.slice(*keys)
84
89
  end
85
90
 
86
91
  # @return [HaveAPI::Client::Communicator]
@@ -15,14 +15,15 @@ module HaveAPI::Client
15
15
  end
16
16
  end
17
17
 
18
- attr_reader :url, :auth
18
+ attr_reader :url, :auth, :verify_ssl
19
19
  attr_accessor :identity
20
20
 
21
- def initialize(url, v = nil)
21
+ def initialize(url, v = nil, verify_ssl: true)
22
22
  @url = url
23
23
  @auth = Authentication::NoAuth.new(self, {}, {})
24
- @rest = RestClient::Resource.new(@url)
24
+ @rest = RestClient::Resource.new(@url, verify_ssl: verify_ssl)
25
25
  @version = v
26
+ @verify_ssl = verify_ssl
26
27
  @identity = 'haveapi-client-ruby'
27
28
  end
28
29
 
@@ -1,6 +1,6 @@
1
1
  module HaveAPI
2
2
  module Client
3
3
  PROTOCOL_VERSION = '2.0'.freeze
4
- VERSION = '0.25.0'.freeze
4
+ VERSION = '0.26.0'.freeze
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haveapi-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.0
4
+ version: 0.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Skokan
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
173
  requirements: []
174
- rubygems_version: 3.5.9
174
+ rubygems_version: 3.5.22
175
175
  signing_key:
176
176
  specification_version: 4
177
177
  summary: Ruby API and CLI for HaveAPI