def _discover_artificial_folder(self, model_subfolder_type, location,
                                 name_token):
     """
     Discover the subfolder that has an artificial connection; the subfolder contains multiple different types
     under one MBean. The model must contain the subfolder type, the artificial type that specifies which it is,
     and the name of the subfolder. This folder is only one layer deep. No need to continue to discover
     additional subfolders
     :param model_subfolder_type: type of the model subfolder
     :param location: context containing the current location information
     :param name_token: for use in the location to contain the folder name
     :return: dictionary containing the discovered folder attributes
     """
     _method_name = '_discover_artifical_folder'
     _logger.entering(model_subfolder_type,
                      str(location),
                      name_token,
                      class_name=_class_name,
                      method_name=_method_name)
     subfolder_result = OrderedDict()
     names = self._find_names_in_folder(location)
     if names is not None:
         for name in names:
             massaged = self._inspect_artificial_folder_name(name, location)
             location.add_name_token(name_token, massaged)
             artificial = self._get_artificial_type(location)
             if artificial is None:
                 if self._alias_helper.is_custom_folder_allowed(location):
                     _logger.fine('WLSDPLY-06148',
                                  model_subfolder_type,
                                  massaged,
                                  location.get_folder_path(),
                                  class_name=_class_name,
                                  method_name=_method_name)
                     subfolder_result.update(
                         self._custom_folder.discover_custom_mbean(
                             location, model_subfolder_type, massaged))
                 else:
                     _logger.warning(
                         'WLSDPLY-06123',
                         self._alias_helper.get_model_folder_path(location),
                         class_name=_class_name,
                         method_name=_method_name)
             else:
                 _logger.finer('WLSDPLY-06120',
                               artificial,
                               massaged,
                               model_subfolder_type,
                               class_name=_class_name,
                               method_name=_method_name)
                 location.append_location(artificial)
                 subfolder_result[massaged] = OrderedDict()
                 subfolder_result[massaged][artificial] = OrderedDict()
                 self._populate_model_parameters(
                     subfolder_result[massaged][artificial], location)
                 location.pop_location()
             location.remove_name_token(name_token)
     _logger.exiting(class_name=_class_name,
                     method_name=_method_name,
                     result=subfolder_result)
     return subfolder_result
Beispiel #2
0
 def inject_variables_keyword_dictionary(self, injector_file_list):
     """
     Takes a variable keyword dictionary and returns a variables for file in a dictionary
     :param injector_file_list: list of injector files for processing variable injection
     :return: variables_dictionary containing the variable properties to persist to the variable file
     """
     _method_name = 'inject_variables_keyword_dictionary'
     _logger.entering(injector_file_list,
                      class_name=_class_name,
                      method_name=_method_name)
     variable_dictionary = OrderedDict()
     for filename in injector_file_list:
         injector_dictionary = _load_injector_file(
             self._replace_tokens(filename))
         entries = self.inject_variables(injector_dictionary)
         if entries:
             _logger.finer('WLSDPLY-19513',
                           filename,
                           class_name=_class_name,
                           method_name=_method_name)
             variable_dictionary.update(entries)
     _logger.exiting(class_name=_class_name,
                     method_name=_method_name,
                     result=variable_dictionary)
     return variable_dictionary
    def check_and_tokenize(self, model_dict, attribute, location):
        """
        If the specified attribute is a security credential, add it to the injector,
        and replace the value in the model dictionary with the token.
        :param model_dict: the model dictionary containing the attribute
        :param attribute: the name of the attribute
        :param location: the location of the attribute
        """
        aliases = self.get_aliases()
        attribute_type = aliases.get_model_attribute_type(location, attribute)
        folder_path = '.'.join(location.get_model_folders())
        model_value = model_dict[attribute]

        if attribute_type == CREDENTIAL:
            injector_commands = OrderedDict()
            injector_commands.update({VARIABLE_VALUE: model_value})
            self.custom_injection(model_dict, attribute, location,
                                  injector_commands)

        elif attribute_type == PASSWORD:
            # STANDARD_PASSWORD_INJECTOR provides an empty value for the mapping
            self.custom_injection(model_dict, attribute, location,
                                  STANDARD_PASSWORD_INJECTOR)

        elif folder_path.endswith(self.JDBC_PROPERTIES_PATH):
            token = aliases.get_name_token(location)
            property_name = location.get_name_for_token(token)
            if (property_name == DRIVER_PARAMS_USER_PROPERTY) and (
                    attribute == DRIVER_PARAMS_PROPERTY_VALUE):
                injector_commands = OrderedDict()
                injector_commands.update({VARIABLE_VALUE: model_value})
                self.custom_injection(model_dict, attribute, location,
                                      injector_commands)

        elif folder_path.endswith(MAIL_SESSION) and (attribute == PROPERTIES):
            # users and passwords are property assignments
            value = model_dict[attribute]
            is_string = isinstance(value, str)

            # for discover, value is a string at this point
            if is_string:
                model_dict[attribute] = OrderedDict()
                split = value.split(';')
                for assign in split:
                    halves = assign.split('=')
                    model_dict[attribute][halves[0]] = halves[1]

            self.custom_injection(model_dict, attribute, location,
                                  self.USER_COMMANDS)
            self.custom_injection(model_dict, attribute, location,
                                  self.PASSWORD_COMMANDS)

            if is_string:
                properties = model_dict[attribute]
                assigns = []
                for key in properties:
                    assigns.append('%s=%s' % (key, properties[key]))
                model_dict[attribute] = ';'.join(assigns)
 def testOrderedDictDictUpdate(self):
     dict1 = OrderedDict()
     dict1['entry1'] = 'you'
     dict2 = dict()
     dict2['entry2'] = 'me'
     dict1.update(dict2)
     self.assertEqual(
         'entry1' in dict1 and 'entry2' in dict1, True,
         "expected ordereddict1 to contain 'entry1' and 'entry2' keys")
