Skip to content

Commit e85ed6e

Browse files
committed
Merge branch 'wdt-878' into 'main'
Adding -discover_opss_wallet feature See merge request weblogic-cloud/weblogic-deploy-tooling!1689
2 parents d702436 + 1202493 commit e85ed6e

File tree

24 files changed

+411
-184
lines changed

24 files changed

+411
-184
lines changed

core/src/main/python/create.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@
6666
CommandLineArgUtil.PASSPHRASE_ENV_SWITCH,
6767
CommandLineArgUtil.PASSPHRASE_FILE_SWITCH,
6868
CommandLineArgUtil.OPSS_WALLET_SWITCH,
69-
CommandLineArgUtil.OPSS_WALLET_PASSPHRASE,
70-
CommandLineArgUtil.OPSS_WALLET_FILE_PASSPHRASE,
71-
CommandLineArgUtil.OPSS_WALLET_ENV_PASSPHRASE,
69+
CommandLineArgUtil.OPSS_WALLET_PASSPHRASE_SWITCH,
70+
CommandLineArgUtil.OPSS_WALLET_PASSPHRASE_FILE_SWITCH,
71+
CommandLineArgUtil.OPSS_WALLET_PASSPHRASE_ENV_SWITCH,
7272
CommandLineArgUtil.UPDATE_RCU_SCHEMA_PASS_SWITCH,
7373
CommandLineArgUtil.PASSPHRASE_PROMPT_SWITCH,
7474
# deprecated in 4.2.0
@@ -174,15 +174,15 @@ def __process_opss_args(optional_arg_map):
174174
_method_name = '__process_opss_args'
175175

176176
if CommandLineArgUtil.OPSS_WALLET_SWITCH in optional_arg_map and \
177-
CommandLineArgUtil.OPSS_WALLET_PASSPHRASE not in optional_arg_map:
177+
CommandLineArgUtil.OPSS_WALLET_PASSPHRASE_SWITCH not in optional_arg_map:
178178
try:
179179
passphrase = getcreds.getpass('WLSDPLY-20027')
180180
except IOException, ioe:
181181
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
182182
'WLSDPLY-20028', ioe.getLocalizedMessage(), error=ioe)
183183
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
184184
raise ex
185-
optional_arg_map[CommandLineArgUtil.OPSS_WALLET_PASSPHRASE] = str(String(passphrase))
185+
optional_arg_map[CommandLineArgUtil.OPSS_WALLET_PASSPHRASE_SWITCH] = str(String(passphrase))
186186

187187

188188
def _get_domain_path(model_context, model):

core/src/main/python/discover.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
import sys
99

1010
from java.io import File
11+
from java.io import IOException
1112
from java.lang import IllegalArgumentException
1213
from java.lang import IllegalStateException
14+
from java.lang import String
1315
from java.lang import System
1416
from oracle.weblogic.deploy.aliases import AliasException
1517
from oracle.weblogic.deploy.discover import DiscoverException
@@ -39,6 +41,7 @@
3941
from wlsdeploy.tool.discover.deployments_discoverer import DeploymentsDiscoverer
4042
from wlsdeploy.tool.discover.domain_info_discoverer import DomainInfoDiscoverer
4143
from wlsdeploy.tool.discover.multi_tenant_discoverer import MultiTenantDiscoverer
44+
from wlsdeploy.tool.discover.opss_wallet_discoverer import OpssWalletDiscoverer
4245
from wlsdeploy.tool.discover.resources_discoverer import ResourcesDiscoverer
4346
from wlsdeploy.tool.discover.security_provider_data_discoverer import SecurityProviderDataDiscoverer
4447
from wlsdeploy.tool.discover.topology_discoverer import TopologyDiscoverer
@@ -52,6 +55,7 @@
5255
from wlsdeploy.util import cla_helper
5356
from wlsdeploy.util import cla_utils
5457
from wlsdeploy.util import env_helper
58+
from wlsdeploy.util import getcreds
5559
from wlsdeploy.util import model_translator
5660
from wlsdeploy.util import path_helper
5761
from wlsdeploy.util import tool_main
@@ -60,6 +64,7 @@
6064
from wlsdeploy.util.exit_code import ExitCode
6165
from wlsdeploy.util.model import Model
6266
from wlsdeploy.util import target_configuration_helper
67+
from wlsdeploy.util import unicode_helper as str_helper
6368

6469
wlst_helper.wlst_functions = globals()
6570

