|
4 | 4 |
|
5 | 5 | The entry point for the discoverDomain tool.
|
6 | 6 | """
|
7 |
| -import os |
| 7 | +import os, re |
8 | 8 | import sys
|
9 | 9 |
|
10 | 10 | from java.io import File
|
|
13 | 13 | from java.lang import IllegalStateException
|
14 | 14 | from java.lang import String
|
15 | 15 | from java.lang import System
|
| 16 | +from java.util import HashSet |
16 | 17 | from oracle.weblogic.deploy.aliases import AliasException
|
17 | 18 | from oracle.weblogic.deploy.discover import DiscoverException
|
18 | 19 | from oracle.weblogic.deploy.json import JsonException
|
|
27 | 28 |
|
28 | 29 | sys.path.insert(0, os.path.dirname(os.path.realpath(sys.argv[0])))
|
29 | 30 |
|
| 31 | +from wlsdeploy.aliases import alias_constants |
30 | 32 | from wlsdeploy.aliases import model_constants
|
31 | 33 | from wlsdeploy.aliases.aliases import Aliases
|
32 | 34 | from wlsdeploy.aliases.location_context import LocationContext
|
33 |
| -from wlsdeploy.aliases.model_constants import DOMAIN_INFO |
34 | 35 | from wlsdeploy.aliases.validation_codes import ValidationCodes
|
35 | 36 | from wlsdeploy.aliases.wlst_modes import WlstModes
|
36 | 37 | from wlsdeploy.exception import exception_helper
|
|
45 | 46 | from wlsdeploy.tool.discover.resources_discoverer import ResourcesDiscoverer
|
46 | 47 | from wlsdeploy.tool.discover.security_provider_data_discoverer import SecurityProviderDataDiscoverer
|
47 | 48 | from wlsdeploy.tool.discover.topology_discoverer import TopologyDiscoverer
|
| 49 | +from wlsdeploy.tool.encrypt import encryption_utils |
48 | 50 | from wlsdeploy.tool.util import filter_helper
|
49 | 51 | from wlsdeploy.tool.util import model_context_helper
|
50 | 52 | from wlsdeploy.tool.util.credential_injector import CredentialInjector
|
|
54 | 56 | from wlsdeploy.tool.validate.validator import Validator
|
55 | 57 | from wlsdeploy.util import cla_helper
|
56 | 58 | from wlsdeploy.util import cla_utils
|
| 59 | +from wlsdeploy.util import dictionary_utils |
57 | 60 | from wlsdeploy.util import env_helper
|
58 | 61 | from wlsdeploy.util import getcreds
|
59 | 62 | from wlsdeploy.util import model_translator
|
|
65 | 68 | from wlsdeploy.util.model import Model
|
66 | 69 | from wlsdeploy.util import target_configuration_helper
|
67 | 70 | from wlsdeploy.util import unicode_helper as str_helper
|
| 71 | +from wlsdeploy.aliases.model_constants import DOMAIN_INFO |
| 72 | +from wlsdeploy.aliases.model_constants import DRIVER_PARAMS_PROPERTY_VALUE |
| 73 | +from wlsdeploy.aliases.model_constants import DRIVER_PARAMS_USER_PROPERTY |
| 74 | +from wlsdeploy.aliases.model_constants import DRIVER_PARAMS_TRUSTSTORE_PROPERTY |
| 75 | +from wlsdeploy.aliases.model_constants import DRIVER_PARAMS_KEYSTORE_PROPERTY |
| 76 | +from wlsdeploy.aliases.model_constants import DRIVER_PARAMS_TRUSTSTORETYPE_PROPERTY |
| 77 | +from wlsdeploy.aliases.model_constants import DRIVER_PARAMS_KEYSTORETYPE_PROPERTY |
| 78 | +from wlsdeploy.aliases.model_constants import DRIVER_PARAMS_TRUSTSTOREPWD_PROPERTY |
| 79 | +from wlsdeploy.aliases.model_constants import DRIVER_PARAMS_KEYSTOREPWD_PROPERTY |
| 80 | +from wlsdeploy.aliases.model_constants import DRIVER_PARAMS_NET_TNS_ADMIN |
| 81 | +from wlsdeploy.aliases.model_constants import JDBC_SYSTEM_RESOURCE |
| 82 | +from wlsdeploy.aliases.model_constants import JDBC_RESOURCE |
| 83 | +from wlsdeploy.aliases.model_constants import JDBC_DRIVER_PARAMS |
| 84 | +from wlsdeploy.aliases.model_constants import ORACLE_DATABASE_CONNECTION_TYPE |
| 85 | +from wlsdeploy.aliases.model_constants import PASSWORD_ENCRYPTED |
| 86 | +from wlsdeploy.aliases.model_constants import PROPERTIES |
| 87 | +from wlsdeploy.aliases.model_constants import RCU_DB_INFO |
| 88 | +from wlsdeploy.aliases.model_constants import RCU_DB_CONN_STRING |
| 89 | +from wlsdeploy.aliases.model_constants import RCU_PREFIX |
| 90 | +from wlsdeploy.aliases.model_constants import RCU_SCHEMA_PASSWORD |
| 91 | +from wlsdeploy.aliases.model_constants import RESOURCES |
| 92 | +from wlsdeploy.aliases.model_constants import URL |
| 93 | + |
| 94 | + |
68 | 95 |
|
69 | 96 | wlst_helper.wlst_functions = globals()
|
70 | 97 |
|
|
101 | 128 | CommandLineArgUtil.PASSPHRASE_FILE_SWITCH,
|
102 | 129 | CommandLineArgUtil.PASSPHRASE_PROMPT_SWITCH,
|
103 | 130 | CommandLineArgUtil.DISCOVER_SECURITY_PROVIDER_DATA_SWITCH,
|
| 131 | + CommandLineArgUtil.DISCOVER_RCU_DATASOURCES_SWITCH, |
104 | 132 | CommandLineArgUtil.DISCOVER_OPSS_WALLET_SWITCH,
|
105 | 133 | CommandLineArgUtil.OPSS_WALLET_PASSPHRASE_SWITCH,
|
106 | 134 | CommandLineArgUtil.OPSS_WALLET_PASSPHRASE_ENV_SWITCH,
|
@@ -326,6 +354,8 @@ def __validate_discover_passwords_and_security_data_args(model_context, argument
|
326 | 354 | elif model_context.is_discover_opss_wallet():
|
327 | 355 | # Allow the encryption passphrase
|
328 | 356 | pass
|
| 357 | + elif model_context.is_discover_rcu_datasources(): |
| 358 | + pass |
329 | 359 | elif model_context.get_encryption_passphrase() is not None:
|
330 | 360 | # Don't allow the passphrase arg unless we are discovering passwords or security provider data.
|
331 | 361 | if CommandLineArgUtil.PASSPHRASE_ENV_SWITCH in argument_map:
|
@@ -394,11 +424,6 @@ def __validate_discover_opss_wallet_args(model_context, argument_map, is_encrypt
|
394 | 424 | _method_name = '__validate_discover_opss_wallet_args'
|
395 | 425 |
|
396 | 426 | if CommandLineArgUtil.DISCOVER_OPSS_WALLET_SWITCH in argument_map:
|
397 |
| - if model_context.get_target_wlst_mode() == WlstModes.OFFLINE: |
398 |
| - ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR, 'WLSDPLY-06060',_program_name, |
399 |
| - CommandLineArgUtil.DISCOVER_OPSS_WALLET_SWITCH) |
400 |
| - __logger.throwing(ex, class_name=_class_name, method_name=_method_name) |
401 |
| - raise ex |
402 | 427 |
|
403 | 428 | # Cannot verify that JRF is installed because the model_content is not fully
|
404 | 429 | # initialized at this point so the domain typedef is not available.
|
@@ -727,6 +752,7 @@ def __check_and_customize_model(model, model_context, aliases, credential_inject
|
727 | 752 | __logger.info('WLSDPLY-06014', _class_name=_class_name, method_name=_method_name)
|
728 | 753 |
|
729 | 754 | filter_helper.apply_final_filters(model.get_model(), model.get_model(), model_context)
|
| 755 | + __fix_discovered_template_datasource(model, model_context) |
730 | 756 |
|
731 | 757 | credential_cache = None
|
732 | 758 | if credential_injector is not None:
|
@@ -764,6 +790,183 @@ def __check_and_customize_model(model, model_context, aliases, credential_inject
|
764 | 790 | __logger.exiting(_class_name, _method_name)
|
765 | 791 | return model
|
766 | 792 |
|
| 793 | +def __fix_discovered_template_datasource(model, model_context): |
| 794 | + # fix the case for discovering template datasources. |
| 795 | + # If all the template datasources use the dame passwords then generate the RUCDbInfo section |
| 796 | + # and remove the template datasources from the model |
| 797 | + # If not using the same passwords then do not generate RCUDbinfo, need to go back to fix the password field value |
| 798 | + |
| 799 | + _method_name = '__fix_discovered_template_datasource' |
| 800 | + __logger.entering(class_name=_class_name, method_name=_method_name) |
| 801 | + |
| 802 | + domain_typedef = model_context.get_domain_typedef() |
| 803 | + if domain_typedef.requires_rcu() and model_context.is_discover_rcu_datasources(): |
| 804 | + resources = model.get_model_resources() |
| 805 | + jdbc_system_resources = dictionary_utils.get_element(resources, JDBC_SYSTEM_RESOURCE) |
| 806 | + discover_filters = domain_typedef._discover_filters |
| 807 | + filtered_ds_patterns = dictionary_utils.get_element(discover_filters,'/JDBCSystemResource') |
| 808 | + passwords = HashSet() |
| 809 | + urls = HashSet() |
| 810 | + prefixes = HashSet() |
| 811 | + properties = __get_urls_and_passwords(model_context, jdbc_system_resources, filtered_ds_patterns, |
| 812 | + urls, passwords, prefixes) |
| 813 | + if _can_generate_rcudb_info(passwords, urls, prefixes): |
| 814 | + __set_rcuinfo_in_model(model, properties, urls[0], passwords[0]) |
| 815 | + __remove_discovered_template_datasource(jdbc_system_resources, filtered_ds_patterns, model) |
| 816 | + __fix_rcudbinfo_passwords(model, model_context, model_context.is_discover_passwords()) |
| 817 | + else: |
| 818 | + __reset_password_to_regular_discovery(jdbc_system_resources, filtered_ds_patterns, model_context) |
| 819 | + |
| 820 | + __logger.exiting(_class_name, _method_name) |
| 821 | + |
| 822 | +def _can_generate_rcudb_info(passwords, urls, prefixes): |
| 823 | + return passwords.size() == 1 and urls.size() == 1 and prefixes.size() == 1 |
| 824 | + |
| 825 | +def __get_urls_and_passwords(model_context, jdbc_system_resources, filtered_ds_patterns, urls, passwords, prefixes): |
| 826 | + properties = None |
| 827 | + for item in jdbc_system_resources: |
| 828 | + if not __match_filtered_ds_name(item, filtered_ds_patterns): |
| 829 | + continue |
| 830 | + jdbc_system_resource = jdbc_system_resources[item] |
| 831 | + jdbc_resource = dictionary_utils.get_element(jdbc_system_resource, JDBC_RESOURCE) |
| 832 | + driver_params = dictionary_utils.get_element(jdbc_resource, JDBC_DRIVER_PARAMS) |
| 833 | + properties = dictionary_utils.get_element(driver_params, PROPERTIES) |
| 834 | + password_encrypted = dictionary_utils.get_element(driver_params, PASSWORD_ENCRYPTED) |
| 835 | + passwords.add(password_encrypted) |
| 836 | + schema_user = __get_driver_param_property_value(properties, DRIVER_PARAMS_USER_PROPERTY) |
| 837 | + prefix = schema_user[0:schema_user.find('_')] |
| 838 | + prefixes.add(prefix) |
| 839 | + url = dictionary_utils.get_element(driver_params, URL) |
| 840 | + urls.add(url) |
| 841 | + |
| 842 | + return properties |
| 843 | + |
| 844 | +def __set_rcuinfo_in_model(model, properties, url, password_encrypted): |
| 845 | + model_dict = model.get_model() |
| 846 | + domain_info = dictionary_utils.get_element(model_dict, DOMAIN_INFO) |
| 847 | + if domain_info is None: |
| 848 | + model_dict[DOMAIN_INFO] = {} |
| 849 | + domain_info = model_dict[DOMAIN_INFO] |
| 850 | + |
| 851 | + schema_user = __get_driver_param_property_value(properties, DRIVER_PARAMS_USER_PROPERTY) |
| 852 | + |
| 853 | + domain_info[RCU_DB_INFO] = {} |
| 854 | + rcudb_info = domain_info[RCU_DB_INFO] |
| 855 | + rcudb_info[RCU_DB_CONN_STRING] = url |
| 856 | + |
| 857 | + rcudb_info[RCU_SCHEMA_PASSWORD] = password_encrypted |
| 858 | + prefix = schema_user[0:schema_user.find('_')] |
| 859 | + rcudb_info[RCU_PREFIX] = prefix |
| 860 | + |
| 861 | + extra_properties = [DRIVER_PARAMS_TRUSTSTORE_PROPERTY, |
| 862 | + DRIVER_PARAMS_KEYSTORE_PROPERTY, |
| 863 | + DRIVER_PARAMS_TRUSTSTORETYPE_PROPERTY, |
| 864 | + DRIVER_PARAMS_KEYSTORETYPE_PROPERTY, |
| 865 | + DRIVER_PARAMS_TRUSTSTOREPWD_PROPERTY, |
| 866 | + DRIVER_PARAMS_KEYSTOREPWD_PROPERTY, |
| 867 | + DRIVER_PARAMS_NET_TNS_ADMIN |
| 868 | + ] |
| 869 | + |
| 870 | + for property in extra_properties: |
| 871 | + __set_rcu_property_ifnecessary(rcudb_info, properties, property) |
| 872 | + |
| 873 | + |
| 874 | + # The ORACLE_DATABASE_CONNECTION_TYPE is only used by WDT for processing |
| 875 | + atp_tns_alias = __find_atp_tns_alias(url) |
| 876 | + if atp_tns_alias is not None: |
| 877 | + # This is just based on the observed pattern in tnsnames.ora file for ATP. |
| 878 | + # we don't set the actual tns.alias since the url format is subjected to change |
| 879 | + rcudb_info[ORACLE_DATABASE_CONNECTION_TYPE] = 'ATP' |
| 880 | + elif __test_if_ssl_properties_are_set(properties): |
| 881 | + rcudb_info[ORACLE_DATABASE_CONNECTION_TYPE] = 'SSL' |
| 882 | + |
| 883 | +def __test_if_ssl_properties_are_set(properties): |
| 884 | + keystore_property = __get_driver_param_property_value(properties, DRIVER_PARAMS_KEYSTORE_PROPERTY) |
| 885 | + truststore_property = __get_driver_param_property_value(properties, DRIVER_PARAMS_TRUSTSTORE_PROPERTY) |
| 886 | + if keystore_property is not None and truststore_property is not None: |
| 887 | + return True |
| 888 | + return False |
| 889 | + |
| 890 | +def __find_atp_tns_alias(url): |
| 891 | + pattern = r'\(service_name=([a-zA-Z0-9]+)_([a-zA-Z0-9_]+)\.adb\.oraclecloud\.com\)' |
| 892 | + match = re.search(pattern, url) |
| 893 | + if match: |
| 894 | + return match.group(2) |
| 895 | + else: |
| 896 | + return None |
| 897 | + |
| 898 | +def __set_rcu_property_ifnecessary(rcu_db_info, properties, name): |
| 899 | + value = __get_driver_param_property_value(properties, name) |
| 900 | + if value is not None: |
| 901 | + rcu_db_info[name] = value |
| 902 | + |
| 903 | +def __get_driver_param_property_value(properties, name): |
| 904 | + try: |
| 905 | + prop = dictionary_utils.get_element(properties, name) |
| 906 | + value = dictionary_utils.get_element(prop, DRIVER_PARAMS_PROPERTY_VALUE) |
| 907 | + return value |
| 908 | + except: |
| 909 | + return None |
| 910 | + |
| 911 | +def __remove_discovered_template_datasource(jdbc_system_resources, filtered_ds_patterns, model): |
| 912 | + remove_items = [] |
| 913 | + for item in jdbc_system_resources: |
| 914 | + if not __match_filtered_ds_name(item, filtered_ds_patterns): |
| 915 | + continue |
| 916 | + remove_items.append(item) |
| 917 | + |
| 918 | + for item in remove_items: |
| 919 | + del jdbc_system_resources[item] |
| 920 | + |
| 921 | + if len(jdbc_system_resources) == 0: |
| 922 | + model_dict = model.get_model() |
| 923 | + resources = model_dict[RESOURCES] |
| 924 | + del resources[JDBC_SYSTEM_RESOURCE] |
| 925 | + if len(resources) == 0: |
| 926 | + del model_dict[RESOURCES] |
| 927 | + |
| 928 | +def __reset_password_to_regular_discovery(jdbc_system_resources, filtered_ds_patterns, model_context): |
| 929 | + for item in jdbc_system_resources: |
| 930 | + if not __match_filtered_ds_name(item, filtered_ds_patterns): |
| 931 | + continue |
| 932 | + jdbc_system_resource = jdbc_system_resources[item] |
| 933 | + jdbc_resource = dictionary_utils.get_element(jdbc_system_resource, JDBC_RESOURCE) |
| 934 | + driver_params = dictionary_utils.get_element(jdbc_resource, JDBC_DRIVER_PARAMS) |
| 935 | + jdbc_ds_password = driver_params[PASSWORD_ENCRYPTED] |
| 936 | + if model_context.is_discover_passwords(): |
| 937 | + encrypted_model_value = encryption_utils.encrypt_one_password( |
| 938 | + model_context.get_encryption_passphrase(), jdbc_ds_password) |
| 939 | + driver_params[PASSWORD_ENCRYPTED] = encrypted_model_value |
| 940 | + else: |
| 941 | + driver_params[PASSWORD_ENCRYPTED] = alias_constants.PASSWORD_TOKEN |
| 942 | + return |
| 943 | + |
| 944 | +def __fix_rcudbinfo_passwords(model, model_context, encrypt=False): |
| 945 | + |
| 946 | + model_dict = model.get_model() |
| 947 | + rcudb_info = model_dict[DOMAIN_INFO][RCU_DB_INFO] |
| 948 | + |
| 949 | + possible_pwds = [ |
| 950 | + RCU_SCHEMA_PASSWORD, |
| 951 | + DRIVER_PARAMS_TRUSTSTOREPWD_PROPERTY, |
| 952 | + DRIVER_PARAMS_KEYSTOREPWD_PROPERTY |
| 953 | + ] |
| 954 | + |
| 955 | + for item in possible_pwds: |
| 956 | + if item in rcudb_info: |
| 957 | + if encrypt: |
| 958 | + passwd = rcudb_info[item] |
| 959 | + rcudb_info[item] = encryption_utils.encrypt_one_password( |
| 960 | + model_context.get_encryption_passphrase(), passwd) |
| 961 | + else: |
| 962 | + rcudb_info[item] = alias_constants.PASSWORD_TOKEN |
| 963 | + |
| 964 | +def __match_filtered_ds_name(name, patterns): |
| 965 | + for pattern in patterns: |
| 966 | + regex = re.compile(pattern) |
| 967 | + if regex.match(name): |
| 968 | + return True |
| 969 | + return False |
767 | 970 |
|
768 | 971 | def __generate_remote_report_json(model_context):
|
769 | 972 | _method_name = '__remote_report'
|
|
0 commit comments