diff --git a/sdk/storage/azure-storage-file-datalake/CHANGELOG.md b/sdk/storage/azure-storage-file-datalake/CHANGELOG.md index a95d71cf49fa0..668a59f25657f 100644 --- a/sdk/storage/azure-storage-file-datalake/CHANGELOG.md +++ b/sdk/storage/azure-storage-file-datalake/CHANGELOG.md @@ -3,6 +3,8 @@ ## 12.30.0-beta.1 (Unreleased) ### Features Added +- Added `DataLakeServiceClientBuilder.blobEndpoint(String)` to configure the Blob service endpoint separately from + the Data Lake service endpoint for custom endpoint and proxy scenarios. ### Breaking Changes @@ -925,4 +927,3 @@ This package's [documentation](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/storage/azure-storage-file-datalake/README.md) and [samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/storage/azure-storage-file-datalake/src/samples/java/com/azure/storage/file/datalake) - diff --git a/sdk/storage/azure-storage-file-datalake/README.md b/sdk/storage/azure-storage-file-datalake/README.md index 2e4ed9b866748..55666ec67f4b9 100644 --- a/sdk/storage/azure-storage-file-datalake/README.md +++ b/sdk/storage/azure-storage-file-datalake/README.md @@ -220,6 +220,17 @@ DataLakeServiceClient dataLakeServiceClient = new DataLakeServiceClientBuilder() .buildClient(); ``` +Some environments expose the Data Lake and Blob services through separate custom or proxy URLs. In that case, set +the Data Lake endpoint with `endpoint` and the Blob endpoint with `blobEndpoint`: + +```java readme-sample-getDataLakeServiceClientWithCustomEndpoints +DataLakeServiceClient dataLakeServiceClient = new DataLakeServiceClientBuilder() + .endpoint("https://dfs-proxy.example.com") + .blobEndpoint("https://blob-proxy.example.com") + .sasToken("") + .buildClient(); +``` + or ```java readme-sample-getDataLakeServiceClient2 @@ -446,5 +457,3 @@ This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For m [coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ [coc_contact]: mailto:opencode@microsoft.com [performance_tuning]: https://github.com/Azure/azure-sdk-for-java/blob/main/docs/performance-tuning.md - - diff --git a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakeServiceClientBuilder.java b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakeServiceClientBuilder.java index 088b981fc19e1..4cb02fb2fbf3b 100644 --- a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakeServiceClientBuilder.java +++ b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakeServiceClientBuilder.java @@ -70,6 +70,7 @@ public class DataLakeServiceClientBuilder implements TokenCredentialTrait") + .buildClient(); + // END: readme-sample-getDataLakeServiceClientWithCustomEndpoints + } +} diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/UrlTests.java b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/UrlTests.java index e72642433a117..d420fbc60a999 100644 --- a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/UrlTests.java +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/UrlTests.java @@ -3,11 +3,13 @@ package com.azure.storage.file.datalake; import com.azure.storage.common.StorageSharedKeyCredential; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class UrlTests { private static final StorageSharedKeyCredential CREDENTIAL @@ -54,4 +56,48 @@ public void testCorrectServiceUrlSet(String url, String expectedBlobUrl, String assertEquals(expectedDfsUrl + "/container/blob", pathClient.getPathUrl()); assertEquals(expectedBlobUrl + "/container/blob", pathClient.blockBlobClient.getBlobUrl()); } + + @Test + public void testExplicitBlobServiceUrl() { + String dfsEndpoint = "https://dfs-proxy.example.com"; + String blobEndpoint = "https://blob-proxy.example.com"; + DataLakeServiceClient serviceClient = new DataLakeServiceClientBuilder().credential(CREDENTIAL) + .endpoint(dfsEndpoint) + .blobEndpoint(blobEndpoint) + .buildClient(); + + assertEquals(dfsEndpoint, serviceClient.getAccountUrl()); + assertEquals(blobEndpoint, serviceClient.blobServiceClient.getAccountUrl()); + } + + @Test + public void testExplicitBlobServiceUrlAsyncEndpointOrderIndependent() { + String dfsEndpoint = "https://dfs-proxy.example.com"; + String blobEndpoint = "https://blob-proxy.example.com"; + DataLakeServiceAsyncClient serviceAsyncClient = new DataLakeServiceClientBuilder().credential(CREDENTIAL) + .blobEndpoint(blobEndpoint) + .endpoint(dfsEndpoint) + .buildAsyncClient(); + + assertEquals(dfsEndpoint, serviceAsyncClient.getAccountUrl()); + assertEquals(blobEndpoint + "/container", + serviceAsyncClient.getFileSystemAsyncClient("container") + .getBlobContainerAsyncClient() + .getBlobContainerUrl()); + } + + @Test + public void testExplicitBlobServiceUrlNormalizesDfsEndpoint() { + DataLakeServiceClient serviceClient = new DataLakeServiceClientBuilder().credential(CREDENTIAL) + .endpoint("https://account.dfs.core.windows.net") + .blobEndpoint("https://account.dfs.core.windows.net") + .buildClient(); + + assertEquals("https://account.blob.core.windows.net", serviceClient.blobServiceClient.getAccountUrl()); + } + + @Test + public void testExplicitBlobServiceUrlRejectsNullEndpoint() { + assertThrows(IllegalArgumentException.class, () -> new DataLakeServiceClientBuilder().blobEndpoint(null)); + } }