Skip to content

Commit 1757c97

Browse files
thaJeztahUlysses Souza
authored andcommitted
docker/api/image: replace use of deprecated "filter" argument
The "filter" argument was deprecated in docker 1.13 (API version 1.25), and removed from API v1.41 and up. See https://github.com/docker/cli/blob/v20.10.0-rc1/docs/deprecated.md#filter-param-for-imagesjson-endpoint This patch applies the name as "reference" filter, instead of "filter" for API 1.25 and up. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 4328197 commit 1757c97

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

docker/api/image.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,18 @@ def images(self, name=None, quiet=False, all=False, filters=None):
8181
If the server returns an error.
8282
"""
8383
params = {
84-
'filter': name,
8584
'only_ids': 1 if quiet else 0,
8685
'all': 1 if all else 0,
8786
}
87+
if name:
88+
if utils.version_lt(self._version, '1.25'):
89+
# only use "filter" on API 1.24 and under, as it is deprecated
90+
params['filter'] = name
91+
else:
92+
if filters:
93+
filters['reference'] = name
94+
else:
95+
filters = {'reference': name}
8896
if filters:
8997
params['filters'] = utils.convert_filters(filters)
9098
res = self._result(self._get(self._url("/images/json"), params=params),

tests/unit/api_image_test.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,18 @@ def test_images(self):
2626
fake_request.assert_called_with(
2727
'GET',
2828
url_prefix + 'images/json',
29-
params={'filter': None, 'only_ids': 0, 'all': 1},
29+
params={'only_ids': 0, 'all': 1},
30+
timeout=DEFAULT_TIMEOUT_SECONDS
31+
)
32+
33+
def test_images_name(self):
34+
self.client.images('foo:bar')
35+
36+
fake_request.assert_called_with(
37+
'GET',
38+
url_prefix + 'images/json',
39+
params={'only_ids': 0, 'all': 0,
40+
'filters': '{"reference": ["foo:bar"]}'},
3041
timeout=DEFAULT_TIMEOUT_SECONDS
3142
)
3243

@@ -36,7 +47,7 @@ def test_images_quiet(self):
3647
fake_request.assert_called_with(
3748
'GET',
3849
url_prefix + 'images/json',
39-
params={'filter': None, 'only_ids': 1, 'all': 1},
50+
params={'only_ids': 1, 'all': 1},
4051
timeout=DEFAULT_TIMEOUT_SECONDS
4152
)
4253

@@ -46,7 +57,7 @@ def test_image_ids(self):
4657
fake_request.assert_called_with(
4758
'GET',
4859
url_prefix + 'images/json',
49-
params={'filter': None, 'only_ids': 1, 'all': 0},
60+
params={'only_ids': 1, 'all': 0},
5061
timeout=DEFAULT_TIMEOUT_SECONDS
5162
)
5263

@@ -56,7 +67,7 @@ def test_images_filters(self):
5667
fake_request.assert_called_with(
5768
'GET',
5869
url_prefix + 'images/json',
59-
params={'filter': None, 'only_ids': 0, 'all': 0,
70+
params={'only_ids': 0, 'all': 0,
6071
'filters': '{"dangling": ["true"]}'},
6172
timeout=DEFAULT_TIMEOUT_SECONDS
6273
)

0 commit comments

Comments
 (0)