Skip to content
Permalink
Browse files
Merge pull request #506 from kunal3112/sas-uri
OAK-9712 - Add support for Azure SAS URIs in oak-run
  • Loading branch information
smiroslav committed Mar 4, 2022
2 parents 1385c05 + 0832fab commit 8fe0b13d4318506967f41ad68cad2d22da5ae88f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
@@ -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(){
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();
@@ -228,4 +241,32 @@ protected String getAzurePersistencePathOrUri() {

return uri.toString();
}

protected String getAzurePersistencePathOrUriSas() {
StringBuilder uri = new StringBuilder("az:");
String sasToken;

try {
sasToken = azurite.getContainer(AZURE_CONTAINER)
.generateSharedAccessSignature(policy(READ_WRITE), null);
} catch (StorageException | InvalidKeyException | URISyntaxException e) {
throw new RuntimeException("Error while accessing container ", e);
}

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 8fe0b13

Please sign in to comment.