@@ -59,6 +59,8 @@ class EnvConfig:
5959 __file_updated = False
6060 __migrated = False
6161
62+ __origin_json_str_str = None
63+
6264 __unconfigured_fields = []
6365
6466 def __init__ (self , config_file_path , properties ):
@@ -70,6 +72,7 @@ def __init__(self, config_file_path, properties):
7072 logging .info ("Reading configuration file '%s'" % (self .__config_file_path ))
7173 with open (self .__config_file_path ) as config_file :
7274 self .__config_json = json .load (config_file )
75+ self .__origin_json_str = json .dumps (self .__config_json , sort_keys = True , indent = 2 )
7376 self .__reset ()
7477 else :
7578 logging .info ("Configuration file '%s' doesn't exist; empty file will be created." % (self .__config_file_path ))
@@ -198,9 +201,10 @@ def get_unconfigured_fields(self):
198201 return self .__unconfigured_fields
199202
200203 def update_config_file (self , force = False ):
201- if self .__missing_vars or self .has_unused_vars () or force or self .__migrated :
204+ new_json_str = json .dumps (self .__config_json , sort_keys = True , indent = 2 )
205+ if self .__origin_json_str != new_json_str :
202206 with open (self .__config_file_path , "w" ) as config_file :
203- json . dump ( self . __config_json , config_file , sort_keys = True , indent = 2 )
207+ config_file . write ( new_json_str )
204208 self .__file_updated = True
205209 logging .info ("Configuration file updated: %s" % (self .__config_file_path ))
206210 if self .__migrated :
@@ -268,6 +272,7 @@ class CertConfig:
268272 __config_json = None
269273 __properties = None
270274 __migrated = False
275+ __origin_json_str = None
271276
272277 def __init__ (self , config_file_path , properties ):
273278 self .__properties = properties
@@ -279,6 +284,7 @@ def __init__(self, config_file_path, properties):
279284
280285 if "certificates" not in self .__config_json :
281286 raise ValueError ("File '%s' is not a valid certification config file; missing 'certificates' attribute!" % (self .__config_file_path ))
287+ self .__origin_json_str = json .dumps (self .__config_json , sort_keys = True , indent = 2 )
282288 self .__migrate ()
283289 else :
284290 logging .info ("Certificate configuration file '%s' doesn't exist; empty file will be created." % (self .__config_file_path ))
@@ -381,9 +387,11 @@ def get_certificates(self):
381387 return certs
382388
383389 def update_config_file (self ):
384- with open (self .__config_file_path , "w" ) as cert_file :
385- json .dump (self .__config_json , cert_file , sort_keys = True , indent = 2 )
386- logging .info ("Certificate configuration file updated: %s" % (self .__config_file_path ))
387- if self .__migrated :
388- logging .info ("Certificate configuration file migrated to new version." )
390+ new_json_str = json .dumps (self .__config_json , sort_keys = True , indent = 2 )
391+ if new_json_str != self .__origin_json_str :
392+ with open (self .__config_file_path , "w" ) as cert_file :
393+ json .dump (self .__config_json , cert_file , sort_keys = True , indent = 2 )
394+ logging .info ("Certificate configuration file updated: %s" % (self .__config_file_path ))
395+ if self .__migrated :
396+ logging .info ("Certificate configuration file migrated to new version." )
389397 return
0 commit comments