Skip to content

Commit

Permalink
SNOW-1889398: Handle endpoint without protocol for GCS (#2038)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dprzybysz authored Jan 20, 2025
1 parent bee2e4b commit f2ec619
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ private void setupGCSClient(
if (accessToken != null) {
// We are authenticated with an oauth access token.
StorageOptions.Builder builder = StorageOptions.newBuilder();
stage.gcsCustomEndpoint().ifPresent(builder::setHost);
overrideHost(stage, builder);

if (areDisabledGcsDefaultCredentials(session)) {
logger.debug(
Expand All @@ -1335,7 +1335,7 @@ private void setupGCSClient(
// Use anonymous authentication.
HttpStorageOptions.Builder builder =
HttpStorageOptions.newBuilder().setCredentials(NoCredentials.getInstance());
stage.gcsCustomEndpoint().ifPresent(builder::setHost);
overrideHost(stage, builder);
this.gcsClient = builder.build().getService();
}

Expand All @@ -1357,6 +1357,19 @@ private void setupGCSClient(
}
}

private static void overrideHost(StageInfo stage, StorageOptions.Builder builder) {
stage
.gcsCustomEndpoint()
.ifPresent(
host -> {
if (host.startsWith("https://")) {
builder.setHost(host);
} else {
builder.setHost("https://" + host);
}
});
}

private static boolean areDisabledGcsDefaultCredentials(SFSession session) {
return session != null && session.getDisableGcsDefaultCredentials()
|| convertSystemPropertyToBooleanValue(
Expand Down

0 comments on commit f2ec619

Please sign in to comment.