| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 """Defines class Rietveld to easily access a rietveld instance. | 4 """Defines class Rietveld to easily access a rietveld instance. |
| 5 | 5 |
| 6 Security implications: | 6 Security implications: |
| 7 | 7 |
| 8 The following hypothesis are made: | 8 The following hypothesis are made: |
| 9 - Rietveld enforces: | 9 - Rietveld enforces: |
| 10 - Nobody else than issue owner can upload a patch set | 10 - Nobody else than issue owner can upload a patch set |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 def xsrf_token(self): | 37 def xsrf_token(self): |
| 38 if (not self._xsrf_token_time or | 38 if (not self._xsrf_token_time or |
| 39 (time.time() - self._xsrf_token_time) > 30*60): | 39 (time.time() - self._xsrf_token_time) > 30*60): |
| 40 self._xsrf_token_time = time.time() | 40 self._xsrf_token_time = time.time() |
| 41 self._xsrf_token = self.get('/xsrf_token', | 41 self._xsrf_token = self.get('/xsrf_token', |
| 42 extra_headers={'X-Requesting-XSRF-Token': '1'}) | 42 extra_headers={'X-Requesting-XSRF-Token': '1'}) |
| 43 return self._xsrf_token | 43 return self._xsrf_token |
| 44 | 44 |
| 45 def close_issue(self, issue): | 45 def close_issue(self, issue): |
| 46 """Closes the Rietveld issue for this changelist.""" | 46 """Closes the Rietveld issue for this changelist.""" |
| 47 logging.info('closing issue %s' % issue) |
| 47 self.post("/%d/close" % issue, [('xsrf_token', self.xsrf_token())]) | 48 self.post("/%d/close" % issue, [('xsrf_token', self.xsrf_token())]) |
| 48 | 49 |
| 49 def get_description(self, issue): | 50 def get_description(self, issue): |
| 50 """Returns the issue's description.""" | 51 """Returns the issue's description.""" |
| 51 return self.get('/%d/description' % issue) | 52 return self.get('/%d/description' % issue) |
| 52 | 53 |
| 53 def get_issue_properties(self, issue): | 54 def get_issue_properties(self, issue): |
| 54 """Returns all the issue's metadata as a dictionary.""" | 55 """Returns all the issue's metadata as a dictionary.""" |
| 55 return json.loads(self.get('/api/%s' % issue)) | 56 return json.loads(self.get('/api/%s' % issue)) |
| 56 | 57 |
| 57 def update_description(self, issue, description): | 58 def update_description(self, issue, description): |
| 58 """Sets the description for an issue on Rietveld.""" | 59 """Sets the description for an issue on Rietveld.""" |
| 59 self.post('/%s/description' % issue, [ | 60 self.post('/%s/description' % issue, [ |
| 60 ('description', description), | 61 ('description', description), |
| 61 ('xsrf_token', self.xsrf_token())]) | 62 ('xsrf_token', self.xsrf_token())]) |
| 62 | 63 |
| 63 def add_comment(self, issue, message): | 64 def add_comment(self, issue, message): |
| 65 logging.info('issue %s; comment: %s' % (issue, message)) |
| 64 return self.post('/%s/publish' % issue, [ | 66 return self.post('/%s/publish' % issue, [ |
| 65 ('xsrf_token', self.xsrf_token()), | 67 ('xsrf_token', self.xsrf_token()), |
| 66 ('message', message), | 68 ('message', message), |
| 67 ('message_only', 'True'), | 69 ('message_only', 'True'), |
| 68 ('send_mail', 'True'), | 70 ('send_mail', 'True'), |
| 69 ('no_redirect', 'True')]) | 71 ('no_redirect', 'True')]) |
| 70 | 72 |
| 71 def set_flag(self, issue, patchset, flag, value): | 73 def set_flag(self, issue, patchset, flag, value): |
| 72 return self.post('/%s/edit_flags' % issue, [ | 74 return self.post('/%s/edit_flags' % issue, [ |
| 73 ('last_patchset', str(patchset)), | 75 ('last_patchset', str(patchset)), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 88 rpc_server = upload.HttpRpcServer(self.url, | 90 rpc_server = upload.HttpRpcServer(self.url, |
| 89 self._get_creds, | 91 self._get_creds, |
| 90 save_cookies=False) | 92 save_cookies=False) |
| 91 try: | 93 try: |
| 92 return rpc_server.Send(request_path, **kwargs) | 94 return rpc_server.Send(request_path, **kwargs) |
| 93 except urllib2.HTTPError, e: | 95 except urllib2.HTTPError, e: |
| 94 if (e.code != 500 and e.code != 503) and retry == (maxtries - 1): | 96 if (e.code != 500 and e.code != 503) and retry == (maxtries - 1): |
| 95 raise | 97 raise |
| 96 # Small backoff. | 98 # Small backoff. |
| 97 time.sleep(1+maxtries*2) | 99 time.sleep(1+maxtries*2) |
| OLD | NEW |