git-remote-sso.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python3
  2. # Copyright 2024 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. import os
  6. import shutil
  7. import sys
  8. import tempfile
  9. from pathlib import Path
  10. THIS_DIR = Path(__file__).parent.absolute()
  11. with tempfile.TemporaryDirectory() as tempdir:
  12. tempdir = Path(tempdir)
  13. target_config = tempdir / "gitconfig"
  14. target_cookies = tempdir / "cookiefile.txt"
  15. shutil.copyfile(THIS_DIR / "gitconfig", target_config)
  16. shutil.copyfile(THIS_DIR / "cookiefile.txt", target_cookies)
  17. print('http.proxy=localhost:12345')
  18. print(f'include.path={target_config}')
  19. print(f'http.cookiefile={target_cookies}')
  20. sys.stdout.flush()
  21. # need to fully close file descriptor, sys.stdout.close() doesn't seem to cut
  22. # it.
  23. os.close(1)
  24. print("OK", file=sys.stderr)
  25. # block until stdin closes, then clean everything via TemporaryDirectory().
  26. #
  27. # This emulates the behavior of the real git-remote-sso helper which just
  28. # prints temporary configuration for a daemon running elsewhere.
  29. sys.stdin.read()