2
2
Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates. All rights reserved.
3
3
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
4
"""
5
+ import os .path
5
6
from java .lang import IllegalArgumentException
6
7
7
8
from oracle .weblogic .deploy .util import PyOrderedDict as OrderedDict
@@ -91,6 +92,7 @@ def get_datasources(self):
91
92
location = LocationContext (self ._base_location )
92
93
location .append_location (model_top_folder_name )
93
94
datasources = self ._find_names_in_folder (location )
95
+ collected_wallet = {}
94
96
if datasources is not None :
95
97
_logger .info ('WLSDPLY-06340' , len (datasources ), class_name = _class_name , method_name = _method_name )
96
98
typedef = self ._model_context .get_domain_typedef ()
@@ -112,11 +114,126 @@ def get_datasources(self):
112
114
resource_result = result [datasource ][model_second_folder ]
113
115
self ._populate_model_parameters (resource_result , location )
114
116
self ._discover_subfolders (resource_result , location )
117
+ self ._collect_jdbc_driver_wallet (datasource , collected_wallet ,
118
+ result [datasource ][model_constants .JDBC_RESOURCE ][model_constants .JDBC_DRIVER_PARAMS ])
115
119
location .remove_name_token (name_token )
116
120
location .pop_location ()
117
121
_logger .exiting (class_name = _class_name , method_name = _method_name , result = result )
118
122
return model_top_folder_name , result
119
123
124
+ def _collect_jdbc_driver_wallet (self , datasource , collected_wallet , driver_params ):
125
+ if not self ._model_context .skip_archive () and model_constants .JDBC_DRIVER_PARAMS_PROPERTIES in driver_params :
126
+ properties = driver_params [model_constants .JDBC_DRIVER_PARAMS_PROPERTIES ]
127
+ self ._update_wallet_property_and_collect_files (collected_wallet , datasource , properties )
128
+
129
+ def _update_wallet_property_and_collect_files (self , collected_wallet , datasource , properties ):
130
+ _method_name = '_update_wallet_property_and_collect_files'
131
+ for connection_property in [model_constants .DRIVER_PARAMS_KEYSTORE_PROPERTY ,
132
+ model_constants .DRIVER_PARAMS_TRUSTSTORE_PROPERTY ,
133
+ model_constants .DRIVER_PARAMS_NET_TNS_ADMIN ]:
134
+ if connection_property in properties :
135
+ qualified_property_value = properties [connection_property ]['Value' ]
136
+ if qualified_property_value :
137
+ if qualified_property_value .startswith (WLSDeployArchive .WLSDPLY_ARCHIVE_BINARY_DIR
138
+ + WLSDeployArchive .ZIP_SEP ):
139
+ qualified_property_value = os .path .join (self ._model_context .get_domain_home ()
140
+ , qualified_property_value )
141
+ if os .path .exists (qualified_property_value ):
142
+ fixed_path = self ._add_wallet_directory_to_archive (datasource , collected_wallet ,
143
+ qualified_property_value )
144
+ _logger .info ('WLSDPLY-06367' , connection_property , fixed_path ,
145
+ class_name = _class_name , method_name = _method_name )
146
+ properties [connection_property ]['Value' ] = fixed_path
147
+ else :
148
+ _logger .severe ('WLSDPLY-06370' , datasource , connection_property ,
149
+ properties [connection_property ]['Value' ])
150
+ de = exception_helper .create_discover_exception ('WLSDPLY-06370' , datasource ,
151
+ connection_property ,
152
+ properties [connection_property ][
153
+ 'Value' ])
154
+ _logger .throwing (class_name = _class_name , method_name = _method_name , error = de )
155
+ raise de
156
+
157
+ def _add_wallet_directory_to_archive (self , datasource , collected_wallet_dictionary , property_value ):
158
+ # error if wallet parent path is at oracle home
159
+ onprem_wallet_parent_path , wallet_name = self ._get_wallet_name_and_path (datasource , property_value )
160
+
161
+ if self ._model_context .is_remote ():
162
+ fixed_path = WLSDeployArchive .getDatabaseWalletArchivePath (wallet_name , property_value )
163
+ self .add_to_remote_map (property_value , fixed_path ,
164
+ WLSDeployArchive .ArchiveEntryType .DB_WALLET .name ())
165
+ return fixed_path
166
+
167
+ onprem_wallet_dir_is_not_flat = self ._is_on_prem_wallet_dir_flat (onprem_wallet_parent_path , property_value )
168
+ archive_file = self ._model_context .get_archive_file ()
169
+
170
+ # keep track of the wallet name and from where it is collected
171
+ # { <onprem_wallet_parentpath> : { 'wallet_name': <name>, 'path_into_archive': <wallet path into archive>,
172
+ # },
173
+ # .... }
174
+ #
175
+ if onprem_wallet_parent_path not in collected_wallet_dictionary :
176
+ if onprem_wallet_dir_is_not_flat :
177
+ # collect the specific file
178
+ fixed_path = archive_file .addDatabaseWallet (wallet_name , os .path .abspath (property_value ))
179
+ path_into_archive = os .path .dirname (fixed_path )
180
+ else :
181
+ fixed_path = archive_file .addDatabaseWallet (wallet_name , onprem_wallet_parent_path )
182
+ path_into_archive = fixed_path
183
+ fixed_path = os .path .join (fixed_path , os .path .basename (property_value ))
184
+
185
+ collected_wallet_dictionary [onprem_wallet_parent_path ] = \
186
+ {'wallet_name' : wallet_name , 'path_into_archive' : path_into_archive }
187
+ else :
188
+ # if the directory has already been visited before
189
+ # check for the wallet to see if the file has already been collected on prem and add only the file
190
+ check_path = os .path .join (
191
+ collected_wallet_dictionary [onprem_wallet_parent_path ]['path_into_archive' ],
192
+ os .path .basename (property_value ))
193
+ if check_path not in archive_file .getArchiveEntries () and os .path .isfile (property_value ):
194
+ # only case is it is not flat directory if the particular file has not been collected before, add
195
+ # it to the previous wallet
196
+ fixed_path = archive_file .addDatabaseWallet (collected_wallet_dictionary [onprem_wallet_parent_path ]['wallet_name' ],
197
+ os .path .abspath (property_value ))
198
+ else :
199
+ # already in archive just figure out the path
200
+ if (os .path .isdir (property_value )):
201
+ fixed_path = collected_wallet_dictionary [onprem_wallet_parent_path ]['path_into_archive' ]
202
+ else :
203
+ fixed_path = os .path .join (collected_wallet_dictionary [onprem_wallet_parent_path ]['path_into_archive' ],
204
+ os .path .basename (property_value ))
205
+
206
+ return fixed_path
207
+
208
+ def _get_wallet_name_and_path (self , datasource , property_value ):
209
+ _method_name = '_get_wallet_name_and_path'
210
+ # fix up name just in case
211
+ wallet_name = datasource .replace (' ' , '' ).replace ('(' , '' ).replace (')' , '' )
212
+ if os .path .isdir (property_value ):
213
+ onprem_wallet_parent_path = os .path .abspath (property_value )
214
+ else :
215
+ onprem_wallet_parent_path = os .path .dirname (os .path .abspath (property_value ))
216
+ if self ._model_context .get_oracle_home () == onprem_wallet_parent_path :
217
+ _logger .severe ('WLSDPLY-06368' , property_value , self ._model_context .get_oracle_home ())
218
+ de = exception_helper .create_discover_exception ('WLSDPLY-06368' , property_value ,
219
+ self ._model_context .get_oracle_home ())
220
+ _logger .throwing (class_name = _class_name , method_name = _method_name , error = de )
221
+ raise de
222
+ return onprem_wallet_parent_path , wallet_name
223
+
224
+ def _is_on_prem_wallet_dir_flat (self , onprem_wallet_parent_path , property_value ):
225
+ # info if wallet parent is not flat and only collect the particular file and not the entire directory
226
+ dir_list = os .listdir (onprem_wallet_parent_path )
227
+ onprem_wallet_dir_is_not_flat = False
228
+ for item in dir_list :
229
+ if os .path .isdir (os .path .join (onprem_wallet_parent_path , item )):
230
+ onprem_wallet_dir_is_not_flat = True
231
+ break
232
+ # put out info for user only particular file is collected and not the entire wallet directory
233
+ if onprem_wallet_dir_is_not_flat :
234
+ _logger .info ('WLSDPLY-06369' , property_value )
235
+ return onprem_wallet_dir_is_not_flat
236
+
120
237
def get_foreign_jndi_providers (self ):
121
238
"""
122
239
Discover Foreign JNDI providers from the domain.
@@ -224,7 +341,6 @@ def archive_file_store_directory(self, file_store_name, file_store_dictionary):
224
341
file_store_dictionary [model_constants .DIRECTORY ] = new_source_name
225
342
226
343
_logger .exiting (class_name = _class_name , method_name = _method_name )
227
- return
228
344
229
345
def get_jdbc_stores (self ):
230
346
"""
0 commit comments