-
Notifications
You must be signed in to change notification settings - Fork 46
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
Conversation
headers = {} | ||
auth_token = dcnm_login_retrieve_token(module) | ||
headers.update(auth_token) | ||
headers.update({'Content-Type': 'application/x-www-form-urlencoded'}) |
There was a problem hiding this comment.
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:
ansible-dcnm/plugins/httpapi/dcnm.py
Line 59 in 238c026
self.headers = {"Content-Type": "application/json"} |
@@ -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"]), |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
This PR is discarded due to fix overhaul. Issue handled through new PR: #490 Thanks, |
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