Skip to content

Commit a3dbe87

Browse files
jshum2479ddsharpe
authored andcommitted
Added OPSS to CLI (#440)
* add command line option for opss key import * add prompting for opss passphrase
1 parent 757aecd commit a3dbe87

File tree

5 files changed

+120
-12
lines changed

5 files changed

+120
-12
lines changed

core/src/main/python/create.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
CommandLineArgUtil.VARIABLE_FILE_SWITCH,
7878
CommandLineArgUtil.USE_ENCRYPTION_SWITCH,
7979
CommandLineArgUtil.PASSPHRASE_SWITCH,
80+
CommandLineArgUtil.OPSS_WALLET_SWITCH,
81+
CommandLineArgUtil.OPSS_WALLET_PASSPHRASE
8082
]
8183

8284

@@ -103,7 +105,8 @@ def __process_args(args):
103105

104106
__process_rcu_args(optional_arg_map, domain_type, domain_typedef)
105107
__process_encryption_args(optional_arg_map)
106-
108+
__process_opss_args(optional_arg_map)
109+
107110
combined_arg_map = optional_arg_map.copy()
108111
combined_arg_map.update(required_arg_map)
109112
model_context = ModelContext(_program_name, combined_arg_map)
@@ -264,6 +267,29 @@ def __process_encryption_args(optional_arg_map):
264267
return
265268

266269

270+
def __process_opss_args(optional_arg_map):
271+
"""
272+
Determine if the user is using opss wallet and if so, get the passphrase.
273+
:param optional_arg_map: the optional arguments map
274+
:raises CLAException: if getting the passphrase from the user fails
275+
"""
276+
_method_name = '__process_opss_args'
277+
278+
if CommandLineArgUtil.OPSS_WALLET_SWITCH in optional_arg_map and \
279+
CommandLineArgUtil.OPSS_WALLET_PASSPHRASE not in optional_arg_map:
280+
try:
281+
passphrase = getcreds.getpass('WLSDPLY-20027')
282+
except IOException, ioe:
283+
ex = exception_helper.create_cla_exception('WLSDPLY-20028', ioe.getLocalizedMessage(),
284+
error=ioe)
285+
ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
286+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
287+
raise ex
288+
optional_arg_map[CommandLineArgUtil.OPSS_WALLET_PASSPHRASE] = String(passphrase)
289+
return
290+
291+
292+
267293
def validate_model(model_dictionary, model_context, aliases):
268294
_method_name = 'validate_model'
269295

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,16 +1164,20 @@ def __configure_opss_secrets(self):
11641164
return
11651165

11661166
self.logger.entering(class_name=self.__class_name, method_name=_method_name)
1167-
extract_path = None
11681167
domain_info = self._domain_info
1169-
if domain_info is not None:
1170-
if OPSS_SECRETS in domain_info:
1171-
opss_secret_password = domain_info[OPSS_SECRETS]
1172-
if self.model_context.get_archive_file_name() and opss_secret_password:
1173-
archive_file = WLSDeployArchive(self.model_context.get_archive_file_name())
1174-
extract_path = self._domain_home + os.sep + 'opsswallet'
1175-
zip_entry = archive_file.getOPSSWallet();
1176-
FileUtils.extractZipFileContent(archive_file, zip_entry, extract_path)
1177-
self.wlst_helper.setSharedSecretStoreWithPassword(extract_path, opss_secret_password)
1168+
if OPSS_SECRETS in domain_info:
1169+
opss_secret_password = domain_info[OPSS_SECRETS]
1170+
if self.model_context.get_archive_file_name() and opss_secret_password:
1171+
archive_file = WLSDeployArchive(self.model_context.get_archive_file_name())
1172+
extract_path = self._domain_home + os.sep + 'opsswallet'
1173+
zip_entry = archive_file.getOPSSWallet();
1174+
FileUtils.extractZipFileContent(archive_file, zip_entry, extract_path)
1175+
self.wlst_helper.setSharedSecretStoreWithPassword(extract_path, opss_secret_password)
1176+
else:
1177+
opss_secret_password = self.model_context.get_opss_wallet_passphrase()
1178+
opss_wallet = self.model_context.get_opss_wallet()
1179+
if opss_wallet is not None and opss_secret_password is not None:
1180+
self.wlst_helper.setSharedSecretStoreWithPassword(opss_wallet, opss_secret_password)
1181+
11781182
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
1179-
return extract_path
1183+
return

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class CommandLineArgUtil(object):
4141
ADMIN_PASS_SWITCH = '-admin_pass'
4242
ARCHIVE_FILE_SWITCH = '-archive_file'
4343
MODEL_FILE_SWITCH = '-model_file'
44+
OPSS_WALLET_SWITCH = '-opss_wallet'
45+
OPSS_WALLET_PASSPHRASE = '-opss_wallet_passphrase'
4446
PREVIOUS_MODEL_FILE_SWITCH = '-prev_model_file'
4547
VARIABLE_FILE_SWITCH = '-variable_file'
4648
PRINT_USAGE_SWITCH = '-print_usage'
@@ -233,6 +235,24 @@ def process_args(self, args, for_domain_create=False):
233235
ex = self._get_out_of_args_exception(key)
234236
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
235237
raise ex
238+
elif self.is_opss_passphrase_key(key):
239+
idx += 1
240+
if idx < args_len:
241+
self._validate_opss_passphrase_arg(args[idx])
242+
self._add_arg(key, args[idx])
243+
else:
244+
ex = self._get_out_of_args_exception(key)
245+
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
246+
raise ex
247+
elif self.is_opss_wallet_key(key):
248+
idx += 1
249+
if idx < args_len:
250+
full_path = self._validate_opss_wallet_arg(args[idx])
251+
self._add_arg(key, full_path, True)
252+
else:
253+
ex = self._get_out_of_args_exception(key)
254+
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
255+
raise ex
236256
elif self.is_model_file_key(key):
237257
idx += 1
238258
if idx < args_len:
@@ -657,6 +677,39 @@ def _validate_archive_file_arg(self, value):
657677
raise ex
658678
return archive.getAbsolutePath()
659679

