import typing
import hashlib


def generate_id(entry: typing.Dict) -> str:
    """
    Generate a fairly unique key for a log entry
    """
    if "@alb" in entry:
        # ALBs already have one
        key = entry["@alb"]["trace_id"]
    else:
        # for ELBs, take the elb id, client socket, timestamp, and size of the client request`
        key = ":".join(
            [
                entry["@elb"]["elb"]["id"],
                entry["@elb"]["client"]["ip"],
                str(entry["@elb"]["client"]["port"]),
                entry["@timestamp"],
                str(entry["@elb"]["received_bytes"]),
            ]
        )
    key = bytes(key, "utf-8")

    # take a shasum of the key, mostly so people don't try to attach meaning to it
    return hashlib.sha256(key).hexdigest()