@@ -96,6 +101,10 @@
96101
CommandLineArgUtil.PASSPHRASE_FILE_SWITCH,
97102
CommandLineArgUtil.PASSPHRASE_PROMPT_SWITCH,
98103
CommandLineArgUtil.DISCOVER_SECURITY_PROVIDER_DATA_SWITCH,
104+
CommandLineArgUtil.DISCOVER_OPSS_WALLET_SWITCH,
105+
CommandLineArgUtil.OPSS_WALLET_PASSPHRASE_SWITCH,
106+
CommandLineArgUtil.OPSS_WALLET_PASSPHRASE_ENV_SWITCH,
107+
CommandLineArgUtil.OPSS_WALLET_PASSPHRASE_FILE_SWITCH,
99108
CommandLineArgUtil.TARGET_SWITCH,
100109
CommandLineArgUtil.REMOTE_SWITCH,
101110
CommandLineArgUtil.SSH_HOST_SWITCH,
@@ -140,6 +149,7 @@ def __process_args(args, is_encryption_supported):
140149

141150
model_context = model_context_helper.create_context(_program_name, argument_map)
142151
__validate_discover_passwords_and_security_data_args(model_context, argument_map, is_encryption_supported)
152+
__validate_discover_opss_wallet_args(model_context, argument_map, is_encryption_supported)
143153
model_context.get_validate_configuration().set_disregard_version_invalid_elements(True)
144154
return model_context
145155

