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.
- checksums.yaml +4 -4
- data/lib/tenable-ruby.rb +45 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a367b214445184f3805e7d99304cfab5341634a93833e9aa3ee2754fd94212f
|
4
|
+
data.tar.gz: 3cbe4522d7639236cbbdd5a59746cd511ba0c240921390bc595bbcd8165a3022
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59c07dcbfa4029a2e24d5b3396a0cfaf17821e723a00beade9f2d4f1fc543578efa66081d79cdfac1804fb67118fe15f7b79131bf3e39fe498f23018e6d0cc62
|
7
|
+
data.tar.gz: 1a9290bc941f16f2c2e5f0dcaf285c2574306271c6459a9aec4e313f09744db17d840f93c87adff1f2ef55068ad8810add28ec4567b2b2dc697ae2e357c7e8c1
|
data/lib/tenable-ruby.rb
CHANGED
@@ -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
|
-
# (
|
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 = {},
|
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
|
-
|
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
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
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
|
-
|
889
|
+
raise TenableRuby::Error::TenableError.new("#{e}: No more retries for http GET '#{opts[:uri]}'")
|
866
890
|
end
|
867
|
-
rescue URI::InvalidURIError
|
868
|
-
|
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
|
-
|
952
|
+
raise TenableRuby::Error::TenableError.new("#{e}: No more retries for http POST '#{opts[:uri]}'")
|
924
953
|
end
|
925
|
-
rescue URI::InvalidURIError
|
926
|
-
|
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
|
+
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-
|
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.
|