Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
System
Lib
cloud
azure
OS Core Lib Azure
Commits
ef16757b
Commit
ef16757b
authored
Nov 16, 2020
by
Kishore Battula
Browse files
Merge branch 'getSasToken' into 'master'
Added getSasToken method in `BlobStore.java` See merge request
!45
parents
1b23b14d
320cdf1e
Pipeline
#15575
passed with stages
in 8 minutes and 54 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/opengroup/osdu/azure/blobstorage/BlobStore.java
View file @
ef16757b
...
...
@@ -18,6 +18,8 @@ import com.azure.storage.blob.BlobContainerClient;
import
com.azure.storage.blob.BlobServiceClient
;
import
com.azure.storage.blob.models.BlobErrorCode
;
import
com.azure.storage.blob.models.BlobStorageException
;
import
com.azure.storage.blob.sas.BlobSasPermission
;
import
com.azure.storage.blob.sas.BlobServiceSasSignatureValues
;
import
com.azure.storage.blob.specialized.BlockBlobClient
;
import
org.opengroup.osdu.core.common.logging.ILogger
;
import
org.opengroup.osdu.core.common.model.http.AppException
;
...
...
@@ -30,6 +32,7 @@ import java.io.ByteArrayOutputStream;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.charset.StandardCharsets
;
import
java.time.OffsetDateTime
;
import
java.util.Collections
;
/**
...
...
@@ -40,7 +43,7 @@ import java.util.Collections;
* @Autowired
* private BlobStore blobStore;
*
* String readFromStorageContainerExam
o
le()
* String readFromStorageContainerExam
p
le()
* {
* String content = blobStorage.readFromStorageContainer("dataPartitionId", "filePath", "containerName");
* if (content != null)
...
...
@@ -56,6 +59,14 @@ import java.util.Collections;
* {
* Boolean success = blobStorage.deleteFromStorageContainer("dataPartitionId", "filePath", "containerName");
* }
*
* void getSasToken()
* {
* int expiryDays = 7;
* OffsetDateTime expiryTime = OffsetDateTime.now().plusDays(expiryDays);
* BlobSasPermission permissions = (new BlobSasPermission()).setReadPermission(true).setCreatePermission(true);
* String sasToken = blobStorage.getSasToken("dataPartitionId", "filePath", "containerName", expiryTime, permissions);
* }
* }
* </pre>
*/
...
...
@@ -147,6 +158,21 @@ public class BlobStore {
}
}
/**
* @param dataPartitionId Data partition id
* @param filePath Path of file (blob) for which SAS token needs to be generated
* @param containerName Name of the storage container
* @param expiryTime Time after which the token expires
* @param permissions Permissions for the given blob
* @return SAS token for the given blob
*/
public
String
getSasToken
(
final
String
dataPartitionId
,
final
String
filePath
,
final
String
containerName
,
final
OffsetDateTime
expiryTime
,
final
BlobSasPermission
permissions
)
{
BlobContainerClient
blobContainerClient
=
getBlobContainerClient
(
dataPartitionId
,
containerName
);
BlockBlobClient
blockBlobClient
=
blobContainerClient
.
getBlobClient
(
filePath
).
getBlockBlobClient
();
BlobServiceSasSignatureValues
blobServiceSasSignatureValues
=
new
BlobServiceSasSignatureValues
(
expiryTime
,
permissions
);
return
blockBlobClient
.
generateSas
(
blobServiceSasSignatureValues
);
}
/**
* @param dataPartitionId Data partition id.
* @param containerName Name of storage container.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment