import base64


def get_api_key_header_val(api_key):
    """
    Check the type of the passed api_key and return the correct header value
    for the `API Key authentication
    <https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html>`
    :arg api_key, either a tuple or a base64 encoded string
    """
    if isinstance(api_key, (tuple, list)):
        s = "{0}:{1}".format(api_key[0], api_key[1]).encode('utf-8')
        return "ApiKey " + base64.b64encode(s).decode('utf-8')
    return "ApiKey " + api_key