MCPcopy Create free account
hub / github.com/quay/clair / Scan

Method Scan

httptransport/client/matcher.go:25–62  ·  view source on GitHub ↗
(ctx context.Context, ir *claircore.IndexReport)

Source from the content-addressed store, hash-verified

23var _ matcher.Service = (*HTTP)(nil)
24
25func (c *HTTP) Scan(ctx context.Context, ir *claircore.IndexReport) (*claircore.VulnerabilityReport, error) {
26 u, err := c.addr.Parse(httptransport.VulnerabilityReportPath)
27 if err != nil {
28 return nil, err
29 }
30 req, err := httputil.NewRequestWithContext(ctx, http.MethodPost, u.String(), codec.JSONReader(ir))
31 if err != nil {
32 return nil, fmt.Errorf("failed to create request: %v", err)
33 }
34 if err := c.sign(ctx, req); err != nil {
35 return nil, fmt.Errorf("failed to create request: %v", err)
36 }
37 req.Header.Set("content-type", `application/json`)
38 resp, err := c.c.Do(req)
39 if err != nil {
40 return nil, err
41 }
42 defer resp.Body.Close()
43 if resp.StatusCode != http.StatusOK {
44 return nil, &clairerror.ErrRequestFail{
45 Code: resp.StatusCode,
46 Status: resp.Status,
47 }
48 }
49
50 var vr claircore.VulnerabilityReport
51 switch ct := req.Header.Get("content-type"); ct {
52 case "", `application/json`:
53 dec := codec.GetDecoder(resp.Body)
54 defer codec.PutDecoder(dec)
55 if err := dec.Decode(&vr); err != nil {
56 return nil, err
57 }
58 default:
59 return nil, fmt.Errorf("unrecognized content-type %q", ct)
60 }
61 return &vr, nil
62}
63
64// DeleteUpdateOperations attempts to delete the referenced update operations.
65func (c *HTTP) DeleteUpdateOperations(ctx context.Context, ref ...uuid.UUID) (int64, error) {

Callers

nothing calls this directly

Calls 8

signMethod · 0.95
NewRequestWithContextFunction · 0.92
JSONReaderFunction · 0.92
GetDecoderFunction · 0.92
PutDecoderFunction · 0.92
CloseMethod · 0.65
StringMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected