tenable-ruby 0.4.1 → 0.5.1

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 +87 -16
  3. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2231c6ad080a26cb3bc60ccc22754bca82e48f3a3f44c4a660188174d785303
4
- data.tar.gz: f0249380a5a091595c10c5a2b0025866cb3b78f27b993e46f091c9b213d09428
3
+ metadata.gz: 0bbc552ceeab05ff6aebf6074bcdb2ec87da1f8edf79a09f0a067d1773352258
4
+ data.tar.gz: f1018caecbc01c67804dd3512702126b3e6041778b587f0f6d27fa9403bdd1b9
5
5
  SHA512:
6
- metadata.gz: e4d9ca21d8b64969a924a3ca5ed71a1cb7c93bfffbb69db11917427f72a4cf194e9b9290887436c798ddd866e7bf736aebcc20406c7f789b341d64d157625422
7
- data.tar.gz: 7440641a013b70196b7105f67da2c5e1c83bd98fe69ea3161bad3a9290d661f10df11cdc1e9b5cd0c116dab6311ccb11568e535f34f724b708f94508870e4aa1
6
+ metadata.gz: 67e194bbd92c3adb2806007517cc17b497dfa5524029ebc5a33b04822975675b35d170fd2def60f02f98255599ea2e44c20aab434e71179d863497373f3028e0
7
+ data.tar.gz: 1cd8b6f489252b80a3ce088aa6984debb3bf06b6a6377ee53629508af4e9eea734278acaa426ae68cd81c001da23df390e55145cccb7f8ad872f5e5d24fd3ee7
@@ -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
- # (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?
@@ -697,6 +722,48 @@ module TenableRuby
697
722
  http_get(:uri => "/container-security/api/v1/reports/by_image_digest?image_digest=#{image_digest}", :fields => header)
698
723
  end
699
724
 
725
+ # Creates a new target group for the current user.
726
+ #
727
+ # Reference:
728
+ # https://developer.tenable.com/reference#target-groups-create
729
+ def create_target_group(name, members, acls: nil)
730
+ http_post(:uri => "/target-groups", :fields => header,
731
+ :data => {:name => name, :members => members, :acls => acls})
732
+ end
733
+
734
+ # Returns the current target groups.
735
+ #
736
+ # Reference:
737
+ # https://developer.tenable.com/reference#target-groups-list
738
+ def list_target_groups
739
+ http_get(:uri => "/target-groups", :fields => header)
740
+ end
741
+
742
+ # Returns details for the specified target group.
743
+ #
744
+ # Reference:
745
+ # https://developer.tenable.com/reference#target-groups-details
746
+ def get_target_group(group_id)
747
+ http_get(:uri => "/target-groups/#{group_id}", :fields => header)
748
+ end
749
+
750
+ # Updates a target group.
751
+ #
752
+ # Reference:
753
+ # https://developer.tenable.com/reference#target-groups-edit
754
+ def update_target_group(group_id, name, members, acls: nil)
755
+ http_put(:uri => "/target-groups/#{group_id}", :fields => header,
756
+ :data => {:name => name, :members => members, :acls => acls})
757
+ end
758
+
759
+ # Deletes a target group.
760
+ #
761
+ # Reference:
762
+ # https://developer.tenable.com/reference#target-groups-delete
763
+ def delete_target_group(group_id)
764
+ http_delete(:uri => "/target-groups/#{group_id}", :fields => header)
765
+ end
766
+
700
767
  private
701
768
 
702
769
  # Perform HTTP put method with uri, data and fields
@@ -804,7 +871,6 @@ module TenableRuby
804
871
  uri = opts[:uri]
805
872
  fields = opts[:fields] || {}
806
873
  raw_content = opts[:raw_content] || false
807
- json = {}
808
874
  tries = @httpretry
809
875
 
810
876
  request = Net::HTTP::Get.new(uri)
@@ -820,11 +886,17 @@ module TenableRuby
820
886
  sleep @httpsleep
821
887
  retry
822
888
  else
823
- return json
889
+ raise TenableRuby::Error::TenableError.new("#{e}: No more retries for http GET '#{opts[:uri]}'")
824
890
  end
825
- rescue URI::InvalidURIError
826
- 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}"
827
898
  end
899
+
828
900
  if !raw_content
829
901
  parse_json(response.body)
830
902
  else
@@ -859,7 +931,6 @@ module TenableRuby
859
931
  fields = opts[:fields] || {}
860
932
  body = opts[:body]
861
933
  ctype = opts[:ctype]
862
- json = {}
863
934
  tries = @httpretry
864
935
 
865
936
  request = Net::HTTP::Post.new(uri)
@@ -878,10 +949,10 @@ module TenableRuby
878
949
  sleep @httpsleep
879
950
  retry
880
951
  else
881
- return json
952
+ raise TenableRuby::Error::TenableError.new("#{e}: No more retries for http POST '#{opts[:uri]}'")
882
953
  end
883
- rescue URI::InvalidURIError
884
- return json
954
+ rescue URI::InvalidURIError => e
955
+ raise TenableRuby::Error::TenableError.new("#{e}: http POST '#{opts[:uri]}'")
885
956
  end
886
957
 
887
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.1
4
+ version: 0.5.1
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-27 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.
@@ -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: []