Skip to content

Commit

Permalink
add: pydantic type validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Archento committed Jul 2, 2024
1 parent 939f964 commit 2c26d83
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 10 deletions.
132 changes: 131 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ bech32 = "^1.2.0"
pycryptodome = "^3.20.0"
pyjwt = "^2.8.0"
eciespy = "^0.4.2"
pydantic = "^2.8.0"

[tool.poetry.group.dev.dependencies]
pytest = "^8.2.2"
Expand Down
5 changes: 2 additions & 3 deletions src/babble/auth.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from dataclasses import dataclass
from datetime import datetime, timezone
from typing import Optional, Tuple

import jwt
import requests
from pydantic import BaseModel

from .config import AUTH_SERVER, DEFAULT_REQUEST_TIMEOUT
from .crypto.identity import Identity
from .encoding import from_base64, to_base64


@dataclass
class TokenMetadata:
class TokenMetadata(BaseModel):
address: str
public_key: str
issued_at: datetime
Expand Down
5 changes: 2 additions & 3 deletions src/babble/client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from dataclasses import dataclass
from datetime import datetime, timedelta, timezone
from typing import List

import bech32
from pydantic import BaseModel

from .auth import authenticate
from .crypto.exceptions import RoutingError
Expand All @@ -24,8 +24,7 @@ def _validate_address(address: str):
raise ValueError(f"Bad delegate address {address}")


@dataclass
class Message:
class Message(BaseModel):
id: str
sender: str
target: str
Expand Down
5 changes: 2 additions & 3 deletions src/babble/mailbox.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from dataclasses import dataclass
from datetime import datetime, timezone
from typing import Any, Dict, List, Optional

import requests
from pydantic import BaseModel

from .config import MEMORANDUM_SERVER

Expand Down Expand Up @@ -115,8 +115,7 @@ def dispatch_messages(token: str, messages: List[str]):
)


@dataclass
class RawMessage:
class RawMessage(BaseModel):
id: str
group_id: str
sender: str
Expand Down

0 comments on commit 2c26d83

Please sign in to comment.