authenticator: allow multiple repos w/ same netloc#1
authenticator: allow multiple repos w/ same netloc#1abn wants to merge 6 commits intohttp-repo-cleanupfrom
Conversation
This change refactors HTTP repository source implementations. The following changes have been made. - CacheControl cache now lives within Authenticator. - Authenticator manages unique sessions for individual netloc. - CacheControl usage now respects disable cache parameter in repos. - Certificate and authentication logic is now managed solely within Authenticator for source repositories taking advantage of recent enhancements. These changes should allow for better handling of cases like those described in python-poetry#3041. Additionally, this forms the foundation for unifying HTTP specific logic within the code base and possibly allowing for migration of requests etc. if/when required.
Co-authored-by: Agni Sairent <agniczech@gmail.com>
ca4d840 to
a8e3fc8
Compare
| # repositories setting is special for now | ||
| repositories = self._get_environment_repositories() | ||
| if repositories: | ||
| return repositories |
There was a problem hiding this comment.
This should probably be merged with global config.
| ) | ||
| def _get_http_auth( | ||
| self, repository: AuthenticatorRepositoryConfig | ||
| ) -> dict[str, str | None] | None: |
There was a problem hiding this comment.
We might want to lookup repository.url in self._credentials in this method. (And populate said cache entry at the end of this method if credentials were found)
| if len(candidates_netloc_only) > 1: | ||
| logger.debug( | ||
| "Multiple source configurations found for %s - %s", | ||
| parsed_url.netloc, | ||
| ", ".join(map(lambda c: c.name, candidates_netloc_only)), | ||
| ) |
There was a problem hiding this comment.
| if len(candidates_netloc_only) > 1: | |
| logger.debug( | |
| "Multiple source configurations found for %s - %s", | |
| parsed_url.netloc, | |
| ", ".join(map(lambda c: c.name, candidates_netloc_only)), | |
| ) | |
| if len(candidates_netloc_only) > 1: | |
| from os.path import commonprefix | |
| candidates_netloc_only.sort(key=lambda c: len(commonprefix([parsed_url.path, c.path])), reverse=True) | |
| logger.debug( | |
| "Multiple source configurations found for %s - %s", | |
| parsed_url.netloc, | |
| ", ".join(map(lambda c: c.name, candidates_netloc_only)), | |
| ) |
Apparently Azure DevOps Artifact Feeds seems to start preferring the guid at some point instead of the Feed's display name.
https://pkgs.dev.azure.com/<ORG NAME>/_packaging/<FEED DISPLAY NAME>/pypi/simple/<PACKAGE>
ends up downloading
https://pkgs.dev.azure.com/<ORG NAME>/_packaging/<FEED GUID>/pypi/simple/<PACKAGE>/<VERSION>/<WHEEL>#sha256=<HASH>
resulting in the str.startswith() check to return False.
My suggestion sort on the longest common prefix for the path component of the url as a best effort.
(Azure DevOps Personal Access Tokens are scroped to an organization, not to individual projects/feeds in an organization, so this works)
|
@Darsstar thanks for the review; I have applied your suggestions and added the changes to python-poetry#5518. Another pass there would be appreciated. |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
No description provided.