mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
Update proto_client to notify the user when auth cookies are accessed
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
parent
2450a2987a
commit
d3c388391e
@ -1 +1 @@
|
|||||||
__version__ = 'v1.0-14-gc4f226bc'
|
__version__ = 'v1.0-69-gd1f8508c'
|
||||||
|
@ -20,6 +20,7 @@ import md5
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import socket
|
import socket
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
import urllib2
|
||||||
@ -29,6 +30,38 @@ from froofle.protobuf.service import RpcChannel
|
|||||||
from froofle.protobuf.service import RpcController
|
from froofle.protobuf.service import RpcController
|
||||||
from need_retry_pb2 import RetryRequestLaterResponse;
|
from need_retry_pb2 import RetryRequestLaterResponse;
|
||||||
|
|
||||||
|
_cookie_jars = {}
|
||||||
|
|
||||||
|
def _open_jar(path):
|
||||||
|
auth = False
|
||||||
|
|
||||||
|
if path is None:
|
||||||
|
c = cookielib.CookieJar()
|
||||||
|
else:
|
||||||
|
c = _cookie_jars.get(path)
|
||||||
|
if c is None:
|
||||||
|
c = cookielib.MozillaCookieJar(path)
|
||||||
|
|
||||||
|
if os.path.exists(path):
|
||||||
|
try:
|
||||||
|
c.load()
|
||||||
|
auth = True
|
||||||
|
except (cookielib.LoadError, IOError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
if auth:
|
||||||
|
print >>sys.stderr, \
|
||||||
|
'Loaded authentication cookies from %s' \
|
||||||
|
% path
|
||||||
|
else:
|
||||||
|
os.close(os.open(path, os.O_CREAT, 0600))
|
||||||
|
os.chmod(path, 0600)
|
||||||
|
_cookie_jars[path] = c
|
||||||
|
else:
|
||||||
|
auth = True
|
||||||
|
return c, auth
|
||||||
|
|
||||||
|
|
||||||
class ClientLoginError(urllib2.HTTPError):
|
class ClientLoginError(urllib2.HTTPError):
|
||||||
"""Raised to indicate an error authenticating with ClientLogin."""
|
"""Raised to indicate an error authenticating with ClientLogin."""
|
||||||
|
|
||||||
@ -269,6 +302,9 @@ class HttpRpc(RpcChannel):
|
|||||||
self._GetAuthCookie(auth_token)
|
self._GetAuthCookie(auth_token)
|
||||||
self.authenticated = True
|
self.authenticated = True
|
||||||
if self.cookie_file is not None:
|
if self.cookie_file is not None:
|
||||||
|
print >>sys.stderr, \
|
||||||
|
'Saving authentication cookies to %s' \
|
||||||
|
% self.cookie_file
|
||||||
self.cookie_jar.save()
|
self.cookie_jar.save()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -337,24 +373,8 @@ class HttpRpc(RpcChannel):
|
|||||||
opener.add_handler(urllib2.HTTPDefaultErrorHandler())
|
opener.add_handler(urllib2.HTTPDefaultErrorHandler())
|
||||||
opener.add_handler(urllib2.HTTPSHandler())
|
opener.add_handler(urllib2.HTTPSHandler())
|
||||||
opener.add_handler(urllib2.HTTPErrorProcessor())
|
opener.add_handler(urllib2.HTTPErrorProcessor())
|
||||||
if self.cookie_file is not None:
|
|
||||||
self.cookie_jar = cookielib.MozillaCookieJar(self.cookie_file)
|
self.cookie_jar, \
|
||||||
if os.path.exists(self.cookie_file):
|
self.authenticated = _open_jar(self.cookie_file)
|
||||||
try:
|
|
||||||
self.cookie_jar.load()
|
|
||||||
self.authenticated = True
|
|
||||||
except (cookielib.LoadError, IOError):
|
|
||||||
# Failed to load cookies - just ignore them.
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
# Create an empty cookie file with mode 600
|
|
||||||
fd = os.open(self.cookie_file, os.O_CREAT, 0600)
|
|
||||||
os.close(fd)
|
|
||||||
# Always chmod the cookie file
|
|
||||||
os.chmod(self.cookie_file, 0600)
|
|
||||||
else:
|
|
||||||
# Don't save cookies across runs of update.py.
|
|
||||||
self.cookie_jar = cookielib.CookieJar()
|
|
||||||
opener.add_handler(urllib2.HTTPCookieProcessor(self.cookie_jar))
|
opener.add_handler(urllib2.HTTPCookieProcessor(self.cookie_jar))
|
||||||
return opener
|
return opener
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user