Skip to content

Commit

Permalink
Add a .NET 8 target to RequiredTargetFrameworks (#46637)
Browse files Browse the repository at this point in the history
* initial updates

* core libraries

* provisioning

* servicebus

* communication

* hold off on API generation

* one more

* move API compat change to be in Directory build common props instead

* identity

* eventhub

* attestation

* tables

* translation

* batch

* tables/storage

* temp

* open AI fixes

* open AI fixes

* more fixes

* updates

* few more exceptions

* feedback p1

* feedback 2

* more feedback

* more updates

* fixes

* provisioning fix

* playwright testing fb

* fixes

* feedback

* updates

* updates

* fix

* another fix

* fb

* feedback and get latest changes

* maps
  • Loading branch information
m-redding authored Nov 18, 2024
1 parent 84dda33 commit d8f5034
Show file tree
Hide file tree
Showing 59 changed files with 258 additions and 154 deletions.
5 changes: 3 additions & 2 deletions eng/Directory.Build.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<!-- Setup default project properties -->
<PropertyGroup>
<LangVersion>11.0</LangVersion>
<LangVersion>latest</LangVersion>
<!--
Disable NU5105 NuGet Pack warning that the version is SemVer 2.0.
SemVer 2.0 is supported by NuGet since 3.0.0 (July 2015) in some capacity, and fully since 3.5.0 (October 2016).
Expand Down Expand Up @@ -106,6 +106,7 @@
<GenerateAPIListing Condition="'$(GenerateAPIListing)' == '' AND '$(IsShippingClientLibrary)' == 'true'">true</GenerateAPIListing>
<EnableSourceLink Condition="'$(EnableSourceLink)' == ''">true</EnableSourceLink>
<DefineConstants Condition="'$(BuildSnippets)' == 'true'">$(DefineConstants);SNIPPET</DefineConstants>
<ApiCompatBaselineTargetFramework Condition="'$(TargetFramework)' == 'net8.0'">netstandard2.0</ApiCompatBaselineTargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(IsShippingClientLibrary)' == 'true' and '$(TF_BUILD)' == 'true'">
Expand Down Expand Up @@ -135,7 +136,7 @@
<SupportsNetStandard20 Condition="'$(SupportsNetStandard20)' == ''">false</SupportsNetStandard20>

<RequiredTargetFrameworks>net452;netstandard1.4;net461;netstandard2.0</RequiredTargetFrameworks>
<RequiredTargetFrameworks Condition="'$(SupportsNetStandard20)' == 'true'">netstandard2.0</RequiredTargetFrameworks>
<RequiredTargetFrameworks Condition="'$(SupportsNetStandard20)' == 'true'">net8.0;netstandard2.0</RequiredTargetFrameworks>
<RequiredTargetFrameworks Condition="'$(IsGeneratorLibrary)' == 'true'">net8.0</RequiredTargetFrameworks>
</PropertyGroup>

Expand Down
9 changes: 9 additions & 0 deletions eng/Directory.Build.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@

</ItemGroup>

<!-- Remove packages built into the .NET 6+ runtime -->
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
<PackageReference Remove="System.Buffers" />
<PackageReference Remove="System.Net.Http" />
<PackageReference Remove="System.Threading.Channels" />
<PackageReference Remove="System.Text.Encodings.Web" />
<PackageReference Remove="System.Text.Json" />
</ItemGroup>

<!-- Add Package Icon to DataPlane Packages -->
<ItemGroup Condition="'$(IsTestProject)' != 'true'">
<None Include="$(PackageIconPath)" Pack="true" PackagePath=""/>
Expand Down
8 changes: 4 additions & 4 deletions eng/scripts/CodeChecks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ try {
& $PSScriptRoot\Update-Snippets.ps1 -ServiceDirectory $ServiceDirectory
}

Write-Host "Re-generating listings"
Invoke-Block {
& $PSScriptRoot\Export-API.ps1 -ServiceDirectory $ServiceDirectory -SDKType $SDKType -SpellCheckPublicApiSurface:$SpellCheckPublicApiSurface
}
# Write-Host "Re-generating listings"
# Invoke-Block {
# & $PSScriptRoot\Export-API.ps1 -ServiceDirectory $ServiceDirectory -SDKType $SDKType -SpellCheckPublicApiSurface:$SpellCheckPublicApiSurface
# }

Write-Host "Validating installation instructions"
Join-Path "$PSScriptRoot/../../sdk" $ServiceDirectory `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,11 @@ private bool ValidateTokenSignature(AttestationSigner[] possibleSigners)
{
// The leaf certificate is defined as the certificate which signed the token, so we just need to look
// at the first certificate in the chain.
#if NET6_0_OR_GREATER
AsymmetricAlgorithm asymmetricAlgorithm = signer.SigningCertificates[0].GetRSAPublicKey();
#else
AsymmetricAlgorithm asymmetricAlgorithm = signer.SigningCertificates[0].PublicKey.Key;
#endif
if (asymmetricAlgorithm is RSA rsaKey)
{
signatureValidated = rsaKey.VerifyData(
Expand Down Expand Up @@ -645,7 +649,11 @@ private static string GenerateSecuredJsonWebToken(BinaryData body, AttestationTo
AsymmetricAlgorithm signer;
if (signingKey.Certificate.HasPrivateKey)
{
#if NET6_0_OR_GREATER
signer = signingKey.Certificate.GetRSAPrivateKey();
#else
signer = signingKey.Certificate.PrivateKey;
#endif
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public AttestationTokenSigningKey(X509Certificate2 certificate)
{
throw new ArgumentException($"Certificate provided {certificate.ToString()} does not have a private key.");
}
#if NET6_0_OR_GREATER
Signer = certificate.GetRSAPublicKey();
#else
Signer = certificate.PrivateKey;
#endif
Certificate = certificate;
VerifySignerMatchesCertificate(Signer, Certificate);
}
Expand All @@ -62,17 +66,26 @@ public AttestationTokenSigningKey(X509Certificate2 certificate)

private static void VerifySignerMatchesCertificate(AsymmetricAlgorithm signer, X509Certificate2 certificate)
{
if (!signer.KeyExchangeAlgorithm.StartsWith(certificate.PublicKey.Key.KeyExchangeAlgorithm, System.StringComparison.Ordinal))
#if NET6_0_OR_GREATER
AsymmetricAlgorithm publicKey = certificate.GetRSAPublicKey();
#else
AsymmetricAlgorithm publicKey = certificate.PublicKey.Key;
#endif
if (!signer.KeyExchangeAlgorithm.StartsWith(publicKey.KeyExchangeAlgorithm, System.StringComparison.Ordinal))
{
throw new ArgumentException($"Signer key algorithm {signer.SignatureAlgorithm} does not match certificate key algorithm {certificate.PublicKey.Key.SignatureAlgorithm}");
throw new ArgumentException($"Signer key algorithm {signer.SignatureAlgorithm} does not match certificate key algorithm {publicKey.SignatureAlgorithm}");
}

// Try to match the public key in the certificate and the signer. If the platform
// supports the ToXmlString API, then use that since it the simplest solution and is relatively fast.
try
{
string signerKey = signer.ToXmlString(false);
#if NET6_0_OR_GREATER
string certificateKey = certificate.GetRSAPublicKey().ToXmlString(false);
#else
string certificateKey = certificate.PublicKey.Key.ToXmlString(false);
#endif
if (signerKey != certificateKey)
{
throw new ArgumentException($"Signer key {signerKey} does not match certificate key {certificateKey}");
Expand All @@ -98,7 +111,7 @@ private static void VerifySignerMatchesCertificate(AsymmetricAlgorithm signer, X
throw new ArgumentException("Signing Key must be either RSA or ECDsa. Unknown signing key found");
}

AsymmetricAlgorithm verifyingAlgorithm = certificate.PublicKey.Key;
AsymmetricAlgorithm verifyingAlgorithm = publicKey;
if (verifyingAlgorithm is RSA verifyingRsa)
{
if (!verifyingRsa.VerifyData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private void BuildCanonicalizedResource(StringBuilder stringBuilder, Uri resourc
private string ComputeSasSignature(string message)
{
#if NET6_0_OR_GREATER
return Convert.ToBase64String(HMACSHA256.HashData(AccountKeyValue, Encoding.UTF8.GetBytes(message)));
return Convert.ToBase64String(HMACSHA256.HashData(AccountKey, Encoding.UTF8.GetBytes(message)));
#else
return Convert.ToBase64String(new HMACSHA256(AccountKey).ComputeHash(Encoding.UTF8.GetBytes(message)));
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ internal bool TryGetAndRemoveEvent(Func<CallAutomationEventBase, bool> predicate
{
// Match any event that matches in the events backlog
var matchingKvp = _eventBacklog.FirstOrDefault(kvp => predicate(kvp.Value.Item1));
matchingEvent = default;

// Try remove the item - if successful, return it as keyValuePair
if (matchingKvp.Key != default && _eventBacklog.TryRemove(matchingKvp.Key, out var returnedValue))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public ScheduledAction(Action action, TimeSpan period)
public void Dispose()
=> _timer.Dispose();

private void OnTimerTick(object _)
private void OnTimerTick(object? _)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Azure.Core.Amqp
public AmqpAddress(string address) { throw null; }
public bool Equals(Azure.Core.Amqp.AmqpAddress other) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override bool Equals(object obj) { throw null; }
public override bool Equals(object? obj) { throw null; }
public bool Equals(string other) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override int GetHashCode() { throw null; }
Expand Down Expand Up @@ -65,7 +65,7 @@ internal AmqpMessageHeader() { }
public AmqpMessageId(string messageId) { throw null; }
public bool Equals(Azure.Core.Amqp.AmqpMessageId other) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override bool Equals(object obj) { throw null; }
public override bool Equals(object? obj) { throw null; }
public bool Equals(string other) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override int GetHashCode() { throw null; }
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core.Amqp/src/AmqpAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override string ToString() =>
/// <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" />.
/// </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (obj is AmqpAddress address)
{
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core.Amqp/src/AmqpMessageId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public AmqpMessageId(string messageId)
/// <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" />.
/// </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (obj is AmqpMessageId messageId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private sealed class StraightCastFlag<T> : TypeFlag<T>
public static StraightCastFlag<T> Instance { get; } = new();

public override T To(in Variant value)
=> Unsafe.As<Union, T>(ref Unsafe.AsRef(value._union));
=> Unsafe.As<Union, T>(ref Unsafe.AsRef(in value._union));
}
}
}
Loading

0 comments on commit d8f5034

Please sign in to comment.