Skip to content

Commit f6cc76c

Browse files
committed
api/types: move ImageSearchOptions to api/types/registry
Note that RequestPrivilegeFunc could not be referenced, as it would introduce a circular import, so copying the definition instead. Also combining the other search-related types in the package to be in the same file. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent b5f15bc commit f6cc76c

7 files changed

Lines changed: 61 additions & 44 deletions

File tree

api/types/client.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,6 @@ type ImageLoadResponse struct {
151151
// if the privilege request fails.
152152
type RequestPrivilegeFunc func(context.Context) (string, error)
153153

154-
// ImageSearchOptions holds parameters to search images with.
155-
type ImageSearchOptions struct {
156-
RegistryAuth string
157-
PrivilegeFunc RequestPrivilegeFunc
158-
Filters filters.Args
159-
Limit int
160-
}
161-
162154
// NodeListOptions holds parameters to list nodes with.
163155
type NodeListOptions struct {
164156
Filters filters.Args

api/types/registry/registry.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -84,32 +84,6 @@ type IndexInfo struct {
8484
Official bool
8585
}
8686

87-
// SearchResult describes a search result returned from a registry
88-
type SearchResult struct {
89-
// StarCount indicates the number of stars this repository has
90-
StarCount int `json:"star_count"`
91-
// IsOfficial is true if the result is from an official repository.
92-
IsOfficial bool `json:"is_official"`
93-
// Name is the name of the repository
94-
Name string `json:"name"`
95-
// IsAutomated indicates whether the result is automated.
96-
//
97-
// Deprecated: the "is_automated" field is deprecated and will always be "false".
98-
IsAutomated bool `json:"is_automated"`
99-
// Description is a textual description of the repository
100-
Description string `json:"description"`
101-
}
102-
103-
// SearchResults lists a collection search results returned from a registry
104-
type SearchResults struct {
105-
// Query contains the query string that generated the search results
106-
Query string `json:"query"`
107-
// NumResults indicates the number of results the query returned
108-
NumResults int `json:"num_results"`
109-
// Results is a slice containing the actual results for the search
110-
Results []SearchResult `json:"results"`
111-
}
112-
11387
// DistributionInspect describes the result obtained from contacting the
11488
// registry to retrieve image metadata
11589
type DistributionInspect struct {

api/types/registry/search.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package registry
2+
3+
import (
4+
"context"
5+
6+
"github.com/docker/docker/api/types/filters"
7+
)
8+
9+
// SearchOptions holds parameters to search images with.
10+
type SearchOptions struct {
11+
RegistryAuth string
12+
13+
// PrivilegeFunc is a [types.RequestPrivilegeFunc] the client can
14+
// supply to retry operations after getting an authorization error.
15+
//
16+
// It must return the registry authentication header value in base64
17+
// format, or an error if the privilege request fails.
18+
PrivilegeFunc func(context.Context) (string, error)
19+
Filters filters.Args
20+
Limit int
21+
}
22+
23+
// SearchResult describes a search result returned from a registry
24+
type SearchResult struct {
25+
// StarCount indicates the number of stars this repository has
26+
StarCount int `json:"star_count"`
27+
// IsOfficial is true if the result is from an official repository.
28+
IsOfficial bool `json:"is_official"`
29+
// Name is the name of the repository
30+
Name string `json:"name"`
31+
// IsAutomated indicates whether the result is automated.
32+
//
33+
// Deprecated: the "is_automated" field is deprecated and will always be "false".
34+
IsAutomated bool `json:"is_automated"`
35+
// Description is a textual description of the repository
36+
Description string `json:"description"`
37+
}
38+
39+
// SearchResults lists a collection search results returned from a registry
40+
type SearchResults struct {
41+
// Query contains the query string that generated the search results
42+
Query string `json:"query"`
43+
// NumResults indicates the number of results the query returned
44+
NumResults int `json:"num_results"`
45+
// Results is a slice containing the actual results for the search
46+
Results []SearchResult `json:"results"`
47+
}

api/types/types_deprecated.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/docker/docker/api/types/events"
66
"github.com/docker/docker/api/types/image"
77
"github.com/docker/docker/api/types/network"
8+
"github.com/docker/docker/api/types/registry"
89
"github.com/docker/docker/api/types/volume"
910
)
1011

@@ -117,3 +118,8 @@ type ContainerStats = container.StatsResponse
117118
//
118119
// Deprecated: use [events.ListOptions].
119120
type EventsOptions = events.ListOptions
121+
122+
// ImageSearchOptions holds parameters to search images with.
123+
//
124+
// Deprecated: use [registry.SearchOptions].
125+
type ImageSearchOptions = registry.SearchOptions

client/image_search.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ import (
77
"net/url"
88
"strconv"
99

10-
"github.com/docker/docker/api/types"
1110
"github.com/docker/docker/api/types/filters"
1211
"github.com/docker/docker/api/types/registry"
1312
"github.com/docker/docker/errdefs"
1413
)
1514

1615
// ImageSearch makes the docker host search by a term in a remote registry.
1716
// The list of results is not sorted in any fashion.
18-
func (cli *Client) ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error) {
17+
func (cli *Client) ImageSearch(ctx context.Context, term string, options registry.SearchOptions) ([]registry.SearchResult, error) {
1918
var results []registry.SearchResult
2019
query := url.Values{}
2120
query.Set("term", term)

client/image_search_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111
"testing"
1212

13-
"github.com/docker/docker/api/types"
1413
"github.com/docker/docker/api/types/filters"
1514
"github.com/docker/docker/api/types/registry"
1615
"github.com/docker/docker/errdefs"
@@ -22,15 +21,15 @@ func TestImageSearchAnyError(t *testing.T) {
2221
client := &Client{
2322
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
2423
}
25-
_, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{})
24+
_, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{})
2625
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
2726
}
2827

2928
func TestImageSearchStatusUnauthorizedError(t *testing.T) {
3029
client := &Client{
3130
client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")),
3231
}
33-
_, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{})
32+
_, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{})
3433
assert.Check(t, is.ErrorType(err, errdefs.IsUnauthorized))
3534
}
3635

