Skip to content

Commit 23104e2

Browse files
committed
feature: use new json_equals function
1 parent 0b3a0c0 commit 23104e2

File tree

3 files changed

+23
-33
lines changed

3 files changed

+23
-33
lines changed

ibmsecurity/isam/aac/risk_profiles.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def _check(isamAppliance, name, active, description, attributes, predefined):
160160
logger.warning("Risk Profile not found, returning no update required.")
161161
return None, update_required, json_data
162162
else:
163-
if ret_obj['data']['predefined'] is True:
163+
if ret_obj['data']['predefined']:
164164
logger.warning("Predefined Risk Profiles can NOT be updated, returning no update required.")
165165
return ret_obj['data']['id'], update_required, {}
166166
else:
@@ -181,11 +181,7 @@ def _check(isamAppliance, name, active, description, attributes, predefined):
181181
id = ret_obj['data']['id']
182182
del ret_obj['data']['id']
183183

184-
sorted_json_data = json.dumps(json_data, skipkeys=True, sort_keys=True)
185-
logger.debug("Sorted input: {0}".format(sorted_json_data))
186-
sorted_ret_obj = json.dumps(ret_obj['data'], skipkeys=True, sort_keys=True)
187-
logger.debug("Sorted existing data: {0}".format(sorted_ret_obj))
188-
if sorted_ret_obj != sorted_json_data:
184+
if not tools.json_equals(ret_obj, json_data):
189185
logger.info("Changes detected, update needed.")
190186
update_required = True
191187

ibmsecurity/isam/base/admin.py

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
import ibmsecurity.utilities.tools
2+
import ibmsecurity.utilities.tools as _tools
33
import json
44

