Skip to content

Commit

Permalink
client: use signer
Browse files Browse the repository at this point in the history
Previous PR that reworked the client+signing scheme forgot to actually
use the signer.

Signed-off-by: Hank Donnay <hdonnay@redhat.com>
  • Loading branch information
hdonnay committed Jan 10, 2023
1 parent 577a55d commit adbaa56
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
7 changes: 7 additions & 0 deletions httptransport/client/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,10 @@ func WithSigner(v Signer) Option {
type Signer interface {
Sign(context.Context, *http.Request) error
}

func (s *HTTP) sign(ctx context.Context, req *http.Request) error {
if s.signer == nil {
return nil
}
return s.signer.Sign(ctx, req)
}
15 changes: 15 additions & 0 deletions httptransport/client/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func (s *HTTP) AffectedManifests(ctx context.Context, v []claircore.Vulnerabilit
if err != nil {
return nil, fmt.Errorf("failed to create request: %v", err)
}
if err := s.sign(ctx, req); err != nil {
return nil, fmt.Errorf("failed to create request: %v", err)
}
req.Header.Set("content-type", `application/json`)
resp, err := s.c.Do(req)
if err != nil {
Expand Down Expand Up @@ -75,6 +78,9 @@ func (s *HTTP) Index(ctx context.Context, manifest *claircore.Manifest) (*clairc
if err != nil {
return nil, fmt.Errorf("failed to create request: %v", err)
}
if err := s.sign(ctx, req); err != nil {
return nil, fmt.Errorf("failed to create request: %v", err)
}
req.Header.Set("content-type", `application/json`)
resp, err := s.c.Do(req)
if err != nil {
Expand Down Expand Up @@ -113,6 +119,9 @@ func (s *HTTP) IndexReport(ctx context.Context, manifest claircore.Digest) (*cla
if err != nil {
return nil, false, fmt.Errorf("failed to create request: %v", err)
}
if err := s.sign(ctx, req); err != nil {
return nil, false, fmt.Errorf("failed to create request: %v", err)
}
resp, err := s.c.Do(req)
if err != nil {
return nil, false, fmt.Errorf("failed to do request: %v", err)
Expand Down Expand Up @@ -149,6 +158,9 @@ func (s *HTTP) State(ctx context.Context) (string, error) {
if err != nil {
return "", fmt.Errorf("failed to create request: %v", err)
}
if err := s.sign(ctx, req); err != nil {
return "", fmt.Errorf("failed to create request: %v", err)
}
resp, err := s.c.Do(req)
if err != nil {
return "", fmt.Errorf("failed to do request: %v", err)
Expand All @@ -174,6 +186,9 @@ func (s *HTTP) DeleteManifests(ctx context.Context, d ...claircore.Digest) ([]cl
if err != nil {
return nil, fmt.Errorf("failed to create request: %v", err)
}
if err := s.sign(ctx, req); err != nil {
return nil, fmt.Errorf("failed to create request: %v", err)
}
resp, err := s.c.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to do request: %v", err)
Expand Down
18 changes: 17 additions & 1 deletion httptransport/client/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ func (c *HTTP) Scan(ctx context.Context, ir *claircore.IndexReport) (*claircore.
}
req, err := httputil.NewRequestWithContext(ctx, http.MethodPost, u.String(), codec.JSONReader(ir))
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create request: %v", err)
}
if err := c.sign(ctx, req); err != nil {
return nil, fmt.Errorf("failed to create request: %v", err)
}
req.Header.Set("content-type", `application/json`)
resp, err := c.c.Do(req)
Expand Down Expand Up @@ -90,6 +93,10 @@ func (c *HTTP) DeleteUpdateOperations(ctx context.Context, ref ...uuid.UUID) (in
errs[i] = err
return
}
if err := c.sign(ctx, req); err != nil {
errs[i] = fmt.Errorf("failed to create request: %v", err)
return
}
res, err := c.c.Do(req)
if err != nil {
errs[i] = err
Expand Down Expand Up @@ -147,6 +154,9 @@ func (c *HTTP) UpdateOperations(ctx context.Context, k driver.UpdateKind, update
if err != nil {
return nil, err
}
if err := c.sign(ctx, req); err != nil {
return nil, fmt.Errorf("failed to create request: %v", err)
}
return c.updateOperations(ctx, req, c.uoCache)
}

Expand Down Expand Up @@ -181,6 +191,9 @@ func (c *HTTP) LatestUpdateOperations(ctx context.Context, k driver.UpdateKind)
// an ouCache is passed in by the caller to cache any responses providing an etag.
// if a subsequent response provides a StatusNotModified status, the map of UpdateOprations is served from cache.
func (c *HTTP) updateOperations(ctx context.Context, req *http.Request, cache *uoCache) (map[string][]driver.UpdateOperation, error) {
if err := c.sign(ctx, req); err != nil {
return nil, fmt.Errorf("failed to create request: %v", err)
}
res, err := c.c.Do(req)
if err != nil {
return nil, err
Expand Down Expand Up @@ -227,6 +240,9 @@ func (c *HTTP) UpdateDiff(ctx context.Context, prev, cur uuid.UUID) (*driver.Upd
}
v.Set("cur", cur.String())
req.URL.RawQuery = v.Encode()
if err := c.sign(ctx, req); err != nil {
return nil, fmt.Errorf("failed to create request: %v", err)
}

res, err := c.c.Do(req)
if err != nil {
Expand Down

0 comments on commit adbaa56

Please sign in to comment.