From 47bf15c68e6a99647e7bb75548958dadfe8df8b3 Mon Sep 17 00:00:00 2001 From: Jon Johnson Date: Thu, 12 Sep 2024 08:44:50 -0700 Subject: [PATCH] Keep standalone DiscoverKeys function (#1303) --- pkg/apk/apk/implementation.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/apk/apk/implementation.go b/pkg/apk/apk/implementation.go index 4e76b138..7d97f274 100644 --- a/pkg/apk/apk/implementation.go +++ b/pkg/apk/apk/implementation.go @@ -825,7 +825,7 @@ type Key struct { } // DiscoverKeys fetches the public keys for the repositories in the APK database using chainguard-style discovery. -func (a *APK) DiscoverKeys(ctx context.Context, repository string) ([]Key, error) { +func DiscoverKeys(ctx context.Context, client *http.Client, auth auth.Authenticator, repository string) ([]Key, error) { ctx, span := otel.Tracer("go-apk").Start(ctx, "DiscoverKeys") defer span.End() @@ -833,10 +833,10 @@ func (a *APK) DiscoverKeys(ctx context.Context, repository string) ([]Key, error if err != nil { return nil, err } - if err := a.auth.AddAuth(ctx, discoveryRequest); err != nil { + if err := auth.AddAuth(ctx, discoveryRequest); err != nil { return nil, err } - discoveryResponse, err := a.client.Do(discoveryRequest) + discoveryResponse, err := client.Do(discoveryRequest) if err != nil { return nil, fmt.Errorf("failed to perform key discovery: %w", err) } @@ -865,10 +865,10 @@ func (a *APK) DiscoverKeys(ctx context.Context, repository string) ([]Key, error if err != nil { return nil, err } - if err := a.auth.AddAuth(ctx, jwksRequest); err != nil { + if err := auth.AddAuth(ctx, jwksRequest); err != nil { return nil, err } - jwksResponse, err := a.client.Do(jwksRequest) + jwksResponse, err := client.Do(jwksRequest) if err != nil { return nil, fmt.Errorf("failed to fetch JWKS: %w", err) } @@ -912,6 +912,10 @@ func (a *APK) DiscoverKeys(ctx context.Context, repository string) ([]Key, error return keys, nil } +func (a *APK) DiscoverKeys(ctx context.Context, repository string) ([]Key, error) { + return DiscoverKeys(ctx, a.client, a.auth, repository) +} + // fetchChainguardKeys fetches the public keys for the repositories in the APK database. func (a *APK) fetchChainguardKeys(ctx context.Context, repository string) error { ctx, span := otel.Tracer("go-apk").Start(ctx, "fetchChainguardKeys")