From b751b9b41ab3ccba3a46facd2a2309e64e935e46 Mon Sep 17 00:00:00 2001 From: Anders Albert <60234212+doctrino@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:59:29 +0100 Subject: [PATCH] [CDF-23155] No warning on private link (#2034) --- CHANGELOG.md | 4 ++++ cognite/client/_version.py | 2 +- cognite/client/config.py | 6 ++++-- pyproject.toml | 2 +- tests/tests_unit/test_config.py | 28 ++++++++++++++++++++-------- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc449ef383..eef519bb63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ Changes are grouped as follows - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. +## [7.67.4] - 2024-11-21 +### Fixed +- Creating a `CogniteClient` no longer gives a `UserWarning` for private link projects. + ## [7.67.3] - 2024-11-20 ### Fixed - Fixed wrong url paths for `client.hosted_extractors.jobs.[list_logs, list_metrics]` diff --git a/cognite/client/_version.py b/cognite/client/_version.py index 039e994b19..ca8a7d2df3 100644 --- a/cognite/client/_version.py +++ b/cognite/client/_version.py @@ -1,4 +1,4 @@ from __future__ import annotations -__version__ = "7.67.3" +__version__ = "7.67.4" __api_subversion__ = "20230101" diff --git a/cognite/client/config.py b/cognite/client/config.py index 45ae37259b..6ab06079d6 100644 --- a/cognite/client/config.py +++ b/cognite/client/config.py @@ -271,6 +271,8 @@ def load(cls, config: dict[str, Any] | str) -> ClientConfig: @property def cdf_cluster(self) -> str | None: # A best effort attempt to extract the cluster from the base url - if match := re.match(r"https?://([^/\.\s]+)\.cognitedata\.com(?::\d+)?(?:/|$)", self.base_url): - return match.group(1) + if match := re.match( + r"https?://([^/\.\s]*\.plink\.)?([^/\.\s]+)\.cognitedata\.com(?::\d+)?(?:/|$)", self.base_url + ): + return match.group(2) return None diff --git a/pyproject.toml b/pyproject.toml index 8bf3083ff4..fd494e1c87 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "cognite-sdk" -version = "7.67.3" +version = "7.67.4" description = "Cognite Python SDK" readme = "README.md" documentation = "https://cognite-sdk-python.readthedocs-hosted.com" diff --git a/tests/tests_unit/test_config.py b/tests/tests_unit/test_config.py index 68ad5b82ab..9ea27a1726 100644 --- a/tests/tests_unit/test_config.py +++ b/tests/tests_unit/test_config.py @@ -69,7 +69,7 @@ def test_load_non_existent_attr(self): @pytest.fixture -def client_config(): +def client_config() -> ClientConfig: return ClientConfig.default( **{ "project": "test-project", @@ -108,14 +108,26 @@ def test_load(self, credentials): @pytest.mark.parametrize("protocol", ("http", "https")) @pytest.mark.parametrize("end", ("", "/", ":8080", "/api/v1/", ":8080/api/v1/")) - def test_extract_cdf_cluster(self, client_config, protocol, end): - for valid in ("3D", "my_clus-ter", "jazz-testing-asia-northeast1-1", "trial-00ed82e12d9cbadfe28e4"): - client_config.base_url = f"{protocol}://{valid}.cognitedata.com{end}" - assert client_config.cdf_cluster == valid + @pytest.mark.parametrize("subdomain", ("", "p001.plink.")) + @pytest.mark.parametrize( + "cluster", ("3D", "my_clus-ter", "jazz-testing-asia-northeast1-1", "trial-00ed82e12d9cbadfe28e4") + ) + def test_extract_valid_cdf_cluster( + self, client_config: ClientConfig, protocol: str, end: str, subdomain: str, cluster: str + ) -> None: + client_config.base_url = f"{protocol}://{subdomain}{cluster}.cognitedata.com{end}" + assert client_config.cdf_cluster == cluster - for invalid in ("", ".", "..", "huh.my_cluster."): - client_config.base_url = f"{protocol}://{valid}cognitedata.com{end}" - assert client_config.cdf_cluster is None + @pytest.mark.parametrize("protocol", ("http", "https")) + @pytest.mark.parametrize("end", ("", "/", ":8080", "/api/v1/", ":8080/api/v1/")) + @pytest.mark.parametrize("subdomain", ("", "p001.plink.")) + @pytest.mark.parametrize("cluster", ("", ".", "..", "huh.my_cluster.")) + def test_extract_invalid_cdf_cluster( + self, client_config: ClientConfig, protocol: str, end: str, subdomain: str, cluster: str + ) -> None: + client_config.base_url = f"{protocol}://{subdomain}{cluster}cognitedata.com{end}" + assert client_config.cdf_cluster is None + def test_extract_invalid_url(self, client_config: ClientConfig) -> None: client_config.base_url = "invalid" assert client_config.cdf_cluster is None