diff options
author | Dan Willemsen <dwillemsen@google.com> | 2015-08-17 13:41:45 -0700 |
---|---|---|
committer | Dan Willemsen <dwillemsen@google.com> | 2015-08-19 10:22:11 -0700 |
commit | 0745bb26571e0cf097baebd48761b8cd743ec7fc (patch) | |
tree | b8d83d1ec06cd3d430dfc2f5447276e38e2f86f7 /project.py | |
parent | 5d0c3a614edc3f3d5967cfc07c7981da7013ea91 (diff) | |
download | git-repo-0745bb26571e0cf097baebd48761b8cd743ec7fc.tar.gz |
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
Diffstat (limited to 'project.py')
-rw-r--r-- | project.py | 39 |
1 files changed, 2 insertions, 37 deletions
@@ -13,7 +13,6 @@ | |||
13 | # limitations under the License. | 13 | # limitations under the License. |
14 | 14 | ||
15 | from __future__ import print_function | 15 | from __future__ import print_function |
16 | import contextlib | ||
17 | import errno | 16 | import errno |
18 | import filecmp | 17 | import filecmp |
19 | import glob | 18 | import glob |
@@ -31,7 +30,7 @@ import traceback | |||
31 | 30 | ||
32 | from color import Coloring | 31 | from color import Coloring |
33 | from git_command import GitCommand, git_require | 32 | from git_command import GitCommand, git_require |
34 | from git_config import GitConfig, IsId, GetSchemeFromUrl, ID_RE | 33 | from git_config import GitConfig, IsId, GetSchemeFromUrl, GetUrlCookieFile, ID_RE |
35 | from error import GitError, HookError, UploadError, DownloadError | 34 | from error import GitError, HookError, UploadError, DownloadError |
36 | from error import ManifestInvalidRevisionError | 35 | from error import ManifestInvalidRevisionError |
37 | from error import NoManifestException | 36 | from error import NoManifestException |
@@ -2030,7 +2029,7 @@ class Project(object): | |||
2030 | os.remove(tmpPath) | 2029 | os.remove(tmpPath) |
2031 | if 'http_proxy' in os.environ and 'darwin' == sys.platform: | 2030 | if 'http_proxy' in os.environ and 'darwin' == sys.platform: |
2032 | cmd += ['--proxy', os.environ['http_proxy']] | 2031 | cmd += ['--proxy', os.environ['http_proxy']] |
2033 | with self._GetBundleCookieFile(srcUrl, quiet) as cookiefile: | 2032 | with GetUrlCookieFile(srcUrl, quiet) as (cookiefile, proxy): |
2034 | if cookiefile: | 2033 | if cookiefile: |
2035 | cmd += ['--cookie', cookiefile, '--cookie-jar', cookiefile] | 2034 | cmd += ['--cookie', cookiefile, '--cookie-jar', cookiefile] |
2036 | if srcUrl.startswith('persistent-'): | 2035 | if srcUrl.startswith('persistent-'): |
@@ -2078,40 +2077,6 @@ class Project(object): | |||
2078 | except OSError: | 2077 | except OSError: |
2079 | return False | 2078 | return False |
2080 | 2079 | ||
2081 | @contextlib.contextmanager | ||
2082 | def _GetBundleCookieFile(self, url, quiet): | ||
2083 | if url.startswith('persistent-'): | ||
2084 | try: | ||
2085 | p = subprocess.Popen( | ||
2086 | ['git-remote-persistent-https', '-print_config', url], | ||
2087 | stdin=subprocess.PIPE, stdout=subprocess.PIPE, | ||
2088 | stderr=subprocess.PIPE) | ||
2089 | try: | ||
2090 | prefix = 'http.cookiefile=' | ||
2091 | cookiefile = None | ||
2092 | for line in p.stdout: | ||
2093 | line = line.strip() | ||
2094 | if line.startswith(prefix): | ||
2095 | cookiefile = line[len(prefix):] | ||
2096 | break | ||
2097 | # Leave subprocess open, as cookie file may be transient. | ||
2098 | if cookiefile: | ||
2099 | yield cookiefile | ||
2100 | return | ||
2101 | finally: | ||
2102 | p.stdin.close() | ||
2103 | if p.wait(): | ||
2104 | err_msg = p.stderr.read() | ||
2105 | if ' -print_config' in err_msg: | ||
2106 | pass # Persistent proxy doesn't support -print_config. | ||
2107 | elif not quiet: | ||
2108 | print(err_msg, file=sys.stderr) | ||
2109 | except OSError as e: | ||
2110 | if e.errno == errno.ENOENT: | ||
2111 | pass # No persistent proxy. | ||
2112 | raise | ||
2113 | yield GitConfig.ForUser().GetString('http.cookiefile') | ||
2114 | |||
2115 | def _Checkout(self, rev, quiet=False): | 2080 | def _Checkout(self, rev, quiet=False): |
2116 | cmd = ['checkout'] | 2081 | cmd = ['checkout'] |
2117 | if quiet: | 2082 | if quiet: |