def generate_request_description(request, original=None): """Generate a description of a device factory request. :param request: a device factory request :param original: an original device factory request or None :return: a string with the description """ attributes = [] original = original or request if not isinstance(request, DeviceFactoryRequest) \ or not isinstance(original, DeviceFactoryRequest): raise ValueError("Not instances of DeviceFactoryRequest") for name, field in get_fields(request).items(): new_value = field.get_data(request) old_value = field.get_data(original) if new_value == old_value: attribute = "{} = {}".format(name, repr(new_value)) else: attribute = "{} = {} -> {}".format(name, repr(old_value), repr(new_value)) attributes.append(attribute) return "\n".join(["{"] + attributes + ["}"])
def hide_secrets(obj: DBusData): """Hide all secrets in the given DBus data object. The function will search fields of the given DBus data object, check if the value of a field is an instance of SecretData and call its method hide_secret. :param obj: a data object with secrets :type obj: an instance of DBusData """ fields = get_fields(obj) hidden = [] for field in fields.values(): value = getattr(obj, field.data_name) if isinstance(value, SecretData): value.hide_secret() hidden.append(field.name) if hidden: log.debug("Hiding DBus fields %s.", ", ".join(hidden))