Skip to content

Commit

Permalink
add ctx to the Index function
Browse files Browse the repository at this point in the history
  • Loading branch information
cpanato committed Sep 20, 2024
1 parent f765ef6 commit 28643a8
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/advisory/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Discover(ctx context.Context, opts DiscoverOptions) error {

var apkindexes []*apk.APKIndex
for _, arch := range opts.Arches {
apkindex, err := index.Index(arch, packageRepositoryURL)
apkindex, err := index.Index(ctx, arch, packageRepositoryURL)
if err != nil {
return fmt.Errorf("unable to get APKINDEX for arch %q: %w", arch, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/advisory_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ newly created advisory and any other advisories for the same package.`,

var apkindexes []*apk.APKIndex
for _, arch := range archs {
idx, err := index.Index(arch, packageRepositoryURL)
idx, err := index.Index(cmd.Context(), arch, packageRepositoryURL)
if err != nil {
return fmt.Errorf("unable to load APKINDEX for %s: %w", arch, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/advisory_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ required fields are missing.`,

var apkindexes []*apk.APKIndex
for _, arch := range archs {
idx, err := index.Index(arch, packageRepositoryURL)
idx, err := index.Index(cmd.Context(), arch, packageRepositoryURL)
if err != nil {
return fmt.Errorf("unable to load APKINDEX for %s: %w", arch, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/advisory_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ print an error message that specifies where and how the data is invalid.`,
return fmt.Errorf("unable to create index of advisories repo: %w", err)
}

apkIndex, err := index.Index("x86_64", apkRepositoryURL)
apkIndex, err := index.Index(ctx, "x86_64", apkRepositoryURL)
if err != nil {
return fmt.Errorf("unable to load APKINDEX: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ func resolveInputsForRemoteTarget(ctx context.Context, inputs []string) (downloa
byArch := map[string]*apk.APKIndex{}
for _, arch := range []string{"x86_64", "aarch64"} {
ig.Go(func() error {
apkindex, err := index.Index(arch, apkRepositoryURL)
apkindex, err := index.Index(ctx, arch, apkRepositoryURL)
if err != nil {
return fmt.Errorf("getting APKINDEX: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import (
"chainguard.dev/apko/pkg/apk/auth"
)

func Index(arch, repo string) (*apk.APKIndex, error) {
func Index(ctx context.Context, arch, repo string) (*apk.APKIndex, error) {
var rc io.ReadCloser
if strings.HasPrefix(repo, "http://") || strings.HasPrefix(repo, "https://") {
u, err := url.Parse(fmt.Sprintf("%s/%s/APKINDEX.tar.gz", repo, arch))
if err != nil {
return nil, err
}
req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, u.String(), nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)
if err != nil {
return nil, err
}
if err := auth.DefaultAuthenticators.AddAuth(context.TODO(), req); err != nil {
if err := auth.DefaultAuthenticators.AddAuth(ctx, req); err != nil {
return nil, err
}
resp, err := http.DefaultClient.Do(req)
Expand Down

0 comments on commit 28643a8

Please sign in to comment.