from pathlib import Path
from typing import Optional
import yaml


def get_key_from_config(config_file: Path) -> Optional[str]:
    """
    In previous versions of the CCN, it was possible to set the key value directly
    in the config file. This function tries to find it in the config or returns None.

    :param config_file: Path to the CCN configuration file.
    :return: The private key used to identify the node on the P2P network, or None
             if the key is not provided in the config file.
    """
    with open(config_file) as f:
        config = yaml.safe_load(f)

    try:
        return config["p2p"]["key"]
    except KeyError:
        return None