Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1732907: Change custom cloud storage header metadata handling to be case-insensitive #1919

Merged
merged 13 commits into from
Oct 18, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import net.snowflake.client.core.HttpUtil;
import net.snowflake.client.core.ObjectMapperFactory;
import net.snowflake.client.core.SFBaseSession;
Expand Down Expand Up @@ -273,7 +275,7 @@ public StorageObjectMetadata getObjectMetadata(String remoteStorageLocation, Str
blob.downloadAttributes(null, null, opContext);

// Get the user-defined BLOB metadata
Map<String, String> userDefinedMetadata = blob.getMetadata();
Map<String, String> userDefinedMetadata = getUserDefinedMetadata(blob);

// Get the BLOB system properties we care about
BlobProperties properties = blob.getProperties();
Expand Down Expand Up @@ -348,7 +350,7 @@ public void download(
blob.downloadAttributes(null, transferOptions, opContext);

// Get the user-defined BLOB metadata
Map<String, String> userDefinedMetadata = blob.getMetadata();
Map<String, String> userDefinedMetadata = getUserDefinedMetadata(blob);
AbstractMap.SimpleEntry<String, String> encryptionData =
parseEncryptionData(userDefinedMetadata.get(AZ_ENCRYPTIONDATAPROP), queryId);

Expand Down Expand Up @@ -447,13 +449,10 @@ public InputStream downloadToStream(
InputStream stream = blob.openInputStream(null, null, opContext);
stopwatch.stop();
long downloadMillis = stopwatch.elapsedMillis();
Map<String, String> userDefinedMetadata = blob.getMetadata();

Map<String, String> userDefinedMetadata = getUserDefinedMetadata(blob);
AbstractMap.SimpleEntry<String, String> encryptionData =
parseEncryptionData(userDefinedMetadata.get(AZ_ENCRYPTIONDATAPROP), queryId);

String key = encryptionData.getKey();

String iv = encryptionData.getValue();

if (this.isEncrypting() && this.getEncryptionKeySize() <= 256) {
Expand Down Expand Up @@ -934,6 +933,17 @@ private static URI buildAzureStorageEndpointURI(String storageEndPoint, String s
return storageEndpoint;
}

/*
* getUserDefinedMetadata
* Method introduced to avoid inconsistencies in custom headers handling, since these are defined on drivers side
* e.g. some drivers might internally convert headers to canonical form.
*/
private Map<String, String> getUserDefinedMetadata(CloudBlob blob) {
sfc-gh-dheyman marked this conversation as resolved.
Show resolved Hide resolved
Map<String, String> userDefinedMetadata = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
userDefinedMetadata.putAll(blob.getMetadata());
return userDefinedMetadata;
}

/*
* buildEncryptionMetadataJSON
* Takes the base64-encoded iv and key and creates the JSON block to be
Expand Down
Loading