From 9736edd21145a27858924ba7e76d4bea121280a8 Mon Sep 17 00:00:00 2001 From: Krzysztof Nozderko Date: Mon, 15 Jul 2024 14:18:50 +0200 Subject: [PATCH] SNOW-1526509 Log connecting area (#992) ### Description SNOW-1526509 Log connecting area ### Checklist - [x] Code compiles correctly - [x] Code is formatted according to [Coding Conventions](../blob/master/CodingConventions.md) - [x] Created tests which fail without the change (if possible) - [x] All tests passing (`dotnet test`) - [x] Extended the README / documentation, if necessary - [x] Provide JIRA issue id (if possible) or GitHub issue id in PR name --- .../UnitTests/SFSessionPropertyTest.cs | 14 +++++++++++++- Snowflake.Data/Core/Session/SFSessionProperty.cs | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs b/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs index 183788e90..a57a9fb74 100644 --- a/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2019 Snowflake Computing Inc. All rights reserved. */ @@ -154,6 +154,18 @@ public void TestValidateDisableSamlUrlCheckProperty(string expectedDisableSamlUr Assert.AreEqual(expectedDisableSamlUrlCheck, properties[SFSessionProperty.DISABLE_SAML_URL_CHECK]); } + [Test] + [TestCase("account.snowflakecomputing.cn", "Connecting to CHINA Snowflake domain")] + [TestCase("account.snowflakecomputing.com", "Connecting to GLOBAL Snowflake domain")] + public void TestResolveConnectionArea(string host, string expectedMessage) + { + // act + var message = SFSessionProperties.ResolveConnectionAreaMessage(host); + + // assert + Assert.AreEqual(expectedMessage, message); + } + public static IEnumerable ConnectionStringTestCases() { string defAccount = "testaccount"; diff --git a/Snowflake.Data/Core/Session/SFSessionProperty.cs b/Snowflake.Data/Core/Session/SFSessionProperty.cs index 226c75cb1..bfbe71a2a 100644 --- a/Snowflake.Data/Core/Session/SFSessionProperty.cs +++ b/Snowflake.Data/Core/Session/SFSessionProperty.cs @@ -281,6 +281,7 @@ internal static SFSessionProperties ParseConnectionString(string connectionStrin properties.Add(SFSessionProperty.HOST, hostName); logger.Info($"Compose host name: {hostName}"); } + logger.Info(ResolveConnectionAreaMessage(properties[SFSessionProperty.HOST])); // Trim the account name to remove the region and cloud platform if any were provided // because the login request data does not expect region and cloud information to be @@ -290,6 +291,11 @@ internal static SFSessionProperties ParseConnectionString(string connectionStrin return properties; } + internal static string ResolveConnectionAreaMessage(string host) => + host.EndsWith(".cn", StringComparison.InvariantCultureIgnoreCase) + ? "Connecting to CHINA Snowflake domain" + : "Connecting to GLOBAL Snowflake domain"; + private static void ValidateAuthenticator(SFSessionProperties properties) { var knownAuthenticators = new[] {