зеркало из https://github.com/Azure/AzureRMR.git
better handling of nulls
This commit is contained in:
Родитель
387102cfdd
Коммит
b2b9530516
|
@ -9,6 +9,8 @@
|
|||
#' @param http_verb The HTTP verb as a string, one of `GET`, `PUT`, `POST`, `DELETE`, `HEAD` or `PATCH`.
|
||||
#' @param http_status_handler How to handle in R the HTTP status code of a response. `"stop"`, `"warn"` or `"message"` will call the appropriate handlers in httr, while `"pass"` ignores the status code.
|
||||
#' @param auto_refresh Whether to refresh/renew the OAuth token if it is no longer valid.
|
||||
#' @param body The body of the request, for `PUT`/`POST`/`PATCH`.
|
||||
#' @param encode The encoding (really content-type) for the request body. The default value "json" means to serialize a list body into a JSON object. If you pass an already-serialized JSON object as the body, set `encode` to "raw".
|
||||
#' @param ... Other arguments passed to lower-level code, ultimately to the appropriate functions in httr.
|
||||
#'
|
||||
#' @details
|
||||
|
@ -37,15 +39,23 @@ call_azure_rm <- function(token, subscription, operation, ...,
|
|||
|
||||
#' @rdname call_azure
|
||||
#' @export
|
||||
call_azure_url <- function(token, url, ...,
|
||||
call_azure_url <- function(token, url, ..., body=NULL, encode="json",
|
||||
http_verb=c("GET", "DELETE", "PUT", "POST", "HEAD", "PATCH"),
|
||||
http_status_handler=c("stop", "warn", "message", "pass"),
|
||||
auto_refresh=TRUE)
|
||||
{
|
||||
headers <- process_headers(token, ..., auto_refresh=auto_refresh)
|
||||
|
||||
# if content-type is json, serialize it manually to ensure proper handling of nulls
|
||||
if(encode == "json")
|
||||
{
|
||||
null <- vapply(body, is.null, logical(1))
|
||||
body <- jsonlite::toJSON(body[!null], auto_unbox=TRUE, digits=22, null="null")
|
||||
encode <- "raw"
|
||||
}
|
||||
|
||||
# do actual API call
|
||||
res <- httr::VERB(match.arg(http_verb), url, headers, ...)
|
||||
res <- httr::VERB(match.arg(http_verb), url, headers, body=body, encode=encode, ...)
|
||||
|
||||
process_response(res, match.arg(http_status_handler))
|
||||
}
|
||||
|
@ -62,12 +72,11 @@ process_headers <- function(token, ..., auto_refresh)
|
|||
|
||||
host <- httr::parse_url(if(token$version == 1) token$resource else token$scope[1])$hostname
|
||||
creds <- token$credentials
|
||||
headers <- c(Authorization=paste(creds$token_type, creds$access_token))
|
||||
|
||||
# default content-type is json, set this if encoding not specified
|
||||
dots <- list(...)
|
||||
if(is_empty(dots) || !("encode" %in% names(dots)) || dots$encode == "raw")
|
||||
headers <- c(headers, `Content-type`="application/json")
|
||||
headers <- c(
|
||||
Host=host,
|
||||
Authorization=paste(creds$token_type, creds$access_token),
|
||||
`Content-Type`="application/json"
|
||||
)
|
||||
|
||||
httr::add_headers(.headers=headers)
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ If you are using a Linux \href{https://azure.microsoft.com/en-us/services/virtua
|
|||
\dontrun{
|
||||
|
||||
# without any arguments, this will create a client using your AAD credentials
|
||||
az <- create_azure_login()
|
||||
az <- create_azure_login()
|
||||
|
||||
# retrieve the login in subsequent sessions
|
||||
az <- get_azure_login()
|
||||
|
|
|
@ -8,9 +8,10 @@
|
|||
call_azure_rm(token, subscription, operation, ..., options = list(),
|
||||
api_version = getOption("azure_api_version"))
|
||||
|
||||
call_azure_url(token, url, ..., http_verb = c("GET", "DELETE", "PUT",
|
||||
"POST", "HEAD", "PATCH"), http_status_handler = c("stop", "warn",
|
||||
"message", "pass"), auto_refresh = TRUE)
|
||||
call_azure_url(token, url, ..., body = NULL, encode = "json",
|
||||
http_verb = c("GET", "DELETE", "PUT", "POST", "HEAD", "PATCH"),
|
||||
http_status_handler = c("stop", "warn", "message", "pass"),
|
||||
auto_refresh = TRUE)
|
||||
}
|
||||
\arguments{
|
||||
\item{token}{An Azure OAuth token, of class \link{AzureToken}.}
|
||||
|
@ -27,6 +28,10 @@ call_azure_url(token, url, ..., http_verb = c("GET", "DELETE", "PUT",
|
|||
|
||||
\item{url}{A complete URL to send to the host.}
|
||||
|
||||
\item{body}{The body of the request, for \code{PUT}/\code{POST}/\code{PATCH}.}
|
||||
|
||||
\item{encode}{The encoding (really content-type) for the request body. The default value "json" means to serialize a list body into a JSON object. If you pass an already-serialized JSON object as the body, set \code{encode} to "raw".}
|
||||
|
||||
\item{http_verb}{The HTTP verb as a string, one of \code{GET}, \code{PUT}, \code{POST}, \code{DELETE}, \code{HEAD} or \code{PATCH}.}
|
||||
|
||||
\item{http_status_handler}{How to handle in R the HTTP status code of a response. \code{"stop"}, \code{"warn"} or \code{"message"} will call the appropriate handlers in httr, while \code{"pass"} ignores the status code.}
|
||||
|
|
|
@ -17,7 +17,7 @@ get_lock(name)
|
|||
|
||||
delete_lock(name)
|
||||
|
||||
list_locks()
|
||||
list_locks()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ get_role_assignment(id)
|
|||
|
||||
remove_role_assignment(id, confirm = TRUE)
|
||||
|
||||
list_role_assignments(filter = "atScope()", as_data_frame = TRUE)
|
||||
list_role_assignments(filter = "atScope()", as_data_frame = TRUE)
|
||||
|
||||
get_role_definition(id)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче