Initial commit
This commit is contained in:
24
src/xmpp_api/util/constraints.py
Normal file
24
src/xmpp_api/util/constraints.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import xmpp_api.api.bot as bot_api
|
||||
import xmpp_api.db.bot as bot_db
|
||||
|
||||
|
||||
def bot_constraint_to_db(constraint: bot_api.BotConstraint) -> bot_db.BotConstraint:
|
||||
match constraint:
|
||||
case bot_api.BotDomainConstraint:
|
||||
return bot_db.BotDomainConstraint(
|
||||
domains=constraint.domains,
|
||||
)
|
||||
case _:
|
||||
# TODO: Proper exception type
|
||||
raise Exception()
|
||||
|
||||
|
||||
def bot_constraint_from_db(constraint: bot_db.BotConstraint) -> bot_api.BotConstraint:
|
||||
match constraint:
|
||||
case bot_db.BotDomainConstraint:
|
||||
return bot_api.BotDomainConstraint(
|
||||
domains=constraint.domains,
|
||||
)
|
||||
case _:
|
||||
# TODO: Proper exception type
|
||||
raise Exception()
|
||||
5
src/xmpp_api/util/db.py
Normal file
5
src/xmpp_api/util/db.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import uuid as py_uuid
|
||||
|
||||
|
||||
def uuid() -> str:
|
||||
return py_uuid.uuid4().hex
|
||||
6
src/xmpp_api/util/token.py
Normal file
6
src/xmpp_api/util/token.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from secrets import token_bytes
|
||||
|
||||
|
||||
def generate_token(length: int = 32) -> str:
|
||||
# TODO: PBKDF2?
|
||||
return token_bytes(length).hex()
|
||||
Reference in New Issue
Block a user