|
2 | 2 | Copyright (c) 2021, Oracle and/or its affiliates.
|
3 | 3 | Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
|
4 | 4 | """
|
| 5 | +from java.util import Properties |
5 | 6 |
|
6 | 7 | from oracle.weblogic.deploy.aliases import AliasException
|
7 | 8 | from oracle.weblogic.deploy.util import PyOrderedDict
|
@@ -65,15 +66,76 @@ def _compare_folders(self, current_folder, past_folder, location, attributes_loc
|
65 | 66 |
|
66 | 67 | # determine if the specified location has named folders, such as topology/Server
|
67 | 68 | has_named_folders = False
|
| 69 | + has_security = False |
68 | 70 | if (location is not None) and not self._aliases.is_artificial_type_folder(location):
|
69 |
| - has_named_folders = self._aliases.supports_multiple_mbean_instances(location) or \ |
70 |
| - self._aliases.requires_artificial_type_subfolder_handling(location) |
| 71 | + if self._aliases.supports_multiple_mbean_instances(location): |
| 72 | + has_named_folders = True |
| 73 | + elif self._aliases.requires_artificial_type_subfolder_handling(location): |
| 74 | + has_security = True |
71 | 75 |
|
72 | 76 | if has_named_folders:
|
73 | 77 | return self._compare_named_folders(current_folder, past_folder, location, attributes_location)
|
| 78 | + elif has_security: |
| 79 | + return self._compare_security_folders(current_folder, past_folder, location, attributes_location) |
74 | 80 | else:
|
75 | 81 | return self._compare_folder_contents(current_folder, past_folder, location, attributes_location)
|
76 | 82 |
|
| 83 | + def _compare_security_folders(self, current_folder, past_folder, location, attributes_location): |
| 84 | + """ |
| 85 | + Compare current and past security configuration provider section. If a provider section has an entry |
| 86 | + that is different from the original, the entire provider section will be returned as differences between |
| 87 | + the two folders. |
| 88 | + :param current_folder: a folder in the current model |
| 89 | + :param past_folder: corresponding folder in the past model |
| 90 | + :param location: the location for the specified folders |
| 91 | + :param attributes_location: the attribute location for the specified folders |
| 92 | + :return: a dictionary of differences between these folders |
| 93 | + """ |
| 94 | + providers = self._aliases.get_model_subfolder_names(location) |
| 95 | + matches = True |
| 96 | + custom = True |
| 97 | + if len(current_folder) == len(past_folder): |
| 98 | + curr_keys = current_folder.keys() |
| 99 | + past_keys = past_folder.keys() |
| 100 | + idx = 0 |
| 101 | + while idx < len(curr_keys): |
| 102 | + if curr_keys[idx] == past_keys[idx]: |
| 103 | + custom = curr_keys[idx] not in providers |
| 104 | + next_curr_folder = current_folder[curr_keys[idx]] |
| 105 | + next_curr_keys = next_curr_folder.keys() |
| 106 | + next_past_folder = past_folder[past_keys[idx]] |
| 107 | + next_past_keys = next_past_folder.keys() |
| 108 | + next_idx = 0 |
| 109 | + while next_idx < len(next_curr_keys): |
| 110 | + if next_curr_keys[next_idx] == next_past_keys[next_idx]: |
| 111 | + if custom: |
| 112 | + changes = self._compare_folder_sc_contents(next_curr_folder, next_past_folder, |
| 113 | + location, attributes_location) |
| 114 | + else: |
| 115 | + changes = self._compare_folder_contents(next_curr_folder, next_past_folder, |
| 116 | + location, attributes_location) |
| 117 | + if changes: |
| 118 | + matches = False |
| 119 | + break |
| 120 | + else: |
| 121 | + matches = False |
| 122 | + break |
| 123 | + next_idx +=1 |
| 124 | + else: |
| 125 | + matches = False |
| 126 | + break |
| 127 | + idx +=1 |
| 128 | + else: |
| 129 | + matches = False |
| 130 | + if matches is False: |
| 131 | + self._messages.add(('WLSDPLY-05716', location.get_folder_path())) |
| 132 | + comment = "Replace entire Security Provider section " |
| 133 | + new_folder = PyOrderedDict() |
| 134 | + _add_comment(comment, new_folder) |
| 135 | + new_folder.update(current_folder) |
| 136 | + return new_folder |
| 137 | + return PyOrderedDict() |
| 138 | + |
77 | 139 | def _compare_named_folders(self, current_folder, past_folder, location, attributes_location):
|
78 | 140 | """
|
79 | 141 | Compare current and past named folders using the specified locations.
|
@@ -113,6 +175,46 @@ def _compare_named_folders(self, current_folder, past_folder, location, attribut
|
113 | 175 |
|
114 | 176 | return change_folder
|
115 | 177 |
|
| 178 | + def _compare_folder_sc_contents(self, current_folder, past_folder, location, attributes_location): |
| 179 | + """ |
| 180 | + Compare the contents of current and past folders, looking at attribute changes for a security provider. |
| 181 | + Return any changes so that calling routine will know changes occurred and the entire section will |
| 182 | + of the current folder will be marked as changed. |
| 183 | + :param current_folder: a folder in the current model |
| 184 | + :param past_folder: corresponding folder in the past model |
| 185 | + :param location: the location for the specified folders |
| 186 | + :param attributes_location: the attribute location for the specified folders |
| 187 | + :return: a dictionary of differences between these folders |
| 188 | + """ |
| 189 | + change_folder = PyOrderedDict() |
| 190 | + |
| 191 | + # check if keys in the current folder are present in the past folder |
| 192 | + for key in current_folder: |
| 193 | + if not self._check_key(key, location): |
| 194 | + continue |
| 195 | + |
| 196 | + if key in past_folder: |
| 197 | + current_value = current_folder[key] |
| 198 | + past_value = past_folder[key] |
| 199 | + |
| 200 | + self._compare_attribute_sc(current_value, past_value, attributes_location, key, change_folder) |
| 201 | + |
| 202 | + else: |
| 203 | + # key is present the current folder, not in the past folder. |
| 204 | + # just add to the change folder, no further recursion needed. |
| 205 | + change_folder[key] = current_folder[key] |
| 206 | + |
| 207 | + # check if keys in the past folder are not in the current folder |
| 208 | + for key in past_folder: |
| 209 | + if not self._check_key(key, location): |
| 210 | + continue |
| 211 | + |
| 212 | + if key not in current_folder: |
| 213 | + change_folder[key] = past_folder[key] |
| 214 | + |
| 215 | + self._finalize_folder(current_folder, past_folder, change_folder, location) |
| 216 | + return change_folder |
| 217 | + |
116 | 218 | def _compare_folder_contents(self, current_folder, past_folder, location, attributes_location):
|
117 | 219 | """
|
118 | 220 | Compare the contents of current and past folders using the specified locations.
|
@@ -197,6 +299,38 @@ def _get_next_location(self, location, key):
|
197 | 299 |
|
198 | 300 | return next_location, next_attributes_location
|
199 | 301 |
|
| 302 | + def _compare_attribute_sc(self, current_value, past_value, location, key, change_folder): |
| 303 | + """ |
| 304 | + Compare values of an attribute from the current and past folders. |
| 305 | + The changed value will signal the calling method that the entire new |
| 306 | + :param current_value: the value from the current model |
| 307 | + :param past_value: the value from the past model |
| 308 | + :param key: the key of the attribute |
| 309 | + :param change_folder: the folder in the change model to be updated |
| 310 | + :param location: the location for attributes in the specified folders |
| 311 | + """ |
| 312 | + if current_value != past_value: |
| 313 | + if type(current_value) == list: |
| 314 | + current_list = list(current_value) |
| 315 | + previous_list = list(past_value) |
| 316 | + |
| 317 | + change_list = list(previous_list) |
| 318 | + for item in current_list: |
| 319 | + if item in previous_list: |
| 320 | + change_list.remove(item) |
| 321 | + else: |
| 322 | + change_list.append(item) |
| 323 | + for item in previous_list: |
| 324 | + if item not in current_list: |
| 325 | + change_list.remove(item) |
| 326 | + change_list.append(model_helper.get_delete_name(item)) |
| 327 | + |
| 328 | + elif isinstance(current_value, Properties): |
| 329 | + self._compare_properties(current_value, past_value, key, change_folder) |
| 330 | + |
| 331 | + else: |
| 332 | + change_folder[key] = current_value |
| 333 | + |
200 | 334 | def _compare_attribute(self, current_value, past_value, location, key, change_folder):
|
201 | 335 | """
|
202 | 336 | Compare values of an attribute from the current and past folders.
|
@@ -278,16 +412,6 @@ def _check_key(self, key, location):
|
278 | 412 | if (location is None) and (key == KUBERNETES):
|
279 | 413 | self._logger.info('WLSDPLY-05713', KUBERNETES, class_name=self._class_name, method_name=_method_name)
|
280 | 414 | return False
|
281 |
| - try: |
282 |
| - if (location is not None) and (not self._aliases.is_artificial_type_folder(location)) and \ |
283 |
| - (self._aliases.requires_artificial_type_subfolder_handling(location)): |
284 |
| - providers = self._aliases.get_model_subfolder_names(location) |
285 |
| - if key not in providers: |
286 |
| - self._logger.warning('WLSDPLY-05716', key, |
287 |
| - class_name=self._class_name, method_name=_method_name) |
288 |
| - return False |
289 |
| - except AliasException: |
290 |
| - return True |
291 | 415 | return True
|
292 | 416 |
|
293 | 417 | def _finalize_folder(self, current_folder, past_folder, change_folder, location):
|
|
0 commit comments