diff --git a/api/types/client.go b/api/types/client.go index 9389636b25..240eb7cc80 100644 --- a/api/types/client.go +++ b/api/types/client.go @@ -151,14 +151,6 @@ type ImageLoadResponse struct { // if the privilege request fails. type RequestPrivilegeFunc func(context.Context) (string, error) -// ImageSearchOptions holds parameters to search images with. -type ImageSearchOptions struct { - RegistryAuth string - PrivilegeFunc RequestPrivilegeFunc - Filters filters.Args - Limit int -} - // NodeListOptions holds parameters to list nodes with. type NodeListOptions struct { Filters filters.Args diff --git a/api/types/registry/registry.go b/api/types/registry/registry.go index 6bbae93ef2..75ee07b15f 100644 --- a/api/types/registry/registry.go +++ b/api/types/registry/registry.go @@ -84,32 +84,6 @@ type IndexInfo struct { Official bool } -// SearchResult describes a search result returned from a registry -type SearchResult struct { - // StarCount indicates the number of stars this repository has - StarCount int `json:"star_count"` - // IsOfficial is true if the result is from an official repository. - IsOfficial bool `json:"is_official"` - // Name is the name of the repository - Name string `json:"name"` - // IsAutomated indicates whether the result is automated. - // - // Deprecated: the "is_automated" field is deprecated and will always be "false". - IsAutomated bool `json:"is_automated"` - // Description is a textual description of the repository - Description string `json:"description"` -} - -// SearchResults lists a collection search results returned from a registry -type SearchResults struct { - // Query contains the query string that generated the search results - Query string `json:"query"` - // NumResults indicates the number of results the query returned - NumResults int `json:"num_results"` - // Results is a slice containing the actual results for the search - Results []SearchResult `json:"results"` -} - // DistributionInspect describes the result obtained from contacting the // registry to retrieve image metadata type DistributionInspect struct { diff --git a/api/types/registry/search.go b/api/types/registry/search.go new file mode 100644 index 0000000000..a0a1eec544 --- /dev/null +++ b/api/types/registry/search.go @@ -0,0 +1,47 @@ +package registry + +import ( + "context" + + "github.com/docker/docker/api/types/filters" +) + +// SearchOptions holds parameters to search images with. +type SearchOptions struct { + RegistryAuth string + + // PrivilegeFunc is a [types.RequestPrivilegeFunc] the client can + // supply to retry operations after getting an authorization error. + // + // It must return the registry authentication header value in base64 + // format, or an error if the privilege request fails. + PrivilegeFunc func(context.Context) (string, error) + Filters filters.Args + Limit int +} + +// SearchResult describes a search result returned from a registry +type SearchResult struct { + // StarCount indicates the number of stars this repository has + StarCount int `json:"star_count"` + // IsOfficial is true if the result is from an official repository. + IsOfficial bool `json:"is_official"` + // Name is the name of the repository + Name string `json:"name"` + // IsAutomated indicates whether the result is automated. + // + // Deprecated: the "is_automated" field is deprecated and will always be "false". + IsAutomated bool `json:"is_automated"` + // Description is a textual description of the repository + Description string `json:"description"` +} + +// SearchResults lists a collection search results returned from a registry +type SearchResults struct { + // Query contains the query string that generated the search results + Query string `json:"query"` + // NumResults indicates the number of results the query returned + NumResults int `json:"num_results"` + // Results is a slice containing the actual results for the search + Results []SearchResult `json:"results"` +} diff --git a/api/types/types_deprecated.go b/api/types/types_deprecated.go index 635558c910..ef426b608d 100644 --- a/api/types/types_deprecated.go +++ b/api/types/types_deprecated.go @@ -5,6 +5,7 @@ import ( "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/network" + "github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/volume" ) @@ -117,3 +118,8 @@ type ContainerStats = container.StatsResponse // // Deprecated: use [events.ListOptions]. type EventsOptions = events.ListOptions + +// ImageSearchOptions holds parameters to search images with. +// +// Deprecated: use [registry.SearchOptions]. +type ImageSearchOptions = registry.SearchOptions diff --git a/client/image_search.go b/client/image_search.go index 3c6fea44a1..0a07457574 100644 --- a/client/image_search.go +++ b/client/image_search.go @@ -7,7 +7,6 @@ import ( "net/url" "strconv" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/registry" "github.com/docker/docker/errdefs" @@ -15,7 +14,7 @@ import ( // ImageSearch makes the docker host search by a term in a remote registry. // The list of results is not sorted in any fashion. -func (cli *Client) ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error) { +func (cli *Client) ImageSearch(ctx context.Context, term string, options registry.SearchOptions) ([]registry.SearchResult, error) { var results []registry.SearchResult query := url.Values{} query.Set("term", term) diff --git a/client/image_search_test.go b/client/image_search_test.go index bd3b579877..32e85e3276 100644 --- a/client/image_search_test.go +++ b/client/image_search_test.go @@ -10,7 +10,6 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/registry" "github.com/docker/docker/errdefs" @@ -22,7 +21,7 @@ func TestImageSearchAnyError(t *testing.T) { client := &Client{ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), } - _, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{}) + _, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{}) assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) } @@ -30,7 +29,7 @@ func TestImageSearchStatusUnauthorizedError(t *testing.T) { client := &Client{ client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), } - _, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{}) + _, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{}) assert.Check(t, is.ErrorType(err, errdefs.IsUnauthorized)) } @@ -41,7 +40,7 @@ func TestImageSearchWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) { privilegeFunc := func(_ context.Context) (string, error) { return "", fmt.Errorf("Error requesting privilege") } - _, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{ + _, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{ PrivilegeFunc: privilegeFunc, }) if err == nil || err.Error() != "Error requesting privilege" { @@ -56,7 +55,7 @@ func TestImageSearchWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing. privilegeFunc := func(_ context.Context) (string, error) { return "a-auth-header", nil } - _, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{ + _, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{ PrivilegeFunc: privilegeFunc, }) assert.Check(t, is.ErrorType(err, errdefs.IsUnauthorized)) @@ -101,7 +100,7 @@ func TestImageSearchWithPrivilegedFuncNoError(t *testing.T) { privilegeFunc := func(_ context.Context) (string, error) { return "IAmValid", nil } - results, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{ + results, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{ RegistryAuth: "NotValid", PrivilegeFunc: privilegeFunc, }) @@ -145,7 +144,7 @@ func TestImageSearchWithoutErrors(t *testing.T) { }, nil }), } - results, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{ + results, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{ Filters: filters.NewArgs( filters.Arg("is-automated", "true"), filters.Arg("stars", "3"), diff --git a/client/interface.go b/client/interface.go index fe9dd43108..7d342a2f46 100644 --- a/client/interface.go +++ b/client/interface.go @@ -99,7 +99,7 @@ type ImageAPIClient interface { ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error) ImagePush(ctx context.Context, ref string, options image.PushOptions) (io.ReadCloser, error) ImageRemove(ctx context.Context, image string, options image.RemoveOptions) ([]image.DeleteResponse, error) - ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error) + ImageSearch(ctx context.Context, term string, options registry.SearchOptions) ([]registry.SearchResult, error) ImageSave(ctx context.Context, images []string) (io.ReadCloser, error) ImageTag(ctx context.Context, image, ref string) error ImagesPrune(ctx context.Context, pruneFilter filters.Args) (image.PruneReport, error)