grr/server/grr_response_server/db_utils.py
def GenerateStatsEntryId(stats_entry):
  """Returns a unique identifier representing a StatsStoreEntry.

  The id returned (bytes) is the SHA2 hash of all fields in the StatsStoreEntry
  that should uniquely identify it in a database.

  Args:
    stats_entry: StatsStoreEntry for which to generate an id.

  Raises:
    ValueError: If a field-type in the StatsStoreEntry doesn't match
      a known MetricFieldDefinition.FieldType.
  """
  # Convert all field values to hex so they can be unambiguously
  # concatenated in a string. We first convert strings to hex so we can use
  # a separator that is guaranteed to not be present in the separate
  # parts.
  hex_field_values = []
  for field_value in stats_entry.metric_value.fields_values:
    field_type = field_value.field_type
    if field_type == rdf_stats.MetricFieldDefinition.FieldType.INT:
      hex_field_values.append(b"%x" % field_value.int_value)
    elif field_type == rdf_stats.MetricFieldDefinition.FieldType.STR:
      hex_field_values.append(_HexBytesFromUnicode(field_value.str_value))
    else:
      raise ValueError("Unknown field type %s." % field_type)

  # Create an unambiguous string representation of the fields
  # that should form an id.
  variable_length_id = b"%s-%s-%s-%x" % (
      _HexBytesFromUnicode(stats_entry.process_id),
      _HexBytesFromUnicode(stats_entry.metric_name),
      (b":".join(hex_field_values)),
      stats_entry.timestamp.AsMicrosecondsSinceEpoch())

  # Convert to a fixed-length id.
  return hashlib.sha256(variable_length_id).digest()
Returns a unique identifier representing a StatsStoreEntry.

  The id returned (bytes) is the SHA2 hash of all fields in the StatsStoreEntry
  that should uniquely identify it in a database.

  Args:
    stats_entry: StatsStoreEntry for which to generate an id.

  Raises:
    ValueError: If a field-type in the StatsStoreEntry doesn't match
      a known MetricFieldDefinition.FieldType.
  
Returns a unique identifier representing a StatsStoreEntry.
The id returned (bytes) is the SHA2 hash of all fields in the StatsStoreEntry
that should uniquely identify it in a database.
Returns a unique identifier representing a StatsStoreEntry . The id returned ( bytes ) is the SHA2 hash of all fields in the StatsStoreEntry that should uniquely identify it in a database .
def GenerateStatsEntryId(stats_entry):
  hex_field_values = []
  for field_value in stats_entry.metric_value.fields_values:
    field_type = field_value.field_type
    if field_type == rdf_stats.MetricFieldDefinition.FieldType.INT:
      hex_field_values.append(b"%x" % field_value.int_value)
    elif field_type == rdf_stats.MetricFieldDefinition.FieldType.STR:
      hex_field_values.append(_HexBytesFromUnicode(field_value.str_value))
    else:
      raise ValueError("Unknown field type %s." % field_type)
  variable_length_id = b"%s-%s-%s-%x" % (
      _HexBytesFromUnicode(stats_entry.process_id),
      _HexBytesFromUnicode(stats_entry.metric_name),
      (b":".join(hex_field_values)),
      stats_entry.timestamp.AsMicrosecondsSinceEpoch())
  return hashlib.sha256(variable_length_id).digest()
def GenerateStatsEntryId ( stats_entry ) : hex_field_values = [ ] for field_value in stats_entry . metric_value . fields_values : field_type = field_value . field_type if field_type == rdf_stats . MetricFieldDefinition . FieldType . INT : hex_field_values . append ( b"%x" % field_value . int_value ) elif field_type == rdf_stats . MetricFieldDefinition . FieldType . STR : hex_field_values . append ( _HexBytesFromUnicode ( field_value . str_value ) ) else : raise ValueError ( "Unknown field type %s." % field_type ) variable_length_id = b"%s-%s-%s-%x" % ( _HexBytesFromUnicode ( stats_entry . process_id ) , _HexBytesFromUnicode ( stats_entry . metric_name ) , ( b":" . join ( hex_field_values ) ) , stats_entry . timestamp . AsMicrosecondsSinceEpoch ( ) ) return hashlib . sha256 ( variable_length_id ) . digest ( )
Returns a unique identifier representing a StatsStoreEntry.
Returns a unique identifier representing a StatsStoreEntry .
"""Returns a unique identifier representing a StatsStoreEntry.

  The id returned (bytes) is the SHA2 hash of all fields in the StatsStoreEntry
  that should uniquely identify it in a database.

  Args:
    stats_entry: StatsStoreEntry for which to generate an id.

  Raises:
    ValueError: If a field-type in the StatsStoreEntry doesn't match
      a known MetricFieldDefinition.FieldType.
  """ # Convert all field values to hex so they can be unambiguously # concatenated in a string. We first convert strings to hex so we can use # a separator that is guaranteed to not be present in the separate # parts. # Create an unambiguous string representation of the fields # that should form an id. # Convert to a fixed-length id.
If a field-type in the StatsStoreEntry doesn't match
a known MetricFieldDefinition.FieldType.
If a field - type in the StatsStoreEntry doesn ' t match a known MetricFieldDefinition . FieldType .
ValueError
stats_entry
StatsStoreEntry for which to generate an id.
StatsStoreEntry for which to generate an id .