Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

application/problem+json Content-Type not handled #12

Open
akiuni opened this issue Feb 14, 2024 · 1 comment
Open

application/problem+json Content-Type not handled #12

akiuni opened this issue Feb 14, 2024 · 1 comment

Comments

@akiuni
Copy link

akiuni commented Feb 14, 2024

Hello

The endpoint may return Content-type "'application/problem+json'" in case of bad authentication.

if 'Content-Type' in response.headers and response.headers['Content-Type'] == 'application/json':

Proposed quick fix could be :

        if 'Content-Type' in response.headers and response.headers['Content-Type'] in ['application/json', 'application/problem+json']:
@akiuni
Copy link
Author

akiuni commented May 23, 2024

I've had to face this bug again. Is it still not resolved ?

In addition, the code underneath searches for attributes of the dict which can be found inside the string: ( if 'message' in content:).

This leads to the following stacktrace :

The full traceback is:
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/ansible/executor/task_executor.py", line 165, in run
    res = self._execute()
          ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/ansible/executor/task_executor.py", line 637, in _execute
    result = self._handler.run(task_vars=vars_copy)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.ansible/collections/ansible_collections/evertrust/horizon/plugins/action/horizon_renew.py", line 27, in run
    response = client.renew(**content)
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.ansible/collections/ansible_collections/evertrust/horizon/plugins/module_utils/horizon.py", line 177, in renew
    return self.post(self.REQUEST_SUBMIT_URL, json)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.ansible/collections/ansible_collections/evertrust/horizon/plugins/module_utils/horizon.py", line 423, in post
    return self.send('POST', path, json=json)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.ansible/collections/ansible_collections/evertrust/horizon/plugins/module_utils/horizon.py", line 458, in send
    error_message = content['message']
                    ~~~~~~~^^^^^^^^^^^
TypeError: string indices must be integers, not 'str'
fatal: [dsi-aah-lp01.interne.ugap.fr -> localhost]: FAILED! => {
    "msg": "Unexpected failure during module execution: string indices must be integers, not 'str'",
    "stdout": ""
}

To give some use cases:

        print(f"DEBUG: {type(content)}")
        if 'message' in content:
            print(f"DEBUG: content: {content}")
            error_message = content['message']

Returns:

DEBUG: <class 'str'>
DEBUG: content: {"error":"SEC-AUTH-002","message":"Invalid credentials or principal does not exist","title":"Invalid credentials or principal does not exist","status":401}
DEBUG: content: {"error":"WEBRA-RENEW-001","message":"Invalid request","title":"Invalid request","detail":"Certificate is not yet in its renewal period (period starts: '2026-04-22T08:33:13.000Z')","status":400}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant