In addition to what Paul C said, you can create a decorator that checks the X-Appengine-Cron header, as shown below. Btw, the header cannot be faked, which means that if a request that was not created from the cron job has that header, App Engine will change the header name. You can also write a similar method for tasks by checking the X-AppEngine-TaskName in this case.
""" Decorator to indicate that this is a cron method and applies request.headers check """ def cron_method(handler): def check_if_cron(self, *args, **kwargs): if self.request.headers.get('X-AppEngine-Cron') is None: self.error(403) else: return handler(self, *args, **kwargs) return check_if_cron
And use it like:
class ClassName(webapp2.RequestHandler): @cron_method def get(self): ....
source share