-
Notifications
You must be signed in to change notification settings - Fork 0
/
images_scan_history.go
36 lines (33 loc) · 1.16 KB
/
images_scan_history.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
package client // import "github.com/BryanKMorrow/aqua-sdk-go/client"
import (
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"log"
"github.com/BryanKMorrow/aqua-sdk-go/types/images"
"github.com/parnurzeal/gorequest"
)
// GetScanHistory - retrieves a single image scan history based on registry, repo and tag
// Path parameters of {registry}, {repo} and {tag}
// Returns response struct
// v2/images/{registry}/{repo}/{tag}/scan_history
func (cli *Client) GetScanHistory(registry, repo, tag string) (images.ScanHistories, error) {
var response images.ScanHistories
request := gorequest.New().TLSClientConfig(&tls.Config{InsecureSkipVerify: true})
request.Set("Authorization", "Bearer "+cli.token)
apiPath := fmt.Sprintf("/api/v2/images/%s/%s/%s/scan_history", registry, repo, tag)
events, body, errs := request.Clone().Get(cli.url + apiPath).End()
if errs != nil {
log.Println(events.StatusCode)
}
if events.StatusCode == 200 {
err := json.Unmarshal([]byte(body), &response)
if err != nil {
log.Printf("Error calling func GetScanHistory from %s%s, %v ", cli.url, apiPath, err)
}
} else {
return response, errors.New("image not found")
}
return response, nil
}