Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ruowan committed Nov 30, 2023
1 parent 37d17fe commit b733361
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 32 deletions.
30 changes: 6 additions & 24 deletions csharp/test/Drivers/Snowflake/ClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ClientTests
{
public ClientTests()
{
Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE));
Skip.IfNot(Utils.CanExecuteTestConfig(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE));
}

/// <summary>
Expand Down Expand Up @@ -151,6 +151,8 @@ public void CanClientExecuteQueryUsingPrivateKey()
{
SnowflakeTestConfiguration testConfiguration = Utils.LoadTestConfiguration<SnowflakeTestConfiguration>(SnowflakeTestingUtils.SNOWFLAKE_TEST_CONFIG_VARIABLE);

Skip.If(testConfiguration.Authentication.SnowflakeJwt is null, "JWT authentication is not configured");

using (Adbc.Client.AdbcConnection adbcConnection = GetSnowflakeAdbcConnectionUsingConnectionString(testConfiguration, SnowflakeAuthentication.AuthJwt))
{
Tests.ClientTests.CanClientExecuteQuery(adbcConnection, testConfiguration);
Expand Down Expand Up @@ -218,7 +220,7 @@ public void VerifySchemaTables()
}
}

private Adbc.Client.AdbcConnection GetSnowflakeAdbcConnectionUsingConnectionString(SnowflakeTestConfiguration testConfiguration, string authType=null)
private Adbc.Client.AdbcConnection GetSnowflakeAdbcConnectionUsingConnectionString(SnowflakeTestConfiguration testConfiguration, string authType = null)
{
// see https://arrow.apache.org/adbc/0.5.1/driver/snowflake.html

Expand All @@ -230,13 +232,7 @@ private Adbc.Client.AdbcConnection GetSnowflakeAdbcConnectionUsingConnectionStri
builder[SnowflakeParameters.USERNAME] = testConfiguration.User;
if (authType == SnowflakeAuthentication.AuthJwt)
{
string privateKeyFile = testConfiguration.Authentication.SnowflakeJwt.PrivateKeyFile;
string privateKey = testConfiguration.Authentication.SnowflakeJwt.PrivateKey;

if (privateKeyFile != null)
{
privateKey = File.ReadAllText(privateKeyFile);
}
builder[SnowflakeParameters.AUTH_TYPE] = SnowflakeAuthentication.AuthJwt;
builder[SnowflakeParameters.PKCS8_VALUE] = privateKey;
builder[SnowflakeParameters.USERNAME] = testConfiguration.Authentication.SnowflakeJwt.User;
Expand All @@ -254,9 +250,9 @@ private Adbc.Client.AdbcConnection GetSnowflakeAdbcConnectionUsingConnectionStri
builder[SnowflakeParameters.USERNAME] = testConfiguration.Authentication.OAuth.User;
}
}
else
else if (string.IsNullOrEmpty(authType) || authType == SnowflakeAuthentication.AuthSnowflake)
{
// default basic auth
// if no auth type is specified, use the snowflake auth
builder[SnowflakeParameters.USERNAME] = testConfiguration.Authentication.Default.User;
builder[SnowflakeParameters.PASSWORD] = testConfiguration.Authentication.Default.Password;
}
Expand All @@ -266,19 +262,5 @@ private Adbc.Client.AdbcConnection GetSnowflakeAdbcConnectionUsingConnectionStri
AdbcDriver = snowflakeDriver
};
}
private Adbc.Client.AdbcConnection GetSnowflakeAdbcConnection(SnowflakeTestConfiguration testConfiguration)
{
Dictionary<string, string> parameters = new Dictionary<string, string>();

AdbcDriver snowflakeDriver = SnowflakeTestingUtils.GetSnowflakeAdbcDriver(testConfiguration, out parameters);

Adbc.Client.AdbcConnection adbcConnection = new Adbc.Client.AdbcConnection(
snowflakeDriver,
parameters: parameters,
options: new Dictionary<string, string>()
);

return adbcConnection;
}
}
}
10 changes: 2 additions & 8 deletions csharp/test/Drivers/Snowflake/SnowflakeTestConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ internal class SnowflakeTestConfiguration : TestConfiguration
[JsonPropertyName("warehouse")]
public string Warehouse { get; set; }

/// <summary>
/// The Snowflake authentication type.
/// </summary>
[JsonPropertyName("authenticationType")]
public string AuthenticationType { get; set; }

/// <summary>
/// The Snowflake use high precision
/// </summary>
Expand All @@ -96,15 +90,15 @@ public class SnowflakeAuthentication
{
public const string AuthOAuth = "auth_oauth";
public const string AuthJwt = "auth_jwt";
public const string AuthDefault = "default";
public const string AuthSnowflake = "auth_snowflake";

[JsonPropertyName(AuthOAuth)]
public OAuthAuthentication OAuth { get; set; }

[JsonPropertyName(AuthJwt)]
public JwtAuthentication SnowflakeJwt { get; set; }

[JsonPropertyName(AuthDefault)]
[JsonPropertyName(AuthSnowflake)]
public DefaultAuthentication Default { get; set; }
}

Expand Down
7 changes: 7 additions & 0 deletions csharp/test/Drivers/Snowflake/SnowflakeTestingUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ out Dictionary<string, string> parameters
{ SnowflakeParameters.USE_HIGH_PRECISION, testConfiguration.UseHighPrecision.ToString().ToLowerInvariant() }
};

if(testConfiguration.Authentication.Default is not null)
{
parameters[SnowflakeParameters.AUTH_TYPE] = SnowflakeAuthentication.AuthSnowflake;
parameters[SnowflakeParameters.USERNAME] = testConfiguration.Authentication.Default.User;
parameters[SnowflakeParameters.PASSWORD] = testConfiguration.Authentication.Default.Password;
}

if(!string.IsNullOrWhiteSpace(testConfiguration.Host))
{
parameters[SnowflakeParameters.HOST] = testConfiguration.Host;
Expand Down

0 comments on commit b733361

Please sign in to comment.