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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "rushdb"
version = "1.9.0"
version = "1.10.0"
description = "RushDB Python SDK"
authors = [
{name = "RushDB Team", email = "hi@rushdb.com"}
Expand Down
13 changes: 13 additions & 0 deletions src/rushdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .api.records import RecordsAPI
from .api.transactions import TransactionsAPI
from .common import RushDBError
from .utils.token_prefix import extract_mixed_properties_from_token


class RushDB:
Expand Down Expand Up @@ -102,6 +103,18 @@ def __init__(self, api_key: str, base_url: Optional[str] = None):
... base_url="https://my-rushdb.company.com/api/v1"
... )
"""
settings, raw_key = extract_mixed_properties_from_token(api_key)

self.server_settings = (
{
"customDB": settings["customDB"],
"managedDB": settings["managedDB"],
"selfHosted": settings["selfHosted"],
"plan_type": settings["planType"],
}
if settings
else None
)
self.base_url = (base_url or self.DEFAULT_BASE_URL).rstrip("/")
self.api_key = api_key
self.records = RecordsAPI(self)
Expand Down
30 changes: 30 additions & 0 deletions src/rushdb/utils/token_prefix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import re
from typing import Dict, Optional, Tuple

PlanPrefix = {
"initial": "in",
"extended": "ex",
"fullFeatured": "ff",
}


def extract_mixed_properties_from_token(
prefixed_token: str,
) -> Tuple[Optional[Dict[str, bool]], str]:
matched = re.match(r"^([a-z]{2})_([01]{4}\d*)_(.+)$", prefixed_token)
if not matched:
return None, prefixed_token

prefix, bits, raw = matched.groups()
plan = next((p for p, plan in PlanPrefix.items() if plan == prefix), None)
if plan is None:
return None, prefixed_token

b_custom, b_managed, b_self = tuple(bits[:3])
settings = {
"planType": plan,
"customDB": b_custom == "1",
"managedDB": b_managed == "1",
"selfHosted": b_self == "1",
}
return settings, raw