docs: def GetMetadataLegacy(client, token=None):
    """Builds ExportedMetadata object for a given client id.
  
    Note: This is a legacy aff4-only implementation.
    TODO(user): deprecate as soon as REL_DB migration is done.
  
    Args:
      client: RDFURN of a client or VFSGRRClient object itself.
      token: Security token.
  
    Returns:
      ExportedMetadata object with metadata of the client.
    """
    if isinstance(client, rdfvalue.RDFURN):
      client_fd = aff4.FACTORY.Open(client, mode="r", token=token)
    else:
      client_fd = client
  
    metadata = ExportedMetadata()
  
    metadata.client_urn = client_fd.urn
    metadata.client_age = client_fd.urn.age
  
    metadata.hostname = utils.SmartUnicode(
        client_fd.Get(client_fd.Schema.HOSTNAME, ""))
  
    metadata.os = utils.SmartUnicode(client_fd.Get(client_fd.Schema.SYSTEM, ""))
  
    metadata.uname = utils.SmartUnicode(client_fd.Get(client_fd.Schema.UNAME, ""))
  
    metadata.os_release = utils.SmartUnicode(
        client_fd.Get(client_fd.Schema.OS_RELEASE, ""))
  
    metadata.os_version = utils.SmartUnicode(
        client_fd.Get(client_fd.Schema.OS_VERSION, ""))
  
    kb = client_fd.Get(client_fd.Schema.KNOWLEDGE_BASE)
    usernames = ""
    if kb:
      usernames = [user.username for user in kb.users] or ""
    metadata.usernames = utils.SmartUnicode(usernames)
  
    metadata.mac_address = utils.SmartUnicode(
        client_fd.Get(client_fd.Schema.MAC_ADDRESS, ""))
  
    system_labels = set()
    user_labels = set()
    for l in client_fd.GetLabels():
      if l.owner == "GRR":
        system_labels.add(l.name)
      else:
        user_labels.add(l.name)
  
    metadata.labels = ",".join(sorted(system_labels | user_labels))
  
    metadata.system_labels = ",".join(sorted(system_labels))
  
    metadata.user_labels = ",".join(sorted(user_labels))
  
    metadata.hardware_info = client_fd.Get(client_fd.Schema.HARDWARE_INFO)
  
    metadata.kernel_version = client_fd.Get(client_fd.Schema.KERNEL)
  
    return metadata