Beispiel #5
0
    def inject_variables(self, injector_dictionary):
        """
        Iterate through the injector dictionary that was loaded from the file for the model
        injector file keyword.
        :param injector_dictionary:
        :return: variable dictionary containing the variable string and model value entries
        """
        variable_dict = OrderedDict()
        if injector_dictionary:
            location = LocationContext()
            domain_token = self.__aliases.get_name_token(location)
            location.add_name_token(domain_token, _fake_name_marker)
            for injector, injector_values in injector_dictionary.iteritems():
                entries_dict = self.__inject_variable(location, injector,
                                                      injector_values)
                if len(entries_dict) > 0:
                    variable_dict.update(entries_dict)

        return variable_dict
Beispiel #6
0
    def _discover_artificial_folder(self,
                                    model_subfolder_type,
                                    location,
                                    name_token,
                                    check_order=False):
        """
        Discover the subfolder that has an artificial connection; the subfolder contains multiple different types
        under one MBean. The model must contain the subfolder type, the artificial type that specifies which it is,
        and the name of the subfolder. This folder is only one layer deep. No need to continue to discover
        additional subfolders
        :param model_subfolder_type: type of the model subfolder
        :param location: context containing the current location information
        :param name_token: for use in the location to contain the folder name
        :param check_order: if true, check the subfolders for order
        :return: dictionary containing the discovered folder attributes
        """
        _method_name = '_discover_artifical_folder'
        _logger.entering(model_subfolder_type,
                         str(location),
                         name_token,
                         class_name=_class_name,
                         method_name=_method_name)
        subfolder_result = OrderedDict()
        names = self._find_names_in_folder(location)
        required_order = self._aliases.get_subfolders_in_order(location)
        attr_map = dict()
        default_list = list()
        if names is not None:
            for name in names:
                location.add_name_token(name_token, name)
                massaged = self._inspect_artificial_folder_name(name, location)
                location.add_name_token(name_token, massaged)
                artificial = self._get_artificial_type(location)
                if artificial is None:
                    if self._aliases.is_custom_folder_allowed(location):
                        _logger.fine('WLSDPLY-06148',
                                     model_subfolder_type,
                                     massaged,
                                     location.get_folder_path(),
                                     class_name=_class_name,
                                     method_name=_method_name)
                        # doesn't matter how many parameters, it is automatically a non-default name
                        default_list.append(massaged)
                        attr_map[massaged] = 0
                        subfolder_result.update(
                            self._custom_folder.discover_custom_mbean(
                                location, model_subfolder_type, massaged))
                    else:
                        _logger.warning(
                            'WLSDPLY-06123',
                            self._aliases.get_model_folder_path(location),
                            class_name=_class_name,
                            method_name=_method_name)
                else:
                    _logger.finer('WLSDPLY-06120',
                                  artificial,
                                  massaged,
                                  model_subfolder_type,
                                  class_name=_class_name,
                                  method_name=_method_name)
                    location.append_location(artificial)
                    subfolder_result[massaged] = OrderedDict()
                    subfolder_result[massaged][artificial] = OrderedDict()
                    self._populate_model_parameters(
                        subfolder_result[massaged][artificial], location)
                    default_list.append(artificial)
                    attr_map[artificial] = len(
                        subfolder_result[massaged][artificial])
                    location.pop_location()
                location.remove_name_token(name_token)

        # check to see if the order and number of the subfolder list is same as required order
        is_default = False
        if check_order and len(required_order) == len(default_list):
            is_default = True
            idx = 0
            while idx < len(required_order):
                if required_order[idx] != default_list[idx] or attr_map[
                        default_list[idx]] > 0:
                    is_default = False
                    break
                idx += 1
        if is_default:
            subfolder_result = None
        _logger.exiting(class_name=_class_name,
                        method_name=_method_name,
                        result=subfolder_result)
        return subfolder_result