@@ -41,7 +40,7 @@ func TestImageSearchWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) {
4140
privilegeFunc := func(_ context.Context) (string, error) {
4241
return "", fmt.Errorf("Error requesting privilege")
4342
}
44-
_, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{
43+
_, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{
4544
PrivilegeFunc: privilegeFunc,
4645
})
4746
if err == nil || err.Error() != "Error requesting privilege" {
@@ -56,7 +55,7 @@ func TestImageSearchWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.
5655
privilegeFunc := func(_ context.Context) (string, error) {
5756
return "a-auth-header", nil
5857
}
59-
_, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{
58+
_, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{
6059
PrivilegeFunc: privilegeFunc,
6160
})
6261
assert.Check(t, is.ErrorType(err, errdefs.IsUnauthorized))
@@ -101,7 +100,7 @@ func TestImageSearchWithPrivilegedFuncNoError(t *testing.T) {
101100
privilegeFunc := func(_ context.Context) (string, error) {
102101
return "IAmValid", nil
103102
}
104-
results, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{
103+
results, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{
105104
RegistryAuth: "NotValid",
106105
PrivilegeFunc: privilegeFunc,
107106
})
@@ -145,7 +144,7 @@ func TestImageSearchWithoutErrors(t *testing.T) {
145144
}, nil
146145
}),
147146
}
148-
results, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{
147+
results, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{
149148
Filters: filters.NewArgs(
150149
filters.Arg("is-automated", "true"),
151150
filters.Arg("stars", "3"),

client/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ type ImageAPIClient interface {
9999
ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error)
100100
ImagePush(ctx context.Context, ref string, options image.PushOptions) (io.ReadCloser, error)
101101
ImageRemove(ctx context.Context, image string, options image.RemoveOptions) ([]image.DeleteResponse, error)
102-
ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error)
102+
ImageSearch(ctx context.Context, term string, options registry.SearchOptions) ([]registry.SearchResult, error)
103103
ImageSave(ctx context.Context, images []string) (io.ReadCloser, error)
104104
ImageTag(ctx context.Context, image, ref string) error
105105
ImagesPrune(ctx context.Context, pruneFilter filters.Args) (image.PruneReport, error)

0 commit comments

Comments
 (0)