Added code for fetching license key from alternate servers if rockfish is not contactable. Alt license server domains are:

io.ayanova.com, europa.ayanova.com, callisto.ayanova.com
This commit is contained in:
2021-11-11 20:30:47 +00:00
parent c5afa9a5fc
commit 3040461bee

View File

@@ -28,8 +28,12 @@ namespace AyaNova.Core
internal static class License internal static class License
{ {
//License server address //License server addresses
private const string LICENSE_SERVER_URL = "https://rockfish.ayanova.com/"; private const string LICENSE_SERVER_URL_ROCKFISH = "https://rockfish.ayanova.com/";
private const string LICENSE_SERVER_URL_IO = "https://io.ayanova.com/";
private const string LICENSE_SERVER_URL_EUROPA = "https://europa.ayanova.com/";
private const string LICENSE_SERVER_URL_CALLISTO = "https://callisto.ayanova.com/";
// #if (DEBUG) // #if (DEBUG)
// private const string LICENSE_SERVER_URL = "http://localhost:3001/"; // private const string LICENSE_SERVER_URL = "http://localhost:3001/";
@@ -454,7 +458,7 @@ namespace AyaNova.Core
trialRequest.DbId = ServerDbId; trialRequest.DbId = ServerDbId;
log.LogDebug($"Requesting trial license for DBID {LicenseDbId}"); log.LogDebug($"Requesting trial license for DBID {LicenseDbId}");
string sUrl = $"{LICENSE_SERVER_URL}rvr"; string sUrl = $"{LICENSE_SERVER_URL_ROCKFISH}rvr";
try try
{ {
var content = new StringContent(JsonConvert.SerializeObject(trialRequest), Encoding.UTF8, "application/json"); var content = new StringContent(JsonConvert.SerializeObject(trialRequest), Encoding.UTF8, "application/json");
@@ -492,7 +496,7 @@ namespace AyaNova.Core
/// </summary> /// </summary>
/// <returns>Result string</returns> /// <returns>Result string</returns>
#if (DEBUG) #if (DEBUG)
internal static async Task<string> FetchKeyAsync(AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ct, ILogger log, bool calledFromInternalJob, bool devTestTrial=false) internal static async Task<string> FetchKeyAsync(AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ct, ILogger log, bool calledFromInternalJob, bool devTestTrial = false)
#else #else
internal static async Task<string> FetchKeyAsync(AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ct, ILogger log, bool calledFromInternalJob) internal static async Task<string> FetchKeyAsync(AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ct, ILogger log, bool calledFromInternalJob)
#endif #endif
@@ -504,22 +508,22 @@ namespace AyaNova.Core
var FetchRequest = new dtoFetchRequest() { DbId = LicenseDbId }; var FetchRequest = new dtoFetchRequest() { DbId = LicenseDbId };
#if (DEBUG) #if (DEBUG)
string sUrl = $"{LICENSE_SERVER_URL}rvf"; string AppendToLicenseUrl = "rvf";
if (devTestTrial) if (devTestTrial)
{ {
sUrl += "?dtt=true";//signal to rockfish to provide a key immediately for dev testing AppendToLicenseUrl += "?dtt=true";//signal to rockfish to provide a key immediately for dev testing
} }
#else #else
string sUrl = $"{LICENSE_SERVER_URL}rvf"; string sUrl = $"rvf";
#endif #endif
try try
{ {
// string ResponseText = await ServiceProviderProvider.HttpClientFactory.CreateClient().GetStringAsync(sUrl);
var content = new StringContent(JsonConvert.SerializeObject(FetchRequest), Encoding.UTF8, "application/json"); var content = new StringContent(JsonConvert.SerializeObject(FetchRequest), Encoding.UTF8, "application/json");
var client = ServiceProviderProvider.HttpClientFactory.CreateClient(); var client = ServiceProviderProvider.HttpClientFactory.CreateClient();
var res = await client.PostAsync(sUrl, content); HttpResponseMessage res = null;
res = await DoFetchAsync(AppendToLicenseUrl, content, client);
if (res.IsSuccessStatusCode) if (res.IsSuccessStatusCode)
{ {
var responseText = await res.Content.ReadAsStringAsync(); var responseText = await res.Content.ReadAsStringAsync();
@@ -587,6 +591,40 @@ namespace AyaNova.Core
} }
} }
private static async Task<HttpResponseMessage> DoFetchAsync(string AppendToLicenseUrl, StringContent content, HttpClient client)
{
var LicenseServer = string.Empty;
for (int x = 0; x < 4; x++)
{
try
{
switch (x)
{
case 0:
LicenseServer = LICENSE_SERVER_URL_CALLISTO;
break;
case 1:
LicenseServer = LICENSE_SERVER_URL_IO;
break;
case 2:
LicenseServer = LICENSE_SERVER_URL_EUROPA;
break;
case 3:
LicenseServer = LICENSE_SERVER_URL_ROCKFISH ;
break;
}
return await client.PostAsync($"{LicenseServer}{AppendToLicenseUrl}", content);
}
catch(System.Net.Http.HttpRequestException){
if(x==3)
throw;
}
}
return null;
}
/// <summary> /// <summary>
/// Initialize the license /// Initialize the license