fix: marketplace add authenticates for private repos#688
fix: marketplace add authenticates for private repos#688jacobokeeffe-ow wants to merge 1 commit intomicrosoft:mainfrom
Conversation
_do_fetch() returned None on unauthenticated 404, preventing try_with_fallback from retrying with a token. GitHub returns 404 (not 403) for private repos to hide existence, so the auth escalation never fired. Now raise on 404 when no token is present so the fallback retries authenticated. Authenticated 404 still returns None (file genuinely missing). Public repos are unaffected.
|
@microsoft-github-policy-service agree company="Oliver Wyman" |
|
@sergio-sisternes-epam apologies for the formatting changes but when I run I might be mistaken but I don't see |
sergio-sisternes-epam
left a comment
There was a problem hiding this comment.
Clean fix -- the 6-line change in _do_fetch() correctly distinguishes "private repo hiding existence" from "file not found" by raising on unauthenticated 404 to trigger try_with_fallback auth retry. Good test coverage with 4 regression tests.
Re: formatting -- we don't enforce black in CI, so the reformatting here is fine (contained to files you touched). We should update the contributing guide to clarify this. Thanks for flagging it!
Note: CI hasn't run yet (fork PR). Would be good to get Build & Test triggered before merge.
|
thanks @sergio-sisternes-epam. I think you might need to give approval in order the get the github action to run? https://github.com/microsoft/apm/actions/runs/24339327316 : "This workflow is awaiting approval from a maintainer" |
Description
Fix
apm marketplace addfailing to fetchmarketplace.jsonfrom private repositories, even when valid authentication tokens are available.Fixes #669
Type of change
Root cause
_do_fetch()inclient.pyreturnedNoneon HTTP 404 regardless of whether a token was present. Sincetry_with_fallback(unauth_first=True)only escalates to authenticated retry on exceptions (notNonereturns), the auth fallback never fired for private repos. GitHub returns 404 (not 403) for private repos to avoid leaking existence, making the unauthenticated 404 indistinguishable from "file not found."Fix
When
_do_fetch()receives a 404 without a token, it now raises viaresp.raise_for_status()so thattry_with_fallbackcatches the exception and retries with authentication. When a 404 is received with a token, it still returnsNone(the file genuinely doesn't exist).This preserves the rate-limit optimization for public repos (unauthenticated requests succeed on first try) while correctly handling private repos.
Testing
4 new tests in
TestPrivateRepoAuth:test_private_repo_unauthenticated_404_retries_with_token— core regression testtest_authenticated_404_returns_none— genuinely missing files still returnNonetest_public_repo_unauthenticated_success— no regression for public repostest_auto_detect_private_repo_finds_marketplace_json— end-to-end through_auto_detect_pathAlso verified against a real private marketplace repo — the fix correctly resolves
marketplace.jsonand returns both plugins.