def format_key_as_mldock_env_var(key, prefix=None):
    """
    Formats key as mldock env variable.
    Replace ' ' and '-', append mldock prefix
    and lastly transforms to uppercase
    """
    if prefix is not None:
        if not key.lower().startswith(prefix.lower()):
            key = "{PREFIX}_{KEY}".format(PREFIX=prefix, KEY=key)

    key = key.replace(" ", "_").replace("-", "_")
    key = key.upper()
    return key