From 7810d18d95f785cd4ed93c13bc4e616ac4a3c427 Mon Sep 17 00:00:00 2001 From: hong-revo Date: Wed, 2 May 2018 02:10:34 +1000 Subject: [PATCH] set package-wide default API version --- R/AzureSMRbase.R | 6 ++++++ R/az_auth.R | 4 ++-- R/az_resgroup.R | 4 ++-- R/az_subscription.R | 4 ++-- R/call_azure_sm.R | 4 +++- 5 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 R/AzureSMRbase.R diff --git a/R/AzureSMRbase.R b/R/AzureSMRbase.R new file mode 100644 index 0000000..b693102 --- /dev/null +++ b/R/AzureSMRbase.R @@ -0,0 +1,6 @@ +.onLoad <- function(libname, pkgname) +{ + azure_api_version="2018-05-01" + options(azure_api_version=azure_api_version) + invisible(NULL) +} diff --git a/R/az_auth.R b/R/az_auth.R index fa1c8ad..7111c64 100644 --- a/R/az_auth.R +++ b/R/az_auth.R @@ -68,9 +68,9 @@ private=list( # obtain subscription IDs owned by this app set_subs=function() { - cont <- call_azure_sm(private$token, subscription="", operation="", api_version="2016-06-01") + cont <- call_azure_sm(private$token, subscription="", operation="") - df <- lapply(cont, data.frame, stringsAsFactors=FALSE) + df <- lapply(cont$value, data.frame, stringsAsFactors=FALSE) df <- do.call(rbind, df) # update subscription IDs; notify if more than one found diff --git a/R/az_resgroup.R b/R/az_resgroup.R index 10553c8..8cc74ef 100644 --- a/R/az_resgroup.R +++ b/R/az_resgroup.R @@ -18,7 +18,7 @@ public=list( self$name <- name op <- paste0("resourcegroups/", self$name) - cont <- call_azure_sm(private$token, self$subscription, operation=op, api_version="2018-05-01") + cont <- call_azure_sm(private$token, self$subscription, op) self$id <- cont$id self$location <- cont$location self$managed_by <- cont$managedBy @@ -40,7 +40,7 @@ private=list( set_res=function() { op <- paste0("resourcegroups/", self$name, "/resources") - cont <- call_azure_sm(private$token, self$subscription, operation=op, api_version="2018-05-01") + cont <- call_azure_sm(private$token, self$subscription, op) self$resources <- sapply(cont$value, `[[`, "name") NULL } diff --git a/R/az_subscription.R b/R/az_subscription.R index c727dda..6ffd613 100644 --- a/R/az_subscription.R +++ b/R/az_subscription.R @@ -14,7 +14,7 @@ public=list( { private$token <- token self$id <- id - info <- call_azure_sm(token, id, "", api_version="2018-05-01") + info <- call_azure_sm(token, id, "") self$name <- info$displayName self$state <- info$state self$policies <- info$subscriptionPolicies @@ -44,7 +44,7 @@ private=list( token=NULL, set_rgrps=function() { - cont <- call_azure_sm(private$token, self$id, operation="resourcegroups", api_version="2018-05-01") + cont <- call_azure_sm(private$token, self$id, "resourcegroups") self$resource_groups <- sapply(cont$value, `[[`, "name") NULL } diff --git a/R/call_azure_sm.R b/R/call_azure_sm.R index 6631d2c..ea7ae9b 100644 --- a/R/call_azure_sm.R +++ b/R/call_azure_sm.R @@ -1,9 +1,11 @@ -call_azure_sm <- function(token, subscription, operation, api_version, +call_azure_sm <- function(token, subscription, operation, api_version=getOption("azure_api_version"), http_verb=c("GET", "DELETE", "PUT", "POST", "HEAD"), catch=c("stop", "warn", "message", "pass"), ...) { creds <- token$credentials + # TODO: if token has expired, renew it + url <- httr::parse_url(creds$resource) url$path <- file.path("subscriptions", subscription, operation, fsep="/") url$query <- list(`api-version`=api_version)