tenable-ruby 0.3.9 → 0.4.4

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 +59 -33
  3. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad9396c3090a68e4d42a7ccdf2200955ed4d4e41d795fc2c2ae147a0b29b0d75
4
- data.tar.gz: 9080fad783c03f4615be2d60df3631cbc563478d01563321ae5d9946dff01867
3
+ metadata.gz: 77917278fce3594ee5fce1156ba4309ef5ed2fdeeaace91d2b3c3626818acd67
4
+ data.tar.gz: 26b073b7ef3de954d470002eb035e3aa52d2bb30bde90b211680f6f2f0bb82b8
5
5
  SHA512:
6
- metadata.gz: 20aed9477d92e9a88e84cf2243abb189b3aafd8378ce2c38342811078f04ca3902a47cddfb7d20ee287cb13d2046ebf7d1ee29e9912b136abbad27ab383b0eb3
7
- data.tar.gz: 385554e3f46578fc8dcf8e3f9de4e97afca808dd39032da1f651005dc63ca9dbc6c5605deb143b280fdaa0c780a478c88d97010fb29ad4f7900cbe1aad61e5ce
6
+ metadata.gz: fa26c48c98bfea63c85c82402c9850c724de8fe77d81315b23d58c6ce45527f9fd2e6f9302b0ac466abedbffe8ec35caa5598275a5e420381be42d584901e18d
7
+ data.tar.gz: 933cbeb33c6c6027b18431edfa5347ffd7c00de1483360f8b067ef9d9ceab1b569861bbac4013567a78c9ecf5f7617535ac42cfea374ef3d04caa442140298fa
@@ -526,11 +526,11 @@ module TenableRuby
526
526
 
527
527
  # Performs scan with scan policy provided (uuid of policy or policy name).
528
528
  # 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))
529
+ # (scan_folder is optional - folder where to save the scan (if that folder exists))
530
530
  # (scanner_id is optional - ID of the scanner/cloud scanner you want to run this scan on)
531
531
  #
532
532
  # returns: JSON parsed object with scan info
533
- def scan_quick_policy(policyname, name, opts = {}, foldername = nil, scanner_id = nil)
533
+ def scan_quick_policy(policyname, name, opts = {}, scan_folder = nil, scanner_id = nil)
534
534
  policies = list_policies['policies']
535
535
  if policies.nil?
536
536
  raise TenableRuby::Error::TenableError, "Tenable API request 'list_policies' responded with 'nil'"
@@ -548,16 +548,18 @@ module TenableRuby
548
548
  settings.merge!(opts)
549
549
  settings['name'] = name
550
550
  settings['policy_id'] = policy['id']
551
- unless foldername.nil?
551
+ if scan_folder.is_a?(Integer)
552
+ settings['folder_id'] = scan_folder
553
+ elsif scan_folder.is_a?(String)
552
554
  folders = list_folders['folders']
553
555
  if folders.nil?
554
556
  raise TenableRuby::Error::TenableError, "Tenable API request 'list_folders' responded with 'nil'"
555
557
  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']
558
+ selected_folder = folders.find { |f| f['name'] == scan_folder }
559
+ if selected_folder
560
+ settings['folder_id'] = selected_folder['id']
561
+ else
562
+ raise TenableRuby::Error::TenableError, "Could not find folder with name #{scan_folder}"
561
563
  end
562
564
  end
563
565
  unless scanner_id.nil?
@@ -566,33 +568,15 @@ module TenableRuby
566
568
  scan_create(template_uuid, settings)
567
569
  end
568
570
 
569
- # Returns scan status by performing a 'scan_details' API call
571
+ # Returns the latest status for a scan.
572
+ #
573
+ # Reference: https://developer.tenable.com/reference#scans-get-latest-status
570
574
  def scan_status(scan_id)
571
- details = scan_details(scan_id)
572
- if details.nil?
573
- raise TenableRuby::Error::TenableError, "Get scan_details returned nil"
574
- end
575
- if not details['error'].nil?
576
- raise TenableRuby::Error::TenableError, "Get scan_details returned the following error: #{details['error']}"
577
- end
578
- details['info']['status']
579
- end
580
-
581
- # Returns the status of the latest history object of a scan by performing a 'scan_details' API call.
582
- # Note this is currently updated more frequently than the scan status in the tenable.io API
583
- def scan_latest_history_status(scan_id)
584
- details = scan_details(scan_id)
585
- if details.nil?
586
- raise TenableRuby::Error::TenableError, "Get scan_details returned nil"
587
- end
588
- if not details['error'].nil?
589
- raise TenableRuby::Error::TenableError, "Get scan_details returned the following error: #{details['error']}"
590
- end
591
- history = details['history']
592
- if history.nil? or history.length == 0
593
- raise TenableRuby::Error::TenableError, "Get scan_details returned empty history object"
575
+ response = http_get(:uri => "/scans/#{scan_id}/latest-status", :fields => header)
576
+ if response.is_a?(Hash) and response.has_key?('status')
577
+ response['status']
594
578
  else
595
- details['history'].last['status']
579
+ raise TenableRuby::Error::TenableError, "Tenable.io did not return a valid status response"
596
580
  end
597
581
  end
598
582
 
@@ -715,6 +699,48 @@ module TenableRuby
715
699
  http_get(:uri => "/container-security/api/v1/reports/by_image_digest?image_digest=#{image_digest}", :fields => header)
716
700
  end
717
701
 
702
+ # Creates a new target group for the current user.
703
+ #
704
+ # Reference:
705
+ # https://developer.tenable.com/reference#target-groups-create
706
+ def create_target_group(name, members, acls: nil)
707
+ http_post(:uri => "/target-groups", :fields => header,
708
+ :data => {:name => name, :members => members, :acls => acls})
709
+ end
710
+
711
+ # Returns the current target groups.
712
+ #
713
+ # Reference:
714
+ # https://developer.tenable.com/reference#target-groups-list
715
+ def list_target_groups
716
+ http_get(:uri => "/target-groups", :fields => header)
717
+ end
718
+
719
+ # Returns details for the specified target group.
720
+ #
721
+ # Reference:
722
+ # https://developer.tenable.com/reference#target-groups-details
723
+ def get_target_group(group_id)
724
+ http_get(:uri => "/target-groups/#{group_id}", :fields => header)
725
+ end
726
+
727
+ # Updates a target group.
728
+ #
729
+ # Reference:
730
+ # https://developer.tenable.com/reference#target-groups-edit
731
+ def update_target_group(group_id, name, members, acls: nil)
732
+ http_put(:uri => "/target-groups/#{group_id}", :fields => header,
733
+ :data => {:name => name, :members => members, :acls => acls})
734
+ end
735
+
736
+ # Deletes a target group.
737
+ #
738
+ # Reference:
739
+ # https://developer.tenable.com/reference#target-groups-delete
740
+ def delete_target_group(group_id)
741
+ http_delete(:uri => "/target-groups/#{group_id}", :fields => header)
742
+ end
743
+
718
744
  private
719
745
 
720
746
  # Perform HTTP put method with uri, data and fields
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.3.9
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Craston
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-07 00:00:00.000000000 Z
11
+ date: 2020-06-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Ruby library for communicating with the tenable.io API.
@@ -25,7 +25,7 @@ homepage: https://gitlab.com/intruder/tenable-ruby
25
25
  licenses:
26
26
  - MIT
27
27
  metadata: {}
28
- post_install_message:
28
+ post_install_message:
29
29
  rdoc_options: []
30
30
  require_paths:
31
31
  - lib
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  version: '0'
42
42
  requirements: []
43
43
  rubygems_version: 3.0.3
44
- signing_key:
44
+ signing_key:
45
45
  specification_version: 4
46
46
  summary: Ruby library for communicating with the tenable.io API
47
47
  test_files: []