From ab62f3e1c5a739bc65fc4923e9e088c9d86c8c17 Mon Sep 17 00:00:00 2001 From: Latent Date: Thu, 28 Nov 2024 16:11:57 -0500 Subject: [PATCH] feature(telemetry): new optional `api_key` feature(telemetry): new optional `custom_api_key` changelog better change log --- CHANGELOG.md | 2 ++ src/ploomber_core/telemetry/telemetry.py | 4 ++-- tests/telemetry/test_telemetry.py | 8 +++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e443306..20548ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.2.26dev +* [Feature] New optional custom telemetry `api_key` + ## 0.2.25 (2024-02-01) * [Feature] Updates cloud message diff --git a/src/ploomber_core/telemetry/telemetry.py b/src/ploomber_core/telemetry/telemetry.py index d109fb4..72d3f95 100644 --- a/src/ploomber_core/telemetry/telemetry.py +++ b/src/ploomber_core/telemetry/telemetry.py @@ -420,12 +420,12 @@ def __init__(self, api_key, package_name, version, *, print_cloud_message=True): self.print_cloud_message = print_cloud_message @classmethod - def from_package(cls, package_name, *, print_cloud_message=True): + def from_package(cls, package_name, *, print_cloud_message=True, api_key=None): """ Initialize a Telemetry client with the default configuration for a package with the given name """ - default_api_key = "phc_P9SpSeypyPwxrMdFn2edOOEooQioF2axppyEeDwtMSP" + default_api_key = api_key or "phc_P9SpSeypyPwxrMdFn2edOOEooQioF2axppyEeDwtMSP" version = get_package_version(package_name) return cls( api_key=default_api_key, diff --git a/tests/telemetry/test_telemetry.py b/tests/telemetry/test_telemetry.py index 68fcdcf..ca577d2 100644 --- a/tests/telemetry/test_telemetry.py +++ b/tests/telemetry/test_telemetry.py @@ -1080,11 +1080,17 @@ def test_check_cloud(tmp_directory, monkeypatch, capsys, last_cloud_check): def test_from_package(): _telemetry = telemetry.Telemetry.from_package("ploomber-core") - assert _telemetry.api_key + assert _telemetry.api_key == "phc_P9SpSeypyPwxrMdFn2edOOEooQioF2axppyEeDwtMSP" assert _telemetry.version assert _telemetry.package_name == "ploomber-core" +def test_from_package_custom_api_key(): + _telemetry = telemetry.Telemetry.from_package("ploomber-core", api_key="test_custom_key") + + assert _telemetry.api_key == "test_custom_key" + + def test_runs_check_cloud(monkeypatch): mock = Mock() monkeypatch.setattr(telemetry, "check_cloud", mock)