Skip to content

Commit 8536aa3

Browse files
authored
Generate secret file with resolved property value if the original value is tokenized as property (#953)
* change method input parameters instead of using class attribute to store variable keys for removal * rename method * add check for none * resolve property value in credential caches * correct logic to remove replaced property variable
1 parent 2eb9e71 commit 8536aa3

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

core/src/main/python/prepare_model.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from oracle.weblogic.deploy.validate import ValidateException
2626

2727
import oracle.weblogic.deploy.util.TranslateException as TranslateException
28+
import wlsdeploy.util.variables as variables
2829
from wlsdeploy.aliases.aliases import Aliases
2930
from wlsdeploy.aliases.location_context import LocationContext
3031
from wlsdeploy.aliases.model_constants import DOMAIN_INFO
@@ -313,6 +314,16 @@ def walk(self):
313314
full_model_dictionary = cla_helper.load_model(_program_name, self.model_context, self._aliases,
314315
"discover", WlstModes.OFFLINE)
315316

317+
# Just in case the credential cache has @@PROP in the model's attribute value,
318+
# we use the original variable file to resolve it,
319+
# so that the generated json/script files have the resolved property value(s) instead of the @@PROP token
320+
321+
original_variables = variables.load_variables(self.model_context.get_variable_file())
322+
credential_caches = self.credential_injector.get_variable_cache()
323+
for key in credential_caches:
324+
if credential_caches[key].find('@@PROP:') == 0:
325+
credential_caches[key] = variables._substitute(credential_caches[key],
326+
original_variables, self.model_context)
316327

317328
target_config = self.model_context.get_target_configuration()
318329
if target_config.generate_script_for_secrets():

core/src/main/python/wlsdeploy/tool/util/variable_injector.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,18 +446,21 @@ def _process_attribute(self, model, attribute, location, injector_values):
446446
variable_value = None
447447
attribute_value = model[attribute]
448448

449-
attribute_type = self.__aliases.get_model_attribute_type(location, attribute)
449+
target_use_credentials = self.__model_context.get_target_configuration().uses_credential_secrets();
450450

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:
451+
if not _already_property(attribute_value) or target_use_credentials:
455452

456453
variable_name = self.get_variable_name(location, attribute)
457454
variable_value = _format_variable_value(attribute_value)
458-
459455
model[attribute] = self.get_variable_token(attribute, variable_name)
460456

457+
# This is the case where the original value is @@PROP but replaced with @@SECRET because of the custom
458+
# injector, we need to clean up the variable file, so add it for later removal.
459+
#
460+
if target_use_credentials and variable_value.find('@@PROP:') == 0 \
461+
and model[attribute].find('@@SECRET:') == 0:
462+
self.add_key_for_variable_removal(attribute_value[7:len(attribute_value) - 2])
463+
461464
_logger.fine('WLSDPLY-19525', variable_name, attribute_value, attribute, variable_value,
462465
class_name=_class_name, method_name=_method_name)
463466
else:

0 commit comments

Comments
 (0)