Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions logtide_sdk/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ class BaseClient:
"""

def __init__(self, options: ClientOptions) -> None:
if not options.local_mode and not options.api_key:
raise RuntimeError(
f"Cannot instantiate {self.__class__.__name__} without api_key with disabled local_mode"
)

self.options = options

self._payload_limits = options.payload_limits or PayloadLimitsOptions()
Expand Down
11 changes: 6 additions & 5 deletions logtide_sdk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ def __post_init__(self) -> None:
self.api_key = self.api_key if self.api_key else dsn_parts.api_key
self.api_url = self.api_url if self.api_url else dsn_parts.api_url

if not self.api_url:
raise ValueError("api_url must be provided")

if not 0.0 <= self.sample_rate <= 1.0:
raise ValueError("sample_rate must be between 0.0 and 1.0")

Expand All @@ -102,8 +99,12 @@ def __post_init__(self) -> None:
"Local mode cannot be positive value other than True or 'if_unset_api_key'"
)

if not self.local_mode and not self.api_key:
raise ValueError("api_key must be provided to options, unless local_mode configured")
# Local mode never reaches the network, so it needs no endpoint configured.
if not self.local_mode:
if not self.api_url:
raise ValueError("api_url must be provided")
if not self.api_key:
raise ValueError("api_key must be provided to options, unless local_mode configured")


@dataclass
Expand Down
10 changes: 10 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ def test_client_options_ignores_unset_api_key_if_set_unset_or_local_mode(
ClientOptions(api_url="https://any.apiurl.dev", api_key=api_key, local_mode=local_mode)


@pytest.mark.parametrize("local_mode", ["if_unset_api_key", True])
def test_client_options_needs_no_url_or_key_in_local_mode(
local_mode: Literal["if_unset_api_key"] | bool,
) -> None:
opts = ClientOptions(local_mode=local_mode)

assert opts.api_url is None
assert opts.api_key is None


def test_client_options_raises_no_api_key_and_without_local_mode():
with pytest.raises(ValueError, match="api_key must be provided"):
ClientOptions(api_url="https://somenetwork:8080")
Expand Down
Loading