Remove dead code from pypi_proxy.py
- Remove unused imports (UpstreamClient, UpstreamClientConfig, UpstreamHTTPError, UpstreamConnectionError, UpstreamTimeoutError) - Simplify matched_source selection logic, removing dead conditional that always evaluated to True due to 'or True'
This commit is contained in:
@@ -19,13 +19,6 @@ from sqlalchemy.orm import Session
|
|||||||
from .database import get_db
|
from .database import get_db
|
||||||
from .models import UpstreamSource, CachedUrl, Artifact, Project, Package, Tag
|
from .models import UpstreamSource, CachedUrl, Artifact, Project, Package, Tag
|
||||||
from .storage import S3Storage, get_storage
|
from .storage import S3Storage, get_storage
|
||||||
from .upstream import (
|
|
||||||
UpstreamClient,
|
|
||||||
UpstreamClientConfig,
|
|
||||||
UpstreamHTTPError,
|
|
||||||
UpstreamConnectionError,
|
|
||||||
UpstreamTimeoutError,
|
|
||||||
)
|
|
||||||
from .config import get_env_upstream_sources
|
from .config import get_env_upstream_sources
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -360,18 +353,10 @@ async def pypi_download_file(
|
|||||||
# Not cached - fetch from upstream
|
# Not cached - fetch from upstream
|
||||||
sources = _get_pypi_upstream_sources(db)
|
sources = _get_pypi_upstream_sources(db)
|
||||||
|
|
||||||
# Find a source that matches the upstream URL
|
# Use the first available source for authentication headers
|
||||||
matched_source = None
|
# Note: The upstream URL may point to files.pythonhosted.org or other CDNs,
|
||||||
for source in sources:
|
# not the configured source URL directly, so we can't strictly validate the host
|
||||||
source_url = getattr(source, 'url', '')
|
matched_source = sources[0] if sources else None
|
||||||
# Check if the upstream URL could come from this source
|
|
||||||
# (This is a loose check - the URL might be from files.pythonhosted.org)
|
|
||||||
if urlparse(upstream_url).netloc in source_url or True: # Allow any source for now
|
|
||||||
matched_source = source
|
|
||||||
break
|
|
||||||
|
|
||||||
if not matched_source and sources:
|
|
||||||
matched_source = sources[0] # Use first source for auth if available
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
headers = {"User-Agent": "Orchard-PyPI-Proxy/1.0"}
|
headers = {"User-Agent": "Orchard-PyPI-Proxy/1.0"}
|
||||||
|
|||||||
Reference in New Issue
Block a user