cyberark / ansible-modules

Ansible Modules for CyberArk Privileged Account Security Web Service SDK
MIT License
37 stars 17 forks source link

Fix urllib based on python version and add better error handling in a… #7

Closed ediz12 closed 8 months ago

ediz12 commented 3 years ago

Fix urllib based on python version and add better error handling in ansible logs

What does this PR do?

Added urllib fix that works based on the python environment you are in. urllib.quote will be used for python2 and urllib.parse.quite will be used for python3.

Added more visible error handling on what exactly was the problem in debug mode (ansible-playbook -vvv) on CyberArk. ("error_body_message" dict and error message in "msg")

New result:


fatal: [localhost]: FAILED! => {
    "changed": false,
    "error_body_message": {
        "ErrorCode": "APPAP306E",
        "ErrorMsg": "Authentication error for App ID [XXXX]. Reason: APPAP133E Failed to verify application authentication data: IP \"123.456.789.000\" is unauthorized"
    },
    "invocation": {
        "module_args": {
            "api_base_url": "TSPAM_URL",
            "app_id": "XXXX",
            "client_cert": null,
            "client_key": null,
            "connection_timeout": 30,
            "fail_request_on_password_change": false,
            "query": "Safe=safe;username=root;address=123.456.789.321",
            "query_format": "Exact",
            "reason": null,
            "state": "present",
            "validate_certs": false
        }
    },
    "msg": "Error while retrieving credential.Please validate parameters provided, and permissions for the application and provider in CyberArk.\n*** end_point=TSPAM_URL/AIMWebService/api/Accounts?AppId=XXXX&Query=Safe%3Dsafe%3Busername%3Droot%3Baddress%3D123.456.789.321&ConnectionTimeout=30&QueryFormat=Exact&FailRequestOnPasswordChange=False\n ==> HTTP Error 403: Forbidden.\nBody error message: Authentication error for App ID [XXXX]. Reason: APPAP133E Failed to verify application authentication data: IP \"123.456.789.000\" is unauthorized",
    "status_code": 403
}

What ticket does this PR close?

Resolves #[relevant GitHub issues, eg 76]

Checklists

Change log

Test coverage

Documentation