From 3c12755bc0b5885ed1379c82d48c4fff1f04c114 Mon Sep 17 00:00:00 2001 From: hong-revo Date: Thu, 17 May 2018 18:49:58 +1000 Subject: [PATCH] make path construction consistent --- R/AzureToken.R | 2 +- R/az_resgroup.R | 2 +- R/az_resource.R | 10 +++++----- R/az_subscription.R | 2 +- R/az_template.R | 2 +- R/call_azure_rm.R | 2 +- R/utils.R | 7 +++++++ 7 files changed, 17 insertions(+), 10 deletions(-) diff --git a/R/AzureToken.R b/R/AzureToken.R index e38f41a..7f995af 100644 --- a/R/AzureToken.R +++ b/R/AzureToken.R @@ -129,7 +129,7 @@ private=list( get_azure_token=function(aad_host, tenant, app, auth_type=c("client_credentials", "device_code"), secret, arm_host) { auth_type <- match.arg(auth_type) - base_url <- file.path(aad_host, tenant, fsep="/") + base_url <- construct_path(aad_host, tenant) if(auth_type == "client_credentials") auth_with_creds(base_url, app, secret, arm_host) else auth_with_device(base_url, app, arm_host) diff --git a/R/az_resgroup.R b/R/az_resgroup.R index a1bc835..12a5ceb 100644 --- a/R/az_resgroup.R +++ b/R/az_resgroup.R @@ -209,7 +209,7 @@ private=list( rg_op=function(op="", ...) { - op <- file.path("resourcegroups", self$name, op) + op <- construct_path("resourcegroups", self$name, op) call_azure_rm(self$token, self$subscription, op, ...) } )) diff --git a/R/az_resource.R b/R/az_resource.R index 00cb110..5fced74 100644 --- a/R/az_resource.R +++ b/R/az_resource.R @@ -116,7 +116,7 @@ public=list( provider <- substr(self$type, 1, slash - 1) path <- substr(self$type, slash + 1, nchar(self$type)) - op <- file.path("providers", provider) + op <- construct_path("providers", provider) apis <- named_list(call_azure_rm(self$token, self$subscription, op)$resourceTypes, "resourceType") names(apis) <- tolower(names(apis)) @@ -144,7 +144,7 @@ public=list( } private$res_op(http_verb="DELETE") - message("Deleting resource '", file.path(self$type, self$name), "'") + message("Deleting resource '", construct_path(self$type, self$name), "'") if(wait) { @@ -207,8 +207,8 @@ private=list( else { if(missing(type)) - type <- file.path(provider, path) - id <- file.path("/subscriptions", self$subscription, "resourceGroups", resource_group, "providers", type, name) + type <- construct_path(provider, path) + id <- construct_path("/subscriptions", self$subscription, "resourceGroups", resource_group, "providers", type, name) } self$resource_group <- resource_group self$type <- type @@ -271,7 +271,7 @@ private=list( if(is.null(private$api_version)) self$set_api_version() - op <- file.path("resourcegroups", self$resource_group, "providers", self$type, self$name, op) + op <- construct_path("resourcegroups", self$resource_group, "providers", self$type, self$name, op) call_azure_rm(self$token, self$subscription, op, ..., api_version=private$api_version) } )) diff --git a/R/az_subscription.R b/R/az_subscription.R index ebe4c08..6172aaf 100644 --- a/R/az_subscription.R +++ b/R/az_subscription.R @@ -77,7 +77,7 @@ public=list( } else { - op <- file.path("providers", provider) + op <- construct_path("providers", provider) apis <- named_list(call_azure_rm(self$token, self$id, op)$resourceTypes, "resourceType") if(!is_empty(type)) { diff --git a/R/az_template.R b/R/az_template.R index 44824b2..c454ede 100644 --- a/R/az_template.R +++ b/R/az_template.R @@ -221,7 +221,7 @@ private=list( tpl_op=function(op="", ...) { - op <- file.path("resourcegroups", self$resource_group, "providers/Microsoft.Resources/deployments", self$name, op) + op <- construct_path("resourcegroups", self$resource_group, "providers/Microsoft.Resources/deployments", self$name, op) call_azure_rm(self$token, self$subscription, op, ...) } )) diff --git a/R/call_azure_rm.R b/R/call_azure_rm.R index 778292b..2d947dd 100644 --- a/R/call_azure_rm.R +++ b/R/call_azure_rm.R @@ -28,7 +28,7 @@ call_azure_rm <- function(token, subscription, operation, ..., api_version=getOption("azure_api_version")) { url <- httr::parse_url(token$credentials$resource) - url$path <- file.path("subscriptions", subscription, operation, fsep="/") + url$path <- construct_path("subscriptions", subscription, operation) url$query <- modifyList(list(`api-version`=api_version), options) call_azure_url(token, httr::build_url(url), ...) diff --git a/R/utils.R b/R/utils.R index 918db65..56fc1c0 100644 --- a/R/utils.R +++ b/R/utils.R @@ -57,3 +57,10 @@ validate_object_names <- function(x, required, optional=character(0)) if(!valid) stop("Invalid object names") } + + +# handle different behaviour of file_path on Windows/Linux wrt trailing / +construct_path <- function(...) +{ + sub("/$", "", file.path(..., fsep="/")) +}