(ctx context.Context, term string, options types.SearchOptions)
| 44 | } |
| 45 | |
| 46 | func Search(ctx context.Context, term string, options types.SearchOptions) error { |
| 47 | // Validate filters before making HTTP request |
| 48 | filterMap, err := validateAndParseFilters(options.Filters) |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | |
| 53 | registryHost, searchTerm := splitReposSearchTerm(term) |
| 54 | |
| 55 | parsedRef, err := referenceutil.Parse(registryHost) |
| 56 | if err != nil { |
| 57 | log.G(ctx).WithError(err).Debugf("failed to parse registry host %q, using as-is", registryHost) |
| 58 | } else { |
| 59 | registryHost = parsedRef.Domain |
| 60 | } |
| 61 | |
| 62 | var dOpts []dockerconfigresolver.Opt |
| 63 | |
| 64 | if options.GOptions.InsecureRegistry { |
| 65 | log.G(ctx).Warnf("skipping verifying HTTPS certs for %q", registryHost) |
| 66 | dOpts = append(dOpts, dockerconfigresolver.WithSkipVerifyCerts(true)) |
| 67 | } |
| 68 | |
| 69 | dOpts = append(dOpts, dockerconfigresolver.WithHostsDirs(options.GOptions.HostsDir)) |
| 70 | |
| 71 | hostOpts, err := dockerconfigresolver.NewHostOptions(ctx, registryHost, dOpts...) |
| 72 | if err != nil { |
| 73 | return fmt.Errorf("failed to create host options: %w", err) |
| 74 | } |
| 75 | |
| 76 | username, password, err := hostOpts.Credentials(registryHost) |
| 77 | if err != nil { |
| 78 | log.G(ctx).WithError(err).Debug("no credentials found, searching anonymously") |
| 79 | } |
| 80 | |
| 81 | scheme := "https" |
| 82 | if hostOpts.DefaultScheme != "" { |
| 83 | scheme = hostOpts.DefaultScheme |
| 84 | } |
| 85 | |
| 86 | searchURL := buildSearchURL(registryHost, searchTerm, scheme) |
| 87 | |
| 88 | req, err := http.NewRequestWithContext(ctx, "GET", searchURL, nil) |
| 89 | if err != nil { |
| 90 | return err |
| 91 | } |
| 92 | |
| 93 | if username != "" && password != "" { |
| 94 | req.SetBasicAuth(username, password) |
| 95 | } |
| 96 | |
| 97 | client := createHTTPClient(hostOpts) |
| 98 | |
| 99 | resp, err := client.Do(req) |
| 100 | if err != nil { |
| 101 | return err |
| 102 | } |
| 103 | defer resp.Body.Close() |
no test coverage detected
searching dependent graphs…