Commit 9414599a authored by ilevy@chromium.org's avatar ilevy@chromium.org

Add anonymous-only option to apply_issue

Add an option to apply_issue to fail if anonymous access
triggers a login prompt.
- cherry-pick upload.py rietveld cl 37c73ece82d0 which
   allows clients to request no authentication.

BUG=240634

Review URL: https://chromiumcodereview.appspot.com/20634003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@214023 0039d316-1c4b-4281-b951-d872f2087c98
parent 8d1a14ff
......@@ -65,6 +65,8 @@ def main():
'--server',
default='http://codereview.chromium.org',
help='Rietveld server')
parser.add_option('--no-auth', action='store_true',
help='Do not attempt authenticated requests.')
options, args = parser.parse_args()
logging.basicConfig(
format='%(levelname)5s %(module)11s(%(lineno)4d): %(message)s',
......@@ -96,6 +98,8 @@ def main():
except urllib2.HTTPError, e:
if e.getcode() != 302:
raise
elif options.no_auth:
exit('FAIL: Login detected -- is issue private?')
# TODO(maruel): A few 'Invalid username or password.' are printed first, we
# should get rid of those.
except rietveld.upload.ClientLoginError, e:
......
......@@ -50,10 +50,8 @@ class Rietveld(object):
if email == '':
# If email is given as an empty string, then assume we want to make
# requests that do not need authentication. Bypass authentication by
# setting the flag to True.
get_creds = lambda: (email, None)
self.rpc_server = upload.HttpRpcServer(url, get_creds)
self.rpc_server.authenticated = True
# setting the auth_function to None.
self.rpc_server = upload.HttpRpcServer(url, None)
else:
self.rpc_server = upload.GetRpcServer(url, email)
......
......@@ -424,7 +424,7 @@ class AbstractRpcServer(object):
"""
# TODO: Don't require authentication. Let the server say
# whether it is necessary.
if not self.authenticated:
if not self.authenticated and self.auth_function:
self._Authenticate()
old_timeout = socket.getdefaulttimeout()
......@@ -451,6 +451,8 @@ class AbstractRpcServer(object):
if tries > 3:
raise
elif e.code == 401 or e.code == 302:
if not self.auth_function:
raise
self._Authenticate()
elif e.code == 301:
# Handle permanent redirect manually.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment