From a73720c103da165823c7eeee4812210f7f3bc774 Mon Sep 17 00:00:00 2001 From: Ricky White Date: Thu, 5 Aug 2021 13:28:32 -0400 Subject: [PATCH] Updated the tss lookup plugin to reflect breaking changes introduced in the underpinning SDK (#3139) * Updated the plugin to reflect breaking changes introduced in the underlying SDK v1.0.0 update. * Added Changelog fragment * Updates based on feedback/review * Added newline to pass CI * Added whitepace for linter * Update changelogs/fragments/3139-tss-lookup-plugin-update-to-make-compatible-with-sdk-v1.yml Co-authored-by: Ajpantuso Co-authored-by: Ajpantuso --- ...-update-to-make-compatible-with-sdk-v1.yml | 3 +++ plugins/lookup/tss.py | 20 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/3139-tss-lookup-plugin-update-to-make-compatible-with-sdk-v1.yml diff --git a/changelogs/fragments/3139-tss-lookup-plugin-update-to-make-compatible-with-sdk-v1.yml b/changelogs/fragments/3139-tss-lookup-plugin-update-to-make-compatible-with-sdk-v1.yml new file mode 100644 index 0000000000..f06fa68ce0 --- /dev/null +++ b/changelogs/fragments/3139-tss-lookup-plugin-update-to-make-compatible-with-sdk-v1.yml @@ -0,0 +1,3 @@ +bugfixes: + - tss lookup plugin - fixed incompatibility with ``python-tss-sdk`` version 1.0.0 + (https://github.com/ansible-collections/community.general/issues/3057, https://github.com/ansible-collections/community.general/pull/3139). diff --git a/plugins/lookup/tss.py b/plugins/lookup/tss.py index b7b7cd85e0..d5e6ea6dcd 100644 --- a/plugins/lookup/tss.py +++ b/plugins/lookup/tss.py @@ -112,16 +112,17 @@ EXAMPLES = r""" - ansible.builtin.debug: msg: the password is {{ secret_password }} """ - +from distutils.version import LooseVersion from ansible.errors import AnsibleError, AnsibleOptionsError sdk_is_missing = False try: + from thycotic import __version__ as sdk_version from thycotic.secrets.server import ( SecretServer, - SecretServerAccessError, SecretServerError, + PasswordGrantAuthorizer, ) except ImportError: sdk_is_missing = True @@ -136,7 +137,20 @@ display = Display() class LookupModule(LookupBase): @staticmethod def Client(server_parameters): - return SecretServer(**server_parameters) + + if LooseVersion(sdk_version) < LooseVersion('1.0.0'): + return SecretServer(**server_parameters) + else: + authorizer = PasswordGrantAuthorizer( + server_parameters["base_url"], + server_parameters["username"], + server_parameters["password"], + server_parameters["token_path_uri"], + ) + + return SecretServer( + server_parameters["base_url"], authorizer, server_parameters["api_path_uri"] + ) def run(self, terms, variables, **kwargs): if sdk_is_missing: