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

- adds support for trimming #278

Merged
merged 4 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Text.Json.Serialization;

namespace Microsoft.Graph.Cli.Core.Configuration;

/// <summary>
Expand All @@ -10,3 +12,8 @@ public class ConfigurationRoot
/// </summary>
public AuthenticationOptions AuthenticationOptions { get; set; } = new AuthenticationOptions();
}

[JsonSerializable(typeof(ConfigurationRoot))]
internal partial class SourceGenerationContext : JsonSerializerContext
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
var options = await ReadAuthenticationIdentifiersAsync(cancellationToken);
var record = await ReadAuthenticationRecordAsync(cancellationToken);
var clientId = record?.ClientId ?? options?.ClientId;
var tenantId = record?.TenantId ?? options?.TenantId;

Check warning on line 115 in src/Microsoft.Graph.Cli.Core/IO/AuthenticationCacheManager.cs

View workflow job for this annotation

GitHub Actions / Build

Remove the unused local variable 'tenantId'. (https://rules.sonarsource.com/csharp/RSPEC-1481)

Check warning on line 115 in src/Microsoft.Graph.Cli.Core/IO/AuthenticationCacheManager.cs

View workflow job for this annotation

GitHub Actions / Build

Remove the unused local variable 'tenantId'. (https://rules.sonarsource.com/csharp/RSPEC-1481)
if (options == null || string.IsNullOrWhiteSpace(clientId))
{
return;
Expand Down Expand Up @@ -174,7 +174,7 @@

try
{
return await JsonSerializer.DeserializeAsync<Configuration.ConfigurationRoot>(fileStream, cancellationToken: cancellationToken);
return await JsonSerializer.DeserializeAsync(fileStream, SourceGenerationContext.Default.ConfigurationRoot, cancellationToken: cancellationToken).ConfigureAwait(false);
}
catch (Exception)
{
Expand All @@ -188,7 +188,7 @@
try
{
using FileStream fileStream = File.Open(path, FileMode.Create, FileAccess.Write);
await JsonSerializer.SerializeAsync(fileStream, configuration, cancellationToken: cancellationToken);
await JsonSerializer.SerializeAsync(fileStream, configuration, SourceGenerationContext.Default.ConfigurationRoot, cancellationToken: cancellationToken).ConfigureAwait(false);
}
catch (DirectoryNotFoundException)
{
Expand All @@ -198,7 +198,7 @@
}
}

private async Task<MsalCacheHelper> GetProtectedCacheHelperAsync(string name, CancellationToken cancellationToken = default)

Check warning on line 201 in src/Microsoft.Graph.Cli.Core/IO/AuthenticationCacheManager.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this unused method parameter 'cancellationToken'. (https://rules.sonarsource.com/csharp/RSPEC-1172)

Check warning on line 201 in src/Microsoft.Graph.Cli.Core/IO/AuthenticationCacheManager.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this unused method parameter 'cancellationToken'. (https://rules.sonarsource.com/csharp/RSPEC-1172)
{
// https://github.com/Azure/azure-sdk-for-net/blob/4b2579556b7271587d2fb122163e23090a043597/sdk/identity/Azure.Identity/src/Constants.cs
string cacheDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ".IdentityService");
Expand All @@ -206,7 +206,7 @@
const string keyringSchema = "msal.cache";
const string keyringCollection = "default";
KeyValuePair<string, string> keyringAttribute1 = new("MsalClientID", "Microsoft.Developer.IdentityService");
KeyValuePair<string, string> keyringAttribute2 = new("Microsoft.Developer.IdentityService", "1.0.0.0");

Check warning on line 209 in src/Microsoft.Graph.Cli.Core/IO/AuthenticationCacheManager.cs

View workflow job for this annotation

GitHub Actions / Build

Make sure using this hardcoded IP address '1.0.0.0' is safe here. (https://rules.sonarsource.com/csharp/RSPEC-1313)

Check warning on line 209 in src/Microsoft.Graph.Cli.Core/IO/AuthenticationCacheManager.cs

View workflow job for this annotation

GitHub Actions / Build

Make sure using this hardcoded IP address '1.0.0.0' is safe here. (https://rules.sonarsource.com/csharp/RSPEC-1313)
StorageCreationProperties storageProperties = new StorageCreationPropertiesBuilder(name, cacheDir)
.WithMacKeyChain(keychainService, name)
.WithLinuxKeyring(keyringSchema, keyringCollection, name, keyringAttribute1, keyringAttribute2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<DebugType>embedded</DebugType>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>preview.8</VersionSuffix>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>

<PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/sample/sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);CS8669</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand All @@ -20,4 +21,4 @@
<ProjectReference Include="..\Microsoft.Graph.Cli.Core\Microsoft.Graph.Cli.Core.csproj" />
</ItemGroup>

</Project>
</Project>
Loading