Skip to content

Commit

Permalink
identityserver hosts and templates - summarize license usage on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
josephdecock committed Jan 8, 2025
1 parent ff31462 commit c7db679
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 17 deletions.
28 changes: 27 additions & 1 deletion identity-server/hosts/AspNetIdentity/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

using Duende.IdentityServer.Licensing;
using IdentityServerHost;
using Serilog;
using System.Globalization;
Expand Down Expand Up @@ -36,6 +37,18 @@
.ConfigureServices()
.ConfigurePipeline();

if (app.Environment.IsDevelopment())
{
app.Lifetime.ApplicationStopping.Register(() =>
{
var usage = app.Services.GetRequiredService<LicenseUsageSummary>();
Console.Write(Summary(usage));
{
Console.ReadKey();
}
});
}

app.Run();
}
catch (Exception ex)
Expand All @@ -46,4 +59,17 @@
{
Log.Information("Shut down complete");
Log.CloseAndFlush();
}
}

static string Summary(LicenseUsageSummary usage)
{
var sb = new StringBuilder();

Check failure on line 66 in identity-server/hosts/AspNetIdentity/Program.cs

View workflow job for this annotation

GitHub Actions / macOS-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/AspNetIdentity/Program.cs

View workflow job for this annotation

GitHub Actions / macOS-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/AspNetIdentity/Program.cs

View workflow job for this annotation

GitHub Actions / macOS-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/AspNetIdentity/Program.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/AspNetIdentity/Program.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/AspNetIdentity/Program.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/AspNetIdentity/Program.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/AspNetIdentity/Program.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/AspNetIdentity/Program.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)
sb.AppendLine("IdentityServer Usage Summary:");
sb.AppendLine(CultureInfo.InvariantCulture, $" License: {usage.LicenseEdition}");
var features = usage.FeaturesUsed.Count > 0 ? string.Join(", ", usage.FeaturesUsed) : "None";
sb.AppendLine(CultureInfo.InvariantCulture, $" Business and Enterprise Edition Features Used: {features}");
sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.ClientsUsed.Count} Client Id(s) Used");
sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.IssuersUsed.Count} Issuer(s) Used");

return sb.ToString();
}
28 changes: 27 additions & 1 deletion identity-server/hosts/Configuration/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

using Duende.IdentityServer.Licensing;
using IdentityServerHost;
using Serilog;
using Serilog.Events;
Expand Down Expand Up @@ -36,6 +37,18 @@
.ConfigureServices()
.ConfigurePipeline();

if (app.Environment.IsDevelopment())
{
app.Lifetime.ApplicationStopping.Register(() =>
{
var usage = app.Services.GetRequiredService<LicenseUsageSummary>();
Console.Write(Summary(usage));
{
Console.ReadKey();
}
});
}

app.Run();
}
catch (Exception ex)
Expand All @@ -46,4 +59,17 @@
{
Log.Information("Shut down complete");
Log.CloseAndFlush();
}
}

static string Summary(LicenseUsageSummary usage)
{
var sb = new StringBuilder();

Check failure on line 66 in identity-server/hosts/Configuration/Program.cs

View workflow job for this annotation

GitHub Actions / macOS-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/Configuration/Program.cs

View workflow job for this annotation

GitHub Actions / macOS-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/Configuration/Program.cs

View workflow job for this annotation

GitHub Actions / macOS-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/Configuration/Program.cs

View workflow job for this annotation

GitHub Actions / macOS-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/Configuration/Program.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/Configuration/Program.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/Configuration/Program.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/Configuration/Program.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/Configuration/Program.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/Configuration/Program.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/Configuration/Program.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/Configuration/Program.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)
sb.AppendLine("IdentityServer Usage Summary:");
sb.AppendLine(CultureInfo.InvariantCulture, $" License: {usage.LicenseEdition}");
var features = usage.FeaturesUsed.Count > 0 ? string.Join(", ", usage.FeaturesUsed) : "None";
sb.AppendLine(CultureInfo.InvariantCulture, $" Business and Enterprise Edition Features Used: {features}");
sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.ClientsUsed.Count} Client Id(s) Used");
sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.IssuersUsed.Count} Issuer(s) Used");

return sb.ToString();
}
28 changes: 27 additions & 1 deletion identity-server/hosts/EntityFramework/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

