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 //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 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 //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"; var msg = $"{reason}\r\nLogin as SuperUser to start evaluation / install license";
SetState(ServerState.OpsOnly, msg); SetState(ServerState.OpsOnly, msg);
@@ -185,7 +191,7 @@ namespace AyaNova.Api.ControllerHelpers
{ {
get get
{ {
return _currentState != ServerState.Closed && _currentState != ServerState.OpsOnly && !SYSTEM_LOCK ; return _currentState != ServerState.Closed && _currentState != ServerState.OpsOnly && !SYSTEM_LOCK;
} }
} }

View File

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

View File

@@ -57,8 +57,9 @@ namespace AyaNova.Biz
await SweepInternalJobsLogsAsync(ct, dtDeleteCutoff); await SweepInternalJobsLogsAsync(ct, dtDeleteCutoff);
//In flight check of user count exceeded in case someone meddled in the DB Directly //In flight check validate the db license related user data in case of attempted circumvention
#if (SUBSCRIPTION_BUILD)
//User count - common check to both build types
if (await AyaNova.Biz.UserBiz.ActiveInternalUserCountAsync() > AyaNova.Core.License.ActiveKey.ActiveInternalUsersCount) 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)"; 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; return;
} }
#if (SUBSCRIPTION_BUILD)
//Customer contact count - check only for subscription build
if (await AyaNova.Biz.UserBiz.ActiveCustomerContactUserCountAsync() > AyaNova.Core.License.ActiveKey.ActiveCustomerContactUsersCount) 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)"; 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); log.LogCritical(msg);
return; 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 #endif
} }

View File

@@ -528,17 +528,17 @@ namespace AyaNova.Core
var FetchRequest = new dtoFetchRequest() { DbId = LicenseDbId }; var FetchRequest = new dtoFetchRequest() { DbId = LicenseDbId };
string LicenseUrlParameter = "rvf"; string LicenseUrlParameter = "rvf";
// #if (DEBUG) // #if (DEBUG)
// if (devTestTrial) // if (devTestTrial)
// { // {
// #if (SUBSCRIPTION_BUILD) // #if (SUBSCRIPTION_BUILD)
// LicenseUrlParameter += "?dtt=true&pp=false";//signal to rockfish to provide a key immediately for dev testing // LicenseUrlParameter += "?dtt=true&pp=false";//signal to rockfish to provide a key immediately for dev testing
// #else // #else
// LicenseUrlParameter += "?dtt=true&pp=true";//signal to rockfish to provide a key immediately for dev testing // LicenseUrlParameter += "?dtt=true&pp=true";//signal to rockfish to provide a key immediately for dev testing
// #endif // #endif
// } // }
// #endif // #endif
try try
{ {
@@ -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> /// <summary>
/// Initialize the license /// Initialize the license
///
/// </summary> /// </summary>
internal static async Task InitializeAsync(AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ct, ILogger log) 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? //Validate the db license related user data in case of attempted circumvention
#if (SUBSCRIPTION_BUILD)
//User count - common check to both build types
if (await AyaNova.Biz.UserBiz.ActiveInternalUserCountAsync() > _ActiveLicense.ActiveInternalUsersCount) if (await AyaNova.Biz.UserBiz.ActiveInternalUserCountAsync() > _ActiveLicense.ActiveInternalUsersCount)
{ {
var msg = $"{SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR} (internal staff User count)"; 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); log.LogCritical(msg);
return; return;
} }
#if (SUBSCRIPTION_BUILD)
//Customer contact count - check only for subscription build
if (await AyaNova.Biz.UserBiz.ActiveCustomerContactUserCountAsync() > _ActiveLicense.ActiveCustomerContactUsersCount) if (await AyaNova.Biz.UserBiz.ActiveCustomerContactUserCountAsync() > _ActiveLicense.ActiveCustomerContactUsersCount)
{ {
var msg = $"{SERVER_STATE_LOCKOUT_DUE_TO_LICENSE_EXCEEDED_CAPACITY_ERROR} (Customer Contact User count)"; 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); log.LogCritical(msg);
return; 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 #endif
//Key is ok, might not have been on first boot so check and clear if locked //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 //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 //if ever changed for other purposes then need to handle that see serverstate for ideas
@@ -945,6 +927,7 @@ namespace AyaNova.Core
#endregion #endregion
#region PARSE and Validate key #region PARSE and Validate key
//################## This is called on Boot up of server and when a new license key is fetched and installed ###############
/// <summary> /// <summary>
/// Parses and validates the integrity of a passed in textual license key /// Parses and validates the integrity of a passed in textual license key
/// </summary> /// </summary>