cisco-en-programmability / dnacentersdk

Cisco DNA Center Python SDK
https://dnacentersdk.readthedocs.io/en/latest/
MIT License
70 stars 33 forks source link

Issue in adding/updating headers while configuring Webhook Destination and ambiguity in Args description for headers in Create/Update Webhook Destination API #150

Closed Abhishek-121 closed 4 months ago

Abhishek-121 commented 5 months ago

Prerequisites

Describe the bug While working on adding headers during the creation/updation of Webhook Destination, I observed that in the DNAC --> Platform --> Developer Toolkit.

API's - Create Rest Webhook Destination/ Update Rest Webhook Destination are accepting headers as a list of dictionary in the payload and able to create/update with mentioned payload.

Dnacentersdk version - 2.9.0, API Used - '/dna/intent/api/v1/event/webhook'

But when I try same by giving the input payload in the playbook as list of dictionary using the below playbook

image

I got this error -

"msg": "Error while Adding the Webhook destination with the name 'webhook Iac2' in Cisco Catalyst Center: We were expecting to receive an instance of one of the following types: 'dict'or 'None'; but instead we received [{'name': 'X-Auth-Token', 'value': 'qejfkq;ejwf;kqjrfkjewqkfjdekwlqjfdklqwe;j', 'defaultValue': None, 'encrypt': None}] which is a 'list'.",

And also when I try to change by passing headers as a dictionary instead of list of dictionary using the below input in playbook -

image

I got this error -

"errors": ["Create WebhookConfig failed due to Parsing WebhookConfig failed Cannot deserialize instance of java.util.ArrayList<com.cisco.dna.event.common.models.flow.Parameter> out of START_OBJECT token\n at [Source: (String)\"{\"name\": \"webhook Iac2\", \"description\": \"webhhok description for iac2.0\", \"url\": [https://10.195.227.14/dna\](https://10.195.227.14/dna/), \"method\": \"POST\", \"trustCert\": false, \"headers\": {\"name\": \"X-Auth-Token\", \"value\": \"qejfkq;ejwf;kqjrfkjewqkfjdekwlqjfdklqwe;j\", \"default_value\": null, \"encrypt\": null}, \"isProxyRoute\": true}\"; line: 1, column: 160] (through reference chain: com.cisco.dna.event.common.models.event.artifact.WebhookConfig[\"headers\"])"]

Console_error

Upon looking more into the Dnacentersdk version - 2.9.0, I got to know that there is ambiguity in both Create/Update Webhook Destination as there in arguments it's mentioned that headers can be list of dictionaries or it can be dictionary only.

sdk_create_webhook sdk_update_webhook

Also in the Args description of both SDK API we are supporting both types that is headers as dict and headers as list.

Expected behavior

As per the Cisco Catalyst GUI we can add only one type of header and if we are try to add other it will give the error -

    **Headers must have a single form of authentication**

image

Screenshots

create_webhook update_webhook image

Environment (please complete the following information):

bvargasre commented 5 months ago

Hello @Abhishek-121, it was a bug, currently our sdk supports custom headers for the request, what happens is that here there is a headers field, causing this error because both had the same name. Upload a new version 2.9.1, try with that and tell me if it worked or not.

Abhishek-121 commented 5 months ago

Hi @bvargasre , with the new sdk version 2.9.1. I am able to execute the playbook with headers but the problem is headers are still not reflected in the DNAC GUI as a result the problem still exists to add/update headers while configuring webhook destination.

webhook_added no_headers Screenshot 2024-05-08 at 2 17 26 PM
bvargasre commented 4 months ago

Hi @Abhishek-121, could you activate the debug in ansible with dnac_debug: True or export DNAC_DEBUG=True and send me the whole output Also to clarify headers is a list

Abhishek-121 commented 4 months ago

logs_output.log

Also, from user we taking input as headers as dict only but in our module code before invoking 'add_webhook_destination' API in the payload we convert headers --> customHeaders.

You can check the payload by filtering the given string - " Payload for creating webhook destination"

bvargasre commented 4 months ago

Hi @Abhishek-121 , in the log you sent me I don't see debug enabled. What I need is that you activate the debug to be able to observe the api calls. The debug in ansible can be activated in two ways:


Finally if you can pass me the output of those logs together with the playbook used for the test, so I can check the behavior and detect if the problem is the playbook or ansible or sdk. The same would be for issue #151. I remain available for any further assistance.

Abhishek-121 commented 4 months ago

Hi @bvargasre , able to add headers via Ansible and it appear on the GUI as well. Instead of customHeader I need to pass payload in the headers parameters as a list only. You can close the issue. Thanks.