Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit b24f20c

Browse files
authored
Switched to R6 sas client (#276)
* Switched to R6 sas client * Added storage endpoint suffix
1 parent 4983fb1 commit b24f20c

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

samples/sas_resource_files/sas_resources_files_example.R

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,45 @@
11
library(doAzureParallel)
22

33
doAzureParallel::setCredentials("credentials.json")
4-
storageAccountName <- "<YOUR_STORAGE_ACCOUNT>"
4+
# Using rAzureBatch directly for storage uploads
5+
config <- rjson::fromJSON(file = paste0("credentials.json"))
6+
7+
storageCredentials <- rAzureBatch::SharedKeyCredentials$new(
8+
name = config$sharedKey$storageAccount$name,
9+
key = config$sharedKey$storageAccount$key
10+
)
11+
12+
storageAccountName <- storageCredentials$name
513
inputContainerName <- "datasets"
614

7-
# Generate a sas tokens with the createSasToken function
15+
storageClient <- rAzureBatch::StorageServiceClient$new(
16+
authentication = storageCredentials,
17+
url = sprintf("https://%s.blob.%s",
18+
storageCredentials$name,
19+
config$sharedKey$storageAccount$endpointSuffix
20+
)
21+
)
822

23+
# Generate a sas tokens with the createSasToken function
924
# Write-only SAS. Will be used for uploading files to storage.
10-
writeSasToken <- rAzureBatch::createSasToken(permission = "w", sr = "c", path = inputContainerName)
25+
writeSasToken <- storageClient$generateSasToken(permission = "w", "c", path = inputContainerName)
1126

1227
# Read-only SAS. Will be used for downloading files from storage.
13-
readSasToken <- rAzureBatch::createSasToken(permission = "r", sr = "c", path = inputContainerName)
28+
readSasToken <- storageClient$generateSasToken(permission = "r", "c", path = inputContainerName)
1429

1530
# Create a Storage container in the Azure Storage account
16-
rAzureBatch::createContainer(inputContainerName)
31+
storageClient$containerOperations$createContainer(inputContainerName, content = "response")
1732

1833
# Upload blobs with a write sasToken
19-
rAzureBatch::uploadBlob(inputContainerName,
20-
fileDirectory = "1989.csv",
21-
sasToken = writeSasToken,
22-
accountName = storageAccountName)
23-
24-
rAzureBatch::uploadBlob(inputContainerName,
25-
fileDirectory = "1990.csv",
26-
sasToken = writeSasToken,
27-
accountName = storageAccountName)
34+
storageClient$blobOperations$uploadBlob(inputContainerName,
35+
fileDirectory = "1989.csv",
36+
sasToken = writeSasToken,
37+
accountName = storageAccountName)
38+
39+
storageClient$blobOperations$uploadBlob(inputContainerName,
40+
fileDirectory = "1990.csv",
41+
sasToken = writeSasToken,
42+
accountName = storageAccountName)
2843

2944
# Create URL paths with read-only permissions
3045
csvFileUrl1 <- rAzureBatch::createBlobUrl(storageAccount = storageAccountName,

0 commit comments

Comments
 (0)