11import logging
2- import ibmsecurity .utilities .tools
2+ import ibmsecurity .utilities .tools as _tools
33import json
44
55logger = 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 )
0 commit comments