Skip to content

Commit

Permalink
Merge pull request moby#47465 from vvoland/v26-remove-deprecated
Browse files Browse the repository at this point in the history
api/search: Reset `is_automated` to false
  • Loading branch information
thaJeztah authored Mar 4, 2024
2 parents 97a5435 + b292150 commit 04c9d7f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 35 deletions.
8 changes: 1 addition & 7 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8774,8 +8774,7 @@ paths:
<p><br /></p>
> **Deprecated**: This field is deprecated and will always
> be "false" in future.
> **Deprecated**: This field is deprecated and will always be "false".
type: "boolean"
example: false
name:
Expand Down Expand Up @@ -8818,13 +8817,8 @@ paths:
description: |
A JSON encoded value of the filters (a `map[string][]string`) to process on the images list. Available filters:
- `is-automated=(true|false)` (deprecated, see below)
- `is-official=(true|false)`
- `stars=<number>` Matches images that has at least 'number' stars.
The `is-automated` filter is deprecated. The `is_automated` field has
been deprecated by Docker Hub's search API. Consequently, searching
for `is-automated=true` will yield no results.
type: "string"
tags: ["Image"]
/images/prune:
Expand Down
2 changes: 1 addition & 1 deletion api/types/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type SearchResult struct {
Name string `json:"name"`
// IsAutomated indicates whether the result is automated.
//
// Deprecated: the "is_automated" field is deprecated and will always be "false" in the future.
// 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"`
Expand Down
3 changes: 3 additions & 0 deletions docs/api/version-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ keywords: "API, Docker, rcli, REST, documentation"

* `POST /containers/create` now supports `VolumeOptions.Subpath` which allows a
subpath of a named volume to be mounted.
* `POST /images/search` will always assume a `false` value for the `is-automated`
field. Consequently, searching for `is-automated=true` will yield no results,
while `is-automated=false` will be a no-op.

## v1.44 API changes

Expand Down
7 changes: 4 additions & 3 deletions integration-cli/docker_cli_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/docker/docker/integration-cli/cli"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)

type DockerCLISearchSuite struct {
Expand Down Expand Up @@ -52,9 +53,9 @@ func (s *DockerCLISearchSuite) TestSearchCmdOptions(c *testing.T) {

outSearchCmdautomated := cli.DockerCmd(c, "search", "--filter", "is-automated=true", "busybox").Combined() // The busybox is a busybox base image, not an AUTOMATED image.
outSearchCmdautomatedSlice := strings.Split(outSearchCmdautomated, "\n")
for i := range outSearchCmdautomatedSlice {
assert.Assert(c, !strings.HasPrefix(outSearchCmdautomatedSlice[i], "busybox "), "The busybox is not an AUTOMATED image: %s", outSearchCmdautomated)
}

// is-automated=true should produce no results (only a header)
assert.Check(c, is.Len(outSearchCmdautomatedSlice, 2))

outSearchCmdNotOfficial := cli.DockerCmd(c, "search", "--filter", "is-official=false", "busybox").Combined() // The busybox is a busybox base image, official image.
outSearchCmdNotOfficialSlice := strings.Split(outSearchCmdNotOfficial, "\n")
Expand Down
17 changes: 10 additions & 7 deletions registry/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ func (s *Service) Search(ctx context.Context, searchFilters filters.Args, term s
return nil, err
}

// TODO(thaJeztah): the "is-automated" field is deprecated; reset the field for the next release (v26.0.0). Return early when using "is-automated=true", and ignore "is-automated=false".
isAutomated, err := searchFilters.GetBoolOrDefault("is-automated", false)
if err != nil {
return nil, err
}

// "is-automated" is deprecated and filtering for `true` will yield no results.
if isAutomated {
return []registry.SearchResult{}, nil
}

isOfficial, err := searchFilters.GetBoolOrDefault("is-official", false)
if err != nil {
return nil, err
Expand All @@ -51,19 +56,13 @@ func (s *Service) Search(ctx context.Context, searchFilters filters.Args, term s
}
}

// TODO(thaJeztah): the "is-automated" field is deprecated. Reset the field for the next release (v26.0.0) if any "true" values are present.
unfilteredResult, err := s.searchUnfiltered(ctx, term, limit, authConfig, headers)
if err != nil {
return nil, err
}

filteredResults := []registry.SearchResult{}
for _, result := range unfilteredResult.Results {
if searchFilters.Contains("is-automated") {
if isAutomated != result.IsAutomated { //nolint:staticcheck // ignore SA1019 for old API versions.
continue
}
}
if searchFilters.Contains("is-official") {
if isOfficial != result.IsOfficial {
continue
Expand All @@ -74,6 +73,10 @@ func (s *Service) Search(ctx context.Context, searchFilters filters.Args, term s
continue
}
}
// "is-automated" is deprecated and the value in Docker Hub search
// results is untrustworthy. Force it to false so as to not mislead our
// clients.
result.IsAutomated = false //nolint:staticcheck // ignore SA1019 (field is deprecated)
filteredResults = append(filteredResults, result)
}

Expand Down
26 changes: 9 additions & 17 deletions registry/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,25 +206,25 @@ func TestSearch(t *testing.T) {
IsAutomated: true, //nolint:staticcheck // ignore SA1019 (field is deprecated).
},
},
expectedResults: []registry.SearchResult{
expectedResults: []registry.SearchResult{},
},
{
name: "is-automated=false, IsAutomated reset to false",
filtersArgs: filters.NewArgs(filters.Arg("is-automated", "false")),
registryResults: []registry.SearchResult{
{
Name: "name",
Description: "description",
IsAutomated: true, //nolint:staticcheck // ignore SA1019 (field is deprecated).
},
},
},
{
name: "is-automated=false, no results",
filtersArgs: filters.NewArgs(filters.Arg("is-automated", "false")),
registryResults: []registry.SearchResult{
expectedResults: []registry.SearchResult{
{
Name: "name",
Description: "description",
IsAutomated: true, //nolint:staticcheck // ignore SA1019 (field is deprecated).
IsAutomated: false, //nolint:staticcheck // ignore SA1019 (field is deprecated).
},
},
expectedResults: []registry.SearchResult{},
},
{
name: "is-automated=false",
Expand Down Expand Up @@ -390,15 +390,7 @@ func TestSearch(t *testing.T) {
IsAutomated: true, //nolint:staticcheck // ignore SA1019 (field is deprecated).
},
},
expectedResults: []registry.SearchResult{
{
Name: "name3",
Description: "description3",
StarCount: 2,
IsOfficial: true,
IsAutomated: true, //nolint:staticcheck // ignore SA1019 (field is deprecated).
},
},
expectedResults: []registry.SearchResult{},
},
}
for _, tc := range successCases {
Expand Down

0 comments on commit 04c9d7f

Please sign in to comment.