-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
o.hostname and self.__hostname don't align for private repos #3398
Copy link
Copy link
Closed
Description
Hi everyone
There is an issue with private domains in the requester:
The following setup, will fail because the way the domains for private repos are matched is currently flawed, when setting a base_url like https://api.github.YOUR-ORG.com in the GitHub class (Library Version 2.8.1)
...
# Create GitHub App integration
auth = Auth.AppAuth(app_id, private_key).get_installation_auth(
installation_id
)
# Create GitHub client with access token
github = Github(base_url="https://api.github.ORG.com", auth=auth)
repo = github.get_repo(f"{repo_owner}/{repo_name}") # <---- Will work without any problems
readme = repo.get_readme(ref=branch) # <---- Will explode because of assertion error
...Will have this error:
Traceback (most recent call last):
File "/home/code/main.py", line 70, in <module>
main()
File "/home/code/main.py", line 66, in main
raise e
File "/home/code/main.py", line 50, in main
readme_content = fetch_github_readme(
^^^^^^^^^^^^^^^^^^^^
File "/home/code/main.py", line 37, in fetch_github_readme
return repo.get_readme(ref=branch).decoded_content.decode("utf-8")
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/code/.venv/lib/python3.12/site-packages/github/Repository.py", line 3513, in get_readme
headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/readme", parameters=url_parameters)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/code/.venv/lib/python3.12/site-packages/github/Requester.py", line 630, in requestJsonAndCheck
self.__customConnection(url),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/code/.venv/lib/python3.12/site-packages/github/Requester.py", line 882, in __customConnection
self.__assertUrlAllowed(url)
File "/home/code/.venv/lib/python3.12/site-packages/github/Requester.py", line 876, in __assertUrlAllowed
assert self.__hostnameHasDomain(o.hostname, self.__hostname), o.hostname
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: github.ORG.com
This is a result of this function not working correctly when comparing the domain and the hostname:
@classmethod
def __hostnameHasDomain(cls, hostname: str, domain_or_domains: str | tuple[str, ...]) -> bool:
if isinstance(domain_or_domains, str):
if hostname == domain_or_domains:
return True
domain_suffix = f".{domain_or_domains}"
return hostname.endswith(domain_suffix)
return any(cls.__hostnameHasDomain(hostname, d) for d in domain_or_domains)In this case, we are matching api.github.ORG.com (self__hostname) with github.ORG.com (o.hostname)
and when I change this to do a bi-directional check, it will work properly and give me the README.md.
I have proposed a fix in a PR mentioned, which resolves the issue of not beeing able to fetch the readme in the way that I have shown above.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels