From f42a81dca2aa7a152677ee1a7d5e14248e9a6e76 Mon Sep 17 00:00:00 2001 From: Sebastiano Mariani Date: Thu, 3 Jun 2021 15:51:52 -0700 Subject: [PATCH] Add the possibility to set a templating driver when creating a new Docker config Signed-off-by: Sebastiano Mariani --- docker/api/config.py | 9 +++++++-- tests/integration/api_config_test.py | 13 +++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docker/api/config.py b/docker/api/config.py index 93e5168f6..303be682a 100644 --- a/docker/api/config.py +++ b/docker/api/config.py @@ -6,8 +6,9 @@ class ConfigApiMixin(object): + # TODO: The templating field is only available starting from API v 1.37 @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 @@ -15,6 +16,9 @@ def create_config(self, name, data, labels=None): 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: } Returns (dict): ID of the newly created config """ @@ -27,7 +31,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') diff --git a/tests/integration/api_config_test.py b/tests/integration/api_config_test.py index 0ffd7675c..7b7d9c186 100644 --- a/tests/integration/api_config_test.py +++ b/tests/integration/api_config_test.py @@ -70,3 +70,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'