|
2 | 2 |
|
3 | 3 | from .. import errors
|
4 | 4 | from ..constants import IS_WINDOWS_PLATFORM
|
5 |
| -from ..utils import format_environment, split_command |
| 5 | +from ..utils import check_resource, format_environment, split_command |
6 | 6 |
|
7 | 7 |
|
8 | 8 | class TaskTemplate(dict):
|
@@ -79,9 +79,12 @@ class ContainerSpec(dict):
|
79 | 79 | :py:class:`~docker.types.Mount` class for details.
|
80 | 80 | stop_grace_period (int): Amount of time to wait for the container to
|
81 | 81 | terminate before forcefully killing it.
|
| 82 | + secrets (list of py:class:`SecretReference`): List of secrets to be |
| 83 | + made available inside the containers. |
82 | 84 | """
|
83 | 85 | def __init__(self, image, command=None, args=None, env=None, workdir=None,
|
84 |
| - user=None, labels=None, mounts=None, stop_grace_period=None): |
| 86 | + user=None, labels=None, mounts=None, stop_grace_period=None, |
| 87 | + secrets=None): |
85 | 88 | self['Image'] = image
|
86 | 89 |
|
87 | 90 | if isinstance(command, six.string_types):
|
@@ -109,6 +112,11 @@ def __init__(self, image, command=None, args=None, env=None, workdir=None,
|
109 | 112 | if stop_grace_period is not None:
|
110 | 113 | self['StopGracePeriod'] = stop_grace_period
|
111 | 114 |
|
| 115 | + if secrets is not None: |
| 116 | + if not isinstance(secrets, list): |
| 117 | + raise TypeError('secrets must be a list') |
| 118 | + self['Secrets'] = secrets |
| 119 | + |
112 | 120 |
|
113 | 121 | class Mount(dict):
|
114 | 122 | """
|
@@ -410,3 +418,31 @@ def replicas(self):
|
410 | 418 | if self.mode != 'replicated':
|
411 | 419 | return None
|
412 | 420 | return self['replicated'].get('Replicas')
|
| 421 | + |
| 422 | + |
| 423 | +class SecretReference(dict): |
| 424 | + """ |
| 425 | + Secret reference to be used as part of a :py:class:`ContainerSpec`. |
| 426 | + Describes how a secret is made accessible inside the service's |
| 427 | + containers. |
| 428 | +
|
| 429 | + Args: |
| 430 | + secret_id (string): Secret's ID |
| 431 | + secret_name (string): Secret's name as defined at its creation. |
| 432 | + filename (string): Name of the file containing the secret. Defaults |
| 433 | + to the secret's name if not specified. |
| 434 | + uid (string): UID of the secret file's owner. Default: 0 |
| 435 | + gid (string): GID of the secret file's group. Default: 0 |
| 436 | + mode (int): File access mode inside the container. Default: 0o444 |
| 437 | + """ |
| 438 | + @check_resource |
| 439 | + def __init__(self, secret_id, secret_name, filename=None, uid=None, |
| 440 | + gid=None, mode=0o444): |
| 441 | + self['SecretName'] = secret_name |
| 442 | + self['SecretID'] = secret_id |
| 443 | + self['File'] = { |
| 444 | + 'Name': filename or secret_name, |
| 445 | + 'UID': uid or '0', |
| 446 | + 'GID': gid or '0', |
| 447 | + 'Mode': mode |
| 448 | + } |
0 commit comments