Skip to content

Commit

Permalink
Merge pull request #83 from DuendeSoftware/brock/licence_logging
Browse files Browse the repository at this point in the history
Improve license logging at startup
  • Loading branch information
leastprivilege authored Jan 21, 2021
2 parents edc52bd + af2239d commit d9d4bcb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
49 changes: 25 additions & 24 deletions src/IdentityServer/Validation/Default/LicenseValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,19 @@ public static void ValidateLicense()
if (_license == null)
{
var message = "You do not have a valid license key for Duende IdentityServer. " +
"This is allowed for development and testing scenarios. " +
"If you are running in production you are required to have a licensed version. Please start a conversation with us: https://duendesoftware.com/contact";
"This is allowed for development and testing scenarios. " +
"If you are running in production you are required to have a licensed version. Please start a conversation with us: https://duendesoftware.com/contact";

_logger.LogWarning(message);
return;
}
else
{
if (_logger.IsEnabled(LogLevel.Debug))
{
_logger.LogDebug("The validated licence key details: {@license}", _license);
}

if (_license.Expiration.HasValue)
{
var diff = DateTime.UtcNow.Date.Subtract(_license.Expiration.Value.Date).TotalDays;
Expand Down Expand Up @@ -94,16 +99,11 @@ public static void ValidateLicense()
{
if (_license.Expiration.HasValue)
{
_logger.LogInformation("You have a valid license key for Duende IdentityServer for use at {licenseCompany}. The license expires on {licenseExpiration}.", _license.CompanyName, _license.Expiration.Value.ToLongDateString());
_logger.LogInformation("You have a valid license key for Duende IdentityServer {edition} edition for use at {licenseCompany}. The license expires on {licenseExpiration}.", _license.Edition, _license.CompanyName, _license.Expiration.Value.ToLongDateString());
}
else
{
_logger.LogInformation("You have a valid license key for Duende IdentityServer for use at {licenseCompany}.", _license.CompanyName);
}

if (_logger.IsEnabled(LogLevel.Debug))
{
_logger.LogDebug("The validated licence details: {@license}", _license);
_logger.LogInformation("You have a valid license key for Duende IdentityServer {edition} edition for use at {licenseCompany}.", _license.Edition, _license.CompanyName);
}
}
}
Expand Down Expand Up @@ -213,7 +213,7 @@ public License(ClaimsPrincipal claims)
}

var edition = claims.FindFirst("edition")?.Value;
if (!Enum.TryParse<License.LienceEdition>(edition, true, out var editionValue))
if (!Enum.TryParse<License.LicenseEdition>(edition, true, out var editionValue))
{
throw new Exception($"Invalid edition in licence: '{edition}'");
}
Expand All @@ -222,18 +222,18 @@ public License(ClaimsPrincipal claims)
KeyManagement = claims.HasClaim("feature", "key_management");
switch (Edition)
{
case LienceEdition.Enterprise:
case LienceEdition.Business:
case LienceEdition.Community:
case LicenseEdition.Enterprise:
case LicenseEdition.Business:
case LicenseEdition.Community:
KeyManagement = true;
break;
}

ResourceIsolation = claims.HasClaim("feature", "resource_isolation");
switch (Edition)
{
case LienceEdition.Enterprise:
case LienceEdition.Community:
case LicenseEdition.Enterprise:
case LicenseEdition.Community:
ResourceIsolation = true;
break;
}
Expand All @@ -252,13 +252,13 @@ public License(ClaimsPrincipal claims)
{
switch (Edition)
{
case LienceEdition.Business:
case LicenseEdition.Business:
ClientLimit = 15;
break;
case LienceEdition.Starter:
case LicenseEdition.Starter:
ClientLimit = 5;
break;
case LienceEdition.Community:
case LicenseEdition.Community:
ClientLimit = 4;
break;
}
Expand Down Expand Up @@ -287,19 +287,20 @@ public License(ClaimsPrincipal claims)

public DateTime? Expiration { get; set; }

public LienceEdition Edition { get; set; }
public bool IsEnterprise => Edition == LienceEdition.Enterprise;
public bool IsBusiness => Edition == LienceEdition.Business;
public bool IsStarter => Edition == LienceEdition.Starter;
public bool IsCommunity => Edition == LienceEdition.Community;
public LicenseEdition Edition { get; set; }

internal bool IsEnterprise => Edition == LicenseEdition.Enterprise;
internal bool IsBusiness => Edition == LicenseEdition.Business;
internal bool IsStarter => Edition == LicenseEdition.Starter;
internal bool IsCommunity => Edition == LicenseEdition.Community;

public int? ClientLimit { get; set; }
public int? IssuerLimit { get; set; }

public bool KeyManagement { get; set; }
public bool ResourceIsolation { get; set; }

public enum LienceEdition
public enum LicenseEdition
{
Enterprise,
Business,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void license_should_parse_edition_and_use_default_values()
{
{
var subject = new License(new Claim("edition", "enterprise"));
subject.Edition.Should().Be(License.LienceEdition.Enterprise);
subject.Edition.Should().Be(License.LicenseEdition.Enterprise);
subject.IsEnterprise.Should().BeTrue();
subject.ClientLimit.Should().BeNull();
subject.IssuerLimit.Should().BeNull();
Expand All @@ -59,7 +59,7 @@ public void license_should_parse_edition_and_use_default_values()
}
{
var subject = new License(new Claim("edition", "business"));
subject.Edition.Should().Be(License.LienceEdition.Business);
subject.Edition.Should().Be(License.LicenseEdition.Business);
subject.IsBusiness.Should().BeTrue();
subject.ClientLimit.Should().Be(15);
subject.IssuerLimit.Should().Be(1);
Expand All @@ -68,7 +68,7 @@ public void license_should_parse_edition_and_use_default_values()
}
{
var subject = new License(new Claim("edition", "starter"));
subject.Edition.Should().Be(License.LienceEdition.Starter);
subject.Edition.Should().Be(License.LicenseEdition.Starter);
subject.IsStarter.Should().BeTrue();
subject.ClientLimit.Should().Be(5);
subject.IssuerLimit.Should().Be(1);
Expand All @@ -77,7 +77,7 @@ public void license_should_parse_edition_and_use_default_values()
}
{
var subject = new License(new Claim("edition", "community"));
subject.Edition.Should().Be(License.LienceEdition.Community);
subject.Edition.Should().Be(License.LicenseEdition.Community);
subject.IsCommunity.Should().BeTrue();
subject.ClientLimit.Should().Be(4);
subject.IssuerLimit.Should().BeNull();
Expand Down

0 comments on commit d9d4bcb

Please sign in to comment.