Skip to content

Commit

Permalink
Merge pull request #2852 from Phat3/feat/add_templating_parameter_doc…
Browse files Browse the repository at this point in the history
…ker_config

Add the possibility to set a templating driver when creating a new Docker config
  • Loading branch information
aiordache authored Oct 7, 2021
2 parents b825867 + aae6be0 commit df59f53
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions docker/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@

class ConfigApiMixin:
@utils.minimum_version('1.30')
def create_config(self, name, data, labels=None):
def create_config(self, name, data, labels=None, templating=None):
"""
Create a config
Args:
name (string): Name of the config
data (bytes): Config data to be stored
labels (dict): A mapping of labels to assign to the config
templating (dict): dictionary containing the name of the
templating driver to be used expressed as
{ name: <templating_driver_name>}
Returns (dict): ID of the newly created config
"""
Expand All @@ -24,7 +27,8 @@ def create_config(self, name, data, labels=None):
body = {
'Data': data,
'Name': name,
'Labels': labels
'Labels': labels,
'Templating': templating
}

url = self._url('/configs/create')
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/api_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,16 @@ def test_list_configs(self):
data = self.client.configs(filters={'name': ['favorite_character']})
assert len(data) == 1
assert data[0]['ID'] == config_id['ID']

@requires_api_version('1.37')
def test_create_config_with_templating(self):
config_id = self.client.create_config(
'favorite_character', 'sakuya izayoi',
templating={ 'name': 'golang'}
)
self.tmp_configs.append(config_id)
assert 'ID' in config_id
data = self.client.inspect_config(config_id)
assert data['Spec']['Name'] == 'favorite_character'
assert 'Templating' in data['Spec']
assert data['Spec']['Templating']['Name'] == 'golang'

0 comments on commit df59f53

Please sign in to comment.