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 <github@gone.nl>
| ... | ... |
@@ -151,14 +151,6 @@ type ImageLoadResponse struct {
|
| 151 | 151 |
// if the privilege request fails. |
| 152 | 152 |
type RequestPrivilegeFunc func(context.Context) (string, error) |
| 153 | 153 |
|
| 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 |
- |
|
| 162 | 154 |
// NodeListOptions holds parameters to list nodes with. |
| 163 | 155 |
type NodeListOptions struct {
|
| 164 | 156 |
Filters filters.Args |
| ... | ... |
@@ -84,32 +84,6 @@ type IndexInfo struct {
|
| 84 | 84 |
Official bool |
| 85 | 85 |
} |
| 86 | 86 |
|
| 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 |
- |
|
| 113 | 87 |
// DistributionInspect describes the result obtained from contacting the |
| 114 | 88 |
// registry to retrieve image metadata |
| 115 | 89 |
type DistributionInspect struct {
|
| 116 | 90 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,47 @@ |
| 0 |
+package registry |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "context" |
|
| 4 |
+ |
|
| 5 |
+ "github.com/docker/docker/api/types/filters" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+// SearchOptions holds parameters to search images with. |
|
| 9 |
+type SearchOptions struct {
|
|
| 10 |
+ RegistryAuth string |
|
| 11 |
+ |
|
| 12 |
+ // PrivilegeFunc is a [types.RequestPrivilegeFunc] the client can |
|
| 13 |
+ // supply to retry operations after getting an authorization error. |
|
| 14 |
+ // |
|
| 15 |
+ // It must return the registry authentication header value in base64 |
|
| 16 |
+ // format, or an error if the privilege request fails. |
|
| 17 |
+ PrivilegeFunc func(context.Context) (string, error) |
|
| 18 |
+ Filters filters.Args |
|
| 19 |
+ Limit int |
|
| 20 |
+} |
|
| 21 |
+ |
|
| 22 |
+// SearchResult describes a search result returned from a registry |
|
| 23 |
+type SearchResult struct {
|
|
| 24 |
+ // StarCount indicates the number of stars this repository has |
|
| 25 |
+ StarCount int `json:"star_count"` |
|
| 26 |
+ // IsOfficial is true if the result is from an official repository. |
|
| 27 |
+ IsOfficial bool `json:"is_official"` |
|
| 28 |
+ // Name is the name of the repository |
|
| 29 |
+ Name string `json:"name"` |
|
| 30 |
+ // IsAutomated indicates whether the result is automated. |
|
| 31 |
+ // |
|
| 32 |
+ // Deprecated: the "is_automated" field is deprecated and will always be "false". |
|
| 33 |
+ IsAutomated bool `json:"is_automated"` |
|
| 34 |
+ // Description is a textual description of the repository |
|
| 35 |
+ Description string `json:"description"` |
|
| 36 |
+} |
|
| 37 |
+ |
|
| 38 |
+// SearchResults lists a collection search results returned from a registry |
|
| 39 |
+type SearchResults struct {
|
|
| 40 |
+ // Query contains the query string that generated the search results |
|
| 41 |
+ Query string `json:"query"` |
|
| 42 |
+ // NumResults indicates the number of results the query returned |
|
| 43 |
+ NumResults int `json:"num_results"` |
|
| 44 |
+ // Results is a slice containing the actual results for the search |
|
| 45 |
+ Results []SearchResult `json:"results"` |
|
| 46 |
+} |
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
"github.com/docker/docker/api/types/events" |
| 6 | 6 |
"github.com/docker/docker/api/types/image" |
| 7 | 7 |
"github.com/docker/docker/api/types/network" |
| 8 |
+ "github.com/docker/docker/api/types/registry" |
|
| 8 | 9 |
"github.com/docker/docker/api/types/volume" |
| 9 | 10 |
) |
| 10 | 11 |
|
| ... | ... |
@@ -117,3 +118,8 @@ type ContainerStats = container.StatsResponse |
| 117 | 117 |
// |
| 118 | 118 |
// Deprecated: use [events.ListOptions]. |
| 119 | 119 |
type EventsOptions = events.ListOptions |
| 120 |
+ |
|
| 121 |
+// ImageSearchOptions holds parameters to search images with. |
|
| 122 |
+// |
|
| 123 |
+// Deprecated: use [registry.SearchOptions]. |
|
| 124 |
+type ImageSearchOptions = registry.SearchOptions |
| ... | ... |
@@ -7,7 +7,6 @@ import ( |
| 7 | 7 |
"net/url" |
| 8 | 8 |
"strconv" |
| 9 | 9 |
|
| 10 |
- "github.com/docker/docker/api/types" |
|
| 11 | 10 |
"github.com/docker/docker/api/types/filters" |
| 12 | 11 |
"github.com/docker/docker/api/types/registry" |
| 13 | 12 |
"github.com/docker/docker/errdefs" |
| ... | ... |
@@ -15,7 +14,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
// ImageSearch makes the docker host search by a term in a remote registry. |
| 17 | 17 |
// 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) {
|
|
| 18 |
+func (cli *Client) ImageSearch(ctx context.Context, term string, options registry.SearchOptions) ([]registry.SearchResult, error) {
|
|
| 19 | 19 |
var results []registry.SearchResult |
| 20 | 20 |
query := url.Values{}
|
| 21 | 21 |
query.Set("term", term)
|
| ... | ... |
@@ -10,7 +10,6 @@ import ( |
| 10 | 10 |
"strings" |
| 11 | 11 |
"testing" |
| 12 | 12 |
|
| 13 |
- "github.com/docker/docker/api/types" |
|
| 14 | 13 |
"github.com/docker/docker/api/types/filters" |
| 15 | 14 |
"github.com/docker/docker/api/types/registry" |
| 16 | 15 |
"github.com/docker/docker/errdefs" |
| ... | ... |
@@ -22,7 +21,7 @@ func TestImageSearchAnyError(t *testing.T) {
|
| 22 | 22 |
client := &Client{
|
| 23 | 23 |
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
| 24 | 24 |
} |
| 25 |
- _, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{})
|
|
| 25 |
+ _, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{})
|
|
| 26 | 26 |
assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) |
| 27 | 27 |
} |
| 28 | 28 |
|
| ... | ... |
@@ -30,7 +29,7 @@ func TestImageSearchStatusUnauthorizedError(t *testing.T) {
|
| 30 | 30 |
client := &Client{
|
| 31 | 31 |
client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), |
| 32 | 32 |
} |
| 33 |
- _, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{})
|
|
| 33 |
+ _, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{})
|
|
| 34 | 34 |
assert.Check(t, is.ErrorType(err, errdefs.IsUnauthorized)) |
| 35 | 35 |
} |
| 36 | 36 |
|
| ... | ... |
@@ -41,7 +40,7 @@ func TestImageSearchWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) {
|
| 41 | 41 |
privilegeFunc := func(_ context.Context) (string, error) {
|
| 42 | 42 |
return "", fmt.Errorf("Error requesting privilege")
|
| 43 | 43 |
} |
| 44 |
- _, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{
|
|
| 44 |
+ _, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{
|
|
| 45 | 45 |
PrivilegeFunc: privilegeFunc, |
| 46 | 46 |
}) |
| 47 | 47 |
if err == nil || err.Error() != "Error requesting privilege" {
|
| ... | ... |
@@ -56,7 +55,7 @@ func TestImageSearchWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing. |
| 56 | 56 |
privilegeFunc := func(_ context.Context) (string, error) {
|
| 57 | 57 |
return "a-auth-header", nil |
| 58 | 58 |
} |
| 59 |
- _, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{
|
|
| 59 |
+ _, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{
|
|
| 60 | 60 |
PrivilegeFunc: privilegeFunc, |
| 61 | 61 |
}) |
| 62 | 62 |
assert.Check(t, is.ErrorType(err, errdefs.IsUnauthorized)) |
| ... | ... |
@@ -101,7 +100,7 @@ func TestImageSearchWithPrivilegedFuncNoError(t *testing.T) {
|
| 101 | 101 |
privilegeFunc := func(_ context.Context) (string, error) {
|
| 102 | 102 |
return "IAmValid", nil |
| 103 | 103 |
} |
| 104 |
- results, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{
|
|
| 104 |
+ results, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{
|
|
| 105 | 105 |
RegistryAuth: "NotValid", |
| 106 | 106 |
PrivilegeFunc: privilegeFunc, |
| 107 | 107 |
}) |
| ... | ... |
@@ -145,7 +144,7 @@ func TestImageSearchWithoutErrors(t *testing.T) {
|
| 145 | 145 |
}, nil |
| 146 | 146 |
}), |
| 147 | 147 |
} |
| 148 |
- results, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{
|
|
| 148 |
+ results, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{
|
|
| 149 | 149 |
Filters: filters.NewArgs( |
| 150 | 150 |
filters.Arg("is-automated", "true"),
|
| 151 | 151 |
filters.Arg("stars", "3"),
|
| ... | ... |
@@ -99,7 +99,7 @@ type ImageAPIClient interface {
|
| 99 | 99 |
ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error) |
| 100 | 100 |
ImagePush(ctx context.Context, ref string, options image.PushOptions) (io.ReadCloser, error) |
| 101 | 101 |
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) |
|
| 103 | 103 |
ImageSave(ctx context.Context, images []string) (io.ReadCloser, error) |
| 104 | 104 |
ImageTag(ctx context.Context, image, ref string) error |
| 105 | 105 |
ImagesPrune(ctx context.Context, pruneFilter filters.Args) (image.PruneReport, error) |