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 /git_config.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 'git_config.py')
| -rw-r--r-- | git_config.py | 39 |
1 files changed, 39 insertions, 0 deletions
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 @@ | |||
| 15 | 15 | ||
| 16 | from __future__ import print_function | 16 | from __future__ import print_function |
| 17 | 17 | ||
| 18 | import contextlib | ||
| 19 | import errno | ||
| 18 | import json | 20 | import json |
| 19 | import os | 21 | import os |
| 20 | import re | 22 | import re |
| @@ -502,6 +504,43 @@ def GetSchemeFromUrl(url): | |||
| 502 | return m.group(1) | 504 | return m.group(1) |
| 503 | return None | 505 | return None |
| 504 | 506 | ||
| 507 | @contextlib.contextmanager | ||
| 508 | def GetUrlCookieFile(url, quiet): | ||
| 509 | if url.startswith('persistent-'): | ||
| 510 | try: | ||
| 511 | p = subprocess.Popen( | ||
| 512 | ['git-remote-persistent-https', '-print_config', url], | ||
| 513 | stdin=subprocess.PIPE, stdout=subprocess.PIPE, | ||
| 514 | stderr=subprocess.PIPE) | ||
| 515 | try: | ||
| 516 | cookieprefix = 'http.cookiefile=' | ||
| 517 | proxyprefix = 'http.proxy=' | ||
| 518 | cookiefile = None | ||
| 519 | proxy = None | ||
| 520 | for line in p.stdout: | ||
| 521 | line = line.strip() | ||
| 522 | if line.startswith(cookieprefix): | ||
| 523 | cookiefile = line[len(cookieprefix):] | ||
| 524 | if line.startswith(proxyprefix): | ||
| 525 | proxy = line[len(proxyprefix):] | ||
| 526 | # Leave subprocess open, as cookie file may be transient. | ||
| 527 | if cookiefile or proxy: | ||
| 528 | yield cookiefile, proxy | ||
| 529 | return | ||
| 530 | finally: | ||
| 531 | p.stdin.close() | ||
| 532 | if p.wait(): | ||
| 533 | err_msg = p.stderr.read() | ||
| 534 | if ' -print_config' in err_msg: | ||
| 535 | pass # Persistent proxy doesn't support -print_config. | ||
| 536 | elif not quiet: | ||
| 537 | print(err_msg, file=sys.stderr) | ||
| 538 | except OSError as e: | ||
| 539 | if e.errno == errno.ENOENT: | ||
| 540 | pass # No persistent proxy. | ||
| 541 | raise | ||
| 542 | yield GitConfig.ForUser().GetString('http.cookiefile'), None | ||
| 543 | |||
| 505 | def _preconnect(url): | 544 | def _preconnect(url): |
| 506 | m = URI_ALL.match(url) | 545 | m = URI_ALL.match(url) |
| 507 | if m: | 546 | if m: |