using Duende.IdentityServer.Licensing;
using IdentityServerHost;
using Serilog;
using Serilog.Events;
Expand Down Expand Up @@ -36,6 +37,18 @@
.ConfigureServices()
.ConfigurePipeline();

if (app.Environment.IsDevelopment())
{
app.Lifetime.ApplicationStopping.Register(() =>
{
var usage = app.Services.GetRequiredService<LicenseUsageSummary>();
Console.Write(Summary(usage));
{
Console.ReadKey();
}
});
}

app.Run();
}
catch (Exception ex)
Expand All @@ -46,4 +59,17 @@
{
Log.Information("Shut down complete");
Log.CloseAndFlush();
}
}

static string Summary(LicenseUsageSummary usage)
{
var sb = new StringBuilder();

Check failure on line 66 in identity-server/hosts/EntityFramework/Program.cs

View workflow job for this annotation

GitHub Actions / macOS-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/EntityFramework/Program.cs

View workflow job for this annotation

GitHub Actions / macOS-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/EntityFramework/Program.cs

View workflow job for this annotation

GitHub Actions / macOS-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/EntityFramework/Program.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/EntityFramework/Program.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/EntityFramework/Program.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/EntityFramework/Program.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/EntityFramework/Program.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 66 in identity-server/hosts/EntityFramework/Program.cs

View workflow job for this annotation

GitHub Actions / windows-latest

The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)
sb.AppendLine("IdentityServer Usage Summary:");
sb.AppendLine(CultureInfo.InvariantCulture, $" License: {usage.LicenseEdition}");
var features = usage.FeaturesUsed.Count > 0 ? string.Join(", ", usage.FeaturesUsed) : "None";
sb.AppendLine(CultureInfo.InvariantCulture, $" Business and Enterprise Edition Features Used: {features}");
sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.ClientsUsed.Count} Client Id(s) Used");
sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.IssuersUsed.Count} Issuer(s) Used");

return sb.ToString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Duende.IdentityServer.AspNetIdentity" version="7.0.6" />
<PackageReference Include="Duende.IdentityServer.AspNetIdentity" version="7.1.0-rc.2" />

<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.3" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
Expand Down
30 changes: 28 additions & 2 deletions templates/src/IdentityServerAspNetIdentity/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using IdentityServerAspNetIdentity;
using Duende.IdentityServer.Licensing;
using IdentityServerAspNetIdentity;
using Serilog;

Log.Logger = new LoggerConfiguration()
Expand Down Expand Up @@ -30,6 +31,18 @@
return;
}

if (app.Environment.IsDevelopment())
{
app.Lifetime.ApplicationStopping.Register(() =>
{
var usage = app.Services.GetRequiredService<LicenseUsageSummary>();
Console.Write(Summary(usage));
{
Console.ReadKey();
}
});
}

app.Run();
}
catch (Exception ex) when (ex is not HostAbortedException)
Expand All @@ -40,4 +53,17 @@
{
Log.Information("Shut down complete");
Log.CloseAndFlush();
}
}

static string Summary(LicenseUsageSummary usage)
{
var sb = new StringBuilder();
sb.AppendLine("IdentityServer Usage Summary:");
sb.AppendLine(CultureInfo.InvariantCulture, $" License: {usage.LicenseEdition}");
var features = usage.FeaturesUsed.Count > 0 ? string.Join(", ", usage.FeaturesUsed) : "None";
sb.AppendLine(CultureInfo.InvariantCulture, $" Business and Enterprise Edition Features Used: {features}");
sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.ClientsUsed.Count} Client Id(s) Used");
sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.IssuersUsed.Count} Issuer(s) Used");

return sb.ToString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Duende.IdentityServer" version="7.0.6" />
<PackageReference Include="Duende.IdentityServer" version="7.1.0-rc.2" />

<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
</ItemGroup>
Expand Down
32 changes: 29 additions & 3 deletions templates/src/IdentityServerEmpty/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using IdentityServerEmpty;
using Duende.IdentityServer.Licensing;
using IdentityServerEmpty;
using Serilog;

Log.Logger = new LoggerConfiguration()
Expand All @@ -19,7 +20,19 @@
var app = builder
.ConfigureServices()
.ConfigurePipeline();


if (app.Environment.IsDevelopment())
{
app.Lifetime.ApplicationStopping.Register(() =>
{
var usage = app.Services.GetRequiredService<LicenseUsageSummary>();
Console.Write(Summary(usage));
{
Console.ReadKey();
}
});
}

