Skip to content

Commit

Permalink
Keep standalone DiscoverKeys function (#1303)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjohnsonjr authored Sep 12, 2024
1 parent 7c36146 commit 47bf15c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pkg/apk/apk/implementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,18 +825,18 @@ 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()

discoveryRequest, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s/%s", strings.TrimSuffix(repository, "/"), "apk-configuration"), nil)
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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 47bf15c

Please sign in to comment.