5
5
"bytes"
6
6
"errors"
7
7
"fmt"
8
- "io/ioutil "
8
+ "io"
9
9
"net/url"
10
- "strings"
11
10
"time"
12
11
13
12
"github.com/go-resty/resty/v2"
@@ -56,11 +55,9 @@ type ScanResult struct {
56
55
57
56
type scanResultInternal struct {
58
57
Manageable []* ScanResult `json:"manageable" tenable:"recurse"`
59
- Useable []* ScanResult `json:"useable " tenable:"recurse"`
58
+ Usable []* ScanResult `json:"usable " tenable:"recurse"`
60
59
}
61
60
62
- // Do the usable/manageable split thing. ffff.
63
-
64
61
// takes startTime + endTime parameters, but defaults to last 30d.
65
62
66
63
func (c * Client ) GetAllScanResults () ([]* ScanResult , error ) {
@@ -69,32 +66,43 @@ func (c *Client) GetAllScanResults() ([]*ScanResult, error) {
69
66
70
67
func (c * Client ) GetAllScanResultsByTime (start , end time.Time ) ([]* ScanResult , error ) {
71
68
72
- v := url.Values {}
73
-
69
+ params := url.Values {}
74
70
if ! start .IsZero () {
75
- v .Add ("startTime" , fmt .Sprintf ("%d" , start .Unix ()))
71
+ params .Add ("startTime" , fmt .Sprintf ("%d" , start .Unix ()))
76
72
}
77
73
if ! end .IsZero () {
78
- v .Add ("endTime" , fmt .Sprintf ("%d" , start .Unix ()))
74
+ params .Add ("endTime" , fmt .Sprintf ("%d" , end .Unix ()))
79
75
}
80
76
81
- resourceURL := strings.Builder {}
82
- resourceURL .WriteString (scanResultEndpoint )
83
- if len (v ) > 0 {
84
- resourceURL .WriteString (fmt .Sprintf ("?%s" , v .Encode ()))
77
+ resourceURL := url.URL {
78
+ Path : scanResultEndpoint ,
79
+ RawQuery : params .Encode (),
85
80
}
86
81
87
82
var resp scanResultInternal
88
-
89
83
if _ , err := c .getResource (resourceURL .String (), & resp ); err != nil {
90
84
return nil , fmt .Errorf ("failed to get scan results: %w" , err )
91
85
}
92
86
93
- return resp .Manageable , nil
87
+ var spOut []* ScanResult
88
+ spMap := make (map [ProbablyString ]bool )
89
+
90
+ for _ , o := range resp .Usable {
91
+ spOut = append (spOut , o )
92
+ spMap [o .ID ] = true
93
+ }
94
+ for _ , o := range resp .Manageable {
95
+ if _ , exists := spMap [o .ID ]; ! exists {
96
+ spOut = append (spOut , o )
97
+ spMap [o .ID ] = true
98
+ }
99
+ }
100
+
101
+ return spOut , nil
94
102
}
95
103
96
104
func (c * Client ) GetScanResult (id string ) (* ScanResult , error ) {
97
- resp := ScanResult {}
105
+ var resp ScanResult
98
106
if _ , err := c .getResource (fmt .Sprintf ("%s/%s" , scanResultEndpoint , id ), & resp ); err != nil {
99
107
return nil , fmt .Errorf ("failed to get scan result %s: %w" , id , err )
100
108
}
@@ -177,7 +185,7 @@ func firstFileFromPKZipSlice(slice []byte) ([]byte, error) {
177
185
178
186
reader , err := zip .NewReader (bytes .NewReader (slice ), int64 (len (slice )))
179
187
if err != nil {
180
- return nil , fmt .Errorf ("nessus scan result zip could not be parsed : %w" , err )
188
+ return nil , fmt .Errorf ("failed to create zip reader : %w" , err )
181
189
}
182
190
183
191
if len (reader .File ) == 0 {
@@ -189,7 +197,7 @@ func firstFileFromPKZipSlice(slice []byte) ([]byte, error) {
189
197
return nil , fmt .Errorf ("could not open first file in zip: %w" , err )
190
198
}
191
199
192
- results , err = ioutil .ReadAll (file )
200
+ results , err = io .ReadAll (file )
193
201
if err != nil {
194
202
return nil , fmt .Errorf ("failed to read zip file: %w" , err )
195
203
}
0 commit comments