Граф коммитов

367 Коммитов

Автор SHA1 Сообщение Дата
Felipe Ruhland d4310b2db0 Fix `KeyError` when creating a new secret
How to reproduce the issue:

```py
>>> import docker
>>> cli = docker.from_env()
>>> cli.secrets.create(name="any_name", data="1")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/docker-py/docker/models/secrets.py", line 10, in __repr__
    return "<%s: '%s'>" % (self.__class__.__name__, self.name)
  File "/home/docker-py/docker/models/secrets.py", line 14, in name
    return self.attrs['Spec']['Name']
KeyError: 'Spec'
```

The exception raises because create secrets API `/secrets/create` only
return the `id` attribute:
https://docs.docker.com/engine/api/v1.41/#operation/SecretCreate
The secret model is created using just the `id` attribute and fails
when looking for Spec.Name attribute.

```py
def __repr__(self):
    return "<%s: '%s'>" % (self.__class__.__name__, self.name)
```

```py
@property
def name(self):
    return self.attrs['Spec']['Name']
```

I came up with a ugly solution but will prevent the problem to happen
again:

```py
def create(self, **kwargs):
    obj = self.client.api.create_secret(**kwargs)
+   obj.setdefault("Spec", {})["Name"] = kwargs.get("name")
    return self.prepare_model(obj)
```

After the API call, I added the name attribute to the right place to be
used on the property name.

```py
>>> import docker
>>> cli = docker.from_env()
>>> cli.secrets.create(name="any_name", data="1")
<Secret: 'any_name'>
```

It isn't the most elegant solution, but it will do the trick.
I had a previous PR #2517 when I propose using the `id` attribute
instead of `name` on the `__repr__` method, but I think this one will be better.

That fixes #2025