app.Run();
}
catch (Exception ex)
Expand All @@ -30,4 +43,17 @@
{
Log.Information("Shut down complete");
Log.CloseAndFlush();
}
}

static string Summary(LicenseUsageSummary usage)
{
var sb = new StringBuilder();
sb.AppendLine("IdentityServer Usage Summary:");
sb.AppendLine(CultureInfo.InvariantCulture, $" License: {usage.LicenseEdition}");
var features = usage.FeaturesUsed.Count > 0 ? string.Join(", ", usage.FeaturesUsed) : "None";
sb.AppendLine(CultureInfo.InvariantCulture, $" Business and Enterprise Edition Features Used: {features}");
sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.ClientsUsed.Count} Client Id(s) Used");
sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.IssuersUsed.Count} Issuer(s) Used");

return sb.ToString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Duende.IdentityServer.EntityFramework" version="7.0.6" />
<PackageReference Include="Duende.IdentityServer.EntityFramework" version="7.1.0-rc.2" />

<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.3" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
Expand Down
30 changes: 28 additions & 2 deletions templates/src/IdentityServerEntityFramework/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using IdentityServerEntityFramework;
using Duende.IdentityServer.Licensing;
using IdentityServerEntityFramework;
using Serilog;

Log.Logger = new LoggerConfiguration()
Expand Down Expand Up @@ -30,6 +31,18 @@
return;
}

if (app.Environment.IsDevelopment())
{
app.Lifetime.ApplicationStopping.Register(() =>
{
var usage = app.Services.GetRequiredService<LicenseUsageSummary>();
Console.Write(Summary(usage));
{
Console.ReadKey();
}
});
}

app.Run();
}
catch (Exception ex) when (ex is not HostAbortedException)
Expand All @@ -40,4 +53,17 @@
{
Log.Information("Shut down complete");
Log.CloseAndFlush();
}
}

static string Summary(LicenseUsageSummary usage)
{
var sb = new StringBuilder();
sb.AppendLine("IdentityServer Usage Summary:");
sb.AppendLine(CultureInfo.InvariantCulture, $" License: {usage.LicenseEdition}");
var features = usage.FeaturesUsed.Count > 0 ? string.Join(", ", usage.FeaturesUsed) : "None";
sb.AppendLine(CultureInfo.InvariantCulture, $" Business and Enterprise Edition Features Used: {features}");
sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.ClientsUsed.Count} Client Id(s) Used");
sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.IssuersUsed.Count} Issuer(s) Used");

return sb.ToString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Duende.IdentityServer" version="7.0.6" />
<PackageReference Include="Duende.IdentityServer" version="7.1.2-rc.2" />

<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.3" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
Expand Down
32 changes: 29 additions & 3 deletions templates/src/IdentityServerInMem/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using IdentityServerInMem;
using Duende.IdentityServer.Licensing;
using IdentityServerInMem;
using Serilog;

Log.Logger = new LoggerConfiguration()
Expand All @@ -19,7 +20,19 @@
var app = builder
.ConfigureServices()
.ConfigurePipeline();


if (app.Environment.IsDevelopment())
{
app.Lifetime.ApplicationStopping.Register(() =>
{
var usage = app.Services.GetRequiredService<LicenseUsageSummary>();
Console.Write(Summary(usage));
{
Console.ReadKey();
}
});
}

app.Run();
}
catch (Exception ex)
Expand All @@ -30,4 +43,17 @@
{
Log.Information("Shut down complete");
Log.CloseAndFlush();
}
}

static string Summary(LicenseUsageSummary usage)
{
var sb = new StringBuilder();
sb.AppendLine("IdentityServer Usage Summary:");
sb.AppendLine(CultureInfo.InvariantCulture, $" License: {usage.LicenseEdition}");
var features = usage.FeaturesUsed.Count > 0 ? string.Join(", ", usage.FeaturesUsed) : "None";
sb.AppendLine(CultureInfo.InvariantCulture, $" Business and Enterprise Edition Features Used: {features}");
sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.ClientsUsed.Count} Client Id(s) Used");
sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.IssuersUsed.Count} Issuer(s) Used");

return sb.ToString();
}

0 comments on commit c7db679

Please sign in to comment.