|
10 | 10 | from java.io import IOException
|
11 | 11 | from java.lang import IllegalArgumentException
|
12 | 12 | from java.lang import String
|
| 13 | +from java.lang import System |
13 | 14 |
|
14 | 15 | from oracle.weblogic.deploy.util import FileUtils
|
15 | 16 | from oracle.weblogic.deploy.util import TranslateException
|
|
25 | 26 | from wlsdeploy.util import cla_utils
|
26 | 27 | from wlsdeploy.util import env_helper
|
27 | 28 | from wlsdeploy.util import getcreds
|
| 29 | +from wlsdeploy.util import model_config |
28 | 30 | from wlsdeploy.util import model_helper
|
29 | 31 | from wlsdeploy.util import model_translator
|
30 | 32 | from wlsdeploy.util import path_helper
|
31 | 33 | from wlsdeploy.util import string_utils
|
| 34 | +from wlsdeploy.util import unicode_helper as str_helper |
32 | 35 |
|
33 | 36 | from wlsdeploy.util import variables
|
34 | 37 | from wlsdeploy.util.cla_utils import CommandLineArgUtil
|
35 | 38 | from wlsdeploy.util.exit_code import ExitCode
|
36 | 39 | from wlsdeploy.util.model_translator import FileToPython
|
37 | 40 | from wlsdeploy.exception.exception_helper import create_cla_exception
|
38 | 41 |
|
| 42 | +MODEL_ENCRYPTION_SECRET_KEY = 'passphrase' |
39 | 43 |
|
40 | 44 | __logger = PlatformLogger('wlsdeploy.util')
|
41 | 45 | _class_name = 'cla_helper'
|
@@ -149,18 +153,42 @@ def process_encryption_args(optional_arg_map, is_encryption_supported):
|
149 | 153 | """
|
150 | 154 | _method_name = '__process_encryption_args'
|
151 | 155 |
|
| 156 | + if is_encryption_supported and CommandLineArgUtil.PASSPHRASE_SWITCH not in optional_arg_map: |
| 157 | + if CommandLineArgUtil.PASSPHRASE_PROMPT_SWITCH in optional_arg_map: |
| 158 | + try: |
| 159 | + passphrase = getcreds.getpass('WLSDPLY-20002') |
| 160 | + except IOException, ioe: |
| 161 | + ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR, |
| 162 | + 'WLSDPLY-20003', ioe.getLocalizedMessage(), error=ioe) |
| 163 | + __logger.throwing(ex, class_name=_class_name, method_name=_method_name) |
| 164 | + raise ex |
152 | 165 |
|
153 |
| - if is_encryption_supported and \ |
154 |
| - CommandLineArgUtil.PASSPHRASE_PROMPT_SWITCH in optional_arg_map and \ |
155 |
| - CommandLineArgUtil.PASSPHRASE_SWITCH not in optional_arg_map: |
156 |
| - try: |
157 |
| - passphrase = getcreds.getpass('WLSDPLY-20002') |
158 |
| - except IOException, ioe: |
159 |
| - ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR, |
160 |
| - 'WLSDPLY-20003', ioe.getLocalizedMessage(), error=ioe) |
161 |
| - __logger.throwing(ex, class_name=_class_name, method_name=_method_name) |
162 |
| - raise ex |
163 |
| - optional_arg_map[CommandLineArgUtil.PASSPHRASE_SWITCH] = String(passphrase) |
| 166 | + optional_arg_map[CommandLineArgUtil.PASSPHRASE_SWITCH] = String(passphrase) |
| 167 | + return |
| 168 | + |
| 169 | + # the encryption passphrase may be in a secret specified by an environment variable. |
| 170 | + # the variable uses the same naming prefix as tool.properties |
| 171 | + env_variable_name = model_config.SYS_PROP_PREFIX + "model.encryption.secret" |
| 172 | + secret_name = System.getProperty(env_variable_name, None) |
| 173 | + if secret_name: |
| 174 | + # we can't use similar methods in variable module, model context is not established, |
| 175 | + # and we don't want to depend on strict/lax mode. |
| 176 | + passphrase = None |
| 177 | + locations = env_helper.getenv(str_helper.to_string(variables.SECRET_DIRS_VARIABLE)) |
| 178 | + if locations is not None: |
| 179 | + for secret_dir in locations.split(","): |
| 180 | + secret_path = os.path.join(secret_dir, secret_name, MODEL_ENCRYPTION_SECRET_KEY) |
| 181 | + if os.path.isfile(secret_path): |
| 182 | + __logger.info('WLSDPLY-02300', secret_path) |
| 183 | + passphrase = cla_utils.get_from_file_value(secret_path) |
| 184 | + optional_arg_map[CommandLineArgUtil.PASSPHRASE_SWITCH] = passphrase |
| 185 | + break |
| 186 | + |
| 187 | + if not passphrase: |
| 188 | + ex = exception_helper.create_cla_exception( |
| 189 | + ExitCode.ARG_VALIDATION_ERROR, 'WLSDPLY-02301', secret_name, locations) |
| 190 | + __logger.throwing(ex, class_name=_class_name, method_name=_method_name) |
| 191 | + raise ex |
164 | 192 |
|
165 | 193 |
|
166 | 194 | def validate_model(program_name, model_dictionary, model_context, aliases, wlst_mode,
|
|
0 commit comments