feat(activity): Simplify query statements and improve code readability
This commit is contained in:
@@ -18,9 +18,7 @@ class AgentAuthContext:
|
||||
|
||||
|
||||
def _find_agent_for_token(session: Session, token: str) -> Agent | None:
|
||||
agents = list(
|
||||
session.exec(select(Agent).where(col(Agent.agent_token_hash).is_not(None)))
|
||||
)
|
||||
agents = list(session.exec(select(Agent).where(col(Agent.agent_token_hash).is_not(None))))
|
||||
for agent in agents:
|
||||
if agent.agent_token_hash and verify_agent_token(token, agent.agent_token_hash):
|
||||
return agent
|
||||
|
||||
@@ -41,7 +41,5 @@ def verify_agent_token(token: str, stored_hash: str) -> bool:
|
||||
return False
|
||||
salt = _b64decode(salt_b64)
|
||||
expected_digest = _b64decode(digest_b64)
|
||||
candidate = hashlib.pbkdf2_hmac(
|
||||
"sha256", token.encode("utf-8"), salt, iterations_int
|
||||
)
|
||||
candidate = hashlib.pbkdf2_hmac("sha256", token.encode("utf-8"), salt, iterations_int)
|
||||
return hmac.compare_digest(candidate, expected_digest)
|
||||
|
||||
@@ -66,9 +66,7 @@ class AppLogFilter(logging.Filter):
|
||||
class JsonFormatter(logging.Formatter):
|
||||
def format(self, record: logging.LogRecord) -> str:
|
||||
payload: dict[str, Any] = {
|
||||
"timestamp": datetime.fromtimestamp(
|
||||
record.created, tz=timezone.utc
|
||||
).isoformat(),
|
||||
"timestamp": datetime.fromtimestamp(record.created, tz=timezone.utc).isoformat(),
|
||||
"level": record.levelname,
|
||||
"logger": record.name,
|
||||
"message": record.getMessage(),
|
||||
|
||||
Reference in New Issue
Block a user