Repository: ansible-collections/community.general

Issue:
community.general.tss Lookup Plugin throws exception when using python-tss-sdk 1.0.0.
### Summary

python-tss-sdk introduced a breaking change by removing the [SecretServerAccessError](https://github.com/thycotic/python-tss-sdk/blob/9727ffea263fd29ed7cb0a64325a95a735162365/thycotic/secrets/server.py#L106) class.

It appears to have been replaced with the [SecretServerClientError](https://github.com/thycotic/python-tss-sdk/blob/6969b8ee2161cab7c72ed01e1b7e6f1cdb2fd7f2/thycotic/secrets/server.py#L105) and [SecretServerServiceError](https://github.com/thycotic/python-tss-sdk/blob/6969b8ee2161cab7c72ed01e1b7e6f1cdb2fd7f2/thycotic/secrets/server.py#L109) classes.

An exception occurs while importing `SecretServerAccessError`

https://github.com/ansible-collections/community.general/blob/9631de49396ab0706df4a38c1cbab6a779a125dc/plugins/lookup/tss.py#L123

Resulting in the following AnsibleError being thrown.

https://github.com/ansible-collections/community.general/blob/9631de49396ab0706df4a38c1cbab6a779a125dc/plugins/lookup/tss.py#L143

### Issue Type

Bug Report

### Component Name

- plugins/lookup/tss.py

### Ansible Version

```console (paste below)
root@61dbe3fe35eb:/ansible# ansible --version
ansible 2.10.12
  config file = /ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Jun  2 2021, 10:49:15) [GCC 9.4.0]
```


### Configuration

```console (paste below)
root@61dbe3fe35eb:/ansible# ansible-config dump --only-changed
ANSIBLE_PIPELINING(/ansible/ansible.cfg) = True
DEFAULT_BECOME(/ansible/ansible.cfg) = True
DEFAULT_CALLBACK_PLUGIN_PATH(/ansible/ansible.cfg) = ['/etc/ansible/plugins/callback_plugins']
DEFAULT_FORKS(/ansible/ansible.cfg) = 25
DEFAULT_INVENTORY_PLUGIN_PATH(/ansible/ansible.cfg) = ['/ansible/inventory_plugins']
DEFAULT_LOAD_CALLBACK_PLUGINS(/ansible/ansible.cfg) = True
DEFAULT_MANAGED_STR(/ansible/ansible.cfg) = Ansible managed. Do NOT edit manually.
DEFAULT_ROLES_PATH(/ansible/ansible.cfg) = ['/ansible/roles']
HOST_KEY_CHECKING(/ansible/ansible.cfg) = False
HOST_PATTERN_MISMATCH(/ansible/ansible.cfg) = ignore
INVENTORY_ENABLED(/ansible/ansible.cfg) = ['pl_infoblox', 'pl_infrastructure', 'auto', 'yaml']
INVENTORY_UNPARSED_IS_FAILED(/ansible/ansible.cfg) = True
RETRY_FILES_ENABLED(/ansible/ansible.cfg) = False
```


### OS / Environment

Ubuntu 20.04

### Steps to Reproduce

requirements.txt
```text
ansible == 2.10.0
python-tss-sdk == 1.0.0
```

requirements.yml
```yaml
collections:
  - name: community.general
    version: 2.1.1
```

playbook.yml
```yaml
- hosts: localhost
  connection: local
  vars:
    thycotic_host: example.secretservercloud.com
    thycotic_username: "{{ tss_user }}"
    thycotic_password: "{{ tss_password }}"
    thycotic_base_uri: https://{{ thycotic_host }}
    secret_id: 1655
    secret: "{{ lookup('community.general.tss',
                                               registration_authority_secret_id,
                                               base_url=thycotic_base_uri,
                                               username=thycotic_username,
                                               password=thycotic_password)
                               }}"
     secret_dict: "{{ registration_authority_secret['items']
                                        | items2dict(key_name='slug', value_name='itemValue')
                                    }}"
    secret_value: "{{ secret_dict['password'] }}" 
  tasks:
  - name: display secret value
    ansible.builtin.debug:
      var: secret_value
```

command
```console
pip install -r requirments.txt
ansible-galaxy install -r requirements.yml
ansible-playbook -i localhost, playbook.yml
```


### Expected Results

I expect the password value to be displayed in an ansible debug statement.

### Actual Results

I get the following exception
```console (paste below)
Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while running the lookup plugin 'community.general.tss'. Error was a <class 'ansible.errors.AnsibleError'>, original message: python-tss-sdk must be installed to use this plugin
```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`lib/ansible/plugins/lookup`](https://github.com/ansible-collections/community.general/blob/master/lib/ansible/plugins/lookup)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
Files identified in the description:
* [`plugins/lookup/tss.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/lookup/tss.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @amigus
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
` SecretServerAccessError` is imported but unused so removing the import should safely fix this.
Pinning it at 0.0.6 will fix the problem in the short term, however, we are working to update this code to use 1.0.0 and expect it to be done in a couple of days.

Resolving patch:
diff --git a/plugins/lookup/tss.py b/plugins/lookup/tss.py
--- a/plugins/lookup/tss.py
+++ b/plugins/lookup/tss.py
@@ -112,16 +112,17 @@
       - 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 @@
 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:


Test patch: