Skip to content

Commit da6c3d9

Browse files
committed
Merge branch 'fix-discover-rcu-issue' into 'main'
Fix discover rcu issue See merge request weblogic-cloud/weblogic-deploy-tooling!1786
2 parents af566d1 + ee4700a commit da6c3d9

File tree

4 files changed

+63
-31
lines changed

4 files changed

+63
-31
lines changed

core/src/main/python/discover.py

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,8 @@ def __check_and_customize_model(model, model_context, aliases, credential_inject
754754
__logger.info('WLSDPLY-06014', _class_name=_class_name, method_name=_method_name)
755755

756756
filter_helper.apply_final_filters(model.get_model(), model.get_model(), model_context)
757-
__fix_discovered_template_datasource(model, model_context)
757+
758+
__fix_discovered_template_datasource(model, model_context, credential_injector)
758759

759760
credential_cache = None
760761
if credential_injector is not None:
@@ -772,7 +773,6 @@ def __check_and_customize_model(model, model_context, aliases, credential_inject
772773

773774
# Apply the injectors specified in model_variable_injector.json, or in the target configuration.
774775
# Include the variable mappings that were collected in credential_cache.
775-
776776
variable_injector = VariableInjector(_program_name, model_context, aliases, variable_dictionary=credential_cache)
777777

778778
variable_injector.add_to_cache(dictionary=extra_tokens)
@@ -809,7 +809,7 @@ def __compare_wls_versions(model_context):
809809
__logger.notification(
810810
'WLSDPLY-06068', message_start, class_name=_class_name, method_name=_method_name)
811811

812-
def __fix_discovered_template_datasource(model, model_context):
812+
def __fix_discovered_template_datasource(model, model_context, credential_injector):
813813
# fix the case for discovering template datasources.
814814
# If all the template datasources use the dame passwords then generate the RUCDbInfo section
815815
# and remove the template datasources from the model
@@ -823,25 +823,27 @@ def __fix_discovered_template_datasource(model, model_context):
823823
resources = model.get_model_resources()
824824
jdbc_system_resources = dictionary_utils.get_element(resources, JDBC_SYSTEM_RESOURCE)
825825
discover_filters = domain_typedef._discover_filters
826-
filtered_ds_patterns = dictionary_utils.get_element(discover_filters,'/JDBCSystemResource')
826+
filtered_ds_patterns = dictionary_utils.get_element(discover_filters,'/JDBCSystemResource',
827+
None)
827828
passwords = HashSet()
828829
urls = HashSet()
829830
prefixes = HashSet()
830-
properties = __get_urls_and_passwords(model_context, jdbc_system_resources, filtered_ds_patterns,
831+
properties = __get_urls_and_passwords(jdbc_system_resources, filtered_ds_patterns,
831832
urls, passwords, prefixes)
832833
if _can_generate_rcudb_info(passwords, urls, prefixes):
833834
__set_rcuinfo_in_model(model, properties, urls.iterator().next(), passwords.iterator().next())
834835
__remove_discovered_template_datasource(jdbc_system_resources, filtered_ds_patterns, model)
835-
__fix_rcudbinfo_passwords(model, model_context, model_context.is_discover_passwords())
836+
__fix_rcudbinfo_passwords(model, model_context, credential_injector)
836837
else:
837-
__reset_password_to_regular_discovery(jdbc_system_resources, filtered_ds_patterns, model_context)
838+
__reset_password_to_regular_discovery(model, filtered_ds_patterns, model_context, credential_injector)
838839

839840
__logger.exiting(_class_name, _method_name)
840841

842+
841843
def _can_generate_rcudb_info(passwords, urls, prefixes):
842844
return passwords.size() == 1 and urls.size() == 1 and prefixes.size() == 1
843845

844-
def __get_urls_and_passwords(model_context, jdbc_system_resources, filtered_ds_patterns, urls, passwords, prefixes):
846+
def __get_urls_and_passwords(jdbc_system_resources, filtered_ds_patterns, urls, passwords, prefixes):
845847
properties = None
846848
for item in jdbc_system_resources:
847849
if not __match_filtered_ds_name(item, filtered_ds_patterns):
@@ -944,10 +946,22 @@ def __remove_discovered_template_datasource(jdbc_system_resources, filtered_ds_p
944946
if len(resources) == 0:
945947
del model_dict[RESOURCES]
946948

947-
def __reset_password_to_regular_discovery(jdbc_system_resources, filtered_ds_patterns, model_context):
949+
def __reset_password_to_regular_discovery(model, filtered_ds_patterns, model_context, credential_injector):
950+
951+
resources = model.get_model_resources()
952+
jdbc_system_resources = dictionary_utils.get_element(resources, JDBC_SYSTEM_RESOURCE)
953+
948954
for item in jdbc_system_resources:
949955
if not __match_filtered_ds_name(item, filtered_ds_patterns):
950956
continue
957+
958+
location = LocationContext().append_location(JDBC_SYSTEM_RESOURCE)
959+
location.append_location(JDBC_RESOURCE, JDBC_DRIVER_PARAMS)
960+
location.add_name_token('DOMAIN', model_context.get_domain_name())
961+
location.add_name_token('DATASOURCE', item)
962+
location.add_name_token('JDBCRESOURCE', item)
963+
location.add_name_token('JDBCDRIVERPARAMS', 'NO_NAME_0')
964+
951965
jdbc_system_resource = jdbc_system_resources[item]
952966
jdbc_resource = dictionary_utils.get_element(jdbc_system_resource, JDBC_RESOURCE)
953967
driver_params = dictionary_utils.get_element(jdbc_resource, JDBC_DRIVER_PARAMS)
@@ -958,9 +972,12 @@ def __reset_password_to_regular_discovery(jdbc_system_resources, filtered_ds_pat
958972
driver_params[PASSWORD_ENCRYPTED] = encrypted_model_value
959973
else:
960974
driver_params[PASSWORD_ENCRYPTED] = alias_constants.PASSWORD_TOKEN
961-
return
962975

963-
def __fix_rcudbinfo_passwords(model, model_context, encrypt=False):
976+
if credential_injector:
977+
credential_injector.check_and_tokenize(driver_params, PASSWORD_ENCRYPTED, location)
978+
979+
980+
def __fix_rcudbinfo_passwords(model, model_context, credential_injector):
964981

965982
model_dict = model.get_model()
966983
rcudb_info = model_dict[DOMAIN_INFO][RCU_DB_INFO]
@@ -971,20 +988,31 @@ def __fix_rcudbinfo_passwords(model, model_context, encrypt=False):
971988
DRIVER_PARAMS_KEYSTOREPWD_PROPERTY
972989
]
973990

991+
is_discover_password = model_context.is_discover_passwords()
992+
993+
location = LocationContext().append_location(RCU_DB_INFO)
994+
974995
for item in possible_pwds:
975996
if item in rcudb_info:
976-
if encrypt:
997+
if is_discover_password:
977998
passwd = rcudb_info[item]
978-
rcudb_info[item] = encryption_utils.encrypt_one_password(
999+
model_value = encryption_utils.encrypt_one_password(
9791000
model_context.get_encryption_passphrase(), passwd)
1001+
rcudb_info[item] = model_value
9801002
else:
9811003
rcudb_info[item] = alias_constants.PASSWORD_TOKEN
9821004

1005+
if credential_injector:
1006+
credential_injector.check_and_tokenize(rcudb_info, item, location)
1007+
1008+
1009+
9831010
def __match_filtered_ds_name(name, patterns):
984-
for pattern in patterns:
985-
regex = re.compile(pattern)
986-
if regex.match(name):
987-
return True
1011+
if patterns is not None:
1012+
for pattern in patterns:
1013+
regex = re.compile(pattern)
1014+
if regex.match(name):
1015+
return True
9881016
return False
9891017

9901018
def __generate_remote_report_json(model_context):
@@ -1056,8 +1084,6 @@ def main(model_context):
10561084
password_key = 'WLSDPLY-06024'
10571085
__logger.info(password_key, class_name=_class_name, method_name=_method_name)
10581086

1059-
__compare_wls_versions(model_context)
1060-
10611087
extra_tokens = {}
10621088
try:
10631089
model = __discover(model_context, aliases, credential_injector, helper, extra_tokens)

core/src/main/python/wlsdeploy/tool/discover/discoverer.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def _add_to_dictionary(self, dictionary, location, wlst_param, wlst_value, wlst_
275275
dictionary[model_param] = model_value
276276

277277
# tokenize the attribute if needed
278-
if self._credential_injector is not None:
278+
if self._credential_injector is not None and not self._is_filtered_datasource_location(location):
279279
self._credential_injector.check_and_tokenize(dictionary, model_param, location)
280280

281281
elif model_param is None:
@@ -394,18 +394,25 @@ def _get_model_password_value(self, location, model_name, model_value):
394394

395395
def _get_decrypted_password_and_is_filtered_datasource(self, location, model_value):
396396
# only do it for templated datasource
397+
filtered_datasource = self._is_filtered_datasource_location(location)
398+
if filtered_datasource:
399+
base_dir = self._model_context.get_domain_home()
400+
if self._model_context.is_ssh():
401+
base_dir = self.download_temporary_dir
402+
model_value = self._weblogic_helper.decrypt(model_value, base_dir)
403+
return filtered_datasource, model_value
404+
405+
def _is_filtered_datasource_location(self, location):
397406
filtered_datasource = False
398407
model_folders = location.get_model_folders()
399-
if (model_folders[0] == JDBC_SYSTEM_RESOURCE):
408+
if (model_folders and model_folders[0] == JDBC_SYSTEM_RESOURCE):
400409
loc = LocationContext()
401410
loc.append_location(JDBC_SYSTEM_RESOURCE)
402411
tokens = location.get_name_tokens()
403412
filtered_datasource = self._model_context.get_domain_typedef().is_filtered(loc, tokens['DATASOURCE'])
404-
405-
base_dir = self._model_context.get_domain_home()
406-
if self._model_context.is_ssh():
407-
base_dir = self.download_temporary_dir
408-
return filtered_datasource, self._weblogic_helper.decrypt(model_value, base_dir)
413+
if filtered_datasource:
414+
return True
415+
return False
409416

410417
def _get_attributes_for_current_location(self, location):
411418
"""

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2018, 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2018, 2025, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import copy
@@ -89,7 +89,6 @@ def __init__(self, program_name, model_context, aliases, variable_dictionary=Non
8989
self._model_context = model_context
9090
self._aliases = aliases
9191
self.__section_keys = model_sections.get_model_top_level_keys()
92-
self.__section_keys.remove(model_sections.get_model_domain_info_key())
9392
self.__variable_dictionary = variable_dictionary
9493
self.__path_helper = path_helper.get_path_helper()
9594

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2017, 2025, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl.
44
55
Module that handles command-line argument parsing and common validation.
@@ -1373,10 +1373,10 @@ def get_from_file_value(file_var):
13731373
value = ifile.readLine()
13741374
ifile.close()
13751375
return value
1376-
except IOException,ioe:
1376+
except (IOException,JIllegalArgumentException),ioe:
13771377
if ifile:
13781378
ifile.close()
13791379
ex = create_cla_exception(ExitCode.ARG_VALIDATION_ERROR, 'WLSDPLY-01651', file_var,
13801380
ioe.getLocalizedMessage(), error=ioe)
1381-
_logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
1381+
_logger.throwing(ex, class_name=CommandLineArgUtil._class_name, method_name=_method_name)
13821382
raise ex

0 commit comments

Comments
 (0)