Ran*_*ang 9 security cron google-app-engine
GAE为预定的工作提供cron工作.如何设置一些安全性以防止某人直接执行http GET?在以下示例中,我可以随时在浏览器的url字段中键入/ updateData以在以下设置中执行作业:
cron:
- description: daily update of the data in the datastore
url: /updateData
schedule: every day 00:00
timezone: ...
Run Code Online (Sandbox Code Playgroud)
小智 11
除了Paul C所说的你可以创建一个装饰器来检查X-Appengine-Cron标题,如下图所示.顺便说一句,标题不能被欺骗,这意味着如果一个未来自cron作业的请求具有此标题,App Engine将更改标题的名称.您也可以为任务编写类似的方法,在这种情况下检查X-AppEngine-TaskName.
"""
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
Run Code Online (Sandbox Code Playgroud)
并将其用作:
class ClassName(webapp2.RequestHandler):
@cron_method
def get(self):
....
Run Code Online (Sandbox Code Playgroud)
你需要添加
login: admin
Run Code Online (Sandbox Code Playgroud)
如此详述:为Cron保护URLS
例如
application: hello-cron
version: 1
runtime: python27
api_version: 1
handlers:
- url: /updateData
script: reports.app
login: admin
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2369 次 |
| 最近记录: |