Ejemplo n.º 1
0
  def Post(self):
    # Pull out the Job ID and reason in the request.
    args = self.request.params.mixed()
    job_id = args.get('job_id')
    reason = args.get('reason')
    if not job_id or not reason:
      raise api_request_handler.BadRequestError()

    job = job_module.JobFromId(job_id)
    if not job:
      raise api_request_handler.NotFoundError()

    # Enforce first that only the users that started the job and administrators
    # can cancel jobs.
    email = utils.GetEmail()
    if not utils.IsAdministrator() and email != job.user:
      raise api_request_handler.ForbiddenError()

    # Truncate the reason down to 255 caracters including ellipses.
    try:
      job.Cancel(email, reason[:252] + '...' if len(reason) > 255 else reason)
      return {'job_id': job.job_id, 'state': 'Cancelled'}
    except errors.CancelError as e:
      self.response.set_status(400)
      return {'job_id': job.job_id, 'message': e.message}
Ejemplo n.º 2
0
 def _CheckUser(self):
   self._CheckIsLoggedIn()
   if not utils.IsTryjobUser():
     raise api_request_handler.ForbiddenError()
Ejemplo n.º 3
0
 def _CheckUser(self):
   if not utils.IsValidSheriffUser():
     raise api_request_handler.ForbiddenError()
Ejemplo n.º 4
0
 def UnprivilegedPost(self):
     # Fall back to ip whitelisting
     if self.request.remote_addr not in utils.GetIpWhitelist():
         raise api_request_handler.ForbiddenError()
     self.PrivilegedPost()
Ejemplo n.º 5
0
 def _CheckUser(self):
     self._CheckIsLoggedIn()
     if not datastore_hooks.IsUnalteredQueryPermitted():
         raise api_request_handler.ForbiddenError()
 def Post(self):
     raise api_request_handler.ForbiddenError()