Skip to content

Commit

Permalink
Merge branch 'master' into SNOW-1693588-upgrade-to-junit5
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/test/java/net/snowflake/client/config/SFConnectionConfigParserTest.java
  • Loading branch information
sfc-gh-astachowski committed Nov 27, 2024
2 parents 7053ce9 + 7fd70cd commit 5e81573
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 50 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
name: Build
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Build
shell: bash
env:
Expand All @@ -56,7 +56,7 @@ jobs:
java-version: ${{ matrix.runConfig.javaVersion }}
distribution: 'temurin'
cache: maven
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.7'
architecture: 'x64'
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
java-version: ${{ matrix.runConfig.javaVersion }}
distribution: 'temurin'
cache: maven
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.7'
- name: Install Homebrew Bash
Expand Down Expand Up @@ -119,7 +119,7 @@ jobs:
{suites: 'FipsTestSuite', name: "TestCategoryFips"}]
additionalMavenProfile: ['', '-Dthin-jar']
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Tests
shell: bash
env:
Expand All @@ -143,7 +143,7 @@ jobs:
{suites: 'LoaderOldDriverTestSuite,ResultSetOldDriverTestSuite', name: 'TestCategoryLoader,TestCategoryResultSet'}]
is_old_driver: ['true']
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Tests
shell: bash
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
name: Check Style
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Check Style
shell: bash
run: mvn clean validate --batch-mode --show-version -P check-style
2 changes: 1 addition & 1 deletion .github/workflows/jira_close.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
repository: snowflakedb/gh-actions
ref: jira_v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/jira_issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
if: ((github.event_name == 'issue_comment' && github.event.comment.body == 'recreate jira' && github.event.comment.user.login == 'sfc-gh-mkeller') || (github.event_name == 'issues' && github.event.pull_request.user.login != 'whitesource-for-github-com[bot]'))
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
repository: snowflakedb/gh-actions
ref: jira_v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/snyk-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout action
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: snowflakedb/whitesource-actions
token: ${{ secrets.WHITESOURCE_ACTION_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/snyk-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ jobs:
if: ${{ github.event.pull_request.user.login == 'sfc-gh-snyk-sca-sa' }}
steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0

- name: checkout action
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: snowflakedb/whitesource-actions
token: ${{ secrets.WHITESOURCE_ACTION_TOKEN }}
Expand Down
28 changes: 28 additions & 0 deletions FIPS/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,22 @@
<pattern>io.grpc</pattern>
<shadedPattern>${shadeBase}.grpc</shadedPattern>
</relocation>
<relocation>
<pattern>META-INF.native.io_grpc_netty_shaded_netty_tcnative</pattern>
<shadedPattern>META-INF.native.${shadeNativeBase}_grpc_netty_shaded_netty_tcnative</shadedPattern>
</relocation>
<relocation>
<pattern>META-INF.native.libio_grpc_netty_shaded_netty_tcnative</pattern>
<shadedPattern>META-INF.native.lib${shadeNativeBase}_grpc_netty_shaded_netty_tcnative</shadedPattern>
</relocation>
<relocation>
<pattern>META-INF.native.io_grpc_netty_shaded_netty_transport_native_epoll</pattern>
<shadedPattern>META-INF.native.${shadeNativeBase}_grpc_netty_shaded_netty_transport_native_epoll</shadedPattern>
</relocation>
<relocation>
<pattern>META-INF.native.libio_grpc_netty_shaded_netty_transport_native_epoll</pattern>
<shadedPattern>META-INF.native.lib${shadeNativeBase}_grpc_netty_shaded_netty_transport_native_epoll</shadedPattern>
</relocation>
<relocation>
<pattern>org.checkerframework</pattern>
<shadedPattern>${shadeBase}.org.checkerframework</shadedPattern>
Expand All @@ -526,6 +542,18 @@
<pattern>org.conscrypt</pattern>
<shadedPattern>${shadeBase}.org.conscrypt</shadedPattern>
</relocation>
<relocation>
<pattern>conscrypt_openjdk_jni</pattern>
<shadedPattern>${shadeNativeBase}_conscrypt_openjdk_jni</shadedPattern>
</relocation>
<relocation>
<pattern>META-INF.native.conscrypt_openjdk_jni</pattern>
<shadedPattern>META-INF.native.${shadeNativeBase}_conscrypt_openjdk_jni</shadedPattern>
</relocation>
<relocation>
<pattern>META-INF.native.libconscrypt_openjdk_jni</pattern>
<shadedPattern>META-INF.native.lib${shadeNativeBase}_conscrypt_openjdk_jni</shadedPattern>
</relocation>
<relocation>
<pattern>opencensus</pattern>
<shadedPattern>${shadeBase}.opencensus</shadedPattern>
Expand Down
1 change: 1 addition & 0 deletions parent-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<relocationBase>net/snowflake/client/jdbc/internal</relocationBase>
<shadeBase>net.snowflake.client.jdbc.internal</shadeBase>
<shadeNativeBase>net_snowflake_client_jdbc_internal</shadeNativeBase>
<slf4j.version>2.0.13</slf4j.version>
<snowflake.common.version>5.1.4</snowflake.common.version>
<integrationTestSuites>UnitTestSuite</integrationTestSuites>
Expand Down
28 changes: 28 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,22 @@
<pattern>io.grpc</pattern>
<shadedPattern>${shadeBase}.grpc</shadedPattern>
</relocation>
<relocation>
<pattern>META-INF.native.io_grpc_netty_shaded_netty_tcnative</pattern>
<shadedPattern>META-INF.native.${shadeNativeBase}_grpc_netty_shaded_netty_tcnative</shadedPattern>
</relocation>
<relocation>
<pattern>META-INF.native.libio_grpc_netty_shaded_netty_tcnative</pattern>
<shadedPattern>META-INF.native.lib${shadeNativeBase}_grpc_netty_shaded_netty_tcnative</shadedPattern>
</relocation>
<relocation>
<pattern>META-INF.native.io_grpc_netty_shaded_netty_transport_native_epoll</pattern>
<shadedPattern>META-INF.native.${shadeNativeBase}_grpc_netty_shaded_netty_transport_native_epoll</shadedPattern>
</relocation>
<relocation>
<pattern>META-INF.native.libio_grpc_netty_shaded_netty_transport_native_epoll</pattern>
<shadedPattern>META-INF.native.lib${shadeNativeBase}_grpc_netty_shaded_netty_transport_native_epoll</shadedPattern>
</relocation>
<relocation>
<pattern>org.checkerframework</pattern>
<shadedPattern>${shadeBase}.org.checkerframework</shadedPattern>
Expand All @@ -973,6 +989,18 @@
<pattern>org.conscrypt</pattern>
<shadedPattern>${shadeBase}.org.conscrypt</shadedPattern>
</relocation>
<relocation>
<pattern>conscrypt_openjdk_jni</pattern>
<shadedPattern>${shadeNativeBase}_conscrypt_openjdk_jni</shadedPattern>
</relocation>
<relocation>
<pattern>META-INF.native.conscrypt_openjdk_jni</pattern>
<shadedPattern>META-INF.native.${shadeNativeBase}_conscrypt_openjdk_jni</shadedPattern>
</relocation>
<relocation>
<pattern>META-INF.native.libconscrypt_openjdk_jni</pattern>
<shadedPattern>META-INF.native.lib${shadeNativeBase}_conscrypt_openjdk_jni</shadedPattern>
</relocation>
<relocation>
<pattern>opencensus</pattern>
<shadedPattern>${shadeBase}.opencensus</shadedPattern>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.snowflake.client.config;

import static net.snowflake.client.jdbc.SnowflakeUtil.convertSystemGetEnvToBooleanValue;
import static net.snowflake.client.jdbc.SnowflakeUtil.systemGetEnv;

import com.fasterxml.jackson.dataformat.toml.TomlMapper;
Expand Down Expand Up @@ -34,6 +35,53 @@ public class SFConnectionConfigParser {
"SNOWFLAKE_DEFAULT_CONNECTION_NAME";
public static final String DEFAULT = "default";
public static final String SNOWFLAKE_TOKEN_FILE_PATH = "/snowflake/session/token";
public static final String SKIP_TOKEN_FILE_PERMISSIONS_VERIFICATION =
"SKIP_TOKEN_FILE_PERMISSIONS_VERIFICATION";

public static ConnectionParameters buildConnectionParameters() throws SnowflakeSQLException {
String defaultConnectionName =
Optional.ofNullable(systemGetEnv(SNOWFLAKE_DEFAULT_CONNECTION_NAME_KEY)).orElse(DEFAULT);
Map<String, String> fileConnectionConfiguration =
loadDefaultConnectionConfiguration(defaultConnectionName);

if (fileConnectionConfiguration != null && !fileConnectionConfiguration.isEmpty()) {
Properties connectionProperties = new Properties();
connectionProperties.putAll(fileConnectionConfiguration);

String url = createUrl(fileConnectionConfiguration);
logger.debug("Url created using parameters from connection configuration file: {}", url);

if ("oauth".equals(fileConnectionConfiguration.get("authenticator"))
&& fileConnectionConfiguration.get("token") == null) {
Path path =
Paths.get(
Optional.ofNullable(fileConnectionConfiguration.get("token_file_path"))
.orElse(SNOWFLAKE_TOKEN_FILE_PATH));
logger.debug("Token used in connect is read from file: {}", path);
try {
boolean shouldSkipTokenFilePermissionsVerification =
convertSystemGetEnvToBooleanValue(SKIP_TOKEN_FILE_PERMISSIONS_VERIFICATION, false);
if (!shouldSkipTokenFilePermissionsVerification) {
verifyFilePermissionSecure(path);
} else {
logger.debug("Skip token file permissions verification");
}
String token = new String(Files.readAllBytes(path), Charset.defaultCharset());
if (!token.isEmpty()) {
putPropertyIfNotNull(connectionProperties, "token", token.trim());
} else {
throw new SnowflakeSQLException(
"Non-empty token must be set when the authenticator type is OAUTH");
}
} catch (Exception ex) {
throw new SnowflakeSQLException(ex, "There is a problem during reading token from file");
}
}
return new ConnectionParameters(url, connectionProperties);
} else {
return null;
}
}

private static Map<String, String> loadDefaultConnectionConfiguration(
String defaultConnectionName) throws SnowflakeSQLException {
Expand Down Expand Up @@ -88,44 +136,6 @@ private static void verifyFilePermissionSecure(Path configFilePath)
}
}

public static ConnectionParameters buildConnectionParameters() throws SnowflakeSQLException {
String defaultConnectionName =
Optional.ofNullable(systemGetEnv(SNOWFLAKE_DEFAULT_CONNECTION_NAME_KEY)).orElse(DEFAULT);
Map<String, String> fileConnectionConfiguration =
loadDefaultConnectionConfiguration(defaultConnectionName);

if (fileConnectionConfiguration != null && !fileConnectionConfiguration.isEmpty()) {
Properties conectionProperties = new Properties();
conectionProperties.putAll(fileConnectionConfiguration);

String url = createUrl(fileConnectionConfiguration);
logger.debug("Url created using parameters from connection configuration file: {}", url);

if ("oauth".equals(fileConnectionConfiguration.get("authenticator"))
&& fileConnectionConfiguration.get("token") == null) {
Path path =
Paths.get(
Optional.ofNullable(fileConnectionConfiguration.get("token_file_path"))
.orElse(SNOWFLAKE_TOKEN_FILE_PATH));
logger.debug("Token used in connect is read from file: {}", path);
try {
verifyFilePermissionSecure(path);
String token = new String(Files.readAllBytes(path), Charset.defaultCharset());
if (!token.isEmpty()) {
putPropertyIfNotNull(conectionProperties, "token", token.trim());
} else {
logger.warn("The token has empty value");
}
} catch (Exception ex) {
throw new SnowflakeSQLException(ex, "There is a problem during reading token from file");
}
}
return new ConnectionParameters(url, conectionProperties);
} else {
return null;
}
}

private static String createUrl(Map<String, String> fileConnectionConfiguration)
throws SnowflakeSQLException {
Optional<String> maybeAccount = Optional.ofNullable(fileConnectionConfiguration.get("account"));
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/net/snowflake/client/jdbc/SnowflakeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,22 @@ public static boolean convertSystemPropertyToBooleanValue(
}
return defaultValue;
}
/**
* Helper function to convert environment variable to boolean
*
* @param envVariableKey property name of the environment variable
* @param defaultValue default value used
* @return the value of the environment variable as boolean, else the default value
*/
@SnowflakeJdbcInternalApi
public static boolean convertSystemGetEnvToBooleanValue(
String envVariableKey, boolean defaultValue) {
String environmentVariableValue = systemGetEnv(envVariableKey);
if (environmentVariableValue != null) {
return Boolean.parseBoolean(environmentVariableValue);
}
return defaultValue;
}

@SnowflakeJdbcInternalApi
public static <T> T mapSFExceptionToSQLException(ThrowingCallable<T, SFException> action)
Expand Down
Loading

0 comments on commit 5e81573

Please sign in to comment.