This commit is contained in:
ari committed 2022-08-31 15:46:08 -04:00
1 parent 499752e02f
commit f58966c735
3 files changed
+10 -37

No files matched your search

+1 -33
View File
@@ -1,44 +1,12 @@
import base64
import json
from typing import Iterable
from src.logger import get_logger
from .errors import (
DBNoAutomationFound,
RepeatedAutomationId,
)
from .errors import DBNoAutomationFound, RepeatedAutomationId
from .types import ExtenededAutomation
logger = get_logger(__file__)
automations_tbl = "autos"
def encode_auto(auto: ExtenededAutomation) -> str:
return base64.b64encode(
json.dumps(auto.to_primitive(include_tags=True)).encode("utf-8")
).decode("utf-8")
def encode_obj(auto: dict | list) -> str:
return base64.b64encode(json.dumps(auto).encode("utf-8")).decode("utf-8")
def decode_auto(
auto_str: str, source_file: str, source_file_type: str, configuration_key: str
) -> ExtenededAutomation:
return ExtenededAutomation(
source_file=source_file,
source_file_type=source_file_type,
configuration_key=decode_obj(configuration_key), # type: ignore
**decode_obj(auto_str),
)
def decode_obj(obj_str: str) -> dict | list:
return json.loads(base64.b64decode(obj_str.encode("utf-8")).decode("utf-8"))
class AutomationDBConnection:
def __init__(self) -> None:
-2
View File
@@ -1,5 +1,3 @@
from pathlib import Path
from tempfile import mktemp
from typing import Optional, Union
from src.errors import ErrorSet, FormattedError