26
26
from wlsdeploy .json .json_translator import JsonToPython
27
27
from wlsdeploy .logging .platform_logger import PlatformLogger
28
28
from wlsdeploy .util import path_utils
29
+ from wlsdeploy .aliases .alias_constants import CREDENTIAL
29
30
30
31
WEBLOGIC_DEPLOY_HOME_TOKEN = '@@WLSDEPLOY@@'
31
32
@@ -103,6 +104,13 @@ def __init__(self, program_name, model, model_context, version=None, variable_di
103
104
else :
104
105
self .__aliases = Aliases (model_context )
105
106
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 )
106
114
107
115
def get_variable_cache (self ):
108
116
"""
@@ -174,7 +182,7 @@ def custom_injection(self, model, attribute, location, injector_values=OrderedDi
174
182
variable_dictionary = self ._add_variable_info (model , attribute , location , injector_values )
175
183
self .add_to_cache (dictionary = variable_dictionary )
176
184
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 ):
178
186
"""
179
187
Replace attribute values with variables and generate a variable dictionary.
180
188
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):
255
263
append = True
256
264
if variable_file_location != new_variable_file_location :
257
265
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 )
260
268
variable_file_location = new_variable_file_location
261
269
262
270
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):
272
280
return variables_inserted , return_model , variable_file_location
273
281
274
282
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 ):
276
284
_method_name = '_filter_duplicate_property'
277
285
_logger .entering (class_name = _class_name , method_name = _method_name )
278
286
try :
279
287
fis = FileInputStream (variable_file_location )
280
288
prop = Properties ()
281
289
prop .load (fis )
282
290
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
+
283
301
for key in variable_dictionary :
284
302
if prop .get (key ) is not None :
285
303
prop .remove (key )
304
+
286
305
fos = FileOutputStream (variable_file_location )
287
306
prop .store (fos , None )
288
307
fos .close ()
@@ -426,7 +445,14 @@ def _process_attribute(self, model, attribute, location, injector_values):
426
445
variable_name = None
427
446
variable_value = None
428
447
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
+
430
456
variable_name = self .get_variable_name (location , attribute )
431
457
variable_value = _format_variable_value (attribute_value )
432
458
0 commit comments