Skip to content

Commit 7be650a

Browse files
author
Shiva Shankar Vaddepally
committed
resoloving url builder issue when filterargs has bool datatype
Signed-off-by: Shiva Shankar Vaddepally <[email protected]>
1 parent c1267e7 commit 7be650a

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

plugins/module_utils/client.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,23 @@ def url_builder(
121121
# http://NSIP/nitro/v1/config/nd6ravariables/1 -- This works
122122
if isinstance(id, float) and id == int(id):
123123
id = int(id)
124+
# Convert boolean to lowercase string
125+
if isinstance(id, bool):
126+
id = str(id).lower()
124127
# Double encode the id
125128
# https://owasp.org/www-community/Double_Encoding
126129
url = "%s/%s" % (url, quote(quote(str(id), safe=""), safe=""))
127130

128131
# Query String Builder
129132
# Construct args
133+
def format_value(val):
134+
"""Convert value to appropriate string format for NITRO API"""
135+
if isinstance(val, bool):
136+
return str(val).lower()
137+
return str(val)
138+
130139
args_val = ",".join(
131-
["%s:%s" % (k, quote(codecs.encode(str(args[k])), safe="")) for k in args]
140+
["%s:%s" % (k, quote(codecs.encode(format_value(args[k])), safe="")) for k in args]
132141
)
133142
args_val = ("args=%s" % args_val) if args_val != "" else ""
134143

@@ -139,10 +148,9 @@ def url_builder(
139148
# Construct filters
140149
# if filter = {'key1':'value1', 'key2':'value2'}
141150
# filter_val=key1:value1,key2:value2
142-
# filter_val = ",".join(["%s:%s" % (k, filter[k]) for k in filter])
143151
filter_val = ",".join(
144152
[
145-
"%s:%s" % (k, quote(codecs.encode(str(filter[k])), safe=""))
153+
"%s:%s" % (k, quote(codecs.encode(format_value(filter[k])), safe=""))
146154
for k in filter
147155
]
148156
)

0 commit comments

Comments
 (0)