1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-21 12:05:42 +01:00

[PM-13317] Add client version log scope (#4869)

* Add client version log scope

* Removed extra dependency.
This commit is contained in:
Todd Martin 2024-10-09 10:08:00 -04:00 committed by GitHub
parent 9d06c7b1e0
commit 6c807d800e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -38,7 +38,8 @@ public sealed class RequestLoggingMiddleware
new RequestLogScope(context.GetIpAddress(_globalSettings), new RequestLogScope(context.GetIpAddress(_globalSettings),
GetHeaderValue(context, "user-agent"), GetHeaderValue(context, "user-agent"),
GetHeaderValue(context, "device-type"), GetHeaderValue(context, "device-type"),
GetHeaderValue(context, "device-type")))) GetHeaderValue(context, "device-type"),
GetHeaderValue(context, "bitwarden-client-version"))))
{ {
return _next(context); return _next(context);
} }
@ -59,12 +60,13 @@ public sealed class RequestLoggingMiddleware
{ {
private string? _cachedToString; private string? _cachedToString;
public RequestLogScope(string? ipAddress, string? userAgent, string? deviceType, string? origin) public RequestLogScope(string? ipAddress, string? userAgent, string? deviceType, string? origin, string? clientVersion)
{ {
IpAddress = ipAddress; IpAddress = ipAddress;
UserAgent = userAgent; UserAgent = userAgent;
DeviceType = deviceType; DeviceType = deviceType;
Origin = origin; Origin = origin;
ClientVersion = clientVersion;
} }
public KeyValuePair<string, object?> this[int index] public KeyValuePair<string, object?> this[int index]
@ -87,17 +89,22 @@ public sealed class RequestLoggingMiddleware
{ {
return new KeyValuePair<string, object?>(nameof(Origin), Origin); return new KeyValuePair<string, object?>(nameof(Origin), Origin);
} }
else if (index == 4)
{
return new KeyValuePair<string, object?>(nameof(ClientVersion), ClientVersion);
}
throw new ArgumentOutOfRangeException(nameof(index)); throw new ArgumentOutOfRangeException(nameof(index));
} }
} }
public int Count => 4; public int Count => 5;
public string? IpAddress { get; } public string? IpAddress { get; }
public string? UserAgent { get; } public string? UserAgent { get; }
public string? DeviceType { get; } public string? DeviceType { get; }
public string? Origin { get; } public string? Origin { get; }
public string? ClientVersion { get; }
public IEnumerator<KeyValuePair<string, object?>> GetEnumerator() public IEnumerator<KeyValuePair<string, object?>> GetEnumerator()
{ {
@ -110,7 +117,7 @@ public sealed class RequestLoggingMiddleware
public override string ToString() public override string ToString()
{ {
_cachedToString ??= $"IpAddress:{IpAddress} UserAgent:{UserAgent} DeviceType:{DeviceType} Origin:{Origin}"; _cachedToString ??= $"IpAddress:{IpAddress} UserAgent:{UserAgent} DeviceType:{DeviceType} Origin:{Origin} ClientVersion:{ClientVersion}";
return _cachedToString; return _cachedToString;
} }
} }