def _process_attribute(self, model, attribute, location, injector_values): _method_name = '_process_attribute' _logger.entering(attribute, location.get_folder_path(), class_name=_class_name, method_name=_method_name) variable_dict = OrderedDict() variable_name = None variable_value = None attribute_value = model[attribute] if not _already_property(attribute_value): variable_name = variable_injector_functions.format_variable_name( location, attribute, self.__aliases) variable_value = _format_variable_value(attribute_value) credentials_method = self.__model_context.get_target_configuration( ).get_credentials_method() # for credentials_method: secrets, assign a secret token to the attribute if credentials_method == SECRETS_METHOD \ and variable_value == alias_constants.PASSWORD_TOKEN: model[ attribute] = target_configuration_helper.format_as_secret_token( variable_name) # for config_override_secrets, assign a placeholder value to the attribute elif credentials_method == CONFIG_OVERRIDES_SECRETS_METHOD \ and variable_value == alias_constants.PASSWORD_TOKEN: if attribute == ADMIN_USERNAME: model[ attribute] = target_configuration_helper.ADMINUSER_PLACEHOLDER else: model[ attribute] = target_configuration_helper.PASSWORD_PLACEHOLDER else: model[attribute] = _format_as_property(variable_name) _logger.fine('WLSDPLY-19525', variable_name, attribute_value, attribute, variable_value, class_name=_class_name, method_name=_method_name) else: _logger.finer('WLSDPLY-19526', attribute_value, attribute, str(location), class_name=_class_name, method_name=_method_name) if variable_value is not None: variable_dict[variable_name] = self._check_replace_variable_value( location, attribute, variable_value, injector_values) _logger.exiting(class_name=_class_name, method_name=_method_name, result=variable_value) return variable_dict
def __substitute_password_with_token(self, model_path, attribute_name, validation_location): """ Add the secret for the specified attribute to the cache. If the target specifies credentials_method: secrets, substitute the secret token into the model. :param model_path: text representation of the model path :param attribute_name: the name of the attribute or (property) :param validation_location: the model location """ model_path_tokens = model_path.split('/') tokens_length = len(model_path_tokens) variable_name = variable_injector_functions.format_variable_name( validation_location, attribute_name, self._aliases) if tokens_length > 1: credentials_method = self.model_context.get_target_configuration( ).get_credentials_method() # by default, don't do any assignment to attribute model_value = None # use attribute name for admin password if model_path_tokens[0] == 'domainInfo:' and model_path_tokens[ 1] == '': cache_key = attribute_name else: cache_key = variable_name # for normal secrets, assign the secret name to the attribute if credentials_method == SECRETS_METHOD: model_value = target_configuration_helper.format_as_secret_token( cache_key, self.model_context.get_target_configuration()) self.cache[cache_key] = '' # for config override secrets, assign a placeholder password to the attribute. # config overrides will be used to override the value in the target domain. if credentials_method == CONFIG_OVERRIDES_SECRETS_METHOD: if attribute_name == ADMIN_USERNAME: model_value = ADMINUSER_PLACEHOLDER else: model_value = PASSWORD_PLACEHOLDER self.cache[cache_key] = '' if model_value is not None: p_dict = self.current_dict for index in range(0, len(model_path_tokens)): token = model_path_tokens[index] if token == '': break if token[-1] == ':': token = token[:-1] p_dict = p_dict[token] p_dict[attribute_name] = model_value
def get_secret_name_for_location(location, domain_uid, aliases): """ Returns the secret name for the specified model location. Example: mydomain-jdbc-mydatasource :param location: the location to be evaluated :param domain_uid: used to prefix the secret name :param aliases: used to examine the location :return: the secret name """ variable_name = variable_injector_functions.format_variable_name(location, '(none)', aliases) secret_name = create_secret_name(variable_name) return domain_uid + '-' + secret_name
def get_secret_name_for_location(location, domain_uid, aliases): """ Returns the secret name for the specified model location. Example: mydomain-jdbc-mydatasource :param location: the location to be evaluated :param domain_uid: used to prefix the secret name :param aliases: used to examine the location :return: the secret name """ variable_name = variable_injector_functions.format_variable_name( location, '(none)', aliases) name_lower_tokens = variable_name.lower().split('.') return domain_uid + '-' + '-'.join(name_lower_tokens[:-1])
def _check_name(self, name, expected_key): """ Verify that the specified name is converted to match the expected key. A machine location is created with the supplied name and converted to a variable name. An expected value is constructed using the expected key and known parameters. :param name: the name to be converted :param expected_key: the expected variable key """ self.location.add_name_token(self.name_token, name) variable_name = variable_injector_functions.format_variable_name( self.location, self.attribute_name, self.aliases) # verify that a property built with this value will parse correctly property_text = '@@PROP:%s@@' % variable_name matches = variables._property_pattern.findall(property_text) self.assertEqual(1, len(matches), "Property %s should parse correctly" % property_text) expected_name = "%s.%s.%s" % (self.short_name, expected_key, self.attribute_name) self.assertEqual(expected_name, variable_name)
def remove_from_cache(self, location, attribute_name): """ For special circumstances, when scrubbing data from the model, remove the property from the cache. :param location: context for current location. This does not work for segmented properties. :param attribute_name: attribute for which to remove property from the cache. :return: """ _method_name = 'remove_from_cache' _logger.entering(attribute_name, class_name=_class_name, method_name=_method_name) cache = self.get_variable_cache() if len(cache) > 0: property_name = variable_injector_functions.format_variable_name( location, attribute_name, self.__aliases) if property_name in cache: _logger.fine('WLSDPLY-19545', property_name, class_name=_class_name, method_name=_method_name) del cache[property_name] _logger.exiting(class_name=_class_name, method_name=_method_name)
def __format_variable_name_segment(self, location, attribute, suffix): path = variable_injector_functions.format_variable_name( location, attribute, self.__aliases) if suffix: return path + SUFFIX_SEP + suffix return path