Add Edge Agent implementation for gateway connection lifecycle, agent commands, Shelly device discovery, relay control, and WebSocket communication with broker. Include unit tests for critical flows.

This commit is contained in:
Jeppe Bundgaard
2026-04-08 19:01:42 +02:00
parent 653680376a
commit 45b7250480
101 changed files with 21583 additions and 16 deletions
+37 -5
View File
@@ -12,6 +12,31 @@ use objects\subusers_o;
class authentication implements authentication_i
{
private function touchResolvedUserSession(users_o $user, string $token): void
{
if (trim($token) === '') {
return;
}
try {
(new system_session_activity_tracker())->touchUser($user, $token);
} catch (\Throwable) {
// Session tracking must never block authentication resolution.
}
}
private function touchResolvedSubuserSession(subusers_o $subuser, string $token, int|null $customerNumberContext = null): void
{
if (trim($token) === '') {
return;
}
try {
(new system_session_activity_tracker())->touchSubuser($subuser, $token, $customerNumberContext);
} catch (\Throwable) {
// Session tracking must never block authentication resolution.
}
}
/**
* @throws Exception
@@ -125,11 +150,11 @@ class authentication implements authentication_i
if (!isset($headers['Authorization'])) {
return false;
}
$token = $headers['Authorization'];
$rawToken = $headers['Authorization'];
// Strip the Bearer prefix
$token = str_replace('Bearer ', '', $token);
$rawToken = str_replace('Bearer ', '', $rawToken);
// Get the token from the database
$token = (new tokens_o())->getToken($token);
$token = (new tokens_o())->getToken($rawToken);
// Check if the token exists
if (!$token->id) {
return false;
@@ -144,7 +169,9 @@ class authentication implements authentication_i
return (new users_o())->getUserByCustomerNumber($customer_number);
}
// Get the user from the database
return (new users_o())->getUserById($token->user_id->value());
$user = (new users_o())->getUserById($token->user_id->value());
$this->touchResolvedUserSession($user, $rawToken);
return $user;
}
public function get_plate_scanner(): plate_scanners_o|false
@@ -197,6 +224,11 @@ class authentication implements authentication_i
if ($subuser === null) {
return false;
}
$customerNumberContext = null;
if (isset($headers['X-Customer-Number'])) {
$customerNumberContext = (int)$headers['X-Customer-Number'];
}
$this->touchResolvedSubuserSession($subuser, $token, $customerNumberContext);
return $subuser;
}
@@ -232,4 +264,4 @@ class authentication implements authentication_i
}
return (int)$headers['X-Customer-Number'];
}
}
}