OLD | NEW |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 """Defines class Rietveld to easily access a rietveld instance. | 5 """Defines class Rietveld to easily access a rietveld instance. |
6 | 6 |
7 Security implications: | 7 Security implications: |
8 | 8 |
9 The following hypothesis are made: | 9 The following hypothesis are made: |
10 - Rietveld enforces: | 10 - Rietveld enforces: |
(...skipping 19 matching lines...) Expand all Loading... |
30 import third_party.oauth2client.client as oa2client | 30 import third_party.oauth2client.client as oa2client |
31 from third_party import httplib2 | 31 from third_party import httplib2 |
32 | 32 |
33 # Appengine replies with 302 when authentication fails (sigh.) | 33 # Appengine replies with 302 when authentication fails (sigh.) |
34 oa2client.REFRESH_STATUS_CODES.append(302) | 34 oa2client.REFRESH_STATUS_CODES.append(302) |
35 upload.LOGGER.setLevel(logging.WARNING) # pylint: disable=E1103 | 35 upload.LOGGER.setLevel(logging.WARNING) # pylint: disable=E1103 |
36 | 36 |
37 | 37 |
38 class Rietveld(object): | 38 class Rietveld(object): |
39 """Accesses rietveld.""" | 39 """Accesses rietveld.""" |
40 def __init__(self, url, email, password, extra_headers=None, maxtries=None): | 40 def __init__( |
| 41 self, url, auth_config, email=None, extra_headers=None, maxtries=None): |
41 self.url = url.rstrip('/') | 42 self.url = url.rstrip('/') |
42 | 43 self.rpc_server = upload.GetRpcServer(self.url, auth_config, email) |
43 # TODO(maruel): It's not awesome but maybe necessary to retrieve the value. | |
44 # It happens when the presubmit check is ran out of process, the cookie | |
45 # needed to be recreated from the credentials. Instead, it should pass the | |
46 # email and the cookie. | |
47 if email and password: | |
48 get_creds = lambda: (email, password) | |
49 self.rpc_server = upload.HttpRpcServer( | |
50 self.url, | |
51 get_creds, | |
52 extra_headers=extra_headers or {}) | |
53 else: | |
54 if email == '': | |
55 # If email is given as an empty string, then assume we want to make | |
56 # requests that do not need authentication. Bypass authentication by | |
57 # setting the auth_function to None. | |
58 self.rpc_server = upload.HttpRpcServer(url, None) | |
59 else: | |
60 self.rpc_server = upload.GetRpcServer(url, email) | |
61 | 44 |
62 self._xsrf_token = None | 45 self._xsrf_token = None |
63 self._xsrf_token_time = None | 46 self._xsrf_token_time = None |
64 | 47 |
65 self._maxtries = maxtries or 40 | 48 self._maxtries = maxtries or 40 |
66 | 49 |
67 def xsrf_token(self): | 50 def xsrf_token(self): |
68 if (not self._xsrf_token_time or | 51 if (not self._xsrf_token_time or |
69 (time.time() - self._xsrf_token_time) > 30*60): | 52 (time.time() - self._xsrf_token_time) > 30*60): |
70 self._xsrf_token_time = time.time() | 53 self._xsrf_token_time = time.time() |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 self, issue, patchset, reason, clobber, revision, builders_and_tests, | 698 self, issue, patchset, reason, clobber, revision, builders_and_tests, |
716 master=None, category='cq'): | 699 master=None, category='cq'): |
717 logging.info('ReadOnlyRietveld: triggering try jobs %r for issue %d' % | 700 logging.info('ReadOnlyRietveld: triggering try jobs %r for issue %d' % |
718 (builders_and_tests, issue)) | 701 (builders_and_tests, issue)) |
719 | 702 |
720 def trigger_distributed_try_jobs( # pylint:disable=R0201 | 703 def trigger_distributed_try_jobs( # pylint:disable=R0201 |
721 self, issue, patchset, reason, clobber, revision, masters, | 704 self, issue, patchset, reason, clobber, revision, masters, |
722 category='cq'): | 705 category='cq'): |
723 logging.info('ReadOnlyRietveld: triggering try jobs %r for issue %d' % | 706 logging.info('ReadOnlyRietveld: triggering try jobs %r for issue %d' % |
724 (masters, issue)) | 707 (masters, issue)) |
OLD | NEW |