|
| 1 | +""" |
| 2 | +Copyright (c) 2010, Oracle Corporation and/or its affiliates. All rights reserved. |
| 3 | +Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
| 4 | +""" |
| 5 | + |
| 6 | +from wlsdeploy.aliases.model_constants import RCU_DB_INFO |
| 7 | +from wlsdeploy.aliases.model_constants import RCU_PREFIX |
| 8 | +from wlsdeploy.aliases.model_constants import RCU_SCHEMA_PASSWORD |
| 9 | +from wlsdeploy.aliases.model_constants import DRIVER_PARAMS_USER_PROPERTY |
| 10 | +from wlsdeploy.aliases.model_constants import JDBC_DRIVER_PARAMS |
| 11 | +from wlsdeploy.aliases.model_constants import JDBC_DRIVER_PARAMS_PROPERTIES |
| 12 | +from wlsdeploy.aliases.model_constants import JDBC_RESOURCE |
| 13 | +from wlsdeploy.aliases.model_constants import JDBC_SYSTEM_RESOURCE |
| 14 | +from wlsdeploy.aliases.model_constants import PASSWORD_ENCRYPTED |
| 15 | +from wlsdeploy.tool.create.rcudbinfo_helper import RcuDbInfo |
| 16 | +from wlsdeploy.aliases.location_context import LocationContext |
| 17 | +from wlsdeploy.tool.deploy.deployer import Deployer |
| 18 | +from wlsdeploy.exception.expection_types import ExceptionType |
| 19 | + |
| 20 | +from wlsdeploy.aliases.wlst_modes import WlstModes |
| 21 | + |
| 22 | +class RCUHelper(Deployer): |
| 23 | + |
| 24 | + def __init__(self, model, model_context, aliases, modifyBootStrapCredential=True): |
| 25 | + Deployer.__init__(self, model, model_context, aliases, wlst_mode=WlstModes.OFFLINE) |
| 26 | + self._exception_type = ExceptionType.DEPLOY |
| 27 | + self._modifyBootStrapCredential = modifyBootStrapCredential |
| 28 | + |
| 29 | + def update_rcu_password(self): |
| 30 | + """ |
| 31 | + Update the password of each rcu schema and then update the bootstrap password |
| 32 | + """ |
| 33 | + |
| 34 | + _method_name = 'update_rcu_password' |
| 35 | + |
| 36 | + domain_info = self.model.get_model_domain_info() |
| 37 | + if RCU_DB_INFO in domain_info: |
| 38 | + rcu_db_info = RcuDbInfo(self.alias_helper, domain_info[RCU_DB_INFO]) |
| 39 | + rcu_schema_pass = rcu_db_info.get_rcu_schema_password() |
| 40 | + rcu_prefix = rcu_db_info.get_rcu_prefix() |
| 41 | + |
| 42 | + location = LocationContext() |
| 43 | + location.append_location(JDBC_SYSTEM_RESOURCE) |
| 44 | + |
| 45 | + folder_path = self.alias_helper.get_wlst_list_path(location) |
| 46 | + self.wlst_helper.cd(folder_path) |
| 47 | + ds_names = self.wlst_helper.lsc() |
| 48 | + domain_typedef = self.model_context.get_domain_typedef() |
| 49 | + rcu_schemas = domain_typedef.get_rcu_schemas() |
| 50 | + if len(rcu_schemas) == 0: |
| 51 | + return |
| 52 | + schemas_len = len(rcu_schemas) |
| 53 | + |
| 54 | + for i in range(0,schemas_len): |
| 55 | + rcu_schemas[i] = rcu_prefix + '_' + rcu_schemas[i] |
| 56 | + |
| 57 | + for ds_name in ds_names: |
| 58 | + location = LocationContext() |
| 59 | + location.append_location(JDBC_SYSTEM_RESOURCE) |
| 60 | + token_name = self.alias_helper.get_name_token(location) |
| 61 | + location.add_name_token(token_name, ds_name) |
| 62 | + |
| 63 | + location.append_location(JDBC_RESOURCE) |
| 64 | + location.append_location(JDBC_DRIVER_PARAMS) |
| 65 | + password_location = LocationContext(location) |
| 66 | + |
| 67 | + wlst_path = self.alias_helper.get_wlst_attributes_path(location) |
| 68 | + self.wlst_helper.cd(wlst_path) |
| 69 | + |
| 70 | + location.append_location(JDBC_DRIVER_PARAMS_PROPERTIES) |
| 71 | + token_name = self.alias_helper.get_name_token(location) |
| 72 | + if token_name is not None: |
| 73 | + location.add_name_token(token_name, DRIVER_PARAMS_USER_PROPERTY) |
| 74 | + wlst_path = self.alias_helper.get_wlst_attributes_path(location) |
| 75 | + self.wlst_helper.cd(wlst_path) |
| 76 | + ds_user = self.wlst_helper.get('Value') |
| 77 | + |
| 78 | + if ds_user in rcu_schemas: |
| 79 | + wlst_path = self.alias_helper.get_wlst_attributes_path(password_location) |
| 80 | + self.wlst_helper.cd(wlst_path) |
| 81 | + wlst_name, wlst_value = \ |
| 82 | + self.alias_helper.get_wlst_attribute_name_and_value(password_location, PASSWORD_ENCRYPTED, |
| 83 | + rcu_schema_pass, masked=True) |
| 84 | + self.wlst_helper.set(wlst_name, wlst_value, masked=True) |
| 85 | + |
| 86 | + domain_home = self.model_context.get_domain_home() |
| 87 | + config_file = domain_home + '/config/fmwconfig/jps-config-jse.xml' |
| 88 | + opss_user = rcu_prefix + '_OPSS' |
| 89 | + if self._modifyBootStrapCredential: |
| 90 | + self.wlst_helper.modify_bootstrap_credentials(jps_configfile=config_file, username=opss_user, password=rcu_schema_pass) |
| 91 | + |
| 92 | + |
0 commit comments