forked from vulncheck-oss/sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
backup.go
63 lines (55 loc) · 1.53 KB
/
backup.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
55
56
57
58
59
60
61
62
63
package sdk
import (
"encoding/json"
"fmt"
)
type BackupFile struct {
Filename string `json:"filename"`
Sha256 string `json:"sha256"`
DateAdded string `json:"date_added"`
URL string `json:"url"`
URLTtlMinutes int `json:"url_ttl_minutes"`
URLExpires string `json:"url_expires"`
}
type BackupResponse struct {
Benchmark float64 `json:"_benchmark"`
Meta struct {
Timestamp string `json:"timestamp"`
Index string `json:"index"`
} `json:"_meta"`
Data []BackupFile `json:"data"`
}
// https://docs.vulncheck.com/api/backup
func (c *Client) GetIndexBackup(index string) (responseJSON *BackupResponse, err error) {
resp, err := c.Request("GET", "/v3/backup/"+index)
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 BackupResponse) String() string {
return fmt.Sprintf("Benchmark: %f\nMeta: %v\nData: %v\n", r.Benchmark, r.Meta, r.Data)
}
// Returns the data from the response
func (r BackupResponse) GetData() []BackupFile {
return r.Data
}
// Returns the list of filenames associated with the backup
func (r BackupResponse) Filenames() []string {
var filenames []string
for _, v := range r.Data {
filenames = append(filenames, v.Filename)
}
return filenames
}
// Returns the list of URLs associated with the backup
func (r BackupResponse) Urls() []string {
var urls []string
for _, v := range r.Data {
urls = append(urls, v.URL)
}
return urls
}