This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Switched to R6 sas client #276
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
|
||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.