Skip to content

Commit befbcdf

Browse files
committed
Added diagnostic entry for basic server info
1 parent 2a4086a commit befbcdf

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

identity-server/src/IdentityServer/Configuration/DependencyInjection/BuilderExtensions/Core.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#nullable enable
66

7+
using System.Net;
78
using Duende.IdentityServer;
89
using Duende.IdentityServer.Configuration;
910
using Duende.IdentityServer.Configuration.DependencyInjection;
@@ -220,6 +221,7 @@ public static IIdentityServerBuilder AddCoreServices(this IIdentityServerBuilder
220221
builder.Services.AddSingleton<IDiagnosticEntry, DataProtectionDiagnosticEntry>();
221222
builder.Services.AddSingleton<IDiagnosticEntry, TokenIssueCountDiagnosticEntry>();
222223
builder.Services.AddSingleton<IDiagnosticEntry, LicenseUsageDiagnosticEntry>();
224+
builder.Services.AddSingleton<IDiagnosticEntry>(new BasicServerInfoDiagnosticEntry(Dns.GetHostName));
223225
builder.Services.AddSingleton<DiagnosticSummary>();
224226
builder.Services.AddHostedService<DiagnosticHostedService>();
225227

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) Duende Software. All rights reserved.
2+
// See LICENSE in the project root for license information.
3+
4+
using System.Text.Json;
5+
6+
namespace Duende.IdentityServer.Licensing.V2.Diagnostics.DiagnosticEntries;
7+
8+
internal class BasicServerInfoDiagnosticEntry(Func<string> hostNameResolver) : IDiagnosticEntry
9+
{
10+
public Task WriteAsync(Utf8JsonWriter writer)
11+
{
12+
writer.WriteStartObject("BasicServerInfo");
13+
14+
writer.WriteString("HostName", hostNameResolver());
15+
16+
writer.WriteEndObject();
17+
18+
return Task.CompletedTask;
19+
}
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Duende Software. All rights reserved.
2+
// See LICENSE in the project root for license information.
3+
4+
using Duende.IdentityServer.Licensing.V2.Diagnostics.DiagnosticEntries;
5+
using IdentityServer.UnitTests.Licensing.V2.DiagnosticEntries;
6+
7+
namespace IdentityServer.UnitTests.Licensing.v2.DiagnosticEntries;
8+
9+
public class BasicServerInfoDiagnosticEntryTests
10+
{
11+
[Fact]
12+
public async Task WriteAsync_ShouldWriteBasicServerInfo()
13+
{
14+
const string expectedHostName = "testing.local";
15+
var subject = new BasicServerInfoDiagnosticEntry(() => expectedHostName);
16+
17+
var result = await DiagnosticEntryTestHelper.WriteEntryToJson(subject);
18+
19+
var basicServerInfo = result.RootElement.GetProperty("BasicServerInfo");
20+
basicServerInfo.GetProperty("HostName").GetString().ShouldBe(expectedHostName);
21+
}
22+
}

0 commit comments

Comments
 (0)