Skip to content

Commit

Permalink
Merge pull request #20 from wherobots/use-new-runtime-ids
Browse files Browse the repository at this point in the history
chore: move to use new runtime IDs, add user agent header
  • Loading branch information
zongsizhang authored Sep 19, 2024
2 parents 23ca30e + 1eb7bfb commit 9fda892
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "wherobots-python-dbapi"
version = "0.7.3"
version = "0.7.4"
description = "Python DB-API driver for Wherobots DB"
authors = ["Maxime Petazzoni <[email protected]>"]
license = "Apache 2.0"
Expand Down
21 changes: 19 additions & 2 deletions wherobots/db/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
"""

import logging
import os
import platform
import urllib.parse
import queue
from importlib import metadata
from importlib.metadata import PackageNotFoundError

import requests
import tenacity
import threading
Expand Down Expand Up @@ -39,6 +42,18 @@
paramstyle = "pyformat"


def gen_user_agent_header():
try:
package_version = metadata.version("wherobots-python-dbapi")
except PackageNotFoundError:
package_version = "unknown"
python_version = platform.python_version()
system = platform.system().lower()
return {
"User-Agent": f"wherobots-python-dbapi/{package_version} os/{system} python/{python_version}"
}


def connect(
host: str = DEFAULT_ENDPOINT,
token: str = None,
Expand All @@ -57,12 +72,14 @@ def connect(
if token and api_key:
raise ValueError("`token` and `api_key` can't be both provided")

headers = {}
headers = gen_user_agent_header()
if token:
headers["Authorization"] = f"Bearer {token}"
elif api_key:
headers["X-API-Key"] = api_key

logging.info(headers)

host = host or DEFAULT_ENDPOINT
runtime = runtime or DEFAULT_RUNTIME
region = region or DEFAULT_REGION
Expand Down
12 changes: 6 additions & 6 deletions wherobots/db/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@


class Runtime(Enum):
SEDONA = "TINY"
SAN_FRANCISCO = "SMALL"
NEW_YORK = "MEDIUM"
CAIRO = "LARGE"
DELHI = "XLARGE"
TOKYO = "XXLARGE"
SEDONA = "tiny"
SAN_FRANCISCO = "small"
NEW_YORK = "medium"
CAIRO = "large"
DELHI = "x-large"
TOKYO = "2x-large"
ATLANTIS = "4x-large"

NEW_YORK_HIMEM = "medium-himem"
Expand Down

0 comments on commit 9fda892

Please sign in to comment.