diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index baad8ff7ba..65de06c3e8 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -611,6 +611,8 @@ Http::init() $auditContext->userAgent = $request->getUserAgent(''); $auditContext->ip = $request->getIP(); $auditContext->hostname = $request->getHostname(); + $auditContext->sdk = \strtolower($request->getHeaderLine('x-sdk-name', '')); + $auditContext->sdkVersion = $request->getHeaderLine('x-sdk-version', ''); $auditContext->event = $route->getLabel('audits.event', ''); $auditContext->project = $project; $auditContext->impersonatorUser = $impersonatorUser->isEmpty() ? null : $impersonatorUser; diff --git a/src/Appwrite/Event/Audit.php b/src/Appwrite/Event/Audit.php index b26083b013..191acdf21a 100644 --- a/src/Appwrite/Event/Audit.php +++ b/src/Appwrite/Event/Audit.php @@ -12,6 +12,8 @@ class Audit extends Event protected string $userAgent = ''; protected string $ip = ''; protected string $hostname = ''; + protected string $sdk = ''; + protected string $sdkVersion = ''; protected bool $critical = false; @@ -140,6 +142,52 @@ class Audit extends Event return $this->hostname; } + /** + * Set SDK name for this audit event. + * + * @param string $sdk + * @return self + */ + public function setSdk(string $sdk): self + { + $this->sdk = $sdk; + + return $this; + } + + /** + * Returns the set audit SDK name. + * + * @return string + */ + public function getSdk(): string + { + return $this->sdk; + } + + /** + * Set SDK version for this audit event. + * + * @param string $sdkVersion + * @return self + */ + public function setSdkVersion(string $sdkVersion): self + { + $this->sdkVersion = $sdkVersion; + + return $this; + } + + /** + * Returns the set audit SDK version. + * + * @return string + */ + public function getSdkVersion(): string + { + return $this->sdkVersion; + } + /** * Prepare payload for queue. * @@ -156,7 +204,9 @@ class Audit extends Event 'ip' => $this->ip, 'userAgent' => $this->userAgent, 'event' => $this->event, - 'hostname' => $this->hostname + 'hostname' => $this->hostname, + 'sdk' => $this->sdk, + 'sdkVersion' => $this->sdkVersion ]; } } diff --git a/src/Appwrite/Event/Context/Audit.php b/src/Appwrite/Event/Context/Audit.php index cb2eab2a1a..7ab5797514 100644 --- a/src/Appwrite/Event/Context/Audit.php +++ b/src/Appwrite/Event/Context/Audit.php @@ -14,6 +14,8 @@ class Audit public string $userAgent = '', public string $ip = '', public string $hostname = '', + public string $sdk = '', + public string $sdkVersion = '', public string $event = '', public string $resource = '', public array $payload = [], @@ -29,6 +31,8 @@ class Audit && $this->userAgent === '' && $this->ip === '' && $this->hostname === '' + && $this->sdk === '' + && $this->sdkVersion === '' && $this->event === '' && $this->resource === '' && $this->payload === []; diff --git a/src/Appwrite/Event/Message/Audit.php b/src/Appwrite/Event/Message/Audit.php index 20cac964cb..63d7842bfe 100644 --- a/src/Appwrite/Event/Message/Audit.php +++ b/src/Appwrite/Event/Message/Audit.php @@ -18,6 +18,8 @@ final class Audit extends Base public readonly string $ip = '', public readonly string $userAgent = '', public readonly string $hostname = '', + public readonly string $sdk = '', + public readonly string $sdkVersion = '', ) { } @@ -38,6 +40,8 @@ final class Audit extends Base 'userAgent' => $this->userAgent, 'event' => $this->event, 'hostname' => $this->hostname, + 'sdk' => $this->sdk, + 'sdkVersion' => $this->sdkVersion, ]; } @@ -54,6 +58,8 @@ final class Audit extends Base ip: $data['ip'] ?? '', userAgent: $data['userAgent'] ?? '', hostname: $data['hostname'] ?? '', + sdk: $data['sdk'] ?? '', + sdkVersion: $data['sdkVersion'] ?? '', ); } @@ -70,6 +76,8 @@ final class Audit extends Base ip: $context->ip, userAgent: $context->userAgent, hostname: $context->hostname, + sdk: $context->sdk, + sdkVersion: $context->sdkVersion, ); } }