From e227d83836b1b40ce702c3183784900d3da2c4de Mon Sep 17 00:00:00 2001 From: hong-revo Date: Sun, 6 May 2018 05:07:26 +1000 Subject: [PATCH] get provider api version 2 --- R/az_resource.R | 18 +++++++++--------- R/az_subscription.R | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/R/az_resource.R b/R/az_resource.R index 2269c7f..d626719 100644 --- a/R/az_resource.R +++ b/R/az_resource.R @@ -24,15 +24,11 @@ public=list( # 4. get from host: resgroup, {provider, path}|type, name # 5. get from host by id: id initialize=function(token, subscription, resource_group, provider, path, type, name, id, ..., - deployed_properties=list(), api_version=NULL) + deployed_properties=list()) { self$token <- token self$subscription <- subscription - if(is.null(api_version)) - private$set_api_version(provider, path, type, id) - else private$api_version <- api_version - parms <- if(!is_empty(list(...))) private$init_and_deploy(resource_group, provider, path, type, name, id, ...) else if(!is_empty(deployed_properties)) @@ -86,9 +82,9 @@ private=list( } init_from_host_by_args <- function(resource_group, type, name) { - self$resource_group <- parms$resource_group - self$type <- parms$type - self$name <- parms$name + self$resource_group <- resource_group + self$type <- type + self$name <- name parms <- private$res_op() @@ -182,19 +178,23 @@ private=list( } op <- file.path("providers", provider) - apis <- named_list(call_azure_rm(self$token, self$id, op)$resourceTypes, "resourceType") + apis <- named_list(call_azure_rm(self$token, self$subscription, op)$resourceTypes, "resourceType") private$api_version <- apis[[path]]$apiVersions[[1]] }, res_op=function(op="", ...) { + if(is.null(private$api_version)) + private$set_api_version(type=self$type) op <- file.path("resourcegroups", self$resource_group, "providers", self$type, self$name, op) call_azure_rm(self$token, self$subscription, op, ..., api_version=private$api_version) }, res_id_op=function(op="", ...) { + if(is.null(private$api_version)) + private$set_api_version(id=self$id) # strip off subscription, which is handled by call_azure_rm separately id <- sub("^.+/resourcegroups", "resourcegroups", self$id, ignore.case=TRUE) op <- file.path(id, op) diff --git a/R/az_subscription.R b/R/az_subscription.R index 3bdb7da..41ff8b4 100644 --- a/R/az_subscription.R +++ b/R/az_subscription.R @@ -44,7 +44,7 @@ public=list( # API versions vary across different providers; find the latest get_provider_api_version=function(provider=NULL, resource_type=NULL, which=1) { - if(is.null(provider)) + if(is_empty(provider)) { apis <- named_list(call_azure_rm(self$token, self$id, "providers")$value, "namespace") lapply(apis, function(api) @@ -57,7 +57,7 @@ public=list( { op <- file.path("providers", provider) apis <- named_list(call_azure_rm(self$token, self$id, op)$resourceTypes, "resourceType") - if(!is.null(resource_type)) + if(!is_empty(resource_type)) { this_api <- apis[[resource_type]] this_api$apiVersions[[which]]