Cleanup and better comments to clarify licensing code

This commit is contained in:
2022-10-25 20:30:57 +00:00
parent bb6c15286b
commit 102c145386
4 changed files with 31 additions and 53 deletions

View File

@@ -45,6 +45,12 @@ namespace AyaNova.Api.ControllerHelpers
//Lock down the server for license related issue
//Only SuperUser account (id=1) can login or do anything, treats as if server was set to closed even if they change it to open
//only way to reset it is to fetch a valid license
// This is set to locked in TWO ways:
// 1) By CoreJobSweeper *if* the user count is mismatched to the license likely due to Users messing directly with the DB
//trying to circumvent licensing
// 2) By License::InitializeAsync upon finding user count mismatch or expired license key
// and initializeasync is called on boot up or when a new key is downloaded and installed only
//
var msg = $"{reason}\r\nLogin as SuperUser to start evaluation / install license";
SetState(ServerState.OpsOnly, msg);

View File

@@ -7,9 +7,10 @@ using AyaNova.Util;
namespace AyaNova.Biz
{
//NOTE: this is not where the license expiration is checked, that's done in corejobsweeper with the user count checks
/// <summary>
/// called by Generator to check for new licenses automatically
/// called by Generator to check RockFish for new licenses automatically
///
/// </summary>
internal static class CoreJobLicense

View File

@@ -57,8 +57,9 @@ namespace AyaNova.Biz
await SweepInternalJobsLogsAsync(ct, dtDeleteCutoff);
//In flight check of user count exceeded in case someone meddled in the DB Directly
#if (SUBSCRIPTION_BUILD)
//In flight check validate the db license related user data in case of attempted circumvention
//User count - common check to both build types
if (await AyaNova.Biz.UserBiz.ActiveInternalUserCountAsync() > AyaNova.Core.License.ActiveKey.ActiveInternalUsersCount)
{
var msg = $"{AyaNova.Core.License.SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR} (internal staff User count)";
@@ -67,6 +68,9 @@ namespace AyaNova.Biz
return;
}
#if (SUBSCRIPTION_BUILD)
//Customer contact count - check only for subscription build
if (await AyaNova.Biz.UserBiz.ActiveCustomerContactUserCountAsync() > AyaNova.Core.License.ActiveKey.ActiveCustomerContactUsersCount)
{
var msg = $"{AyaNova.Core.License.SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR} (Customer Contact User count)";
@@ -74,22 +78,6 @@ namespace AyaNova.Biz
log.LogCritical(msg);
return;
}
#else
// if (await UserBiz.ActiveTechUserCountAsync() > AyaNova.Core.License.ActiveKey.ActiveTechsCount)
// {
// //Warning: magic string, do not change this, triggers special login procedures to fix license issue
// AyaNova.Util.ServiceProviderProvider.ServerState.SetSystemLock(AyaNova.Core.License.SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR);
// log.LogCritical(AyaNova.Core.License.SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR);
// return;
// }
if (await AyaNova.Biz.UserBiz.ActiveInternalUserCountAsync() > AyaNova.Core.License.ActiveKey.ActiveInternalUsersCount)
{
var msg = $"{AyaNova.Core.License.SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR} (internal staff User count)";
AyaNova.Util.ServiceProviderProvider.ServerState.SetSystemLock(msg);
log.LogCritical(msg);
return;
}
#endif
}

View File

@@ -692,9 +692,9 @@ namespace AyaNova.Core
}
//################## This is called on Boot up of server and when a new license key is fetched and installed ###############
/// <summary>
/// Initialize the license
///
/// </summary>
internal static async Task InitializeAsync(AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ct, ILogger log)
{
@@ -783,9 +783,9 @@ namespace AyaNova.Core
}
//Has someone been trying funny business with the active techs in the db?
#if (SUBSCRIPTION_BUILD)
//Validate the db license related user data in case of attempted circumvention
//User count - common check to both build types
if (await AyaNova.Biz.UserBiz.ActiveInternalUserCountAsync() > _ActiveLicense.ActiveInternalUsersCount)
{
var msg = $"{SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR} (internal staff User count)";
@@ -793,8 +793,8 @@ namespace AyaNova.Core
log.LogCritical(msg);
return;
}
#if (SUBSCRIPTION_BUILD)
//Customer contact count - check only for subscription build
if (await AyaNova.Biz.UserBiz.ActiveCustomerContactUserCountAsync() > _ActiveLicense.ActiveCustomerContactUsersCount)
{
var msg = $"{SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR} (Customer Contact User count)";
@@ -802,26 +802,8 @@ namespace AyaNova.Core
log.LogCritical(msg);
return;
}
#else
// if (await AyaNova.Biz.UserBiz.ActiveTechUserCountAsync() > _ActiveLicense.ActiveTechsCount)
// {
// apiServerState.SetSystemLock(SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR);
// log.LogCritical(SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR);
// return;
//}
if (await AyaNova.Biz.UserBiz.ActiveInternalUserCountAsync() > _ActiveLicense.ActiveInternalUsersCount)
{
var msg = $"{SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR} (internal staff User count)";
apiServerState.SetSystemLock(msg);
log.LogCritical(msg);
return;
}
#endif
//Key is ok, might not have been on first boot so check and clear if locked
//This works for now because system lock only means license lock
//if ever changed for other purposes then need to handle that see serverstate for ideas
@@ -945,6 +927,7 @@ namespace AyaNova.Core
#endregion
#region PARSE and Validate key
//################## This is called on Boot up of server and when a new license key is fetched and installed ###############
/// <summary>
/// Parses and validates the integrity of a passed in textual license key
/// </summary>