Skip to content

Commit

Permalink
bump pybotx to feature/kl/pydantic-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiruha01 committed May 24, 2024
1 parent cd8b898 commit d509b4f
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 169 deletions.
19 changes: 13 additions & 6 deletions app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
from typing import Any, List
from uuid import UUID

from pydantic_settings import BaseSettings, SettingsConfigDict

from pybotx import BotAccountWithSecret
from pydantic import BaseSettings, validator
from pydantic import validator


class AppSettings(BaseSettings):
class Config: # noqa: WPS431
env_file = ".env"
model_config = SettingsConfigDict(env_file = ".env")

# TODO: Change type to `List[BotAccount]` after closing:
# https://github.com/samuelcolvin/pydantic/issues/1458
Expand Down Expand Up @@ -37,15 +38,21 @@ def parse_bot_credentials(cls, raw_credentials: Any) -> List[BotAccountWithSecre

@classmethod
def _build_credentials_from_string(
cls, credentials_str: str
cls, credentials_str: str
) -> BotAccountWithSecret:
credentials_str = credentials_str.replace("|", "@")
assert credentials_str.count("@") == 2, "Have you forgot to add `bot_id`?"

host, secret_key, bot_id = [
cts_url, secret_key, bot_id = [
str_value.strip() for str_value in credentials_str.split("@")
]
return BotAccountWithSecret(host=host, secret_key=secret_key, id=UUID(bot_id))

if "://" not in cts_url:
cts_url = f"https://{cts_url}"

return BotAccountWithSecret(
id=UUID(bot_id), cts_url=cts_url, secret_key=secret_key
)


settings = AppSettings()
Loading

0 comments on commit d509b4f

Please sign in to comment.