2626from  wlsdeploy .json .json_translator  import  JsonToPython 
2727from  wlsdeploy .logging .platform_logger  import  PlatformLogger 
2828from  wlsdeploy .util  import  path_utils 
29+ from  wlsdeploy .aliases .alias_constants  import  CREDENTIAL 
2930
3031WEBLOGIC_DEPLOY_HOME_TOKEN  =  '@@WLSDEPLOY@@' 
3132
@@ -103,6 +104,13 @@ def __init__(self, program_name, model, model_context, version=None, variable_di
103104 else :
104105 self .__aliases  =  Aliases (model_context )
105106 self .__variable_dictionary  =  variable_dictionary 
107+  self .__keys_for_variable_removal  =  []
108+ 
109+  def  get_variable_removal_keys (self ):
110+  return  self .__keys_for_variable_removal 
111+ 
112+  def  add_key_for_variable_removal (self , key ):
113+  self .__keys_for_variable_removal .append (key )
106114
107115 def  get_variable_cache (self ):
108116 """ 
@@ -174,7 +182,7 @@ def custom_injection(self, model, attribute, location, injector_values=OrderedDi
174182 variable_dictionary  =  self ._add_variable_info (model , attribute , location , injector_values )
175183 self .add_to_cache (dictionary = variable_dictionary )
176184
177-  def  inject_variables_keyword_file (self , append_option = None ):
185+  def  inject_variables_keyword_file (self , append_option = None ,  variable_keys_to_remove = None ):
178186 """ 
179187 Replace attribute values with variables and generate a variable dictionary. 
180188 The variable replacement is driven from the values in the model variable helper file. 
@@ -255,8 +263,8 @@ def inject_variables_keyword_file(self, append_option=None):
255263 append  =  True 
256264 if  variable_file_location  !=  new_variable_file_location :
257265 shutil .copyfile (variable_file_location , new_variable_file_location )
258-  self ._filter_duplicate_properties (new_variable_file_location , variable_dictionary ) 
259- 
266+  self ._filter_duplicate_and_unused_properties (new_variable_file_location , variable_dictionary , 
267+   variable_keys_to_remove ) 
260268 variable_file_location  =  new_variable_file_location 
261269
262270 variables_inserted  =  self ._write_variables_file (variable_dictionary , variable_file_location , append )
@@ -272,17 +280,28 @@ def inject_variables_keyword_file(self, append_option=None):
272280 return  variables_inserted , return_model , variable_file_location 
273281
274282
275-  def  _filter_duplicate_properties (self , variable_file_location , variable_dictionary ):
283+  def  _filter_duplicate_and_unused_properties (self , variable_file_location , variable_dictionary ,  variable_keys_to_remove ):
276284 _method_name  =  '_filter_duplicate_property' 
277285 _logger .entering (class_name = _class_name , method_name = _method_name )
278286 try :
279287 fis  =  FileInputStream (variable_file_location )
280288 prop  =  Properties ()
281289 prop .load (fis )
282290 fis .close ()
291+ 
292+  # remove from the original properties file and then remove from the variable dictionary 
293+  # so that it won't be added back later 
294+  if  variable_keys_to_remove  is  not None :
295+  for  key  in  variable_keys_to_remove :
296+  if  variable_dictionary .has_key (key ):
297+  variable_dictionary .pop (key )
298+  if  prop .containsKey (key ):
299+  prop .remove (key )
300+ 
283301 for  key  in  variable_dictionary :
284302 if  prop .get (key ) is  not None :
285303 prop .remove (key )
304+ 
286305 fos  =  FileOutputStream (variable_file_location )
287306 prop .store (fos , None )
288307 fos .close ()
@@ -426,7 +445,14 @@ def _process_attribute(self, model, attribute, location, injector_values):
426445 variable_name  =  None 
427446 variable_value  =  None 
428447 attribute_value  =  model [attribute ]
429-  if  not  _already_property (attribute_value ):
448+ 
449+  attribute_type  =  self .__aliases .get_model_attribute_type (location , attribute )
450+ 
451+  if  _already_property (attribute_value ) and  attribute_type  ==  CREDENTIAL :
452+  self .add_key_for_variable_removal (attribute_value [7 :len (attribute_value ) -  2 ])
453+ 
454+  if  not  _already_property (attribute_value ) or  attribute_type  ==  CREDENTIAL :
455+ 
430456 variable_name  =  self .get_variable_name (location , attribute )
431457 variable_value  =  _format_variable_value (attribute_value )
432458
0 commit comments