| 45 | |
| 46 | |
| 47 | def github_host_endpoints(host: str) -> GithubHostEndpoints: |
| 48 | normalized: Final = normalized_github_host(host) |
| 49 | if normalized is None: |
| 50 | raise ValueError("host must be github.com or a single-subdomain GHE.com hostname") |
| 51 | client_id: Final = os.getenv("GITHUB_COPILOT_CLIENT_ID", DEFAULT_GITHUB_CLIENT_ID) |
| 52 | if normalized == GITHUB_COPILOT_DEFAULT_HOST: |
| 53 | return GithubHostEndpoints( |
| 54 | host=normalized, |
| 55 | device_code_url=os.getenv("GITHUB_COPILOT_DEVICE_CODE_URL", DEFAULT_GITHUB_DEVICE_CODE_URL), |
| 56 | access_token_url=os.getenv("GITHUB_COPILOT_ACCESS_TOKEN_URL", DEFAULT_GITHUB_ACCESS_TOKEN_URL), |
| 57 | copilot_user_url=DEFAULT_GITHUB_COPILOT_USER_URL, |
| 58 | user_url="https://api.github.com/user", |
| 59 | client_id=client_id, |
| 60 | copilot_api_hosts=frozenset({"githubcopilot.com"}), |
| 61 | copilot_api_host_suffix=".githubcopilot.com", |
| 62 | default_copilot_api_base="https://api.githubcopilot.com", |
| 63 | ) |
| 64 | |
| 65 | subdomain: Final = normalized.removesuffix(".ghe.com") |
| 66 | api_host: Final = f"api.{subdomain}.ghe.com" |
| 67 | copilot_api_host: Final = f"copilot-api.{subdomain}.ghe.com" |
| 68 | return GithubHostEndpoints( |
| 69 | host=normalized, |
| 70 | device_code_url=f"https://{normalized}/login/device/code", |
| 71 | access_token_url=f"https://{normalized}/login/oauth/access_token", |
| 72 | copilot_user_url=f"https://{api_host}/copilot_internal/user", |
| 73 | user_url=f"https://{api_host}/user", |
| 74 | client_id=client_id, |
| 75 | copilot_api_hosts=frozenset({copilot_api_host}), |
| 76 | copilot_api_host_suffix=None, |
| 77 | default_copilot_api_base=f"https://{copilot_api_host}", |
| 78 | ) |