Created
June 26, 2019 15:14
-
-
Save revodavid/acf3a15c4e4466f77c625878a011ee25 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
library(AzureRMR) | |
library(AzureGraph) | |
library(AzureStor) | |
# set your Azure organization and subscription details here | |
tenant <- "mytenant" | |
sub_id <- "12345678-aaaa-bbbb-cccc-0123456789ab" | |
# create a Graph client | |
gr <- AzureGraph::create_graph_login(tenant) | |
# create an app (associated service principal will also | |
# be created automatically) | |
app <- gr$create_app("AzureRapp") | |
# create a Resource Manager client | |
az <- AzureRMR::create_azure_login(tenant) | |
# create the resource group and storage account | |
rg <- az$ | |
get_subscription(sub_id)$ | |
create_resource_group("AzureRsample", location="westus") | |
# create a storage account -- StorageV2, Standard_LRS | |
stor <- rg$create_storage_account("azurerstor") | |
# give blob contributor rights to the app | |
stor$add_role_assignment(app, "Storage blob data contributor") | |
## client side: | |
# authenticate with the app | |
token <- AzureAuth::get_azure_token( | |
resource="https://storage.azure.com", | |
tenant=tenant, | |
app=app$properties$appId, | |
password=app$password | |
) | |
# blob endpoint object | |
stor_client <- storage_endpoint("https://azurerstor.blob.core.windows.net", token=token) | |
# create a blob container -- | |
# authentication details passed down from endpoint | |
stor_container <- create_storage_container(stor_client, "mycontainer") | |
# upload a file | |
storage_upload(stor_container, "/path/to/mybigfile.txt", "mybigfile.txt") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment