Skip to content

Commit

Permalink
docker/api/image: replace use of deprecated "filter" argument
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
thaJeztah authored and ulyssessouza committed Nov 26, 2020
1 parent 4328197 commit 1757c97
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
10 changes: 9 additions & 1 deletion docker/api/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,18 @@ def images(self, name=None, quiet=False, all=False, filters=None):
If the server returns an error.
"""
params = {
'filter': name,
'only_ids': 1 if quiet else 0,
'all': 1 if all else 0,
}
if name:
if utils.version_lt(self._version, '1.25'):
# only use "filter" on API 1.24 and under, as it is deprecated
params['filter'] = name
else:
if filters:
filters['reference'] = name
else:
filters = {'reference': name}
if filters:
params['filters'] = utils.convert_filters(filters)
res = self._result(self._get(self._url("/images/json"), params=params),
Expand Down
19 changes: 15 additions & 4 deletions tests/unit/api_image_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@ def test_images(self):
fake_request.assert_called_with(
'GET',
url_prefix + 'images/json',
params={'filter': None, 'only_ids': 0, 'all': 1},
params={'only_ids': 0, 'all': 1},
timeout=DEFAULT_TIMEOUT_SECONDS
)

def test_images_name(self):
self.client.images('foo:bar')

fake_request.assert_called_with(
'GET',
url_prefix + 'images/json',
params={'only_ids': 0, 'all': 0,
'filters': '{"reference": ["foo:bar"]}'},
timeout=DEFAULT_TIMEOUT_SECONDS
)

Expand All @@ -36,7 +47,7 @@ def test_images_quiet(self):
fake_request.assert_called_with(
'GET',
url_prefix + 'images/json',
params={'filter': None, 'only_ids': 1, 'all': 1},
params={'only_ids': 1, 'all': 1},
timeout=DEFAULT_TIMEOUT_SECONDS
)

Expand All @@ -46,7 +57,7 @@ def test_image_ids(self):
fake_request.assert_called_with(
'GET',
url_prefix + 'images/json',
params={'filter': None, 'only_ids': 1, 'all': 0},
params={'only_ids': 1, 'all': 0},
timeout=DEFAULT_TIMEOUT_SECONDS
)

Expand All @@ -56,7 +67,7 @@ def test_images_filters(self):
fake_request.assert_called_with(
'GET',
url_prefix + 'images/json',
params={'filter': None, 'only_ids': 0, 'all': 0,
params={'only_ids': 0, 'all': 0,
'filters': '{"dangling": ["true"]}'},
timeout=DEFAULT_TIMEOUT_SECONDS
)
Expand Down

0 comments on commit 1757c97

Please sign in to comment.