(ctx context.Context, ir *claircore.IndexReport)
| 23 | var _ matcher.Service = (*HTTP)(nil) |
| 24 | |
| 25 | func (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. |
| 65 | func (c *HTTP) DeleteUpdateOperations(ctx context.Context, ref ...uuid.UUID) (int64, error) { |
nothing calls this directly
no test coverage detected