class SchedulerUtil:
    """
    Auxiliary class for Google Cloud Scheduler
    """
    CRON_HEADERS = ['X-Appengine-User-Ip', 'X-Appengine-Cron']
    CRON_VALID_IPS = ['10.0.0.1', '0.1.0.1']

    @classmethod
    def is_cron_request(cls, request):
        """
        Verify if a flask request is generated by GCloud Cron Service

        "The X-Appengine-Cron header is set internally by Google App Engine. If your request handler finds
        this header it can trust that the request is a cron request. The X- headers are stripped by App Engine
        when they originate from external sources so that you can trust this header."

        Reference:
        https://cloud.google.com/appengine/docs/standard/python3/scheduling-jobs-with-cron-yaml#validating_cron_requests

        :param request: Flask Response object
        :return:        If the request was created by a google cloud cron job
        """
        headers = dict(t for t in request.headers if t[0] in cls.CRON_HEADERS)

        if set(cls.CRON_HEADERS) == headers.keys():
            return headers['X-Appengine-Cron'] and headers['X-Appengine-User-Ip'] in cls.CRON_VALID_IPS

        return False
