github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/api/handlers/compat/images_search.go (about) 1 package compat 2 3 import ( 4 "fmt" 5 "net/http" 6 7 "github.com/containers/image/v5/types" 8 "github.com/hanks177/podman/v4/libpod" 9 "github.com/hanks177/podman/v4/pkg/api/handlers/utils" 10 api "github.com/hanks177/podman/v4/pkg/api/types" 11 "github.com/hanks177/podman/v4/pkg/auth" 12 "github.com/hanks177/podman/v4/pkg/domain/entities" 13 "github.com/hanks177/podman/v4/pkg/domain/infra/abi" 14 "github.com/containers/storage" 15 "github.com/gorilla/schema" 16 "github.com/pkg/errors" 17 ) 18 19 func SearchImages(w http.ResponseWriter, r *http.Request) { 20 runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) 21 decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder) 22 query := struct { 23 Term string `json:"term"` 24 Limit int `json:"limit"` 25 Filters map[string][]string `json:"filters"` 26 TLSVerify bool `json:"tlsVerify"` 27 ListTags bool `json:"listTags"` 28 }{ 29 // This is where you can override the golang default value for one of fields 30 } 31 32 if err := decoder.Decode(&query, r.URL.Query()); err != nil { 33 utils.Error(w, http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String())) 34 return 35 } 36 37 _, authfile, err := auth.GetCredentials(r) 38 if err != nil { 39 utils.Error(w, http.StatusBadRequest, err) 40 return 41 } 42 defer auth.RemoveAuthfile(authfile) 43 44 filters := []string{} 45 for key, val := range query.Filters { 46 filters = append(filters, fmt.Sprintf("%s=%s", key, val[0])) 47 } 48 49 options := entities.ImageSearchOptions{ 50 Authfile: authfile, 51 Limit: query.Limit, 52 ListTags: query.ListTags, 53 Filters: filters, 54 } 55 if _, found := r.URL.Query()["tlsVerify"]; found { 56 options.SkipTLSVerify = types.NewOptionalBool(!query.TLSVerify) 57 } 58 ir := abi.ImageEngine{Libpod: runtime} 59 reports, err := ir.Search(r.Context(), query.Term, options) 60 if err != nil { 61 utils.Error(w, http.StatusInternalServerError, err) 62 return 63 } 64 if !utils.IsLibpodRequest(r) { 65 if len(reports) == 0 { 66 utils.ImageNotFound(w, query.Term, storage.ErrImageUnknown) 67 return 68 } 69 } 70 71 utils.WriteResponse(w, http.StatusOK, reports) 72 }