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
Esempio n. 2
0
 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
Esempio n. 5
0
    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