This commit is contained in:
2020-06-13 18:12:13 +00:00
parent 0f1a529ec4
commit dd4a4cb68c
2 changed files with 26 additions and 21 deletions

View File

@@ -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;
}
}