Skip to content

DCNM_REST: Add support for Encoding Type 'x-www-form-urlencoded' #462

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

Closed
wants to merge 3 commits into from

Conversation

AKDRG
Copy link
Collaborator

@AKDRG AKDRG commented Jul 4, 2025

Issue:
#366

Fix:
Add support for body-data encoding type 'x-www-form-urlencoded', through attribute "encoding" in the dcnm_rest module. Available options : json, text and urlencoded. Without specifying the attribute, it takes the default value of "json".

Example:
tasks:
- name: Set Default Credentials
cisco.dcnm.dcnm_rest:
method: POST
path: 'https://192.168.1.2/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/lanConfig/saveRobotCredentials'
data: '{"password": "password","confirmPassword": "password","isRobot":true,"username": "admin"}'
encoding: urlencoded
register: result

@AKDRG AKDRG requested a review from mikewiebe July 4, 2025 16:03
headers = {}
auth_token = dcnm_login_retrieve_token(module)
headers.update(auth_token)
headers.update({'Content-Type': 'application/x-www-form-urlencoded'})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not need to login directly here in this module. Can you explore handling this as another option like we do for json and text in our connection plugin?

See:

self.headers = {"Content-Type": "application/json"}

@mikewiebe mikewiebe self-assigned this Jul 14, 2025
@@ -101,6 +106,7 @@ def main():
method=dict(required=True, choices=["GET", "POST", "PUT", "DELETE"]),
path=dict(required=True, type="str"),
data=dict(type="raw", required=False, default=None, aliases=["json_data"]),
encoding=dict(type="str", default="json", choices=["json", "text", "urlencoded"]),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer we follow the same method we used for text and not require the user to pass in the encoding type. Do we get back a python exception for urlencoded that we can use similar to text?

def dcnm_post_request(path, hdrs, verify_flag, upload_files):
def dcnm_post_request(path, hdrs, **kwargs):
# Keyword Arguments
verify_flag = kwargs.get("verify")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, but why was this changed to use kwargs? Mainly readability or was it a functional problem you were fixing here?

@@ -636,7 +636,7 @@ def dcnm_image_upload_handle_local_file_transfer(self, elem):
if file_path:
upload_files = {"file": open(file_path, "rb")}

resp = dcnm_post_request(path, headers, False, upload_files)
resp = dcnm_post_request(path, headers, verify=False, files=upload_files)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test this fix with the dcnm_image_upload module?

@AKDRG AKDRG closed this Aug 6, 2025
@AKDRG
Copy link
Collaborator Author

AKDRG commented Aug 6, 2025

This PR is discarded due to fix overhaul.

Issue handled through new PR: #490

Thanks,
Akshay

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

Successfully merging this pull request may close these issues.

2 participants