Skip to content
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

fix(api): fixed a bug when splitting the argument string #45

Merged
merged 8 commits into from
Sep 29, 2021
16 changes: 11 additions & 5 deletions plugins/modules/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
from ansible.module_utils.common.text.converters import to_native

import ssl
import shlex
import traceback

LIB_IMP_ERR = None
Expand Down Expand Up @@ -312,7 +313,7 @@ def __init__(self):
self.module.params['ca_path'],
)

self.path = self.list_remove_empty(self.module.params['path'].split(' '))
self.path = self.list_remove_empty(self.split_params(self.module.params['path']))
self.add = self.module.params['add']
self.remove = self.module.params['remove']
self.update = self.module.params['update']
Expand All @@ -321,7 +322,7 @@ def __init__(self):
self.where = None
self.query = self.module.params['query']
if self.query:
self.query = self.list_remove_empty(self.query.split(' '))
self.query = self.list_remove_empty(self.split_params(self.query))
try:
idx = self.query.index('WHERE')
self.where = self.query[idx + 1:]
Expand Down Expand Up @@ -365,6 +366,11 @@ def list_to_dic(self, ldict):
dict[p[0]] = p[1]
return dict

def split_params(self, params):
if not isinstance(params, str):
self.errors('Parameters can only be a string, received %s' % type(params))
return shlex.split(params)

def api_add_path(self, api, path):
api_path = api.path()
for p in path:
Expand All @@ -380,7 +386,7 @@ def api_get_all(self):
self.errors(e)

def api_add(self):
param = self.list_to_dic(self.add.split(' '))
param = self.list_to_dic(self.split_params(self.add))
try:
self.result['message'].append("added: .id= %s"
% self.api_path.add(**param))
Expand All @@ -397,7 +403,7 @@ def api_remove(self):
self.errors(e)

def api_update(self):
param = self.list_to_dic(self.update.split(' '))
param = self.list_to_dic(self.split_params(self.update))
if '.id' not in param.keys():
self.errors("missing '.id' for %s" % param)
try:
Expand Down Expand Up @@ -448,7 +454,7 @@ def api_query(self):

def api_arbitrary(self):
param = {}
self.arbitrary = self.arbitrary.split(' ')
self.arbitrary = self.split_params(self.arbitrary)
arb_cmd = self.arbitrary[0]
if len(self.arbitrary) > 1:
param = self.list_to_dic(self.arbitrary[1:])
Expand Down