You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mi...@apache.org on 2022/02/10 15:53:55 UTC
[jackrabbit-oak] branch trunk updated: OAK-9689 Enable configuring connection string wiht SAS URI and account name
This is an automated email from the ASF dual-hosted git repository.
miroslav pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new 9b65d59 OAK-9689 Enable configuring connection string wiht SAS URI and account name
new 819db78 Merge pull request #488 from smiroslav/issue/OAK-9689
9b65d59 is described below
commit 9b65d593bfe47673652b91225588dbc946e4ffdb
Author: smiroslav <mi...@apache.org>
AuthorDate: Wed Feb 9 17:00:01 2022 +0100
OAK-9689 Enable configuring connection string wiht SAS URI and account name
---
.../oak/blob/cloud/azure/blobstorage/Utils.java | 17 ++++++++++++-----
.../oak/blob/cloud/azure/blobstorage/UtilsTest.java | 10 ++++++++++
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/oak-blob-cloud-azure/src/main/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/Utils.java b/oak-blob-cloud-azure/src/main/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/Utils.java
index 159a33a..1de50fd 100644
--- a/oak-blob-cloud-azure/src/main/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/Utils.java
+++ b/oak-blob-cloud-azure/src/main/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/Utils.java
@@ -40,6 +40,7 @@ import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.blob.BlobRequestOptions;
import com.microsoft.azure.storage.blob.CloudBlobClient;
import com.microsoft.azure.storage.blob.CloudBlobContainer;
+import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.core.data.DataStoreException;
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
import org.jetbrains.annotations.NotNull;
@@ -127,22 +128,28 @@ public final class Utils {
String sasUri = properties.getProperty(AzureConstants.AZURE_SAS, "");
String blobEndpoint = properties.getProperty(AzureConstants.AZURE_BLOB_ENDPOINT, "");
String connectionString = properties.getProperty(AzureConstants.AZURE_CONNECTION_STRING, "");
+ String accountName = properties.getProperty(AzureConstants.AZURE_STORAGE_ACCOUNT_NAME, "");
+ String accountKey = properties.getProperty(AzureConstants.AZURE_STORAGE_ACCOUNT_KEY, "");
if (!connectionString.isEmpty()) {
return connectionString;
}
if (!sasUri.isEmpty()) {
- return getConnectionStringForSas(sasUri, blobEndpoint);
+ return getConnectionStringForSas(sasUri, blobEndpoint, accountName);
}
return getConnectionString(
- properties.getProperty(AzureConstants.AZURE_STORAGE_ACCOUNT_NAME, ""),
- properties.getProperty(AzureConstants.AZURE_STORAGE_ACCOUNT_KEY, ""));
+ accountName,
+ accountKey);
}
- private static String getConnectionStringForSas(String sasUri, String blobEndpoint) {
- return String.format("BlobEndpoint=%s;SharedAccessSignature=%s", blobEndpoint, sasUri);
+ private static String getConnectionStringForSas(String sasUri, String blobEndpoint, String accountName) {
+ if (StringUtils.isEmpty(blobEndpoint)) {
+ return String.format("AccountName=%s;SharedAccessSignature=%s", accountName, sasUri);
+ } else {
+ return String.format("BlobEndpoint=%s;SharedAccessSignature=%s", blobEndpoint, sasUri);
+ }
}
public static String getConnectionString(final String accountName, final String accountKey) {
diff --git a/oak-blob-cloud-azure/src/test/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/UtilsTest.java b/oak-blob-cloud-azure/src/test/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/UtilsTest.java
index 34f787e..5776fbb 100644
--- a/oak-blob-cloud-azure/src/test/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/UtilsTest.java
+++ b/oak-blob-cloud-azure/src/test/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/UtilsTest.java
@@ -43,6 +43,16 @@ public class UtilsTest {
}
@Test
+ public void testConnectionStringIsBasedOnSASWithoutEndpoint() {
+ Properties properties = new Properties();
+ properties.put(AzureConstants.AZURE_SAS, "sas");
+ properties.put(AzureConstants.AZURE_STORAGE_ACCOUNT_NAME, "account");
+ String connectionString = Utils.getConnectionStringFromProperties(properties);
+ assertEquals(connectionString,
+ String.format("AccountName=%s;SharedAccessSignature=%s", "account", "sas"));
+ }
+
+ @Test
public void testConnectionStringIsBasedOnAccessKeyIfSASMissing() {
Properties properties = new Properties();
properties.put(AzureConstants.AZURE_STORAGE_ACCOUNT_NAME, "accessKey");