Signed-off-by: Felipe Ruhland <felipe.ruhland@gmail.com>
2021-03-24 18:03:54 +01:00
Ulysses Souza c8fba210a2 Remove support to pre python 3.6
Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
2021-03-22 10:18:23 -03:00
Nicolas De Loof 563124163a relax PORT_SPEC regex so it accept and ignore square brackets
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2021-03-10 11:25:18 +01:00
Felipe Ruhland 7d316641a3 Add limit parameter to image search endpoint
Signed-off-by: Felipe Ruhland <felipe.ruhland@gmail.com>
2021-02-24 23:42:20 +01:00
aiordache 2807fde6c9 Fix SSH port parsing and add regression tests
Signed-off-by: aiordache <anca.iordache@docker.com>
2021-02-18 10:56:29 -03:00
WojciechowskiPiotr 6d1dffe3e5 Unit and integration tests added
Signed-off-by: WojciechowskiPiotr <devel@it-playground.pl>
2021-02-09 21:37:26 +01:00
Sebastiaan van Stijn 1757c974fa 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 <github@gone.nl>
2020-11-26 17:07:27 +00:00
Mariano Scazzariello bb1c528ab3
Add max_pool_size parameter (#2699)
* Add max_pool_size parameter

Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>

* Add client version to tests

Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>

* Fix parameter position

Signed-off-by: Mariano Scazzariello <marianoscazzariello@gmail.com>
2020-11-17 15:42:36 +01:00
aiordache cec152db5f Set image default tag on pull
Signed-off-by: aiordache <anca.iordache@docker.com>
2020-09-16 17:36:50 +02:00
aiordache c7c5b551fc set engine version for unit tests to avoid querying the engine
Signed-off-by: aiordache <anca.iordache@docker.com>
2020-08-20 15:29:24 +02:00
Anca Iordache 2c522fb362
Fix memory conversion to bytes (#2645)
* Fix memory conversion to bytes

Co-authored-by: Ulysses Souza <ulysses.souza@gmail.com>

Signed-off-by: aiordache <anca.iordache@docker.com>
2020-08-17 18:32:48 +02:00
Anca Iordache 6367bbee2e
Merge pull request #2520 from Nicceboy/master
Disable compression by default when using container:get_archive method
2020-08-07 14:42:58 +02:00
Ville Skyttä 631abd156a
Spelling fixes (#2571)
Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
2020-08-07 14:33:19 +02:00
Lucidiot dd0450a14c
Add device requests (#2471)
* Add DeviceRequest type

Signed-off-by: Erwan Rouchet <rouchet@teklia.com>

* Add device_requests kwarg in host config

Signed-off-by: Erwan Rouchet <rouchet@teklia.com>

* Add unit test for device requests

Signed-off-by: Erwan Rouchet <rouchet@teklia.com>

* Fix unit test

Signed-off-by: Erwan Rouchet <rouchet@teklia.com>

* Use parentheses for multiline import

Signed-off-by: Erwan Rouchet <rouchet@teklia.com>

* Create 1.40 client for device-requests test

Signed-off-by: Laurie O <laurie_opperman@hotmail.com>

Co-authored-by: Laurie O <laurie_opperman@hotmail.com>
Co-authored-by: Bastien Abadie <abadie@teklia.com>
2020-08-07 13:58:35 +02:00
Ulysses Souza 74a0734d37
Merge pull request #2551 from haboustak/2550-add-driveropts-to-endpointconfig
Add support for DriverOpts in EndpointConfig
2020-07-02 10:51:35 +02:00
Ulysses Souza 3ce2d8959d Specify when to use `tls` on Context constructor
Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
2020-05-28 20:53:45 +02:00
Mike Haboustak df7bf5f5e0
Add support for DriverOpts in EndpointConfig
Docker API 1.32 added support for providing options to a network driver
via EndpointConfig when connecting a container to a network.

Signed-off-by: Mike Haboustak <haboustak@gmail.com>
2020-04-30 05:27:45 -04:00
Niklas Saari 51fd6dd1ce
Disable compression by default when using get_archive method
Signed-off-by: Niklas Saari <niklas.saari@tutanota.com>
2020-02-26 23:09:38 +02:00
Anca Iordache 64fdb32ae8 Implement context management, lifecycle and unittests.
Signed-off-by: Anca Iordache <anca.iordache@docker.com>
2020-02-05 14:49:42 +01:00
Matt Fluet aa13df40b1 Fix for empty auth keys in config.json
Signed-off-by: Matt Fluet <matt.fluet@appian.com>
2019-08-15 18:15:57 -04:00
Joffrey F a823acc2ca Make dockerpycreds part of the SDK under docker.credentials
Signed-off-by: Joffrey F <joffrey@docker.com>
2019-04-30 23:37:55 -07:00
Ulysses Souza b2175c9475 Fix base_url to keep TCP protocol
This fix lets the responsability of changing the
protocol to `parse_host` afterwards, letting
`base_url` with the original value.

Signed-off-by: Ulysses Souza <ulysses.souza@docker.com>
2019-03-26 16:04:06 +01:00
Ian Campbell c1fea8ee4a
Merge pull request #2288 from hannseman/container-run-create-volume_driver
Move volume_driver to RUN_HOST_CONFIG_KWARGS
2019-03-25 12:24:54 +00:00
Hannes Ljungberg 523371e21d Move volume_driver to RUN_HOST_CONFIG_KWARGS
Fixes #2271

Signed-off-by: Hannes Ljungberg <hannes@5monkeys.se>
2019-03-23 20:57:23 +01:00
Hannes Ljungberg 35714c46b1 Test all split_port with all valid protocols
Signed-off-by: Hannes Ljungberg <hannes@5monkeys.se>
2019-03-18 22:15:45 +01:00
Joffrey F a579e9e205 Remove use_config_proxy from exec. Add use_config_proxy docs to DockerClient
Signed-off-by: Joffrey F <joffrey@docker.com>
2019-01-09 14:45:13 -08:00
Sebastiaan van Stijn 219c52141e
Regression 443 test: relax status-code check
This test was testing for a 500 status, but this status
is actually a bug in the API (as it's due to an invalid
request), and the API should actually return a 400 status.

To make this test handle both situations, relax the test
to accept either a 4xx or 5xx status.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-01-09 21:23:11 +01:00
Corentin Henry 2c4a8651a8 By default, disable proxy support
This is to avoid a breaking change

Signed-off-by: Corentin Henry <corentinhenry@gmail.com>
2019-01-09 11:30:58 -08:00
Corentin Henry 545adc2a59 add unit tests for ProxyConfig
Signed-off-by: Corentin Henry <corentinhenry@gmail.com>
2019-01-09 11:30:58 -08:00
Corentin Henry 6e227895d3 tests: remove outdated code
the _cfg attribute does not exist anymore

Signed-off-by: Corentin Henry <corentinhenry@gmail.com>
2019-01-09 11:30:58 -08:00
Joffrey F 72f4f527ad Update test dependencies to latest version, fix some flake8 errors
Signed-off-by: Joffrey F <joffrey@docker.com>
2019-01-09 11:18:40 -08:00
Joffrey F c344660f20
Merge pull request #2188 from docker/c6374-credhelpers
Modernize auth management
2018-11-30 15:32:30 -08:00
Joffrey F b2ad302636 Fix test names
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-11-30 14:58:18 -08:00
Joffrey F ee6ec4c6e8 Merge branch 'master' of https://github.com/little-dude/docker-py into little-dude-master 2018-11-30 14:48:19 -08:00
Joffrey F cc38efa68e Add some credHelpers tests
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-11-30 14:41:56 -08:00
Joffrey F 01ccaa6af2 Make AuthConfig a dict subclass for backward-compatibility
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-11-30 13:51:01 -08:00
Joffrey F bc5d7c8cb6 Modernize auth management
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-11-28 19:32:01 -08:00
Corentin Henry 7b3b83dfdb fix exec api inconsistency
Signed-off-by: Corentin Henry <corentinhenry@gmail.com>
2018-11-28 15:16:23 -08:00
Corentin Henry 6540900dae add tests for _read_from_socket
Check that the return value against the various combination of
parameters this function can take (tty, stream, and demux).

This commit also fixes a bug that the tests uncovered a bug in
consume_socket_output.

Signed-off-by: Corentin Henry <corentinhenry@gmail.com>
2018-11-28 13:37:10 -08:00
Joffrey F c53423f118 Update DockerClient.images.pull to always stream response
Also raise a warning when users attempt to specify the "stream" parameter

Signed-off-by: Joffrey F <joffrey@docker.com>
2018-11-28 11:27:04 -08:00
adw1n a74d546864 Fix pulling images with `stream=True`
Pulling an image with option `stream=True` like this:
```
client.api.pull('docker.io/user/repo_name', tag='latest', stream=True)
```
without consuming the generator oftentimes results in premature drop of the connection. Docker daemon tries to send progress of pulling the image to the client, but it encounters an error (broken pipe) and therefore cancells the pull action:
```
Thread 1 "dockerd-dev" received signal SIGPIPE, Broken pipe.
ERRO[2018-09-03T05:12:35.746497638+02:00] Not continuing with pull after error: context canceled
```
As described in issue #2116, even though client receives response with status code 200, image is not pulled.

Closes #2116

Signed-off-by: Przemysław Adamek <adw1n@users.noreply.github.com>
2018-11-28 11:27:04 -08:00
Corentin Henry 5f157bbaca implement stream demultiplexing for exec commands
fixes https://github.com/docker/docker-py/issues/1952

Signed-off-by: Corentin Henry <corentinhenry@gmail.com>
2018-11-27 17:01:48 -08:00
Joffrey F 114630161a Correctly handle longpath prefix in process_dockerfile when joining paths
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-11-26 17:34:26 -08:00
Corentin Henry 47c10aa383 tests: fix failure due to pytest deprecation
Signed-off-by: Corentin Henry <corentinhenry@gmail.com>
2018-11-21 17:17:50 -08:00
Joffrey F f83fe7c959 Properly convert non-string filters to expected string format
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-11-08 17:22:24 -08:00
Joffrey F f302756599 Rewrite utils.parse_host to detect more invalid addresses.
The method now uses parsing methods from urllib to better split provided URLs.
Addresses containing query strings, parameters, passwords or fragments no longer fail silently.
SSH addresses containing paths are no longer accepted.

Signed-off-by: Joffrey F <joffrey@docker.com>
2018-11-01 15:44:43 -07:00
Joffrey F cc766633de
Merge pull request #2103 from asottile/allow_uid_integer_0
Allow user=0 to be passed in create_container
2018-08-06 14:21:32 -07:00
Joffrey F c28ff85542 Improve placement handling in DockerClient.services.create
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-08-03 14:04:04 -07:00
Anthony Sottile 3c9738a584 Allow user=0 to be passed in create_container
Signed-off-by: Anthony Sottile <asottile@umich.edu>
2018-08-02 12:00:55 -07:00
Joffrey F b3d2e54a2d
Merge pull request #2063 from mtszb/master
Add support for `uts_mode` parameter in `Client.create_host_config`.
2018-06-29 11:20:51 -07:00
Marco Trillo 098318ad95 Add support for `uts_mode` parameter in `Client.create_host_config`.
This parameter allows to set the UTS namespace of the container, as in
the `--uts=X` Docker CLI parameter:
<https://docs.docker.com/engine/reference/run/#uts-settings---uts>
The only allowed value, if set, is "host".

Signed-off-by: Marco Trillo <martri@arantia.com>
Signed-off-by: Diego Alvarez <dyako.developer@gmail.com>
2018-06-29 14:54:49 +02:00
Joffrey F ced86ec813 On Windows, convert paths to use forward slashes before fnmatch call
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-06-28 17:11:24 -07:00
Joffrey F 81b7d48ad6 Improved .dockerignore pattern processing to better match Docker CLI behavior
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-06-28 17:11:24 -07:00
Joffrey F 8c35eee0fb Fix support for legacy .dockercfg auth config format
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-06-27 17:04:32 -07:00
Joffrey F f1189bfb4b Allow passing of env overrides to credstore through APIClient ctor
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-06-08 15:43:58 -07:00
Joffrey F dbe52dcb7d Fix socket reading function for TCP (non-HTTPS) connections on Windows
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-06-06 17:53:50 -07:00
Joffrey F 9709dd454b Add ignore_removed param to containers.list() to control whether to
raise or ignore NotFound

Signed-off-by: Joffrey F <joffrey@docker.com>
2018-04-25 17:18:26 -07:00
Joffrey F da028d88a2 Total timeout should be HTTP timeout + operation timeout
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-04-25 15:31:26 -07:00
Matthieu Nottale cef9940ed3 stop(), restart(): Adjust request timeout.
Signed-off-by: Matthieu Nottale <matthieu.nottale@docker.com>
2018-04-25 15:31:26 -07:00
Joffrey F 7a28cad58e Don't descend into symlinks when building context tar
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-03-21 14:20:41 +01:00
Joffrey F 33f1ca9a48 Use same split rules for Dockerfile as other include/exclude patterns
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-03-14 14:11:42 -07:00
Joffrey F 9b8e022fa1
Merge pull request #1928 from mnottale/fix-spurious-resolution-macos-slowdown
Workaround requests resolving our unix socket URL on macosx.
2018-02-27 08:58:59 -08:00
Joffrey F fe966764ef
Merge pull request #1927 from mefyl/master
Add test for "/.." patterns in .dockerignore.
2018-02-26 10:53:41 -08:00
Matthieu Nottale 15c26e7057 Workaround requests resolving our unix socket URL on macosx.
Signed-off-by: Matthieu Nottale <matthieu.nottale@docker.com>
2018-02-26 14:47:26 +01:00
mefyl 4295919103
Add test for "/.." patterns in .dockerignore.
Signed-off-by: mefyl <quentin.hocquet@docker.com>
2018-02-26 12:59:46 +01:00
Joffrey F 9a4cc53c52 Merge branch 'release' into 3.1.0-release
Signed-off-by: Joffrey F <joffrey@docker.com>

Conflicts:
	docker/version.py
	tests/unit/api_test.py
	tests/unit/utils_test.py
2018-02-22 13:36:15 -08:00
mefyl bb3ad64060
Fix .dockerignore: accept wildcard in inclusion pattern, honor last line precedence.
Signed-off-by: mefyl <quentin.hocquet@docker.com>
2018-02-21 17:05:26 +01:00
mefyl c8f5a5ad40
Fix dockerignore handling of absolute path exceptions.
Signed-off-by: mefyl <quentin.hocquet@docker.com>
2018-02-21 17:05:26 +01:00
mefyl 181c1c8eb9 Revert "Correctly support absolute paths in .dockerignore"
This reverts commit 34d50483e2.

Signed-off-by: mefyl <quentin.hocquet@docker.com>
2018-02-19 13:37:35 +01:00
Joffrey F 4c708f568c Fix test_login flakes
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-02-14 16:22:33 -08:00
Joffrey F 08803743c5
Merge pull request #1906 from docker/1352-data_stream_control
Add chunk_size parameter to data downloading methods
2018-02-14 16:22:02 -08:00
Joffrey F 581ccc9f7e Add chunk_size parameter to data downloading methods (export, get_archive, save)
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-02-14 16:07:19 -08:00
Joffrey F 3498b63fb0 Fix authconfig resolution when credStore is used combined with login()
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-02-13 18:55:56 -08:00
Joffrey F 34d50483e2 Correctly support absolute paths in .dockerignore
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-02-12 14:59:41 -08:00
Joffrey F 6de7bab22f Rewrite access check in create_archive with EAFP
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-02-05 13:38:32 -08:00
Joffrey F 539b321bd1 Add login data to the right subdict in auth_configs
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-02-05 13:38:19 -08:00
Joffrey F a60011ca3a Add workaround for bpo-32713
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-02-05 13:38:03 -08:00
Joffrey F 7c19772eb6
Merge pull request #1901 from docker/1899-create_archive_fix
Rewrite access check in create_archive with EAFP
2018-02-05 13:37:01 -08:00
Joffrey F 58639aecfa Rewrite access check in create_archive with EAFP
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-02-05 13:11:19 -08:00
Joffrey F 855b71eabe
Merge pull request #1896 from docker/1895-login-auths
Add login data to the right subdict in auth_configs
2018-02-02 10:29:33 -08:00
Joffrey F 04bf470f6e Add workaround for bpo-32713
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-02-01 16:51:36 -08:00
Joffrey F 83d185d695 Add login data to the right subdict in auth_configs
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-02-01 16:02:09 -08:00
Joffrey F 7fabcdaa4c Update wait to always return a dict
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-01-31 16:52:26 -08:00
Joffrey F ea44212969
Merge pull request #1888 from docker/1884-create_volumes_win32
Correctly parse volumes with Windows paths
2018-01-31 15:25:49 -08:00
Joffrey F 209ae2423d Correctly parse volumes with Windows paths
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-01-31 15:12:15 -08:00
Joffrey F df8422d079 Refuse API version < 1.21 ; Remove associated code paths
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-01-31 14:42:01 -08:00
Joffrey F 5347c168d0 Add support for publish mode for endpointspec ports
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-01-31 12:42:11 -08:00
Joffrey F ccbde11c8d Improve separation between auth_configs and general_configs
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-01-30 18:42:38 -08:00
Fumiaki MATSUSHIMA dd858648a0 Use config.json for detachKeys
Signed-off-by: Fumiaki Matsushima <mtsmfm@gmail.com>
2018-01-30 17:16:23 -08:00
Joffrey F 17aa31456d Properly support pulling all tags in DockerClient.images.pull
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-01-30 16:47:04 -08:00
Joffrey F a05922e949
Merge pull request #1881 from docker/pytest-asserts
Use pytest asserts
2018-01-30 16:29:07 -08:00
Joffrey F 3422211309 Use pytest asserts
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-01-30 14:26:24 -08:00
Joffrey F 4e34300379 Do not break when archiving broken symlinks
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-01-29 18:27:12 -08:00
Joffrey F 6e6eaece81 Return tuple instead of dict in exec_run
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-01-26 14:21:23 -08:00
Joffrey F b0cc4b5520 Merge branch 'add_exit_code_to_exec_run' of https://github.com/hnq90/docker-py into hnq90-add_exit_code_to_exec_run 2018-01-26 14:13:15 -08:00
Joffrey F abd60aedc7 Bump default API version to 1.35
Add ContainerSpec.isolation support
Add until support in logs
Add condition support in wait
Add workdir support in exec_create

Signed-off-by: Joffrey F <joffrey@docker.com>
2018-01-26 13:56:01 -08:00
Joffrey F f95b958429 Add support for experimental platform flag in build and pull
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-01-23 16:59:09 -08:00
Joffrey F ac68a36a89
Merge pull request #1727 from mbelang/join-swarn-default-listen-address
Add join_swarm default listen address
2017-12-18 17:16:41 -08:00
Joffrey F 5736436966
Merge pull request #1828 from pkit/fix_error_from_httpex
fixes create_api_error_from_http_exception()
2017-12-18 14:26:47 -08:00
Constantine Peresypkin b20f800db6 fixes create_api_error_from_http_exception()
`create_api_error_from_http_exception()` is never tested in the original code
and will fail miserably when fed with empty `HTTPError` object
see fixes in requests for this behaviour: https://github.com/requests/requests/pull/3179

Signed-off-by: Constantine Peresypkin <pconstantine@gmail.com>
2017-12-18 17:15:48 +02:00