Skip to content

Commit 1f4aab3

Browse files
SNOW-2032703: Add support for virtual style domains (#1165)
1 parent 77bc96d commit 1f4aab3

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

Snowflake.Data.Tests/UnitTests/SFGCSClientTest.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,37 @@ public void TestUseUriWithRegionsWhenNeeded(string region, string endPoint, bool
368368
Assert.AreEqual(expectedRequestUri, uri);
369369
}
370370

371+
[Test]
372+
[TestCase("mock-stage", null, false, true, "https://mock-stage.storage.googleapis.com/")]
373+
[TestCase("mock-stage/mock-id/mock-key", null, false, true, "https://mock-stage.storage.googleapis.com/mock-id/mock-key/")]
374+
[TestCase("mock-stage/mock-id/mock-key", null, true, true, "https://mock-stage.storage.googleapis.com/mock-id/mock-key/")]
375+
[TestCase("mock-stage/mock-id/mock-key", "https://example.com", true, true, "https://example.com/mock-id/mock-key/")]
376+
public void TestUsesVirtualUrlWhenExpected(string location, string endPoint, bool useRegionalUrl, bool useVirtualUrl, string expectedRequestUri)
377+
{
378+
var fileMetadata = new SFFileMetadata()
379+
{
380+
stageInfo = new PutGetStageInfo()
381+
{
382+
endPoint = endPoint,
383+
location = location,
384+
locationType = SFRemoteStorageUtil.GCS_FS,
385+
path = LocationPath,
386+
presignedUrl = null,
387+
region = null,
388+
stageCredentials = _stageCredentials,
389+
storageAccount = null,
390+
useRegionalUrl = useRegionalUrl,
391+
useVirtualUrl = useVirtualUrl
392+
}
393+
};
394+
395+
// act
396+
var uri = _client.FormBaseRequest(fileMetadata, "PUT").RequestUri.ToString();
397+
398+
// assert
399+
Assert.AreEqual(expectedRequestUri, uri);
400+
}
401+
371402
[Test]
372403
[TestCase("some-header-name", "SOME-HEADER-NAME")]
373404
[TestCase("SOME-HEADER-NAME", "some-header-name")]

Snowflake.Data/Core/FileTransfer/StorageClient/SFGCSClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ internal string generateFileURL(PutGetStageInfo stageInfo, string fileName)
238238
var storageHostPath = ExtractStorageHostPath(stageInfo);
239239
var gcsLocation = ExtractBucketNameAndPath(stageInfo.location);
240240
var fullFilePath = gcsLocation.key + fileName;
241-
var link = storageHostPath + gcsLocation.bucket + "/" + fullFilePath;
241+
var path = stageInfo.useVirtualUrl ? fullFilePath : gcsLocation.bucket + "/" + fullFilePath;
242+
var link = storageHostPath + path;
242243
return link;
243244
}
244245

Snowflake.Data/Core/RestResponse.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,9 @@ internal class PutGetStageInfo
448448
[JsonProperty(PropertyName = "useRegionalUrl", NullValueHandling = NullValueHandling.Ignore)]
449449
internal bool useRegionalUrl { get; set; }
450450

451+
[JsonProperty(PropertyName = "useVirtualUrl", NullValueHandling = NullValueHandling.Ignore)]
452+
internal bool useVirtualUrl { get; set; }
453+
451454
private const string GcsRegionMeCentral2 = "me-central2";
452455

453456
internal string GcsCustomEndpoint()
@@ -456,6 +459,11 @@ internal string GcsCustomEndpoint()
456459
return null;
457460
if (!string.IsNullOrWhiteSpace(endPoint) && endPoint != "null")
458461
return endPoint;
462+
if (useVirtualUrl)
463+
{
464+
var bucketName = location.Contains("/") ? location.Substring(0, location.IndexOf('/')) : location;
465+
return $"{bucketName}.storage.googleapis.com";
466+
}
459467
if (GcsRegionMeCentral2.Equals(region, StringComparison.OrdinalIgnoreCase) || useRegionalUrl)
460468
return $"storage.{region.ToLower()}.rep.googleapis.com";
461469
return null;

0 commit comments

Comments
 (0)