Skip to content

Commit f42a81d

Browse files
committed
Add the possibility to set a templating driver when creating a new Docker config
Signed-off-by: Sebastiano Mariani <[email protected]>
1 parent 96c1272 commit f42a81d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

docker/api/config.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66

77

88
class ConfigApiMixin(object):
9+
# TODO: The templating field is only available starting from API v 1.37
910
@utils.minimum_version('1.30')
10-
def create_config(self, name, data, labels=None):
11+
def create_config(self, name, data, labels=None, templating=None):
1112
"""
1213
Create a config
1314
1415
Args:
1516
name (string): Name of the config
1617
data (bytes): Config data to be stored
1718
labels (dict): A mapping of labels to assign to the config
19+
templating (dict): dictionary containing the name of the
20+
templating driver to be used expressed as
21+
{ name: <templating_driver_name>}
1822
1923
Returns (dict): ID of the newly created config
2024
"""
@@ -27,7 +31,8 @@ def create_config(self, name, data, labels=None):
2731
body = {
2832
'Data': data,
2933
'Name': name,
30-
'Labels': labels
34+
'Labels': labels,
35+
'Templating': templating
3136
}
3237

3338
url = self._url('/configs/create')

tests/integration/api_config_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,16 @@ def test_list_configs(self):
7070
data = self.client.configs(filters={'name': ['favorite_character']})
7171
assert len(data) == 1
7272
assert data[0]['ID'] == config_id['ID']
73+
74+
@requires_api_version('1.37')
75+
def test_create_config_with_templating(self):
76+
config_id = self.client.create_config(
77+
'favorite_character', 'sakuya izayoi',
78+
templating={ 'name': 'golang'}
79+
)
80+
self.tmp_configs.append(config_id)
81+
assert 'ID' in config_id
82+
data = self.client.inspect_config(config_id)
83+
assert data['Spec']['Name'] == 'favorite_character'
84+
assert 'Templating' in data['Spec']
85+
assert data['Spec']['Templating']['Name'] == 'golang'

0 commit comments

Comments
 (0)