From 393762a427591884a783bae4a3c593dd533d197b Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-lf <115584722+sfc-gh-ext-simba-lf@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:51:45 -0700 Subject: [PATCH] SNOW-798828: Target .NET Standard 2.0 (#867) ### Description Change the target framework to .NET Standard 2.0 ### Checklist - [ ] Code compiles correctly - [ ] Code is formatted according to [Coding Conventions](../CodingConventions.md) - [ ] Created tests which fail without the change (if possible) - [ ] All tests passing (`dotnet test`) - [ ] Extended the README / documentation, if necessary - [ ] Provide JIRA issue id (if possible) or GitHub issue id in PR name --- .github/workflows/main.yml | 8 ++--- README.md | 8 ++++- .../Snowflake.Data.Tests.csproj | 8 ++--- .../UnitTests/ArrowResultChunkTest.cs | 2 +- .../UnitTests/ArrowResultSetTest.cs | 16 ++++++--- .../UnitTests/SFEnvironmentTest.cs | 36 +++++++++++++++++++ .../Util/SnowflakeDbExceptionAssert.cs | 4 --- Snowflake.Data/Core/ArrowResultChunk.cs | 1 - .../ExternalBrowserAuthenticator.cs | 5 --- .../Core/Authenticator/OktaAuthenticator.cs | 6 +--- Snowflake.Data/Core/RestParams.cs | 31 +++++++++------- Snowflake.Data/Snowflake.Data.csproj | 13 ++----- 12 files changed, 85 insertions(+), 53 deletions(-) create mode 100644 Snowflake.Data.Tests/UnitTests/SFEnvironmentTest.cs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 171778d11..55eef86c7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,7 @@ concurrency: cancel-in-progress: true # uncomment to run the tests sequentially - #SEQUENTIAL_ENV: SEQUENTIAL_TEST_RUN + # SEQUENTIAL_ENV: SEQUENTIAL_TEST_RUN jobs: test-windows: @@ -31,7 +31,7 @@ jobs: strategy: fail-fast: false matrix: - dotnet: ['net8.0','net6.0', 'net472', 'net471'] + dotnet: ['net6.0', 'net7.0', 'net8.0', 'net462', 'net471', 'net472', 'net48', 'net481'] cloud_env: ['AZURE', 'GCP', 'AWS'] steps: - name: Checkout code @@ -92,7 +92,7 @@ jobs: strategy: fail-fast: false matrix: - dotnet: ['net6.0', 'net8.0'] + dotnet: ['net6.0', 'net7.0', 'net8.0'] cloud_env: ['AZURE', 'GCP', 'AWS'] steps: - uses: actions/checkout@v3 @@ -151,7 +151,7 @@ jobs: strategy: fail-fast: false matrix: - dotnet: ['net6.0', 'net8.0'] + dotnet: ['net6.0', 'net7.0', 'net8.0'] cloud_env: ['AZURE', 'GCP', 'AWS'] steps: - uses: actions/checkout@v4 diff --git a/README.md b/README.md index 7b8766853..58fff4767 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,17 @@ The Snowflake .NET connector supports the the following .NET framework and libraries versions: +- .NET Framework 4.6.2 - .NET Framework 4.7.1 - .NET Framework 4.7.2 +- .NET Framework 4.8 +- .NET Framework 4.8.1 - .NET 6.0 +- .NET 7.0 - .NET 8.0 +Disclaimer: While the connector targets netstandard2.0 and may work with versions in its [support matrix](https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-0#select-net-standard-version), only the versions listed above are supported and tested by the connector + Please refer to the [Notice](#notice) section below for information about safe usage of the .NET Driver # Coding conventions for the project @@ -144,7 +150,7 @@ Logging description and configuration: were not performed where the insecureMode flag was set to false, which is the default setting. From version v2.1.5 CRL is working back as intended. -Note that the driver is now targeting .NET 6.0. When upgrading, you might also need to run “Update-Package -reinstall” to update the dependencies. +Note that the driver is now targeting .NET Standard 2.0. When upgrading, you might also need to run “Update-Package -reinstall” to update the dependencies. See more: * [Security Policy](SECURITY.md) diff --git a/Snowflake.Data.Tests/Snowflake.Data.Tests.csproj b/Snowflake.Data.Tests/Snowflake.Data.Tests.csproj index 0188d4552..cc895154e 100644 --- a/Snowflake.Data.Tests/Snowflake.Data.Tests.csproj +++ b/Snowflake.Data.Tests/Snowflake.Data.Tests.csproj @@ -1,9 +1,7 @@ - + - net8.0;net6.0;net471;net472 - net6.0;net8.0 - 6.0.0 - 8.0.0 + net6.0;net7.0;net8.0;net462;net471;net472;net48;net481 + net6.0;net7.0;net8.0; Snowflake.Data.Tests Snowflake Connector for .NET Snowflake Computing, Inc diff --git a/Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs b/Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs index 8197409be..fd70c80c9 100755 --- a/Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs +++ b/Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved. */ diff --git a/Snowflake.Data.Tests/UnitTests/ArrowResultSetTest.cs b/Snowflake.Data.Tests/UnitTests/ArrowResultSetTest.cs index cf8746b75..026671783 100755 --- a/Snowflake.Data.Tests/UnitTests/ArrowResultSetTest.cs +++ b/Snowflake.Data.Tests/UnitTests/ArrowResultSetTest.cs @@ -275,10 +275,18 @@ public void TestGetText() [Test] public void TestGetTextWithOneChar() { - var testValues = - TestDataGenarator.AsciiCodes.ToCharArray() - .Append(TestDataGenarator.SnowflakeUnicode) - .ToArray(); + char[] testValues; + +#if NET462 + var charArr = TestDataGenarator.AsciiCodes.ToList(); + charArr.Add(TestDataGenarator.SnowflakeUnicode); + testValues = charArr.ToArray(); +#else + testValues = + TestDataGenarator.AsciiCodes.ToCharArray() + .Append(TestDataGenarator.SnowflakeUnicode) + .ToArray(); +#endif PrepareTestCase(SFDataType.TEXT, 0, testValues); diff --git a/Snowflake.Data.Tests/UnitTests/SFEnvironmentTest.cs b/Snowflake.Data.Tests/UnitTests/SFEnvironmentTest.cs new file mode 100644 index 000000000..34aa60f2c --- /dev/null +++ b/Snowflake.Data.Tests/UnitTests/SFEnvironmentTest.cs @@ -0,0 +1,36 @@ +using NUnit.Framework; +using Snowflake.Data.Core; + +namespace Snowflake.Data.Tests.UnitTests +{ + [TestFixture] + class SFEnvironmentTest + { + [Test] + public void TestRuntimeExtraction() + { + // Arrange + string expectedRuntime = ".NET"; + string expectedVersion; + +#if NETFRAMEWORK + expectedRuntime += "Framework"; + expectedVersion = "4.8"; +#elif NET6_0 + expectedVersion = "6.0"; +#elif NET7_0 + expectedVersion = "7.0"; +#elif NET8_0 + expectedVersion = "8.0"; +#endif + + // Act + var actualRuntime = SFEnvironment.ExtractRuntime(); + var actualVersion = SFEnvironment.ExtractVersion(); + + // Assert + Assert.AreEqual(expectedRuntime, actualRuntime); + Assert.AreEqual(expectedVersion, actualVersion); + } + } +} diff --git a/Snowflake.Data.Tests/Util/SnowflakeDbExceptionAssert.cs b/Snowflake.Data.Tests/Util/SnowflakeDbExceptionAssert.cs index 881cba861..f06a73871 100644 --- a/Snowflake.Data.Tests/Util/SnowflakeDbExceptionAssert.cs +++ b/Snowflake.Data.Tests/Util/SnowflakeDbExceptionAssert.cs @@ -41,11 +41,7 @@ public static void HasHttpErrorCodeInExceptionChain(Exception exception, HttpSta case SnowflakeDbException se: return se.ErrorCode == (int)expected; case HttpRequestException he: -#if NETFRAMEWORK return he.Message.Contains(((int)expected).ToString()); -#else - return he.StatusCode == expected; -#endif default: return false; } diff --git a/Snowflake.Data/Core/ArrowResultChunk.cs b/Snowflake.Data/Core/ArrowResultChunk.cs index 4422d1957..901c01692 100755 --- a/Snowflake.Data/Core/ArrowResultChunk.cs +++ b/Snowflake.Data/Core/ArrowResultChunk.cs @@ -138,7 +138,6 @@ public override UTF8Buffer ExtractCell(int rowIndex, int columnIndex) throw new NotSupportedException(); } - [Obsolete("ExtractCell with columnIndex is deprecated", false)] public override UTF8Buffer ExtractCell(int columnIndex) { throw new NotSupportedException(); diff --git a/Snowflake.Data/Core/Authenticator/ExternalBrowserAuthenticator.cs b/Snowflake.Data/Core/Authenticator/ExternalBrowserAuthenticator.cs index 3b882a05b..e39ec18f8 100644 --- a/Snowflake.Data/Core/Authenticator/ExternalBrowserAuthenticator.cs +++ b/Snowflake.Data/Core/Authenticator/ExternalBrowserAuthenticator.cs @@ -204,10 +204,6 @@ private static void StartBrowser(string url) } // The following code is learnt from https://brockallen.com/2016/09/24/process-start-for-urls-on-net-core/ -#if NETFRAMEWORK - // .net standard would pass here - Process.Start(new ProcessStartInfo(url) { UseShellExecute = true }); -#else // hack because of this: https://github.com/dotnet/corefx/issues/10361 if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { @@ -226,7 +222,6 @@ private static void StartBrowser(string url) { throw new SnowflakeDbException(SFError.UNSUPPORTED_PLATFORM); } -#endif } private static string ValidateAndExtractToken(HttpListenerRequest request) diff --git a/Snowflake.Data/Core/Authenticator/OktaAuthenticator.cs b/Snowflake.Data/Core/Authenticator/OktaAuthenticator.cs index 1780ccffc..d26a7e543 100644 --- a/Snowflake.Data/Core/Authenticator/OktaAuthenticator.cs +++ b/Snowflake.Data/Core/Authenticator/OktaAuthenticator.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved. */ @@ -82,11 +82,7 @@ async Task IAuthenticator.AuthenticateAsync(CancellationToken cancellationToken) s_logger.Debug("step 4: Get SAML response from SSO"); var samlRestRequest = BuildSamlRestRequest(ssoUrl, onetimeToken); samlRawResponse = await session.restRequester.GetAsync(samlRestRequest, cancellationToken).ConfigureAwait(false); -#if NETFRAMEWORK _rawSamlTokenHtmlString = await samlRawResponse.Content.ReadAsStringAsync().ConfigureAwait(false); -#else - _rawSamlTokenHtmlString = await samlRawResponse.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); -#endif s_logger.Debug("step 5: Verify postback URL in SAML response"); VerifyPostbackUrl(); diff --git a/Snowflake.Data/Core/RestParams.cs b/Snowflake.Data/Core/RestParams.cs index 72b910847..1340400ca 100644 --- a/Snowflake.Data/Core/RestParams.cs +++ b/Snowflake.Data/Core/RestParams.cs @@ -1,6 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System; +using System.Reflection; +using System.Runtime.InteropServices; namespace Snowflake.Data.Core { @@ -59,17 +59,12 @@ static SFEnvironment() ClientEnv = new LoginRequestClientEnv() { application = System.Diagnostics.Process.GetCurrentProcess().ProcessName, - osVersion = System.Environment.OSVersion.VersionString, -#if NETFRAMEWORK - netRuntime = "NETFramework", - netVersion = "4.7.1", -#else - netRuntime = "NETCore", - netVersion ="2.0", -#endif + osVersion = Environment.OSVersion.VersionString, + netRuntime = ExtractRuntime(), + netVersion = ExtractVersion(), }; - DriverVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); + DriverVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); DriverName = ".NET"; } @@ -77,5 +72,17 @@ static SFEnvironment() internal static string DriverName { get; set; } internal static string DriverVersion { get; set; } internal static LoginRequestClientEnv ClientEnv { get; private set; } + + internal static string ExtractRuntime() + { + return RuntimeInformation.FrameworkDescription.Substring(0, RuntimeInformation.FrameworkDescription.LastIndexOf(' ')).Replace(" ", ""); + } + + internal static string ExtractVersion() + { + var version = RuntimeInformation.FrameworkDescription.Substring(RuntimeInformation.FrameworkDescription.LastIndexOf(' ')).Replace(" ", ""); + int secondPeriodIndex = version.IndexOf('.', version.IndexOf('.') + 1); + return version.Substring(0, secondPeriodIndex); + } } } diff --git a/Snowflake.Data/Snowflake.Data.csproj b/Snowflake.Data/Snowflake.Data.csproj index d2c2065f2..c79c58e43 100644 --- a/Snowflake.Data/Snowflake.Data.csproj +++ b/Snowflake.Data/Snowflake.Data.csproj @@ -1,7 +1,6 @@  - net8.0;net6.0;net471;net472 - net6.0;net8.0 + netstandard2.0 Snowflake.Data Snowflake.Data https://github.com/snowflakedb/snowflake-connector-net/blob/master/LICENSE @@ -26,7 +25,7 @@ - + @@ -37,14 +36,6 @@ - - - - - - - -