Skip to content

Commit

Permalink
Allow overriding remote options (#3049)
Browse files Browse the repository at this point in the history
RegistryOptions.GetRegistryClientOpts is used in a bunch of places, and
it always instantiates a new set of options. This is ~fine for callers
that only use the options once (e.g. the cosign CLI), but is unfortunate
for callers that would like to reuse those options.

It's useful to reuse these options because they represent a shared
context that eliminates a lot of duplicate work across calls
(e.g. authenticating with the registry and doing existence checks).

Signed-off-by: Jon Johnson <[email protected]>
  • Loading branch information
jonjohnsonjr authored Jun 13, 2023
1 parent 1660de7 commit 86da4aa
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/cosign/cli/options/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type RegistryOptions struct {
KubernetesKeychain bool
RefOpts ReferenceOptions
Keychain Keychain

// RegistryClientOpts allows overriding the result of GetRegistryClientOpts.
RegistryClientOpts []remote.Option
}

var _ Interface = (*RegistryOptions)(nil)
Expand Down Expand Up @@ -86,6 +89,12 @@ func (o *RegistryOptions) NameOptions() []name.Option {
}

func (o *RegistryOptions) GetRegistryClientOpts(ctx context.Context) []remote.Option {
if o.RegistryClientOpts != nil {
ropts := o.RegistryClientOpts
ropts = append(ropts, remote.WithContext(ctx))
return ropts
}

opts := []remote.Option{
remote.WithContext(ctx),
remote.WithUserAgent(UserAgent()),
Expand Down

0 comments on commit 86da4aa

Please sign in to comment.