Checks that the key_path exists and the key_mode is either 0400 or 0600.

    Returns True or False.

    .. versionadded:: 2016.3.0

    provider
        The provider name that the key_path to check belongs to.

    key_path
        The key_path to ensure that it exists and to check adequate permissions
        against.

def check_key_path_and_mode(provider, key_path):
    '''
    Checks that the key_path exists and the key_mode is either 0400 or 0600.

    Returns True or False.

    .. versionadded:: 2016.3.0

    provider
        The provider name that the key_path to check belongs to.

    key_path
        The key_path to ensure that it exists and to check adequate permissions
        against.
    '''
    if not os.path.exists(key_path):
        log.error(
            'The key file \'%s\' used in the \'%s\' provider configuration '
            'does not exist.\n', key_path, provider
        )
        return False

    key_mode = stat.S_IMODE(os.stat(key_path).st_mode)
    if key_mode not in (0o400, 0o600):
        log.error(
            'The key file \'%s\' used in the \'%s\' provider configuration '
            'needs to be set to mode 0400 or 0600.\n', key_path, provider
        )
        return False

    return True