Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RandomComputerId to CliAnalyticsCollectInputDto. #17559

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
var accessToken = await AuthenticationService.GetAccessTokenAsync(configuration);

File.WriteAllText(CliPaths.AccessToken, accessToken, Encoding.UTF8);

await WriteRandomComputerIdAsync();

Check warning on line 94 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs#L94

Added line #L94 was not covered by tests
}

public async Task DeviceLoginAsync()
Expand All @@ -105,6 +107,8 @@
var accessToken = await AuthenticationService.GetAccessTokenAsync(configuration);

File.WriteAllText(CliPaths.AccessToken, accessToken, Encoding.UTF8);

await WriteRandomComputerIdAsync();

Check warning on line 111 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs#L111

Added line #L111 was not covered by tests
}

public async Task LogoutAsync()
Expand All @@ -125,6 +129,8 @@

File.Delete(CliPaths.Lic);
}

await WriteRandomComputerIdAsync();

Check warning on line 133 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs#L133

Added line #L133 was not covered by tests
}

public async Task<bool> CheckMultipleOrganizationsAsync(string username)
Expand Down Expand Up @@ -177,4 +183,17 @@
{
return File.Exists(CliPaths.AccessToken);
}

private async Task WriteRandomComputerIdAsync()
{
var loginInfo = await GetLoginInfoAsync();
if (loginInfo != null && loginInfo.Id.HasValue)
{
File.WriteAllText(CliPaths.RandomComputerId, loginInfo.Id.Value.ToString("D"), Encoding.UTF8);
}

Check warning on line 193 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs#L188-L193

Added lines #L188 - L193 were not covered by tests
else
{
File.WriteAllText(CliPaths.RandomComputerId, Guid.NewGuid().ToString("D"), Encoding.UTF8);
}
}

Check warning on line 198 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs#L195-L198

Added lines #L195 - L198 were not covered by tests
}
1 change: 1 addition & 0 deletions framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public static string Log => Path.Combine(AbpRootPath, "cli", "logs");
public static string Root => Path.Combine(AbpRootPath, "cli");
public static string AccessToken => Path.Combine(AbpRootPath, "cli", "access-token.bin");
public static string RandomComputerId => Path.Combine(AbpRootPath, "cli", "random-computer-id.bin");

Check warning on line 13 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs#L13

Added line #L13 was not covered by tests
public static string Memory => Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)!, "memory.bin");
public static string Build => Path.Combine(AbpRootPath, "build");
public static string Lic => Path.Combine(Path.GetTempPath(), Encoding.ASCII.GetString(new byte[] { 65, 98, 112, 76, 105, 99, 101, 110, 115, 101, 46, 98, 105, 110 }));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Cli.Auth;
using Volo.Abp.Cli.Http;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Http;
Expand All @@ -19,22 +21,39 @@
private readonly ILogger<CliAnalyticsCollect> _logger;
private readonly IRemoteServiceExceptionHandler _remoteServiceExceptionHandler;
private readonly CliHttpClientFactory _cliHttpClientFactory;
private readonly IAuthService _authService;

public CliAnalyticsCollect(
ICancellationTokenProvider cancellationTokenProvider,
IJsonSerializer jsonSerializer,
IRemoteServiceExceptionHandler remoteServiceExceptionHandler,
CliHttpClientFactory cliHttpClientFactory)
CliHttpClientFactory cliHttpClientFactory,
IAuthService authService)
{
_cancellationTokenProvider = cancellationTokenProvider;
_jsonSerializer = jsonSerializer;
_remoteServiceExceptionHandler = remoteServiceExceptionHandler;
_cliHttpClientFactory = cliHttpClientFactory;
_authService = authService;
_logger = NullLogger<CliAnalyticsCollect>.Instance;
}

public async Task CollectAsync(CliAnalyticsCollectInputDto input)
{
if (input.RandomComputerId.IsNullOrWhiteSpace())
{
if (!File.Exists(CliPaths.RandomComputerId))
{
var randomComputerId = Guid.NewGuid().ToString("D");
input.RandomComputerId = randomComputerId;
File.WriteAllText(CliPaths.RandomComputerId, randomComputerId, Encoding.UTF8);
}

Check warning on line 50 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Analyticses/CliAnalyticsCollect.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Analyticses/CliAnalyticsCollect.cs#L43-L50

Added lines #L43 - L50 were not covered by tests
else
{
input.RandomComputerId = File.ReadAllText(CliPaths.RandomComputerId, Encoding.UTF8);
}
}

Check warning on line 55 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Analyticses/CliAnalyticsCollect.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Analyticses/CliAnalyticsCollect.cs#L52-L55

Added lines #L52 - L55 were not covered by tests

var postData = _jsonSerializer.Serialize(input);
var url = $"{CliUrls.WwwAbpIo}api/clianalytics/collect";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@
public string Language { get; set; }

public string Ip { get; set; }

public string RandomComputerId { get; set; }

Check warning on line 27 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Analyticses/CliAnalyticsCollectInputDto.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Analyticses/CliAnalyticsCollectInputDto.cs#L27

Added line #L27 was not covered by tests
}
Loading