From 0745bb26571e0cf097baebd48761b8cd743ec7fc Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Mon, 17 Aug 2015 13:41:45 -0700 Subject: Support smart-sync through persistent-http[s] Use the same cookies and proxy that git traffic goes through for persistent-http[s] to support authentication for smart-sync. Change-Id: I20f4a281c259053a5a4fdbc48b1bca48e781c692 --- git_config.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'git_config.py') diff --git a/git_config.py b/git_config.py index 8ded7c25..0379181a 100644 --- a/git_config.py +++ b/git_config.py @@ -15,6 +15,8 @@ from __future__ import print_function +import contextlib +import errno import json import os import re @@ -502,6 +504,43 @@ def GetSchemeFromUrl(url): return m.group(1) return None +@contextlib.contextmanager +def GetUrlCookieFile(url, quiet): + if url.startswith('persistent-'): + try: + p = subprocess.Popen( + ['git-remote-persistent-https', '-print_config', url], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + try: + cookieprefix = 'http.cookiefile=' + proxyprefix = 'http.proxy=' + cookiefile = None + proxy = None + for line in p.stdout: + line = line.strip() + if line.startswith(cookieprefix): + cookiefile = line[len(cookieprefix):] + if line.startswith(proxyprefix): + proxy = line[len(proxyprefix):] + # Leave subprocess open, as cookie file may be transient. + if cookiefile or proxy: + yield cookiefile, proxy + return + finally: + p.stdin.close() + if p.wait(): + err_msg = p.stderr.read() + if ' -print_config' in err_msg: + pass # Persistent proxy doesn't support -print_config. + elif not quiet: + print(err_msg, file=sys.stderr) + except OSError as e: + if e.errno == errno.ENOENT: + pass # No persistent proxy. + raise + yield GitConfig.ForUser().GetString('http.cookiefile'), None + def _preconnect(url): m = URI_ALL.match(url) if m: -- cgit v1.2.3-54-g00ecf