From 6ac410b3f617074bb7af86050d8adfa4d495a3e6 Mon Sep 17 00:00:00 2001 From: Ricky White Date: Wed, 18 Aug 2021 03:26:44 -0400 Subject: [PATCH] tss: added fix for bug report in issue #3192 (#3199) * Added fix for bug report in issue #3192 * Added changelog fragment * Typo fix * Added Importerror to exception - as req by linters * Moved the conditional import statement to try/except block --- ...gin-bugfix-for-backwards-compatibility.yml | 3 +++ plugins/lookup/tss.py | 26 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/3199-tss-lookup-plugin-bugfix-for-backwards-compatibility.yml diff --git a/changelogs/fragments/3199-tss-lookup-plugin-bugfix-for-backwards-compatibility.yml b/changelogs/fragments/3199-tss-lookup-plugin-bugfix-for-backwards-compatibility.yml new file mode 100644 index 0000000000..3909286487 --- /dev/null +++ b/changelogs/fragments/3199-tss-lookup-plugin-bugfix-for-backwards-compatibility.yml @@ -0,0 +1,3 @@ +bugfixes: + - tss lookup plugin - fixed backwards compatibility issue with ``python-tss-sdk`` version <=0.0.5 + (https://github.com/ansible-collections/community.general/issues/3192, https://github.com/ansible-collections/community.general/pull/3199). diff --git a/plugins/lookup/tss.py b/plugins/lookup/tss.py index d5e6ea6dcd..65f8b114f6 100644 --- a/plugins/lookup/tss.py +++ b/plugins/lookup/tss.py @@ -118,15 +118,23 @@ from ansible.errors import AnsibleError, AnsibleOptionsError sdk_is_missing = False try: - from thycotic import __version__ as sdk_version - from thycotic.secrets.server import ( - SecretServer, - SecretServerError, - PasswordGrantAuthorizer, - ) + from thycotic.secrets.server import SecretServer, SecretServerError except ImportError: sdk_is_missing = True +# Added for backwards compatability - See issue #3192 +# https://github.com/ansible-collections/community.general/issues/3192 +try: + from thycotic import __version__ as sdk_version +except ImportError: + sdk_version = "0.0.5" + +try: + from thycotic.secrets.server import PasswordGrantAuthorizer + sdK_version_below_v1 = False +except ImportError: + sdK_version_below_v1 = True + from ansible.utils.display import Display from ansible.plugins.lookup import LookupBase @@ -138,9 +146,13 @@ class LookupModule(LookupBase): @staticmethod def Client(server_parameters): - if LooseVersion(sdk_version) < LooseVersion('1.0.0'): + if LooseVersion(sdk_version) < LooseVersion('1.0.0') or sdK_version_below_v1: return SecretServer(**server_parameters) else: + # The Password Authorizer became available in v1.0.0 and beyond. + # Import only if sdk_version requires it. + # from thycotic.secrets.server import PasswordGrantAuthorizer + authorizer = PasswordGrantAuthorizer( server_parameters["base_url"], server_parameters["username"],