Skip to content

Commit 16db766

Browse files
committed
Merge branch 'model-validator-tokens' into 'main'
Resolve tokens before extended validation of attributes See merge request weblogic-cloud/weblogic-deploy-tooling!1734
2 parents 5dadb3b + 2fccb22 commit 16db766

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

core/src/main/python/wlsdeploy/tool/validate/domain_info_validator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ def __validate_wls_credential_mappings_section(self, mappings_dict):
189189

190190
remote_resources_dict = dictionary_utils.get_dictionary_element(mappings_dict, REMOTE_RESOURCE)
191191
for mapping_name, mapping_dict in remote_resources_dict.iteritems():
192-
method = dictionary_utils.get_element(mapping_dict, METHOD)
192+
method = self._get_validation_value(mapping_dict, METHOD)
193193
if method and method not in RESOURCE_METHODS:
194194
self._logger.severe('WLSDPLY-05313', method, REMOTE_RESOURCE, mapping_name, METHOD,
195195
', '.join(RESOURCE_METHODS), class_name=_class_name, method_name=_method_name)
196196

197-
protocol = dictionary_utils.get_element(mapping_dict, PROTOCOL)
197+
protocol = self._get_validation_value(mapping_dict, PROTOCOL)
198198
if protocol and protocol not in RESOURCE_PROTOCOLS:
199199
self._logger.severe('WLSDPLY-05313', protocol, REMOTE_RESOURCE, mapping_name, PROTOCOL,
200200
', '.join(RESOURCE_PROTOCOLS), class_name=_class_name, method_name=_method_name)
@@ -211,29 +211,29 @@ def __validate_rcu_db_info_section(self, info_dict):
211211
self._check_deprecated_field(ATP_TEMPORARY_TABLESPACE, info_dict, RCU_DB_INFO, RCU_TEMP_TBLSPACE)
212212

213213
# deprecated DATABASE_TYPE, must be ORACLE, ATP, or SSL if specified
214-
old_database_type = dictionary_utils.get_element(info_dict, DATABASE_TYPE)
214+
old_database_type = self._get_validation_value(info_dict, DATABASE_TYPE)
215215
if old_database_type and old_database_type not in DEPRECATED_DB_TYPES:
216216
self._logger.severe(
217217
'WLSDPLY-05302', old_database_type, RCU_DB_INFO, DATABASE_TYPE,
218218
', '.join(DEPRECATED_DB_TYPES), class_name=_class_name, method_name=_method_name)
219219

220220
# RCU_DATABASE_TYPE must be one of allowed types if specified
221-
database_type = dictionary_utils.get_element(info_dict, RCU_DATABASE_TYPE)
221+
database_type = self._get_validation_value(info_dict, RCU_DATABASE_TYPE)
222222
if database_type and database_type not in ALL_DB_TYPES:
223223
self._logger.severe(
224224
'WLSDPLY-05302', database_type, RCU_DB_INFO, RCU_DATABASE_TYPE,
225225
', '.join(ALL_DB_TYPES), class_name=_class_name, method_name=_method_name)
226226

227227
# ORACLE_DATABASE_CONNECTION_TYPE must be one of allowed types if specified
228-
connection_type = dictionary_utils.get_element(info_dict, ORACLE_DATABASE_CONNECTION_TYPE)
228+
connection_type = self._get_validation_value(info_dict, ORACLE_DATABASE_CONNECTION_TYPE)
229229
if connection_type and connection_type not in ORACLE_DB_CONNECTION_TYPES:
230230
self._logger.severe(
231231
'WLSDPLY-05302', connection_type, RCU_DB_INFO, ORACLE_DATABASE_CONNECTION_TYPE,
232232
', '.join(ORACLE_DB_CONNECTION_TYPES), class_name=_class_name, method_name=_method_name)
233233

234234
# *StoreType must be one of allowed types if specified
235235
for type_field in [DRIVER_PARAMS_TRUSTSTORETYPE_PROPERTY, DRIVER_PARAMS_KEYSTORETYPE_PROPERTY]:
236-
type_value = dictionary_utils.get_element(info_dict, type_field)
236+
type_value = self._get_validation_value(info_dict, type_field)
237237
if type_value and type_value.upper() not in STORE_TYPES:
238238
self._logger.severe(
239239
'WLSDPLY-05302', type_value, RCU_DB_INFO, type_field,

core/src/main/python/wlsdeploy/tool/validate/model_validator.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,25 @@ def _log_context_invalid(self, message, method_name):
617617
log_method = self._logger.info
618618
log_method('WLSDPLY-05027', message, class_name=_class_name, method_name=method_name)
619619

620+
def _get_validation_value(self, model_dict, attribute_name):
621+
"""
622+
Get the derived value of the specified attribute, de-tokenizing as needed.
623+
If unresolved tokens remain in the value, None is returned to prevent further checks.
624+
Validation has already checked for unresolved variables, depending on validation mode.
625+
:param model_dict: the dictionary containing the value to be examined
626+
:param attribute_name: the name of the attribute to be examined
627+
:return: the value to use for additional validation checks
628+
"""
629+
value = dictionary_utils.get_element(model_dict, attribute_name)
630+
if isinstance(value, (str, unicode)) and variables.has_tokens(value):
631+
value = variables.substitute_attribute(value, self._variable_properties, self._model_context,
632+
attribute_name=attribute_name)
633+
if variables.has_tokens(value):
634+
# avoid further checks if unresolved tokens remain.
635+
# validation has already checked if unresolved tokens are errors.
636+
return None
637+
return value
638+
620639
####################################################################################
621640
#
622641
# Private methods, private inner classes and static methods only, beyond here please

core/src/main/python/wlsdeploy/util/variables.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,18 @@ def substitute_key(text, variables):
565565

566566
return text
567567

568+
def substitute_attribute(text, variables, model_context, attribute_name=None):
569+
"""
570+
Return the de-tokenized value of the specified text.
571+
Follow the rules of the configured validation mode.
572+
:param text: the text to be evaluated
573+
:param variables: the variable map
574+
:param model_context: used to determine the validation mode
575+
:param attribute_name: the name of the attribute
576+
:return: the de-tokenized text value
577+
"""
578+
error_info = {'errorCount': 0}
579+
return _substitute(text, variables, model_context, error_info, attribute_name)
568580

569581
def has_variables(text):
570582
"""
@@ -575,6 +587,9 @@ def has_variables(text):
575587
matches = _property_pattern.findall(text)
576588
return len(matches) > 0
577589

590+
def has_tokens(text):
591+
matches = _unresolved_token_pattern.findall(text)
592+
return len(matches) > 0
578593

579594
def get_variable_matches(text):
580595
"""

0 commit comments

Comments
 (0)