Carry sdk and sdkVersion through audit event

This commit is contained in:
Damodar Lohani committed 2026-07-12 12:03:35 +05:45
1 parent 142803e5d4
commit 89c87d7abf
4 files changed
+65 -1

No files matched your search

+2
View File
@@ -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;
+51 -1
View File
@@ -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
];
}
}
+4
View File
@@ -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 === [];
+8
View File
@@ -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,
);
}
}