55
logger = logging.getLogger(__name__)
@@ -29,13 +29,13 @@ def set_pw(isamAppliance, oldPassword, newPassword, sessionTimeout="30", httpsPo
2929
"sessionTimeout": sessionTimeout
3030
}
3131
if httpsPort is not None:
32-
if ibmsecurity.utilities.tools.version_compare(isamAppliance.facts['version'], "9.0.1.0") < 0:
32+
if _tools.version_compare(isamAppliance.facts['version'], "9.0.1.0") < 0:
3333
warnings.append(
3434
"Appliance at version: {0}, httpsPort not supported. Needs 9.0.1.0 or higher. Ignoring httpsPort for this call.")
3535
else:
3636
json_data['httpsPort'] = httpsPort
3737
else:
38-
if ibmsecurity.utilities.tools.version_compare(isamAppliance.facts['version'], "9.0.1.0") < 0:
38+
if _tools.version_compare(isamAppliance.facts['version'], "9.0.1.0") < 0:
3939
pass # Can safely ignore httpsPort
4040
else:
4141
warnings.append("Default httpsPort of 443 will be set on the appliance.")
@@ -168,67 +168,56 @@ def _check(isamAppliance,
168168
json_data["confirmPassword"] = v
169169
if k in ["minHeapSize", "maxHeapSize", "httpPort", "httpsPort", "minThreads", "maxThreads", "maxPoolSize", "maxFiles", "maxFileSize", "sshdPort", "sessionCachePurge", "sessionInactivityTimeout", "sshdClientAliveInterval", "baSessionTimeout"]:
170170
# int values
171-
if k == "sshdPort" and ibmsecurity.utilities.tools.version_compare(iviaVersion, "9.0.3.0") < 0:
171+
if k == "sshdPort" and _tools.version_compare(iviaVersion, "9.0.3.0") < 0:
172172
warnings.append(f"Appliance at version: {iviaVersion}, sshdPort: {v} is not supported. Needs 9.0.3.0 or higher. Ignoring sshdPort for this call.")
173173
continue
174-
if k in ["sessionCachePurge", "sessionInactivityTimeout", "sshdClientAliveInterval"] and ibmsecurity.utilities.tools.version_compare(iviaVersion, "9.0.5.0") < 0:
174+
if k in ["sessionCachePurge", "sessionInactivityTimeout", "sshdClientAliveInterval"] and _tools.version_compare(iviaVersion, "9.0.5.0") < 0:
175175
warnings.append(f"Appliance at version: {iviaVersion}, {k}: {v} is not supported. Needs 9.0.5.0 or higher. Ignoring.")
176176
continue
177-
if k in ["baSessionTimeout"] and ibmsecurity.utilities.tools.version_compare(iviaVersion, "10.0.2.0") < 0:
177+
if k in ["baSessionTimeout"] and _tools.version_compare(iviaVersion, "10.0.2.0") < 0:
178178
warnings.append(
179179
f"Appliance at version: {iviaVersion}, {k}: {v} is not supported. Needs 10.0.2.0 or higher. Ignoring.")
180180
continue
181181
json_data[k] = int(v)
182182
continue
183183
if k == "enableSSLv3":
184-
if ibmsecurity.utilities.tools.version_compare(iviaVersion, "10.0.3.0") >= 0:
184+
if _tools.version_compare(iviaVersion, "10.0.3.0") >= 0:
185185
warnings.append(f"Appliance at version: {iviaVersion}, enableSSLv3: {v} is not supported. Needs max. 10.0.2.0. Ignoring for this call.")
186186
continue
187187
if k == "consoleLogLevel":
188188
if 'consoleLogLevel' in ret_obj['data'] and ret_obj['data']['consoleLogLevel'] == 'OFF':
189189
ret_obj['data']['consoleLogLevel'] = 'OFF'
190190
if k == "enabledTLS":
191-
if ibmsecurity.utilities.tools.version_compare(iviaVersion, "9.0.4.0") < 0:
191+
if _tools.version_compare(iviaVersion, "9.0.4.0") < 0:
192192
warnings.append(f"Appliance at version: {iviaVersion}, enabledTLS: {v} is not supported. Needs 9.0.4.0 or higher. Ignoring enabledTLS for this call.")
193193
continue
194194
if k in ["swapFileSize", "httpProxy"]:
195-
if ibmsecurity.utilities.tools.version_compare(iviaVersion, "9.0.5.0") < 0:
195+
if _tools.version_compare(iviaVersion, "9.0.5.0") < 0:
196196
warnings.append(f"Appliance at version: {iviaVersion}, {k}: {v} is not supported. Needs 9.0.5.0 or higher. Ignoring.")
197197
continue
198198
if k in ["enabledServerProtocols", "loginHeader", "loginMessage", "pendingChangesLifetime", "httpsProxy"]:
199-
if ibmsecurity.utilities.tools.version_compare(iviaVersion, "9.0.7.0") < 0:
199+
if _tools.version_compare(iviaVersion, "9.0.7.0") < 0:
200200
warnings.append(
201201
f"Appliance at version: {iviaVersion}, {k}: {v} is not supported. Needs 9.0.7.0 or higher. Ignoring.")
202202
continue
203203
if k in ["accessLogFormat"]:
204-
if ibmsecurity.utilities.tools.version_compare(iviaVersion, "10.0.0.0") < 0:
204+
if _tools.version_compare(iviaVersion, "10.0.0.0") < 0:
205205
warnings.append(f"Appliance at version: {iviaVersion}, {k}: {v} is not supported. Needs 10.0.0.0 or higher. Ignoring.")
206206
continue
207207
if k in ["lmiMessageTimeout", "validVerifyDomains"]:
208-
if ibmsecurity.utilities.tools.version_compare(iviaVersion, "10.0.2.0") < 0:
208+
if _tools.version_compare(iviaVersion, "10.0.2.0") < 0:
209209
warnings.append(f"Appliance at version: {iviaVersion}, {k}: {v} is not supported. Needs 10.0.0.0 or higher. Ignoring.")
210210
continue
211211
if k == "jsVersion":
212-
if ibmsecurity.utilities.tools.version_compare(iviaVersion, "10.0.9.0") < 0:
212+
if _tools.version_compare(iviaVersion, "10.0.9.0") < 0:
213213
warnings.append(f"Appliance at version: {iviaVersion}, {k}: {v} is not supported. Needs 10.0.9.0 or higher. Ignoring.")
214214
continue
215215

216216
# Add to the json_data dict
217217
json_data[k] = v
218218

219-
# Remove keys from ret_obj that are not in json_data
220-
fCurrentEntries = {k: v for k, v in ret_obj["data"].items() if k in json_data.keys()}
221-
#
222-
sorted_ret_obj = json.dumps(fCurrentEntries, skipkeys=True, sort_keys=True)
223-
sorted_json_data = json.dumps(json_data, skipkeys=True, sort_keys=True)
224-
logger.debug(f"Sorted Existing Data:\n\n{sorted_ret_obj}")
225-
logger.debug(f"Sorted Desired Data:\n\n{sorted_json_data}")
226-
if sorted_ret_obj != sorted_json_data:
219+
if not _tools.json_equals(ret_obj, json_data):
227220
logger.debug("Admin Settings are found to be different. See above JSON for difference.")
228-
# Ensure users know how REST API handles httpsPort default value - I think everybody should know this by now
229-
# if json_data.get("httpsPort", "") == "" and ibmsecurity.utilities.tools.version_compare(isamAppliance.facts['version'],
230-
# "9.0.1.0") >= 0:
231-
# warnings.append("Default httpsPort of 443 will be set on the appliance.")
232221
return True, warnings, json_data
233222
else: # No changes required
234223
return False, warnings, json_data
@@ -241,4 +230,4 @@ def compare(isamAppliance1, isamAppliance2):
241230
ret_obj1 = get(isamAppliance1)
242231
ret_obj2 = get(isamAppliance2)
243232

244-
return ibmsecurity.utilities.tools.json_compare(ret_obj1, ret_obj2)
233+
return _tools.json_compare(ret_obj1, ret_obj2)

ibmsecurity/isam/base/runtime/tuning_parameters.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ def _setMultipleValues(isamAppliance, values=None, ignore_endpoints=True, check
5454
This is typically set using the specific endpoint configurations.
5555
"""
5656
currentRuntimeParameters = get(isamAppliance)
57-
warnings = currentRuntimeParameters['warnings']
57+
warnings = []
5858
logger.debug("Setting multiple values for runtime tuning parameters")
59+
if ignore_endpoints:
60+
logger.info("Ignoring endpoint configuration in comparison")
61+
warnings.append("Ignoring endpoint configuration in comparison")
62+
currentRuntimeParameters.pop("endpoints", None)
63+
values.pop("endpoints", None)
5964
if force or not _tools.json_equals(currentRuntimeParameters, values):
6065
if check_mode:
6166
return isamAppliance.create_return_object(changed=True, warnings=warnings)

0 commit comments

Comments
 (0)