Restores config files from backup and instructs user on final folder removal.
()
| 2823 | def ensure_github_connected_for_sponsors(): |
| 2824 | """Uses the existing gh login flow before accessing Sponsors-Only content.""" |
| 2825 | if not github_cli_available(): |
| 2826 | print("[!] GitHub CLI (gh) could not be installed. Run manually: pkg install gh") |
| 2827 | return False |
| 2828 | |
| 2829 | if github_auth_status(): |
| 2830 | username = github_current_username() |
| 2831 | config = load_github_account_config() |
| 2832 | if username and (not config.get("connected") or config.get("username") != username): |
| 2833 | save_github_account_config({ |
| 2834 | "connected": True, |
| 2835 | "username": username, |
| 2836 | "connected_at": config.get("connected_at", time.time()), |
| 2837 | "prompt_auto_username": config.get("prompt_auto_username", True), |
| 2838 | }) |
| 2839 | return True |
| 2840 | |
| 2841 | answer = input(_("GitHub is not connected yet. Connect GitHub now? (y/n): ")).strip().lower() |
| 2842 | if answer not in ("y", "yes"): |
| 2843 | print(_("GitHub connection is required for Sponsors-Only scripts.")) |
| 2844 | return False |
| 2845 | |
| 2846 | connect_github_account() |
| 2847 | return github_auth_status() |
| 2848 | |
| 2849 | |
| 2850 | def github_token_for_sponsors(): |
| 2851 | """Returns the active gh token without printing it.""" |
| 2852 | token = github_auth_token() |
| 2853 | return (token or "").strip() |
| 2854 | |
| 2855 | |
| 2856 | def _write_sponsors_git_askpass(token): |
| 2857 | """Creates a temporary GIT_ASKPASS helper so private git access avoids gh GraphQL.""" |
| 2858 | askpass_path = os.path.join(HOME_DIR, f".dedsec_sponsors_askpass_{os.getpid()}.py") |
| 2859 | script = """#!/usr/bin/env python3 |
| 2860 | import os |
| 2861 | import sys |
| 2862 | prompt = " ".join(sys.argv[1:]).lower() |
| 2863 | if "username" in prompt: |
| 2864 | print("x-access-token") |
| 2865 | else: |
| 2866 | print(os.environ.get("DEDSEC_GITHUB_TOKEN", "")) |
| 2867 | """ |
no test coverage detected