tenable-ruby 0.4.2 → 0.5.2
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 +49 -20
- 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: 819f8651b369e488bf93369f4ebd57888b78f30d76395252597971ca5d69f06b
|
4
|
+
data.tar.gz: 7b77a9e7f582e4a3de408b702c338b21364ca7c149cf0e7b163918a6038625f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2baf2dd3de8b86fab0f6cb88b97957d29fe638a9ef64b247d085d10ad784f389f2a815d64c9b89073fe06620bbe69cf5b50a47931dc71c2904a2d61d9928ab5
|
7
|
+
data.tar.gz: 828494940880467224183077a2b1a535e3173be53b63bb89f7982a415d1961473e8a7ef582a4780dbeda3d6886185c6bd8673f655ff56347abe271ac285dd61a
|
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
|
+
},
|
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?
|
@@ -701,9 +726,9 @@ module TenableRuby
|
|
701
726
|
#
|
702
727
|
# Reference:
|
703
728
|
# https://developer.tenable.com/reference#target-groups-create
|
704
|
-
def create_target_group(name, members, acls:
|
729
|
+
def create_target_group(name, members, acls: nil)
|
705
730
|
http_post(:uri => "/target-groups", :fields => header,
|
706
|
-
:
|
731
|
+
:data => {:name => name, :members => members, :acls => acls})
|
707
732
|
end
|
708
733
|
|
709
734
|
# Returns the current target groups.
|
@@ -726,9 +751,9 @@ module TenableRuby
|
|
726
751
|
#
|
727
752
|
# Reference:
|
728
753
|
# https://developer.tenable.com/reference#target-groups-edit
|
729
|
-
def update_target_group(group_id
|
754
|
+
def update_target_group(group_id, name, members, acls: nil)
|
730
755
|
http_put(:uri => "/target-groups/#{group_id}", :fields => header,
|
731
|
-
:
|
756
|
+
:data => {:name => name, :members => members, :acls => acls})
|
732
757
|
end
|
733
758
|
|
734
759
|
# Deletes a target group.
|
@@ -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.2
|
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.
|