Skip to content

Commit

Permalink
[CDF-23155] No warning on private link (#2034)
Browse files Browse the repository at this point in the history
  • Loading branch information
doctrino authored Nov 21, 2024
1 parent 49f1521 commit b751b9b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]`
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations

__version__ = "7.67.3"
__version__ = "7.67.4"
__api_subversion__ = "20230101"
6 changes: 4 additions & 2 deletions cognite/client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
28 changes: 20 additions & 8 deletions tests/tests_unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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

0 comments on commit b751b9b

Please sign in to comment.