tenable-ruby 0.4.3 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tenable-ruby.rb +45 -16
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddc71aa2ebeed0c75267eef28edbbe2170a81af29c7ce9cc8be9bcc41d22790e
4
- data.tar.gz: 40e8d3c8a4dff5f9b89d88a439753ec1fcd6d92c50a2d0d8c3c77ce1244e6a7d
3
+ metadata.gz: 4a367b214445184f3805e7d99304cfab5341634a93833e9aa3ee2754fd94212f
4
+ data.tar.gz: 3cbe4522d7639236cbbdd5a59746cd511ba0c240921390bc595bbcd8165a3022
5
5
  SHA512:
6
- metadata.gz: b36308298ed4a9a4708699da058c481545c25bc9f95333bbb3ed444777efcecf3108cd3484a4da6892cee8c62181acb4fa10a55e9713f36d7abd7c5dfbadab63
7
- data.tar.gz: 82ff9c6ece45a2052532363cc194cdbe8c2af7637e40b5e1d9c2f21f3679ee8461d5b0ae5c7305b6d7917c246a71a1b83b12aa546aa0250d3f1d6243df6fe786
6
+ metadata.gz: 59c07dcbfa4029a2e24d5b3396a0cfaf17821e723a00beade9f2d4f1fc543578efa66081d79cdfac1804fb67118fe15f7b79131bf3e39fe498f23018e6d0cc62
7
+ data.tar.gz: 1a9290bc941f16f2c2e5f0dcaf285c2574306271c6459a9aec4e313f09744db17d840f93c87adff1f2ef55068ad8810add28ec4567b2b2dc697ae2e357c7e8c1
@@ -307,6 +307,29 @@ module TenableRuby
307
307
  http_put(options)
308
308
  end
309
309
 
310
+ # Unlinks an agent
311
+ #
312
+ # Reference
313
+ # https://developer.tenable.com/reference#agents-delete
314
+ def agent_unlink(scanner_id, agent_id)
315
+ http_delete(:uri => "/scanners/#{scanner_id}/agents/#{agent_id}", :fields => header)
316
+ end
317
+
318
+ # Creates a bulk operation task to unlink agents
319
+ #
320
+ # Reference
321
+ # https://developer.tenable.com/reference#bulk-unlink-agents
322
+ def agent_bulk_unlink(scanner_id, agent_ids)
323
+ http_post(
324
+ :uri => "/scanners/#{scanner_id}/agents/_bulk/unlink",
325
+ :fields => header,
326
+ :body => {
327
+ :items => agent_ids
328
+ }.to_json,
329
+ :ctype => 'application/json',
330
+ )
331
+ end
332
+
310
333
  # Returns details of the specified asset.
311
334
  #
312
335
  # Reference:
@@ -526,11 +549,11 @@ module TenableRuby
526
549
 
527
550
  # Performs scan with scan policy provided (uuid of policy or policy name).
528
551
  # Name is your scan name and opts is your scan configuration hash
529
- # (foldername is optional - folder where to save the scan (if that folder exists))
552
+ # (scan_folder is optional - folder where to save the scan (if that folder exists))
530
553
  # (scanner_id is optional - ID of the scanner/cloud scanner you want to run this scan on)
531
554
  #
532
555
  # returns: JSON parsed object with scan info
533
- def scan_quick_policy(policyname, name, opts = {}, foldername = nil, scanner_id = nil)
556
+ def scan_quick_policy(policyname, name, opts = {}, scan_folder = nil, scanner_id = nil)
534
557
  policies = list_policies['policies']
535
558
  if policies.nil?
536
559
  raise TenableRuby::Error::TenableError, "Tenable API request 'list_policies' responded with 'nil'"
@@ -548,16 +571,18 @@ module TenableRuby
548
571
  settings.merge!(opts)
549
572
  settings['name'] = name
550
573
  settings['policy_id'] = policy['id']
551
- unless foldername.nil?
574
+ if scan_folder.is_a?(Integer)
575
+ settings['folder_id'] = scan_folder
576
+ elsif scan_folder.is_a?(String)
552
577
  folders = list_folders['folders']
553
578
  if folders.nil?
554
579
  raise TenableRuby::Error::TenableError, "Tenable API request 'list_folders' responded with 'nil'"
555
580
  end
556
- selected_folders = folders.select do |folder|
557
- folder['name'] == foldername
558
- end
559
- unless selected_folders.size == 0
560
- settings['folder_id'] = selected_folders.first['id']
581
+ selected_folder = folders.find { |f| f['name'] == scan_folder }
582
+ if selected_folder
583
+ settings['folder_id'] = selected_folder['id']
584
+ else
585
+ raise TenableRuby::Error::TenableError, "Could not find folder with name #{scan_folder}"
561
586
  end
562
587
  end
563
588
  unless scanner_id.nil?
@@ -846,7 +871,6 @@ module TenableRuby
846
871
  uri = opts[:uri]
847
872
  fields = opts[:fields] || {}
848
873
  raw_content = opts[:raw_content] || false
849
- json = {}
850
874
  tries = @httpretry
851
875
 
852
876
  request = Net::HTTP::Get.new(uri)
@@ -862,11 +886,17 @@ module TenableRuby
862
886
  sleep @httpsleep
863
887
  retry
864
888
  else
865
- return json
889
+ raise TenableRuby::Error::TenableError.new("#{e}: No more retries for http GET '#{opts[:uri]}'")
866
890
  end
867
- rescue URI::InvalidURIError
868
- return json
891
+ rescue URI::InvalidURIError => e
892
+ raise TenableRuby::Error::TenableError.new("#{e}: http GET '#{opts[:uri]}'")
893
+ end
894
+
895
+ if response.code.to_s != "200"
896
+ raise TenableRuby::Error::TenableError.new(response: response),
897
+ "Tenable API request '#{opts[:uri]}' responded with response code #{response.code}"
869
898
  end
899
+
870
900
  if !raw_content
871
901
  parse_json(response.body)
872
902
  else
@@ -901,7 +931,6 @@ module TenableRuby
901
931
  fields = opts[:fields] || {}
902
932
  body = opts[:body]
903
933
  ctype = opts[:ctype]
904
- json = {}
905
934
  tries = @httpretry
906
935
 
907
936
  request = Net::HTTP::Post.new(uri)
@@ -920,10 +949,10 @@ module TenableRuby
920
949
  sleep @httpsleep
921
950
  retry
922
951
  else
923
- return json
952
+ raise TenableRuby::Error::TenableError.new("#{e}: No more retries for http POST '#{opts[:uri]}'")
924
953
  end
925
- rescue URI::InvalidURIError
926
- return json
954
+ rescue URI::InvalidURIError => e
955
+ raise TenableRuby::Error::TenableError.new("#{e}: http POST '#{opts[:uri]}'")
927
956
  end
928
957
 
929
958
  if response.code.to_s != "200"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tenable-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Craston
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-15 00:00:00.000000000 Z
11
+ date: 2020-07-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Ruby library for communicating with the tenable.io API.