MCPcopy Create free account
hub / github.com/containerd/nerdctl / Search

Function Search

pkg/cmd/search/search.go:46–120  ·  view source on GitHub ↗
(ctx context.Context, term string, options types.SearchOptions)

Source from the content-addressed store, hash-verified

44}
45
46func 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()

Callers 1

runSearchFunction · 0.92

Calls 11

ParseFunction · 0.92
WithSkipVerifyCertsFunction · 0.92
WithHostsDirsFunction · 0.92
NewHostOptionsFunction · 0.92
validateAndParseFiltersFunction · 0.85
splitReposSearchTermFunction · 0.85
buildSearchURLFunction · 0.85
createHTTPClientFunction · 0.85
printSearchResultsFunction · 0.85
applyFiltersFunction · 0.70
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…