diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AbfsConfiguration.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AbfsConfiguration.java index a326f3061af80..53783175cea4a 100644 --- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AbfsConfiguration.java +++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AbfsConfiguration.java @@ -452,6 +452,7 @@ public class AbfsConfiguration{ * Constructor for AbfsConfiguration for specified service type. * @param rawConfig used to initialize the configuration. * @param accountName the name of the azure storage account. + * @param fsName the name of the file system (container name). * @param fsConfiguredServiceType service type configured for the file system. * @throws IllegalAccessException if the field is not accessible. * @throws IOException if an I/O error occurs. @@ -666,7 +667,7 @@ public int getInt(String key, int defaultValue) { */ public String getPasswordString(String key) throws IOException { char[] passchars = rawConfig.getPassword(containerConf(key)); - if (passchars == null) { + if(passchars == null) { passchars = rawConfig.getPassword(accountConf(key)); if(passchars == null){ passchars = rawConfig.getPassword(key); diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/constants/ConfigurationKeys.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/constants/ConfigurationKeys.java index b4e0fa6c2eca1..fa91e2e6891e3 100644 --- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/constants/ConfigurationKeys.java +++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/constants/ConfigurationKeys.java @@ -322,8 +322,8 @@ public static String accountProperty(String property, String account) { return property + "." + account; } - public static String containerProperty(String property, String FsName, String account) { - return property + "." + FsName + "." + account; + public static String containerProperty(String property, String fsName, String account) { + return property + "." + fsName + "." + account; } public static final String FS_AZURE_ENABLE_DELEGATION_TOKEN = "fs.azure.enable.delegation.token"; diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemChooseSAS.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemChooseSAS.java index 8e8c522e4f254..cdf3d1a689e58 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemChooseSAS.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemChooseSAS.java @@ -146,6 +146,13 @@ public void testBothProviderFixedTokenConfigured() throws Exception { } } + /** + * Helper method to get the Fixed SAS token value + */ + private String getFixedSASToken(AbfsConfiguration config) throws Exception { + return config.getSASTokenProvider().getSASToken(this.getAccountName(), this.getFileSystemName(), getMethodName(), "read"); + } + /** * Tests the implementation sequence if all fixed SAS configs are set. * The expected sequence is Container Specific Fixed SAS, Account Specific Fixed SAS, Account Agnostic Fixed SAS. @@ -161,21 +168,18 @@ public void testFixedTokenPreference() throws Exception { testAbfsConfig.set(containerProperty(FS_AZURE_SAS_FIXED_TOKEN, this.getFileSystemName(), this.getAccountName()), containerSAS); testAbfsConfig.set(accountProperty(FS_AZURE_SAS_FIXED_TOKEN, this.getAccountName()), accountSAS); testAbfsConfig.set(FS_AZURE_SAS_FIXED_TOKEN, accountSAS); - String ContainerSASExpected = testAbfsConfig.getSASTokenProvider().getSASToken(this.getAccountName(), this.getFileSystemName(), getMethodName(), "read"); // Assert that Container Specific Fixed SAS is used - Assertions.assertThat(ContainerSASExpected).contains("sr=c"); + Assertions.assertThat(getFixedSASToken(testAbfsConfig)).contains("sr=c"); // Assert that Account Specific Fixed SAS is used if container SAS isn't set testAbfsConfig.unset(containerProperty(FS_AZURE_SAS_FIXED_TOKEN, this.getFileSystemName(), this.getAccountName())); - String AccountSASExpected = testAbfsConfig.getSASTokenProvider().getSASToken(this.getAccountName(), this.getFileSystemName(), getMethodName(), "read"); - Assertions.assertThat(AccountSASExpected).contains("ss=bf"); + Assertions.assertThat(getFixedSASToken(testAbfsConfig)).contains("ss=bf"); //Assert that Account-Agnostic fixed SAS is used if no other fixed SAS configs are set. // The token is the same as the Account Specific Fixed SAS. - testAbfsConfig.unset(FS_AZURE_SAS_FIXED_TOKEN); - String AccountAgnosticSASExpected = testAbfsConfig.getSASTokenProvider().getSASToken(this.getAccountName(), this.getFileSystemName(), getMethodName(), "read"); - Assertions.assertThat(AccountAgnosticSASExpected).contains("ss=bf"); + testAbfsConfig.unset(accountProperty(FS_AZURE_SAS_FIXED_TOKEN, this.getAccountName())); + Assertions.assertThat(getFixedSASToken(testAbfsConfig)).contains("ss=bf"); } /**