@@ -280,13 +290,22 @@ def __validate_discover_passwords_and_security_data_args(model_context, argument
280290
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
281291
raise ex
282292
elif model_context.is_discover_security_provider_data():
293+
if model_context.get_target_wlst_mode() == WlstModes.OFFLINE:
294+
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR, 'WLSDPLY-06059',_program_name,
295+
CommandLineArgUtil.DISCOVER_SECURITY_PROVIDER_DATA_SWITCH)
296+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
297+
raise ex
298+
283299
# -remote cannot be supported because we need access to the exported data files and possibly SSI.dat.
284300
if model_context.is_remote():
285301
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR, 'WLSDPLY-06058',_program_name,
286302
CommandLineArgUtil.DISCOVER_SECURITY_PROVIDER_DATA_SWITCH,
287303
CommandLineArgUtil.REMOTE_SWITCH)
288304
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
289305
raise ex
306+
elif model_context.is_discover_opss_wallet():
307+
# Allow the encryption passphrase
308+
pass
290309
elif model_context.get_encryption_passphrase() is not None:
291310
# Don't allow the passphrase arg unless we are discovering passwords or security provider data.
292311
if CommandLineArgUtil.PASSPHRASE_ENV_SWITCH in argument_map:
@@ -323,7 +342,8 @@ def __validate_discover_passwords_and_security_data_args(model_context, argument
323342
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
324343
raise ex
325344

326-
if model_context.is_discover_passwords() or model_context.is_discover_security_provider_data():
345+
if model_context.is_discover_passwords() or model_context.is_discover_security_provider_data() or \
346+
model_context.is_discover_opss_wallet():
327347
if not model_context.is_encrypt_discovered_passwords() and model_context.get_encryption_passphrase() is not None:
328348
# don't allow turning off encryption and supplying an encryption passphrase
329349
if model_context.is_discover_passwords():
@@ -345,6 +365,36 @@ def __validate_discover_passwords_and_security_data_args(model_context, argument
345365
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
346366
raise ex
347367

368+
369+
def __validate_discover_opss_wallet_args(model_context, argument_map, is_encryption_supported):
370+
_method_name = '__validate_discover_opss_wallet_args'
371+
372+
if CommandLineArgUtil.DISCOVER_OPSS_WALLET_SWITCH in argument_map:
373+
if model_context.get_target_wlst_mode() == WlstModes.OFFLINE:
374+
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR, 'WLSDPLY-06060',_program_name,
375+
CommandLineArgUtil.DISCOVER_OPSS_WALLET_SWITCH)
376+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
377+
raise ex
378+
379+
# Cannot verify that JRF is installed because the model_content is not fully
380+
# initialized at this point so the domain typedef is not available.
381+
if model_context.get_opss_wallet_passphrase() is None:
382+
try:
383+
passphrase_char_array = getcreds.getpass('WLSDPLY-06061')
384+
except IOException, ioe:
385+
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,'WLSDPLY-06062',
386+
ioe.getLocalizedMessage(), error=ioe)
387+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
388+
raise ex
389+
390+
if passphrase_char_array is not None:
391+
opss_wallet_passphrase = str_helper.to_string(String(passphrase_char_array))
392+
model_context.set_opss_wallet_passphrase(opss_wallet_passphrase)
393+
else:
394+
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,'WLSDPLY-06063')
395+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
396+
raise ex
397+
348398
def __discover(model_context, aliases, credential_injector, helper, extra_tokens):
349399
"""
350400
Populate the model from the domain.
@@ -378,6 +428,8 @@ def __discover(model_context, aliases, credential_injector, helper, extra_tokens
378428
extra_tokens=extra_tokens).discover()
379429
SecurityProviderDataDiscoverer(model_context, model, base_location, wlst_mode=__wlst_mode, aliases=aliases,
380430
credential_injector=credential_injector).discover(security_provider_map)
431+
OpssWalletDiscoverer(model_context, model.get_model_domain_info(), base_location, wlst_mode=__wlst_mode,
432+
aliases=aliases, credential_injector=credential_injector).discover()
381433
__discover_multi_tenant(model, model_context, base_location, aliases, credential_injector)
382434
except AliasException, ae:
383435
wls_version = model_context.get_effective_wls_version()

core/src/main/python/wlsdeploy/tool/create/domain_creator.py

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def __extend_domain_with_select_template(self, domain_home):
437437
fmw_ds_names = []
438438
if len(extension_templates) > 0:
439439
fmw_ds_names = self.rcu_helper.configure_fmw_infra_database()
440-
self.__configure_opss_secrets()
440+
self.__configure_opss_wallet_and_passphrase()
441441

442442
topology_folder_list = self.aliases.get_model_topology_top_level_folder_names()
443443
topology_folder_list.remove(SECURITY)
@@ -1055,30 +1055,50 @@ def __run_post_create_domain_script(self):
10551055
self.logger.info('WLSDPLY-12576', script, class_name=self.__class_name, method_name=_method_name)
10561056
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
10571057

1058-
def __configure_opss_secrets(self):
1059-
_method_name = '__configure_opss_secrets'
1058+
def __configure_opss_wallet_and_passphrase(self):
1059+
_method_name = '__configure_opss_wallet_and_passphrase'
10601060
self.logger.entering(class_name=self.__class_name, method_name=_method_name)
10611061

10621062
if not self._domain_typedef.has_jrf_with_database_store():
10631063
return
10641064

1065-
domain_info = self._domain_info
1065+
# Check the model for the OPSS wallet passphrase first
1066+
key = 'WLSDPLY-12579'
10661067
opss_wallet_password = None
1067-
if OPSS_WALLET_PASSPHRASE in domain_info:
1068-
opss_wallet_password = domain_info[OPSS_WALLET_PASSPHRASE]
1069-
elif OPSS_SECRETS in domain_info:
1068+
if OPSS_WALLET_PASSPHRASE in self._domain_info:
1069+
opss_wallet_password = self.aliases.decrypt_password(self._domain_info[OPSS_WALLET_PASSPHRASE])
1070+
elif OPSS_SECRETS in self._domain_info:
10701071
self.logger.deprecation('WLSDPLY-22000', OPSS_SECRETS, OPSS_WALLET_PASSPHRASE,
10711072
class_name=self.__class_name, method_name=_method_name)
1072-
opss_wallet_password = domain_info[OPSS_SECRETS]
1073+
opss_wallet_password = self.aliases.decrypt_password(self._domain_info[OPSS_SECRETS])
10731074

1074-
if opss_wallet_password is not None:
1075-
if self.archive_helper and opss_wallet_password:
1076-
extract_path = self.archive_helper.extract_opss_wallet()
1077-
self.wlst_helper.set_shared_secret_store_with_password(extract_path, opss_wallet_password)
1078-
else:
1079-
opss_wallet_password = self.model_context.get_opss_wallet_passphrase()
1080-
opss_wallet = self.model_context.get_opss_wallet()
1081-
if opss_wallet is not None and opss_wallet_password is not None:
1075+
# Check the command-line args for the OPSS wallet passphrase
1076+
# and give it preference over the one in the model.
1077+
cla_passphrase = self.model_context.get_opss_wallet_passphrase()
1078+
if not string_utils.is_empty(cla_passphrase):
1079+
opss_wallet_password = cla_passphrase
1080+
key = 'WLSDPLY-12580'
1081+
1082+
if not string_utils.is_empty(opss_wallet_password):
1083+
opss_wallet = None
1084+
1085+
# Check the archive for the OPSS wallet and extract it, if present
1086+
if self.archive_helper:
1087+
opss_wallet = self.archive_helper.extract_opss_wallet()
1088+
1089+
# Check the OPSS wallet in the command-line args and give it
1090+
# preference over the one in the archive.
1091+
cla__wallet = self.model_context.get_opss_wallet()
1092+
if not string_utils.is_empty(cla__wallet):
1093+
opss_wallet = cla__wallet
1094+
1095+
if not string_utils.is_empty(opss_wallet):
10821096
self.wlst_helper.set_shared_secret_store_with_password(opss_wallet, opss_wallet_password)
1097+
else:
1098+
# It seems like the user wanted to create a domain with
1099+
# RCU schemas and attach to the existing RCU schemas.
1100+
ex = exception_helper.create_create_exception(key)
1101+
self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
1102+
raise ex
10831103

10841104
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)

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

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def __init__(self, model_context, base_location, wlst_mode, aliases=None, creden
7777
self._mbean_utils = MBeanUtils(self._model_context, self._aliases, ExceptionType.DISCOVER)
7878
self._wls_version = model_context.get_effective_wls_version()
7979
self.path_helper = path_helper.get_path_helper()
80+
self._export_tmp_directory = None
81+
self._local_tmp_directory = None
8082

8183
if model_context.is_ssh():
8284
if _ssh_download_dir is None:
@@ -95,7 +97,7 @@ def __init__(self, model_context, base_location, wlst_mode, aliases=None, creden
9597
'SerializedSystemIni.dat')
9698
self.download_deployment_from_remote_server(remote_ssi_dat, _ssh_download_dir, 'security')
9799

98-
self.download_temporary_dir = _ssh_download_dir
100+
self.download_temporary_dir = _ssh_download_dir
99101

100102
def add_to_remote_map(self, local_name, archive_name, file_type):
101103
# we don't know the remote machine type, so automatically
@@ -909,6 +911,52 @@ def wlst_cd(self, path, location):
909911
class_name=_class_name, method_name=_method_name)
910912
return result
911913

914+
def _create_tmp_directories(self, error_key):
915+
"""
916+
Create the temporary directory(ies) required for exporting the data files and reading the data files.
917+
In the case of SSH, the export directory is remote and the read directory is local. Otherwise, they are
918+
the same.
919+
:return:
920+
"""
921+
_method_name = '_create_tmp_directories'
922+
_logger.entering(error_key, class_name=_class_name, method_name=_method_name)
923+
if self._model_context.is_ssh():
924+
export_tmp_directory = \
925+
self._model_context.get_ssh_context().create_temp_directory_for_security_data_export()
926+
local_tmp_directory = self.download_temporary_dir
927+
else:
928+
try:
929+
export_dir_file = FileUtils.createTempDirectory('wdt_export_temp')
930+
# comment out this line to see exported files...
931+
export_dir_file.deleteOnExit()
932+
except IOException, e:
933+
ex = exception_helper.create_discover_exception(error_key,e.getLocalizedMessage(), error=e)
934+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
935+
raise ex
936+
export_tmp_directory = export_dir_file.getAbsolutePath()
937+
local_tmp_directory = export_tmp_directory
938+
939+
_logger.exiting(class_name=_class_name, method_name=_method_name,
940+
result=[export_tmp_directory, local_tmp_directory])
941+
return export_tmp_directory, local_tmp_directory
942+
943+
def _clean_up_tmp_directories(self, error_key):
944+
_method_name = '_clean_up_tmp_directories'
945+
_logger.entering(class_name=_class_name, method_name=_method_name)
946+
947+
# local directory in both SSH and non-SSH case is already set with java.io.File.deleteOnExit() so
948+
# the only cleanup needed is the temp directory on the SSH host machine, if applicable.
949+
if self._model_context.is_ssh():
950+
ssh_helper = self._model_context.get_ssh_context()
951+
try:
952+
if ssh_helper.does_directory_exist(self._export_tmp_directory):
953+
ssh_helper.remove_file_or_directory(self._export_tmp_directory)
954+
except DiscoverException, de:
955+
# Best effort to remove. If remove fails, log a warning and continue...
956+
_logger.warning(error_key, self._export_tmp_directory, self._model_context.get_ssh_host(),
957+
de.getLocalizedMessage(), class_name=_class_name, method_name=_method_name)
958+
959+
_logger.exiting(class_name=_class_name, method_name=_method_name)
912960
def _validate_artificial_folder_name(self, folder_name, location):
913961
"""
914962
Validate the folder name.

0 commit comments

Comments
 (0)