Skip to content

Commit b292150

Browse files
committed
api/search: Reset is_automated field to false
The field will still be present in the response, but will always be `false`. Searching for `is-automated=true` will yield no results, while `is-automated=false` will effectively be a no-op. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
1 parent 137a9d6 commit b292150

File tree

6 files changed

+28
-35
lines changed

6 files changed

+28
-35
lines changed

api/swagger.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8774,8 +8774,7 @@ paths:
87748774
87758775
<p><br /></p>
87768776
8777-
> **Deprecated**: This field is deprecated and will always
8778-
> be "false" in future.
8777+
> **Deprecated**: This field is deprecated and will always be "false".
87798778
type: "boolean"
87808779
example: false
87818780
name:
@@ -8818,13 +8817,8 @@ paths:
88188817
description: |
88198818
A JSON encoded value of the filters (a `map[string][]string`) to process on the images list. Available filters:
88208819
8821-
- `is-automated=(true|false)` (deprecated, see below)
88228820
- `is-official=(true|false)`
88238821
- `stars=<number>` Matches images that has at least 'number' stars.
8824-
8825-
The `is-automated` filter is deprecated. The `is_automated` field has
8826-
been deprecated by Docker Hub's search API. Consequently, searching
8827-
for `is-automated=true` will yield no results.
88288822
type: "string"
88298823
tags: ["Image"]
88308824
/images/prune:

api/types/registry/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ type SearchResult struct {
9494
Name string `json:"name"`
9595
// IsAutomated indicates whether the result is automated.
9696
//
97-
// Deprecated: the "is_automated" field is deprecated and will always be "false" in the future.
97+
// Deprecated: the "is_automated" field is deprecated and will always be "false".
9898
IsAutomated bool `json:"is_automated"`
9999
// Description is a textual description of the repository
100100
Description string `json:"description"`

docs/api/version-history.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ keywords: "API, Docker, rcli, REST, documentation"
1919

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

2326
## v1.44 API changes
2427

integration-cli/docker_cli_search_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/docker/docker/integration-cli/cli"
1010
"gotest.tools/v3/assert"
11+
is "gotest.tools/v3/assert/cmp"
1112
)
1213

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

5354
outSearchCmdautomated := cli.DockerCmd(c, "search", "--filter", "is-automated=true", "busybox").Combined() // The busybox is a busybox base image, not an AUTOMATED image.
5455
outSearchCmdautomatedSlice := strings.Split(outSearchCmdautomated, "\n")
55-
for i := range outSearchCmdautomatedSlice {
56-
assert.Assert(c, !strings.HasPrefix(outSearchCmdautomatedSlice[i], "busybox "), "The busybox is not an AUTOMATED image: %s", outSearchCmdautomated)
57-
}
56+
57+
// is-automated=true should produce no results (only a header)
58+
assert.Check(c, is.Len(outSearchCmdautomatedSlice, 2))
5859

5960
outSearchCmdNotOfficial := cli.DockerCmd(c, "search", "--filter", "is-official=false", "busybox").Combined() // The busybox is a busybox base image, official image.
6061
outSearchCmdNotOfficialSlice := strings.Split(outSearchCmdNotOfficial, "\n")

registry/search.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ func (s *Service) Search(ctx context.Context, searchFilters filters.Args, term s
2727
return nil, err
2828
}
2929

30-
// 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".
3130
isAutomated, err := searchFilters.GetBoolOrDefault("is-automated", false)
3231
if err != nil {
3332
return nil, err
3433
}
34+
35+
// "is-automated" is deprecated and filtering for `true` will yield no results.
36+
if isAutomated {
37+
return []registry.SearchResult{}, nil
38+
}
39+
3540
isOfficial, err := searchFilters.GetBoolOrDefault("is-official", false)
3641
if err != nil {
3742
return nil, err
@@ -51,19 +56,13 @@ func (s *Service) Search(ctx context.Context, searchFilters filters.Args, term s
5156
}
5257
}
5358

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

6064
filteredResults := []registry.SearchResult{}
6165
for _, result := range unfilteredResult.Results {
62-
if searchFilters.Contains("is-automated") {
63-
if isAutomated != result.IsAutomated { //nolint:staticcheck // ignore SA1019 for old API versions.
64-
continue
65-
}
66-
}
6766
if searchFilters.Contains("is-official") {
6867
if isOfficial != result.IsOfficial {
6968
continue
@@ -74,6 +73,10 @@ func (s *Service) Search(ctx context.Context, searchFilters filters.Args, term s
7473
continue
7574
}
7675
}
76+
// "is-automated" is deprecated and the value in Docker Hub search
77+
// results is untrustworthy. Force it to false so as to not mislead our
78+
// clients.
79+
result.IsAutomated = false //nolint:staticcheck // ignore SA1019 (field is deprecated)
7780
filteredResults = append(filteredResults, result)
7881
}
7982

registry/search_test.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -206,25 +206,25 @@ func TestSearch(t *testing.T) {
206206
IsAutomated: true, //nolint:staticcheck // ignore SA1019 (field is deprecated).
207207
},
208208
},
209-
expectedResults: []registry.SearchResult{
209+
expectedResults: []registry.SearchResult{},
210+
},
211+
{
212+
name: "is-automated=false, IsAutomated reset to false",
213+
filtersArgs: filters.NewArgs(filters.Arg("is-automated", "false")),
214+
registryResults: []registry.SearchResult{
210215
{
211216
Name: "name",
212217
Description: "description",
213218
IsAutomated: true, //nolint:staticcheck // ignore SA1019 (field is deprecated).
214219
},
215220
},
216-
},
217-
{
218-
name: "is-automated=false, no results",
219-
filtersArgs: filters.NewArgs(filters.Arg("is-automated", "false")),
220-
registryResults: []registry.SearchResult{
221+
expectedResults: []registry.SearchResult{
221222
{
222223
Name: "name",
223224
Description: "description",
224-
IsAutomated: true, //nolint:staticcheck // ignore SA1019 (field is deprecated).
225+
IsAutomated: false, //nolint:staticcheck // ignore SA1019 (field is deprecated).
225226
},
226227
},
227-
expectedResults: []registry.SearchResult{},
228228
},
229229
{
230230
name: "is-automated=false",
@@ -390,15 +390,7 @@ func TestSearch(t *testing.T) {
390390
IsAutomated: true, //nolint:staticcheck // ignore SA1019 (field is deprecated).
391391
},
392392
},
393-
expectedResults: []registry.SearchResult{
394-
{
395-
Name: "name3",
396-
Description: "description3",
397-
StarCount: 2,
398-
IsOfficial: true,
399-
IsAutomated: true, //nolint:staticcheck // ignore SA1019 (field is deprecated).
400-
},
401-
},
393+
expectedResults: []registry.SearchResult{},
402394
},
403395
}
404396
for _, tc := range successCases {

0 commit comments

Comments
 (0)