Skip to content

Commit e08f397

Browse files
committed
service: add signer option
Signed-off-by: Hank Donnay <[email protected]>
1 parent 3b9ff6d commit e08f397

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

initialize/services.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,7 @@ func localIndexer(ctx context.Context, cfg *config.Config) (indexer.Service, err
179179
}
180180
}
181181
}
182-
tr := http.DefaultTransport.(*http.Transport).Clone()
183-
// Use an empty claim because this shouldn't be talking to something that
184-
// needs preconfigured authz. Callers should be providing credentials to the
185-
// indexing process in the submitted manifest.
186-
c, _, err := httputil.Client(tr, nil, cfg)
182+
c, err := httputil.NewClient(ctx, cfg.Indexer.Airgap)
187183
if err != nil {
188184
return nil, mkErr(err)
189185
}
@@ -210,16 +206,19 @@ func remoteIndexer(ctx context.Context, cfg *config.Config, addr string) (indexe
210206
}
211207

212208
func remoteClient(ctx context.Context, cfg *config.Config, claim jwt.Claims, addr string) (*client.HTTP, error) {
213-
tr := http.DefaultTransport.(*http.Transport).Clone()
214-
c, auth, err := httputil.Client(tr, &claim, cfg)
215-
switch {
216-
case err != nil:
209+
c, err := httputil.NewClient(ctx, false) // ???
210+
if err != nil {
217211
return nil, err
218-
case !auth && cfg.Auth.Any():
219-
return nil, errors.New("client authorization required but not provided")
220-
default: // OK
221212
}
222-
return client.NewHTTP(ctx, client.WithAddr(addr), client.WithClient(c))
213+
opts := []client.Option{client.WithAddr(addr), client.WithClient(c)}
214+
if cfg.Auth.Any() {
215+
s, err := httputil.NewSigner(ctx, cfg, claim)
216+
if err != nil {
217+
return nil, err
218+
}
219+
opts = append(opts, client.WithSigner(s))
220+
}
221+
return client.NewHTTP(ctx, opts...)
223222
}
224223

225224
func localMatcher(ctx context.Context, cfg *config.Config) (matcher.Service, error) {
@@ -319,8 +318,11 @@ func localNotifier(ctx context.Context, cfg *config.Config, i indexer.Service, m
319318
}
320319
}
321320

322-
tr := http.DefaultTransport.(*http.Transport).Clone()
323-
c, _, err := httputil.Client(tr, &notifierClaim, cfg)
321+
c, err := httputil.NewClient(ctx, false) // No airgap flag.
322+
if err != nil {
323+
return nil, mkErr(err)
324+
}
325+
signer, err := httputil.NewSigner(ctx, cfg, notifierClaim)
324326
if err != nil {
325327
return nil, mkErr(err)
326328
}
@@ -350,6 +352,7 @@ func localNotifier(ctx context.Context, cfg *config.Config, i indexer.Service, m
350352
Indexer: i,
351353
Matcher: m,
352354
Client: c,
355+
Signer: signer,
353356
PollInterval: cfg.Notifier.PollInterval,
354357
DisableSummary: cfg.Notifier.DisableSummary,
355358
Webhook: cfg.Notifier.Webhook,

notifier/service/notifier.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func (s *Notifier) DeleteNotifications(ctx context.Context, id uuid.UUID) error
5555
type Opts struct {
5656
Matcher matcher.Service
5757
Indexer indexer.Service
58+
Signer webhook.Signer
5859
Client *http.Client
5960
Webhook *config.Webhook
6061
AMQP *config.AMQP
@@ -100,7 +101,7 @@ func New(ctx context.Context, store notifier.Store, locks notifier.Locker, opts
100101
zlog.Info(ctx).
101102
Int("count", deliveries).
102103
Msg("initializing webhook deliverers")
103-
del, err = webhook.New(opts.Webhook, opts.Client)
104+
del, err = webhook.New(opts.Webhook, opts.Client, opts.Signer)
104105
if err != nil {
105106
return nil, fmt.Errorf("failed to create webhook deliverer: %v", err)
106107
}

0 commit comments

Comments
 (0)