Commit ec06e610 authored by Kishore Battula's avatar Kishore Battula
Browse files

Merge branch 'container-sas-url' into 'master'

Container sas url

See merge request !50
parents be7c9317 58abf2be
Pipeline #17207 passed with stages
in 8 minutes and 13 seconds
......@@ -20,7 +20,7 @@
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<packaging>jar</packaging>
<version>0.0.45</version>
<version>0.0.46</version>
<name>core-lib-azure</name>
<properties>
......
......@@ -20,6 +20,7 @@ import com.azure.storage.blob.BlobServiceClient;
import com.azure.storage.blob.models.BlobCopyInfo;
import com.azure.storage.blob.models.BlobErrorCode;
import com.azure.storage.blob.models.BlobStorageException;
import com.azure.storage.blob.sas.BlobContainerSasPermission;
import com.azure.storage.blob.sas.BlobSasPermission;
import com.azure.storage.blob.sas.BlobServiceSasSignatureValues;
import com.azure.storage.blob.specialized.BlockBlobClient;
......@@ -195,6 +196,19 @@ public class BlobStore {
return blockBlobClient.getBlobUrl() + "?" + generateSASToken(blockBlobClient, expiryTime, permissions);
}
/**
* Generates pre-signed url to a blob container.
* @param dataPartitionId data partition id
* @param containerName Name of the storage container
* @param expiryTime Time after which the token expires
* @param permissions permissions for the given container
* @return Generates pre-signed url for a given container
*/
public String generatePreSignedURL(final String dataPartitionId, final String containerName, final OffsetDateTime expiryTime, final BlobContainerSasPermission permissions) {
BlobContainerClient blobContainerClient = getBlobContainerClient(dataPartitionId, containerName);
return blobContainerClient.getBlobContainerUrl() + "?" + generateSASToken(blobContainerClient, expiryTime, permissions);
}
/**
* Method is used to copy a file specified at Source URL to the provided destination.
* @param dataPartitionId Data partition id
......@@ -223,6 +237,17 @@ public class BlobStore {
return blockBlobClient.generateSas(blobServiceSasSignatureValues);
}
/**
* @param client Container client
* @param expiryTime Time after which SAS Token expires
* @param permissions Permissions for the given container
* @return Generates SAS Token.
*/
private String generateSASToken(final BlobContainerClient client, final OffsetDateTime expiryTime, final BlobContainerSasPermission permissions) {
BlobServiceSasSignatureValues blobServiceSasSignatureValues = new BlobServiceSasSignatureValues(expiryTime, permissions);
return client.generateSas(blobServiceSasSignatureValues);
}
/**
* @param dataPartitionId Data partition id.
* @param containerName Name of storage container.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment