mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-09-30 13:33:21 -07:00
Meraki util - Add method to encode parameters in the URL (#49015)
* Add new method to encode parameters in the URL - I'm not really encoding, I'm sure this is broke - There maybe an Ansible native way to do this * Fix whitepace * Added urlencode support - Relies on urllib module - Fixed string delimiter * Enable URL params - construct_params_list() creates a list of parameters to encode - encode_url_params() does encoding in a simple manner * Added proper methods for urlencoding * Remove duplicate functions * Remove blank line for PEP8
This commit is contained in:
parent
76dba7aa4f
commit
91237fa414
1 changed files with 24 additions and 2 deletions
|
@ -32,6 +32,7 @@
|
||||||
import os
|
import os
|
||||||
from ansible.module_utils.basic import AnsibleModule, json, env_fallback
|
from ansible.module_utils.basic import AnsibleModule, json, env_fallback
|
||||||
from ansible.module_utils.urls import fetch_url
|
from ansible.module_utils.urls import fetch_url
|
||||||
|
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||||
from ansible.module_utils._text import to_native, to_bytes, to_text
|
from ansible.module_utils._text import to_native, to_bytes, to_text
|
||||||
|
|
||||||
|
|
||||||
|
@ -249,9 +250,28 @@ class MerakiModule(object):
|
||||||
return template['id']
|
return template['id']
|
||||||
self.fail_json(msg='No configuration template named {0} found'.format(name))
|
self.fail_json(msg='No configuration template named {0} found'.format(name))
|
||||||
|
|
||||||
def construct_path(self, action, function=None, org_id=None, net_id=None, org_name=None, custom=None):
|
def construct_params_list(self, keys, aliases=None):
|
||||||
"""Build a path from the URL catalog.
|
qs = {}
|
||||||
|
for key in keys:
|
||||||
|
if key in aliases:
|
||||||
|
qs[aliases[key]] = self.module.params[key]
|
||||||
|
else:
|
||||||
|
qs[key] = self.module.params[key]
|
||||||
|
return qs
|
||||||
|
|
||||||
|
def encode_url_params(self, params):
|
||||||
|
"""Encodes key value pairs for URL"""
|
||||||
|
return "?{0}".format(urlencode(params))
|
||||||
|
|
||||||
|
def construct_path(self,
|
||||||
|
action,
|
||||||
|
function=None,
|
||||||
|
org_id=None,
|
||||||
|
net_id=None,
|
||||||
|
org_name=None,
|
||||||
|
custom=None,
|
||||||
|
params=None):
|
||||||
|
"""Build a path from the URL catalog.
|
||||||
Uses function property from class for catalog lookup.
|
Uses function property from class for catalog lookup.
|
||||||
"""
|
"""
|
||||||
built_path = None
|
built_path = None
|
||||||
|
@ -265,6 +285,8 @@ class MerakiModule(object):
|
||||||
built_path = built_path.format(org_id=org_id, net_id=net_id, **custom)
|
built_path = built_path.format(org_id=org_id, net_id=net_id, **custom)
|
||||||
else:
|
else:
|
||||||
built_path = built_path.format(org_id=org_id, net_id=net_id)
|
built_path = built_path.format(org_id=org_id, net_id=net_id)
|
||||||
|
if params:
|
||||||
|
built_path += self.encode_url_params(params)
|
||||||
return built_path
|
return built_path
|
||||||
|
|
||||||
def request(self, path, method=None, payload=None):
|
def request(self, path, method=None, payload=None):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue