Browse Source

Merge pull request #2635 from abpframework/fix-cli-incorrect-license-error-and-warning

fix cli incorrect license error and warning
pull/2637/head
Halil İbrahim Kalkan 7 years ago
committed by GitHub
parent
commit
496fa23c31
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs
  2. 3
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClient.cs
  3. 16
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Licensing/AbpIoApiKeyService.cs

5
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs

@ -45,5 +45,10 @@ namespace Volo.Abp.Cli.Auth
FileHelper.DeleteIfExists(CliPaths.AccessToken); FileHelper.DeleteIfExists(CliPaths.AccessToken);
return Task.CompletedTask; return Task.CompletedTask;
} }
public static bool IsLoggedIn()
{
return File.Exists(CliPaths.AccessToken);
}
} }
} }

3
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClient.cs

@ -3,6 +3,7 @@ using System.IO;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
using IdentityModel.Client; using IdentityModel.Client;
using Volo.Abp.Cli.Auth;
namespace Volo.Abp.Cli.Http namespace Volo.Abp.Cli.Http
{ {
@ -29,7 +30,7 @@ namespace Volo.Abp.Cli.Http
private static void AddAuthentication(HttpClient client) private static void AddAuthentication(HttpClient client)
{ {
if (!File.Exists(CliPaths.AccessToken)) if (!AuthService.IsLoggedIn())
{ {
return; return;
} }

16
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Licensing/AbpIoApiKeyService.cs

@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using Polly; using Polly;
using Polly.Extensions.Http; using Polly.Extensions.Http;
using Volo.Abp.Cli.Auth;
using Volo.Abp.Cli.Http; using Volo.Abp.Cli.Http;
using Volo.Abp.Cli.ProjectBuilding; using Volo.Abp.Cli.ProjectBuilding;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
@ -31,6 +32,11 @@ namespace Volo.Abp.Cli.Licensing
public async Task<DeveloperApiKeyResult> GetApiKeyOrNullAsync(bool invalidateCache = false) public async Task<DeveloperApiKeyResult> GetApiKeyOrNullAsync(bool invalidateCache = false)
{ {
if (!AuthService.IsLoggedIn())
{
return null;
}
if (invalidateCache) if (invalidateCache)
{ {
_apiKeyResult = null; _apiKeyResult = null;
@ -81,16 +87,6 @@ namespace Volo.Abp.Cli.Licensing
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var apiKeyResult = JsonSerializer.Deserialize<DeveloperApiKeyResult>(responseContent); var apiKeyResult = JsonSerializer.Deserialize<DeveloperApiKeyResult>(responseContent);
if (string.IsNullOrEmpty(apiKeyResult?.ApiKey))
{
_logger.LogError("Couldn't retrieve your NuGet API key!");
_logger.LogWarning(File.Exists(CliPaths.AccessToken)
? "Make sure you have an active session and license on commercial.abp.io. To re-sign in you can use the CLI command \"abp login <username>\"."
: "You are not signed in to commercial.abp.io. Use the CLI command \"abp login <username>\" to sign in.");
return null;
}
return apiKeyResult; return apiKeyResult;
} }
} }

Loading…
Cancel
Save