This commit is contained in:
@@ -479,29 +479,36 @@ namespace AyaNova.Core
|
||||
/// Fetch a key, validate it and install it in the db then initialize with it
|
||||
/// </summary>
|
||||
/// <returns>Result string</returns>
|
||||
internal static async Task FetchKeyAsync(AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ct, ILogger log)
|
||||
internal static async Task<string> FetchKeyAsync(AyaNova.Api.ControllerHelpers.ApiServerState apiServerState, AyContext ct, ILogger log, bool calledFromInternalJob = true)
|
||||
{
|
||||
log.LogDebug($"Fetching license for DBID {LicenseDbId.ToString()}");
|
||||
string sUrl = $"{LICENSE_SERVER_URL}rvf/{LicenseDbId.ToString()}";
|
||||
try
|
||||
{
|
||||
string RawTextKeyFromRockfish = await ServiceProviderProvider.HttpClientFactory.CreateClient().GetStringAsync(sUrl);
|
||||
//FUTURE: if there is any kind of error response or REASON or LicenseFetchStatus then here is
|
||||
//where to deal with it
|
||||
//todo: key should hang off json data object as text version of key
|
||||
//that way we can put other objects on the data return object
|
||||
|
||||
AyaNovaLicenseKey ParsedKey = Parse(RawTextKeyFromRockfish, log);
|
||||
if (ParsedKey != null)
|
||||
// string ResponseText = await ServiceProviderProvider.HttpClientFactory.CreateClient().GetStringAsync(sUrl);
|
||||
var client = ServiceProviderProvider.HttpClientFactory.CreateClient();
|
||||
var res = await client.GetAsync(sUrl);
|
||||
if (res.IsSuccessStatusCode)
|
||||
{
|
||||
await InstallAsync(RawTextKeyFromRockfish, ParsedKey, apiServerState, ct, log);
|
||||
var responseText = await res.Content.ReadAsStringAsync();
|
||||
AyaNovaLicenseKey ParsedKey = Parse(responseText, log);
|
||||
if (ParsedKey != null)
|
||||
{
|
||||
await InstallAsync(responseText, ParsedKey, apiServerState, ct, log);
|
||||
return "ok";
|
||||
}
|
||||
return $"E1020 - Error fetching license key: No key was returned";
|
||||
}
|
||||
else
|
||||
return $"E1020 - Error fetching license key: {res.ReasonPhrase}";
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (calledFromInternalJob) throw ex;
|
||||
var msg = "E1020 - Error fetching license key";
|
||||
log.LogError(ex, msg);
|
||||
throw new ApplicationException(msg, ex);
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user