Skip to content

Commit a64035d

Browse files
SNOW-2032706 Implement AWS SDK strategy for GCS
1 parent 94a3a4d commit a64035d

File tree

6 files changed

+412
-4
lines changed

6 files changed

+412
-4
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package net.snowflake.client.jdbc.cloud.storage;
2+
3+
import com.amazonaws.SignableRequest;
4+
import com.amazonaws.auth.AWS4Signer;
5+
import com.amazonaws.auth.AWSCredentials;
6+
import com.amazonaws.http.HttpMethodName;
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
import java.util.stream.Collectors;
10+
import net.snowflake.client.core.SnowflakeJdbcInternalApi;
11+
12+
@SnowflakeJdbcInternalApi
13+
public class AwsSdkGCPSigner extends AWS4Signer {
14+
private static final Map<String, String> headerMap =
15+
new HashMap<String, String>() {
16+
{
17+
put("x-amz-storage-class", "x-goog-storage-class");
18+
put("x-amz-acl", "x-goog-acl");
19+
put("x-amz-date", "x-goog-date");
20+
put("x-amz-copy-source", "x-goog-copy-source");
21+
put("x-amz-metadata-directive", "x-goog-metadata-directive");
22+
put("x-amz-copy-source-if-match", "x-goog-copy-source-if-match");
23+
put("x-amz-copy-source-if-none-match", "x-goog-copy-source-if-none-match");
24+
put("x-amz-copy-source-if-unmodified-since", "x-goog-copy-source-if-unmodified-since");
25+
put("x-amz-copy-source-if-modified-since", "x-goog-copy-source-if-modified-since");
26+
}
27+
};
28+
29+
@Override
30+
public void sign(SignableRequest<?> request, AWSCredentials credentials) {
31+
if (credentials.getAWSAccessKeyId() != null && !"".equals(credentials.getAWSAccessKeyId())) {
32+
request.addHeader("Authorization", "Bearer " + credentials.getAWSAccessKeyId());
33+
}
34+
35+
if (request.getHttpMethod() == HttpMethodName.GET) {
36+
request.addHeader("Accept-Encoding", "gzip,deflate");
37+
}
38+
39+
Map<String, String> headerCopy =
40+
request.getHeaders().entrySet().stream()
41+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
42+
43+
for (Map.Entry<String, String> entry : headerCopy.entrySet()) {
44+
String entryKey = entry.getKey().toLowerCase();
45+
if (headerMap.containsKey(entryKey)) {
46+
request.addHeader(headerMap.get(entryKey), entry.getValue());
47+
} else if (entryKey.startsWith("x-amz-meta-")) {
48+
request.addHeader(entryKey.replace("x-amz-meta-", "x-goog-meta-"), entry.getValue());
49+
}
50+
}
51+
}
52+
}

src/main/java/net/snowflake/client/jdbc/cloud/storage/GCSAccessStrategy.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ boolean handleStorageException(
3939
String queryId,
4040
SnowflakeGCSClient gcsClient)
4141
throws SnowflakeSQLException;
42+
43+
void shutdown();
4244
}

0 commit comments

Comments
 (0)