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

Switched to R6 sas client #276

Merged
merged 2 commits into from
May 18, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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$storageAccount$name,
key = config$storageAccount$key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be better to use endpoint from config file so the sample can run in national clouds as well.

)

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,
"core.windows.net"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be better to use endpoint from config file so the sample can run in national clouds as well.

)
)

# 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