From 892f222f42640c051bfc80b44a606d47f173eb95 Mon Sep 17 00:00:00 2001 From: Diego Lovison Date: Mon, 22 Apr 2024 13:42:21 -0300 Subject: [PATCH] Output trusted host as hostname Signed-off-by: Diego Lovison --- sdk/python/kfp/cli/component_test.py | 8 ++++---- sdk/python/kfp/dsl/component_factory.py | 7 +++++-- sdk/python/kfp/dsl/component_factory_test.py | 2 +- sdk/python/requirements-dev.txt | 1 + .../test_data/components/component_with_pip_install.yaml | 4 ++-- .../pipelines/component_with_pip_index_urls.yaml | 4 ++-- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/sdk/python/kfp/cli/component_test.py b/sdk/python/kfp/cli/component_test.py index c7279559194..30b1396bd7a 100644 --- a/sdk/python/kfp/cli/component_test.py +++ b/sdk/python/kfp/cli/component_test.py @@ -496,9 +496,9 @@ def test_docker_file_is_created_correctly_with_one_url(self): WORKDIR /usr/local/src/kfp/components COPY runtime-requirements.txt runtime-requirements.txt - RUN pip install --index-url https://pypi.org/simple --trusted-host https://pypi.org/simple --no-cache-dir -r runtime-requirements.txt + RUN pip install --index-url https://pypi.org/simple --trusted-host pypi.org --no-cache-dir -r runtime-requirements.txt - RUN pip install --index-url https://pypi.org/simple --trusted-host https://pypi.org/simple --no-cache-dir kfp==1.2.3 + RUN pip install --index-url https://pypi.org/simple --trusted-host pypi.org --no-cache-dir kfp==1.2.3 COPY . . ''')) @@ -527,9 +527,9 @@ def test_docker_file_is_created_correctly_with_two_urls(self): WORKDIR /usr/local/src/kfp/components COPY runtime-requirements.txt runtime-requirements.txt - RUN pip install --index-url https://pypi.org/simple --trusted-host https://pypi.org/simple --extra-index-url https://example.com/pypi/simple --trusted-host https://example.com/pypi/simple --no-cache-dir -r runtime-requirements.txt + RUN pip install --index-url https://pypi.org/simple --trusted-host pypi.org --extra-index-url https://example.com/pypi/simple --trusted-host example.com --no-cache-dir -r runtime-requirements.txt - RUN pip install --index-url https://pypi.org/simple --trusted-host https://pypi.org/simple --extra-index-url https://example.com/pypi/simple --trusted-host https://example.com/pypi/simple --no-cache-dir kfp==1.2.3 + RUN pip install --index-url https://pypi.org/simple --trusted-host pypi.org --extra-index-url https://example.com/pypi/simple --trusted-host example.com --no-cache-dir kfp==1.2.3 COPY . . ''')) diff --git a/sdk/python/kfp/dsl/component_factory.py b/sdk/python/kfp/dsl/component_factory.py index 1af26d80bfc..c0e4dcabd9f 100644 --- a/sdk/python/kfp/dsl/component_factory.py +++ b/sdk/python/kfp/dsl/component_factory.py @@ -19,6 +19,7 @@ import textwrap from typing import (Any, Callable, Dict, List, Mapping, Optional, Tuple, Type, Union) +import urllib import warnings import docstring_parser @@ -94,9 +95,11 @@ def make_index_url_options(pip_index_urls: Optional[List[str]]) -> str: index_url = pip_index_urls[0] extra_index_urls = pip_index_urls[1:] - options = [f'--index-url {index_url} --trusted-host {index_url}'] + options = [ + f'--index-url {index_url} --trusted-host {urllib.parse.urlparse(index_url).hostname}' + ] options.extend( - f'--extra-index-url {extra_index_url} --trusted-host {extra_index_url}' + f'--extra-index-url {extra_index_url} --trusted-host {urllib.parse.urlparse(extra_index_url).hostname}' for extra_index_url in extra_index_urls) return ' '.join(options) + ' ' diff --git a/sdk/python/kfp/dsl/component_factory_test.py b/sdk/python/kfp/dsl/component_factory_test.py index b602be241fd..f6fcc2d3bb5 100644 --- a/sdk/python/kfp/dsl/component_factory_test.py +++ b/sdk/python/kfp/dsl/component_factory_test.py @@ -149,7 +149,7 @@ def test_with_packages_to_install_with_pip_index_url(self): strip_kfp_version(command), strip_kfp_version([ 'sh', '-c', - '\nif ! [ -x "$(command -v pip)" ]; then\n python3 -m ensurepip || python3 -m ensurepip --user || apt-get install python3-pip\nfi\n\nPIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --quiet --no-warn-script-location --index-url https://myurl.org/simple --trusted-host https://myurl.org/simple \'kfp==2.1.3\' \'--no-deps\' \'typing-extensions>=3.7.4,<5; python_version<"3.9"\' && python3 -m pip install --quiet --no-warn-script-location --index-url https://myurl.org/simple --trusted-host https://myurl.org/simple \'package1\' \'package2\' && "$0" "$@"\n' + '\nif ! [ -x "$(command -v pip)" ]; then\n python3 -m ensurepip || python3 -m ensurepip --user || apt-get install python3-pip\nfi\n\nPIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --quiet --no-warn-script-location --index-url https://myurl.org/simple --trusted-host myurl.org \'kfp==2.1.3\' \'--no-deps\' \'typing-extensions>=3.7.4,<5; python_version<"3.9"\' && python3 -m pip install --quiet --no-warn-script-location --index-url https://myurl.org/simple --trusted-host myurl.org \'package1\' \'package2\' && "$0" "$@"\n' ])) diff --git a/sdk/python/requirements-dev.txt b/sdk/python/requirements-dev.txt index 57c61075dee..b375d7e1234 100644 --- a/sdk/python/requirements-dev.txt +++ b/sdk/python/requirements-dev.txt @@ -15,3 +15,4 @@ types-PyYAML==6.0.5 types-requests==2.27.14 types-tabulate==0.8.6 yapf==0.32.0 +uritemplate>=3.0.1,<4 \ No newline at end of file diff --git a/sdk/python/test_data/components/component_with_pip_install.yaml b/sdk/python/test_data/components/component_with_pip_install.yaml index 75d72967614..604350f3191 100644 --- a/sdk/python/test_data/components/component_with_pip_install.yaml +++ b/sdk/python/test_data/components/component_with_pip_install.yaml @@ -18,9 +18,9 @@ deploymentSpec: - "\nif ! [ -x \"$(command -v pip)\" ]; then\n python3 -m ensurepip ||\ \ python3 -m ensurepip --user || apt-get install python3-pip\nfi\n\nPIP_DISABLE_PIP_VERSION_CHECK=1\ \ python3 -m pip install --quiet --no-warn-script-location --index-url https://pypi.org/simple\ - \ --trusted-host https://pypi.org/simple 'kfp==2.7.0' '--no-deps' 'typing-extensions>=3.7.4,<5;\ + \ --trusted-host pypi.org 'kfp==2.7.0' '--no-deps' 'typing-extensions>=3.7.4,<5;\ \ python_version<\"3.9\"' && python3 -m pip install --quiet --no-warn-script-location\ - \ --index-url https://pypi.org/simple --trusted-host https://pypi.org/simple\ + \ --index-url https://pypi.org/simple --trusted-host pypi.org\ \ 'yapf' && \"$0\" \"$@\"\n" - sh - -ec diff --git a/sdk/python/test_data/pipelines/component_with_pip_index_urls.yaml b/sdk/python/test_data/pipelines/component_with_pip_index_urls.yaml index 0359a4955c7..adf07f428cc 100644 --- a/sdk/python/test_data/pipelines/component_with_pip_index_urls.yaml +++ b/sdk/python/test_data/pipelines/component_with_pip_index_urls.yaml @@ -18,9 +18,9 @@ deploymentSpec: - "\nif ! [ -x \"$(command -v pip)\" ]; then\n python3 -m ensurepip ||\ \ python3 -m ensurepip --user || apt-get install python3-pip\nfi\n\nPIP_DISABLE_PIP_VERSION_CHECK=1\ \ python3 -m pip install --quiet --no-warn-script-location --index-url https://pypi.org/simple\ - \ --trusted-host https://pypi.org/simple 'kfp==2.7.0' '--no-deps' 'typing-extensions>=3.7.4,<5;\ + \ --trusted-host pypi.org 'kfp==2.7.0' '--no-deps' 'typing-extensions>=3.7.4,<5;\ \ python_version<\"3.9\"' && python3 -m pip install --quiet --no-warn-script-location\ - \ --index-url https://pypi.org/simple --trusted-host https://pypi.org/simple\ + \ --index-url https://pypi.org/simple --trusted-host pypi.org\ \ 'yapf' && \"$0\" \"$@\"\n" - sh - -ec