forked from vulncheck-oss/sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cpe.go
54 lines (48 loc) · 1.45 KB
/
cpe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package sdk
import (
"encoding/json"
"fmt"
)
type CpeResponse struct {
Benchmark float64 `json:"_benchmark"`
Meta struct {
Cpe string `json:"cpe"`
CpeMeta CpeMeta `json:"cpe_struct"`
Timestamp string `json:"timestamp"`
TotalDocuments float64 `json:"total_documents"`
} `json:"_meta"`
Data []string `json:"data"`
}
type CpeMeta struct {
Part string `json:"part"`
Vendor string `json:"vendor"`
Product string `json:"product"`
Version string `json:"version"`
Update string `json:"update"`
Edition string `json:"edition"`
Language string `json:"language"`
SwEdition string `json:"sw_edition"`
TargetSw string `json:"target_sw"`
TargetHw string `json:"target_hw"`
Other string `json:"other"`
}
// https://docs.vulncheck.com/api/cpe
func (c *Client) GetCpe(cpe string) (responseJSON *CpeResponse, err error) {
resp, err := c.Query("cpe", cpe).Request("GET", "/v3/cpe")
if err != nil {
return nil, err
}
defer resp.Body.Close()
_ = json.NewDecoder(resp.Body).Decode(&responseJSON)
return responseJSON, nil
}
// Strings representation of the response
func (r CpeResponse) String() string {
return fmt.Sprintf("Benchmark: %f\nMeta: %v\nData: %v\n", r.Benchmark, r.Meta, r.Data)
}
// GetData Returns the data from the response
func (r CpeResponse) GetData() []string {
return r.Data
}
// GetCpeMeta Returns the CpeMeta from the Metadata
func (r CpeResponse) CpeMeta() CpeMeta { return r.Meta.CpeMeta }