def encrypt_model_dictionary(self, model_dict): """ Encrypt the model dictionary (and referenced variables, if provided) using the specified passphrase. :param model_dict: the model dictionary :return: the number of model elements encrypted, and the number of variables encrypted :raises EncryptionException if an error occurs """ if model.get_model_domain_info_key() in model_dict: domain_info_dict = model_dict[model.get_model_domain_info_key()] self._encrypt_info_nodes(domain_info_dict) if model.get_model_topology_key() in model_dict: top_folder_names = self.alias_helper.get_model_topology_top_level_folder_names() topology_nodes = model_dict[model.get_model_topology_key()] location = LocationContext() self._encrypt_nodes(location, topology_nodes, top_folder_names) if model.get_model_resources_key() in model_dict: top_folder_names = self.alias_helper.get_model_resources_top_level_folder_names() resources_nodes = model_dict[model.get_model_resources_key()] location = LocationContext() self._encrypt_nodes(location, resources_nodes, top_folder_names) if model.get_model_deployments_key() in model_dict: top_folder_names = self.alias_helper.get_model_app_deployments_top_level_folder_names() deployments_nodes = model_dict[model.get_model_deployments_key()] location = LocationContext() self._encrypt_nodes(location, deployments_nodes, top_folder_names) return self.model_changes, self.variable_changes
def __init__(self): self._validation_result_dict = { '%s Section' % model.get_model_domain_info_key(): None, '%s Section' % model.get_model_topology_key(): None, '%s Section' % model.get_model_deployments_key(): None, '%s Section' % model.get_model_resources_key(): None }
def __init__(self): self._validation_result_dict = { '%s Section' % model.get_model_domain_info_key(): None, '%s Section' % model.get_model_topology_key(): None, '%s Section' % model.get_model_deployments_key(): None, '%s Section' % model.get_model_resources_key(): None, '%s Section' % model_constants.GLOBAL_VARIABLE_SUBSTITUTION: None }
def encrypt_model_dictionary(passphrase, model_dict, variables=None): """ Encrypt the model dictionary (and referenced variables, if provided) using the specified passphrase. :param passphrase: the passphrase used to encrypt/decrypt the passwords :param model_dict: the model dictionary :param variables: the variables property object :raises EncryptionException if an error occurs """ _initialize_password_field_names() model_changes = 0 variable_changes = 0 if model.get_model_domain_info_key() in model_dict: domain_info_dict = model_dict[model.get_model_domain_info_key()] _model_changes, _variable_changes = \ _search_and_replace_passwords(passphrase, model.get_model_domain_info_key(), domain_info_dict, variables) model_changes += _model_changes variable_changes += _variable_changes if model.get_model_topology_key() in model_dict: topology_dict = model_dict[model.get_model_topology_key()] _model_changes, _variable_changes = \ _search_and_replace_passwords(passphrase, model.get_model_topology_key(), topology_dict, variables) model_changes += _model_changes variable_changes += _variable_changes if model.get_model_resources_key() in model_dict: resources_dict = model_dict[model.get_model_resources_key()] _model_changes, _variable_changes = \ _search_and_replace_passwords(passphrase, model.get_model_resources_key(), resources_dict, variables) model_changes += _model_changes variable_changes += _variable_changes if model.get_model_deployments_key() in model_dict: deployments_dict = model_dict[model.get_model_deployments_key()] _model_changes, _variable_changes = \ _search_and_replace_passwords(passphrase, model.get_model_deployments_key(), deployments_dict, variables) model_changes += _model_changes variable_changes += _variable_changes return model_changes, variable_changes
def admin_server_list(model): """ Return the domain admin server in list format :param model: to process for admin server list :return: admin server in list format """ _method_name = 'admin_server_list' _logger.entering(class_name=_class_name, method_name=_method_name) as_name_list = [] topology_constant = model_sections.get_model_topology_key() if topology_constant in model: topology = model[topology_constant] if topology and model_constants.ADMIN_SERVER_NAME in topology: as_name_list.append(topology[model_constants.ADMIN_SERVER_NAME]) _logger.exiting(class_name=_class_name, method_name=_method_name, result=as_name_list) return as_name_list
def managed_server_list(model): """ Return a managed server name list from the provided model. :param model: to process for managed server list :return: list of managed server names or empty list if no managed servers """ _method_name = 'managed_server_list' _logger.entering(class_name=_class_name, method_name=_method_name) ms_name_list = [] topology_constant = model_sections.get_model_topology_key() if topology_constant in model: topology = model[topology_constant] if model_constants.SERVER in topology: ms_name_list = topology[model_constants.SERVER].keys() if model_constants.ADMIN_SERVER_NAME in topology: admin_server = topology[model_constants.ADMIN_SERVER_NAME] if admin_server in ms_name_list: ms_name_list.remove(admin_server) _logger.exiting(class_name=_class_name, method_name=_method_name, result=ms_name_list) return ms_name_list
def __inject_variable(self, location, injector, injector_values): _method_name = '__inject_variable' _logger.entering(injector, class_name=_class_name, method_name=_method_name) variable_dict = dict() start_mbean_list, attribute = _split_injector(injector) def _traverse_variables(model_section, mbean_list): if mbean_list: mbean = mbean_list.pop(0) mbean, mbean_name_list = self._find_special_name(mbean) _logger.finer('WLSDPLY-19523', mbean, location.get_folder_path(), class_name=_class_name, method_name=_method_name) if mbean in model_section: _logger.finest('WLSDPLY-19514', mbean, class_name=_class_name, method_name=_method_name) next_model_section = model_section[mbean] location.append_location(mbean) name_token = self.__aliases.get_name_token(location) if not mbean_name_list: if self.__aliases.supports_multiple_mbean_instances( location): mbean_name_list = next_model_section else: self._check_name_token(location, name_token) else: _logger.fine('WLSDPLY-19506', mbean_name_list, attribute, location.get_folder_path(), class_name=_class_name, method_name=_method_name) if mbean_name_list: for mbean_name in mbean_name_list: if mbean_name in next_model_section: continue_mbean_list = copy.copy(mbean_list) location.add_name_token(name_token, mbean_name) _traverse_variables( next_model_section[mbean_name], continue_mbean_list) location.remove_name_token(name_token) else: _traverse_variables(next_model_section, mbean_list) location.pop_location() else: self._log_mbean_not_found(mbean, injector, location) return False else: self._check_insert_attribute_model(location, model_section, attribute, injector_values) if attribute in model_section: returned_dict = self._variable_info( model_section, attribute, location, injector_values) if returned_dict: variable_dict.update(returned_dict) else: _logger.finer('WLSDPLY-19517', attribute, injector, location.get_folder_path(), class_name=_class_name, method_name=_method_name) return True section = self.__model if start_mbean_list: # Find out in what section is the mbean top folder so can move to that section in the model top_mbean, __ = self._find_special_name(start_mbean_list[0]) for entry in self.__section_keys: if entry in self.__model and top_mbean in self.__model[entry]: section = self.__model[entry] break else: # This is a domain attribute section = self.__model[model_sections.get_model_topology_key()] # if it wasn't found, will log appropriately in the called method # This also will allow someone to put the section in the injector string _traverse_variables(section, start_mbean_list) _logger.exiting(class_name=_class_name, method_name=_method_name, result=variable_dict) return variable_dict
def walk(self): """ Replace password attributes in each model file with secret tokens, and write each model. Generate a script to create the required secrets. Create any additional output specified for the target environment. """ _method_name = "walk" model_file_name = None try: model_file_list = self.model_files.split(',') for model_file in model_file_list: self.cache.clear() if os.path.splitext(model_file)[1].lower() == ".yaml": model_file_name = model_file FileToPython(model_file_name, True).parse() aliases = Aliases(model_context=self.model_context, wlst_mode=WlstModes.OFFLINE) validator = Validator(self.model_context, aliases, wlst_mode=WlstModes.OFFLINE) # Just merge and validate but without substitution model_dictionary = cla_helper.merge_model_files( model_file_name, None) variable_file = self.model_context.get_variable_file() if not os.path.exists(variable_file): variable_file = None return_code = validator.validate_in_tool_mode( model_dictionary, variables_file_name=variable_file, archive_file_name=None) if return_code == Validator.ReturnCode.STOP: self._logger.severe('WLSDPLY-05705', model_file_name) return VALIDATION_FAIL self.current_dict = model_dictionary self.__walk_model_section( model.get_model_domain_info_key(), self.current_dict, aliases.get_model_section_top_level_folder_names( DOMAIN_INFO)) self.__walk_model_section( model.get_model_topology_key(), self.current_dict, aliases.get_model_topology_top_level_folder_names()) self.__walk_model_section( model.get_model_resources_key(), self.current_dict, aliases.get_model_resources_top_level_folder_names()) self.current_dict = self._apply_filter_and_inject_variable( self.current_dict, self.model_context, validator) file_name = os.path.join(self.output_dir, os.path.basename(model_file_name)) fos = JFileOutputStream(file_name, False) writer = JPrintWriter(fos, True) pty = PythonToYaml(self.current_dict) pty._write_dictionary_to_yaml_file(self.current_dict, writer) writer.close() self.cache.clear() for key in self.secrets_to_generate: self.cache[key] = '' # use a merged, substituted, filtered model to get domain name and create additional target output. full_model_dictionary = cla_helper.load_model( _program_name, self.model_context, self._aliases, "discover", WlstModes.OFFLINE) target_configuration_helper.generate_k8s_script( self.model_context, self.cache, full_model_dictionary) # create any additional outputs from full model dictionary target_configuration_helper.create_additional_output( Model(full_model_dictionary), self.model_context, self._aliases, ExceptionType.VALIDATE) except ValidateException, te: self._logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(), error=te, class_name=_class_name, method_name=_method_name) ex = exception_helper.create_compare_exception( te.getLocalizedMessage(), error=te) self._logger.throwing(ex, class_name=_class_name, method_name=_method_name) return VALIDATION_FAIL
def walk(self): _method_name = "walk" model_file_name = None try: model_file_list = self.model_files.split(',') for model_file in model_file_list: self.cache.clear() if os.path.splitext(model_file)[1].lower() == ".yaml": model_file_name = model_file FileToPython(model_file_name, True).parse() aliases = Aliases(model_context=self.model_context, wlst_mode=WlstModes.OFFLINE) validator = Validator(self.model_context, aliases, wlst_mode=WlstModes.OFFLINE) # Just merge and validate but without substitution model_dictionary = cla_helper.merge_model_files(model_file_name, None) variable_file = self.model_context.get_variable_file() if not os.path.exists(variable_file): variable_file=None return_code = validator.validate_in_tool_mode(model_dictionary, variables_file_name=variable_file, archive_file_name=None) if return_code == Validator.ReturnCode.STOP: __logger.severe('WLSDPLY-05705', model_file_name) return VALIDATION_FAIL self.current_dict = model_dictionary self.__walk_model_section(model.get_model_domain_info_key(), self.current_dict, aliases.get_model_section_top_level_folder_names(DOMAIN_INFO)) self.__walk_model_section(model.get_model_topology_key(), self.current_dict, aliases.get_model_topology_top_level_folder_names()) self.__walk_model_section(model.get_model_resources_key(), self.current_dict, aliases.get_model_resources_top_level_folder_names()) self.current_dict = self._apply_filter_and_inject_variable(self.current_dict, self.model_context, validator) file_name = os.path.join(self.output_dir, os.path.basename(model_file_name)) fos = JFileOutputStream(file_name, False) writer = JPrintWriter(fos, True) pty = PythonToYaml(self.current_dict) pty._write_dictionary_to_yaml_file(self.current_dict, writer) writer.close() self.cache.clear() for key in self.secrets_to_generate: self.cache[key] = '' target_configuration_helper.generate_k8s_script(self.model_context.get_kubernetes_variable_file(), self.cache) except ValidateException, te: __logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(), error=te, class_name=_class_name, method_name=_method_name) ex = exception_helper.create_compare_exception(te.getLocalizedMessage(), error=te) __logger.throwing(ex, class_name=_class_name, method_name=_method_name) return VALIDATION_FAIL