Skip to content

Commit

Permalink
SNOW-1526509 Log connecting area (#992)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
sfc-gh-knozderko authored Jul 15, 2024
1 parent bc329ab commit 9736edd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2019 Snowflake Computing Inc. All rights reserved.
*/

Expand Down Expand Up @@ -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<TestCase> ConnectionStringTestCases()
{
string defAccount = "testaccount";
Expand Down
6 changes: 6 additions & 0 deletions Snowflake.Data/Core/Session/SFSessionProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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[] {
Expand Down

0 comments on commit 9736edd

Please sign in to comment.