From f12226b8d01b1c7e63a17a9fbf9acc43b62a492c Mon Sep 17 00:00:00 2001 From: Gavin Schneider Date: Tue, 7 Jul 2015 14:04:22 -0700 Subject: [PATCH 1/2] Update FilteredAsset's site_id -Add site_ids attribute, array of 1 or more site IDs -Change site_id to get first ID from site_ids Note that consoles which do not have Asset Linking enabled can use site_id without any issues. However, consoles with Asset Linking enabled should use site_ids instead. --- lib/nexpose/filter.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/nexpose/filter.rb b/lib/nexpose/filter.rb index dc0b7479..f36265c5 100644 --- a/lib/nexpose/filter.rb +++ b/lib/nexpose/filter.rb @@ -375,7 +375,11 @@ class FilteredAsset attr_reader :vuln_count attr_reader :risk_score + # The first Site ID returned for this asset. + # Not recommended if Asset Linking feature is enabled. attr_reader :site_id + # Array of Site IDs for the asset. Use when Asset Linking is enabled. + attr_reader :site_ids attr_reader :last_scan def initialize(json) @@ -387,7 +391,11 @@ def initialize(json) @malware_count = json['malwareCount'].to_i @vuln_count = json['vulnCount'].to_i @risk_score = json['riskScore'].to_f - @site_id = json['siteID'] + @site_ids = [] + json['sitePermissions'].each do |site_perm| + @site_ids << site_perm['siteID'] + end + @site_id = @site_ids.first @last_scan = Time.at(json['lastScanDate'].to_i / 1000) end end From c63ff5ff6194ee7541061ac363c11c3f3c8f715e Mon Sep 17 00:00:00 2001 From: Gavin Schneider Date: Tue, 7 Jul 2015 14:38:17 -0700 Subject: [PATCH 2/2] Apply code review feedback Saved some lines by using map. Removed an extra space from comment. --- lib/nexpose/filter.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/nexpose/filter.rb b/lib/nexpose/filter.rb index f36265c5..96d15e95 100644 --- a/lib/nexpose/filter.rb +++ b/lib/nexpose/filter.rb @@ -376,7 +376,7 @@ class FilteredAsset attr_reader :risk_score # The first Site ID returned for this asset. - # Not recommended if Asset Linking feature is enabled. + # Not recommended if Asset Linking feature is enabled. attr_reader :site_id # Array of Site IDs for the asset. Use when Asset Linking is enabled. attr_reader :site_ids @@ -391,10 +391,7 @@ def initialize(json) @malware_count = json['malwareCount'].to_i @vuln_count = json['vulnCount'].to_i @risk_score = json['riskScore'].to_f - @site_ids = [] - json['sitePermissions'].each do |site_perm| - @site_ids << site_perm['siteID'] - end + @site_ids = json['sitePermissions'].map { |site| site['siteID'] } @site_id = @site_ids.first @last_scan = Time.at(json['lastScanDate'].to_i / 1000) end