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

Commit

Permalink
Switched to R6 sas client (#276)
Browse files Browse the repository at this point in the history
* Switched to R6 sas client

* Added storage endpoint suffix
  • Loading branch information
brnleehng authored May 18, 2018
1 parent 4983fb1 commit b24f20c
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions samples/sas_resource_files/sas_resources_files_example.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
library(doAzureParallel)

doAzureParallel::setCredentials("credentials.json")
storageAccountName <- "<YOUR_STORAGE_ACCOUNT>"
# Using rAzureBatch directly for storage uploads
config <- rjson::fromJSON(file = paste0("credentials.json"))

storageCredentials <- rAzureBatch::SharedKeyCredentials$new(
name = config$sharedKey$storageAccount$name,
key = config$sharedKey$storageAccount$key
)

storageAccountName <- storageCredentials$name
inputContainerName <- "datasets"

# Generate a sas tokens with the createSasToken function
storageClient <- rAzureBatch::StorageServiceClient$new(
authentication = storageCredentials,
url = sprintf("https://%s.blob.%s",
storageCredentials$name,
config$sharedKey$storageAccount$endpointSuffix
)
)

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

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

# Create a Storage container in the Azure Storage account
rAzureBatch::createContainer(inputContainerName)
storageClient$containerOperations$createContainer(inputContainerName, content = "response")

# Upload blobs with a write sasToken
rAzureBatch::uploadBlob(inputContainerName,
fileDirectory = "1989.csv",
sasToken = writeSasToken,
accountName = storageAccountName)

rAzureBatch::uploadBlob(inputContainerName,
fileDirectory = "1990.csv",
sasToken = writeSasToken,
accountName = storageAccountName)
storageClient$blobOperations$uploadBlob(inputContainerName,
fileDirectory = "1989.csv",
sasToken = writeSasToken,
accountName = storageAccountName)

storageClient$blobOperations$uploadBlob(inputContainerName,
fileDirectory = "1990.csv",
sasToken = writeSasToken,
accountName = storageAccountName)

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

0 comments on commit b24f20c

Please sign in to comment.