Skip to content

Commit

Permalink
Addresses Issue pypa#5572: Implement PIP_TRUSTED_HOSTS logic...
Browse files Browse the repository at this point in the history
Duplicated logic from `import_requirements()` in requirements.py
to `do_install()` in `install.py` to allow users to specify index
via `--index` command-line option and validate against
`PIP_TRUSTED_HOSTS` when determining `verify_ssl` value.
  • Loading branch information
kalebmckale committed Mar 10, 2023
1 parent 8c8d3d1 commit d7dec99
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/5572.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement PIP_TRUSTED_HOSTS logic from importing requirements to specified --index URL.
17 changes: 15 additions & 2 deletions pipenv/routines/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pipenv.routines.lock import do_lock
from pipenv.utils.dependencies import convert_deps_to_pip, is_star
from pipenv.utils.indexes import get_source_list
from pipenv.utils.internet import download_file, is_valid_url
from pipenv.utils.internet import download_file, get_host_and_port, is_valid_url
from pipenv.utils.pip import (
format_pip_error,
format_pip_output,
Expand Down Expand Up @@ -334,8 +334,21 @@ def do_install(
)
# Add the package to the Pipfile.
if index_url:
trusted_hosts = get_trusted_hosts()
host_and_port = get_host_and_port(index_url)
require_valid_https = not any(
(
v in trusted_hosts
for v in (
host_and_port,
host_and_port.partition(":")[
0
], # also check if hostname without port is in trusted_hosts
)
)
)
index_name = project.add_index_to_pipfile(
index_url, verify_ssl=index_url.startswith("https:")
index_url, verify_ssl=require_valid_https
)
pkg_requirement.index = index_name
try:
Expand Down

0 comments on commit d7dec99

Please sign in to comment.