Skip to content
Permalink
Browse files
Add support for Azure SAS URIs in oak-run
  • Loading branch information
Kunal Shubham committed Feb 28, 2022
1 parent 74299ff commit ce36f9a8713811d333dc5a5b1a39492473a8ee0f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
@@ -142,6 +142,10 @@ Microsoft Azure node stores are also supported using the following command. The

$ java -jar oak-run-*.jar explore az:https://myaccount.blob.core.windows.net/container/repository [--skip-size-check]

If using a Shared Access Signature, the SAS token has to be appended to the azure URI.

$ java -jar oak-run-*.jar explore az:https://myaccount.blob.core.windows.net/container/repository?<sas-token> [--skip-size-check]

frozennoderefsbyscanning
------------------------

@@ -0,0 +1,26 @@
package oak.apache.jackrabbit.oak.segment.azure.tool;

import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence;


public class SegmentCopyAzureSasToTarTest extends SegmentCopyTestBase{
@Override
protected SegmentNodeStorePersistence getSrcPersistence() throws Exception {
return getAzurePersistence();
}

@Override
protected SegmentNodeStorePersistence getDestPersistence() {
return getTarPersistence();
}

@Override
protected String getSrcPathOrUri() throws Exception {
return getAzurePersistencePathOrUriSas();
}

@Override
protected String getDestPathOrUri() {
return getTarPersistencePathOrUri();
}
}
@@ -18,6 +18,7 @@
*/
package oak.apache.jackrabbit.oak.segment.azure.tool;

import static com.microsoft.azure.storage.blob.SharedAccessBlobPermissions.*;
import static org.apache.jackrabbit.oak.segment.azure.tool.ToolUtils.newFileStore;
import static org.apache.jackrabbit.oak.segment.azure.tool.ToolUtils.newSegmentNodeStorePersistence;
import static org.junit.Assert.assertEquals;
@@ -26,9 +27,18 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URISyntaxException;
import java.security.InvalidKeyException;
import java.time.Duration;
import java.time.Instant;
import java.util.Collections;
import java.util.Date;
import java.util.EnumSet;
import java.util.List;

import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.blob.SharedAccessBlobPermissions;
import com.microsoft.azure.storage.blob.SharedAccessBlobPolicy;
import org.apache.jackrabbit.oak.commons.Buffer;
import org.apache.jackrabbit.oak.segment.SegmentCache;
import org.apache.jackrabbit.oak.segment.SegmentNodeStore;
@@ -50,14 +60,17 @@
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.jetbrains.annotations.NotNull;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;


public abstract class SegmentCopyTestBase {
private static final String AZURE_DIRECTORY = "repository";
private static final String AZURE_CONTAINER = "oak-test";
private static final EnumSet<SharedAccessBlobPermissions> READ_WRITE = EnumSet.of(READ, LIST, CREATE, WRITE, ADD);

@ClassRule
public static AzuriteDockerRule azurite = new AzuriteDockerRule();
@@ -69,7 +82,7 @@ public abstract class SegmentCopyTestBase {

protected abstract SegmentNodeStorePersistence getDestPersistence() throws Exception;

protected abstract String getSrcPathOrUri();
protected abstract String getSrcPathOrUri() throws URISyntaxException, InvalidKeyException, StorageException, Exception;

protected abstract String getDestPathOrUri();

@@ -228,4 +241,25 @@ protected String getAzurePersistencePathOrUri() {

return uri.toString();
}

protected String getAzurePersistencePathOrUriSas() throws Exception {
StringBuilder uri = new StringBuilder("az:");
String sasToken = azurite.getContainer(AZURE_CONTAINER)
.generateSharedAccessSignature(policy(READ_WRITE), null);
uri.append("http://127.0.0.1:");
uri.append(azurite.getMappedPort()).append("/");
uri.append(AZURE_CONTAINER).append("/");
uri.append(AZURE_DIRECTORY).append("?");
uri.append(sasToken);

return uri.toString();
}

@NotNull
private static SharedAccessBlobPolicy policy(EnumSet<SharedAccessBlobPermissions> permissions) {
SharedAccessBlobPolicy sharedAccessBlobPolicy = new SharedAccessBlobPolicy();
sharedAccessBlobPolicy.setPermissions(permissions);
sharedAccessBlobPolicy.setSharedAccessExpiryTime(Date.from(Instant.now().plus(Duration.ofDays(7))));
return sharedAccessBlobPolicy;
}
}

0 comments on commit ce36f9a

Please sign in to comment.