From 2adb0d8c3080916e11ed2cdd781898d9b799de78 Mon Sep 17 00:00:00 2001 From: Felipe Ruhland Date: Thu, 28 Nov 2019 14:32:31 -0300 Subject: [PATCH] Fix secrets repr issue - Change id_attribute to Id - add new property id - add name fallback Fixes #2025 Signed-off-by: Felipe Ruhland --- docker/models/secrets.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docker/models/secrets.py b/docker/models/secrets.py index ca11edeb08..5c17faa17e 100644 --- a/docker/models/secrets.py +++ b/docker/models/secrets.py @@ -4,14 +4,22 @@ class Secret(Model): """A secret.""" - id_attribute = 'ID' + id_attribute = 'Id' def __repr__(self): return "<%s: '%s'>" % (self.__class__.__name__, self.name) @property def name(self): - return self.attrs['Spec']['Name'] + """ + Create secret only returns Id field, so if the name field is not + present, it will show id value instead. + Issue #2025 + """ + if self.attrs.get('Spec', {}).get('Name'): + return self.attrs['Spec']['Name'] + + return self.id def remove(self): """