680+
def get_opss_passphrase_key(self):
681+
return self.OPSS_WALLET_PASSPHRASE
682+
683+
def is_opss_passphrase_key(self, key):
684+
685+
return self.OPSS_WALLET_PASSPHRASE == key
686+
687+
def _validate_opss_passphrase_arg(self, value):
688+
method_name = '_validate_opss_passphrase_arg'
689+
if value is None or len(value) == 0:
690+
ex = exception_helper.create_cla_exception('WLSDPLY-01615')
691+
ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
692+
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
693+
raise ex
694+
return
695+
696+
def get_opss_wallet_key(self):
697+
return self.OPSS_WALLET_SWITCH
698+
699+
def is_opss_wallet_key(self, key):
700+
return self.OPSS_WALLET_SWITCH == key
701+
702+
def _validate_opss_wallet_arg(self, value):
703+
method_name = '_validate_opss_wallet_arg'
704+
try:
705+
opss_wallet = JFileUtils.validateDirectoryName(value)
706+
except JIllegalArgumentException, iae:
707+
ex = exception_helper.create_cla_exception('WLSDPLY-01616', value, iae.getLocalizedMessage(), error=iae)
708+
ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
709+
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
710+
raise ex
711+
return opss_wallet.getAbsolutePath()
712+
660713
def get_model_file_key(self):
661714
return self.MODEL_FILE_SWITCH
662715

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ def __init__(self, program_name, arg_map):
6161
self._recursive = False
6262
self._attributes_only = False
6363
self._folders_only = False
64+
self._opss_wallet_passphrase = None
65+
self._opss_wallet = None
6466

6567
if CommandLineArgUtil.ORACLE_HOME_SWITCH in arg_map:
6668
self._oracle_home = arg_map[CommandLineArgUtil.ORACLE_HOME_SWITCH]
@@ -145,6 +147,12 @@ def __init__(self, program_name, arg_map):
145147
if CommandLineArgUtil.ARCHIVE_FILE in arg_map:
146148
self._archive_file = arg_map[CommandLineArgUtil.ARCHIVE_FILE]
147149

150+
if CommandLineArgUtil.OPSS_WALLET_PASSPHRASE in arg_map:
151+
self._opss_wallet_passphrase = arg_map[CommandLineArgUtil.OPSS_WALLET_PASSPHRASE]
152+
153+
if CommandLineArgUtil.OPSS_WALLET_SWITCH in arg_map:
154+
self._opss_wallet = arg_map[CommandLineArgUtil.OPSS_WALLET_SWITCH]
155+
148156
if CommandLineArgUtil.TARGET_VERSION_SWITCH in arg_map:
149157
self._wl_version = arg_map[CommandLineArgUtil.TARGET_VERSION_SWITCH]
150158

@@ -265,6 +273,21 @@ def get_archive_file_name(self):
265273
"""
266274
return self._archive_file_name
267275

276+
def get_opss_wallet(self):
277+
"""
278+
Get the opss wallet.
279+
:return: the opss wallet
280+
"""
281+
return self._opss_wallet
282+
283+
def get_opss_wallet_passphrase(self):
284+
"""
285+
Get the wallet passphrase.
286+
:return: the wallet passphrase
287+
"""
288+
return self._opss_wallet_passphrase
289+
290+
268291
def get_archive_file(self):
269292
"""
270293
Get the archive file.

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,8 @@ WLSDPLY-20023={0} unable to add model file {1} to archive as {2}: {3}
14441444
WLSDPLY-20024={0} failed to persist the model to the archive file {1}: {2}
14451445
WLSDPLY-20025=For {0}, specify the {1} or {2} argument, but not both
14461446
WLSDPLY-20026={0} failed to find a model file in archive {1}, and {2} argument not specified
1447+
WLSDPLY-20027=Enter the OPSS wallet passphrase
1448+
WLSDPLY-20028=Failed to read the OPSS wallet passphrase input from the user: {0}
14471449

14481450
# Common messages used for tool exit and clean-up
14491451
WLSDPLY-21000={0} Messages:

0 commit comments

Comments
 (0)