зеркало из https://github.com/Azure/AzureStor.git
fixes for sas, printing
This commit is contained in:
Родитель
2b1375417d
Коммит
95779dbb2b
|
@ -3,7 +3,7 @@
|
|||
#' Get, list, create, or delete blob containers.
|
||||
#'
|
||||
#' @param endpoint Either a blob endpoint object as created by [storage_endpoint], or a character string giving the URL of the endpoint.
|
||||
#' @param key,sas If an endpoint object is not supplied, authentication details. If neither an access key nor a SAS are provided, only public (anonymous) access to the share is possible.
|
||||
#' @param key,sas If an endpoint object is not supplied, authentication details. If a key is provided, the SAS is not used. If neither an access key nor a SAS are provided, only public (anonymous) access to the share is possible.
|
||||
#' @param api_version If an endpoint object is not supplied, the storage API version to use when interacting with the host. Currently defaults to `"2017-07-29"`.
|
||||
#' @param name The name of the blob container to get, create, or delete.
|
||||
#' @param confirm For deleting a container, whether to ask for confirmation.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#'
|
||||
#' @param endpoint The URL (hostname) for the endpoint. This must be of the form `http[s]://{account-name}.{type}.{core-host-name}`, where `type` is one of `"blob"`, `"file"`, `"queue"` or `"table"`. On the public Azure cloud, endpoints will be of the form `https://{account-name}.{type}.core.windows.net`.
|
||||
#' @param key The access key for the storage account.
|
||||
#' @param sas A shared access signature for the account. If neither `key` nor `sas` are provided, only public (anonymous) access to the endpoint is possible.
|
||||
#' @param sas A shared access signature (SAS) for the account. If `key` is also provided, the SAS is not used. If neither `key` nor `sas` are provided, only public (anonymous) access to the endpoint is possible.
|
||||
#' @param api_version The storage API version to use when interacting with the host. Currently defaults to `"2017-07-29"`.
|
||||
#'
|
||||
#' @details
|
||||
|
@ -53,7 +53,7 @@ print.storage_endpoint <- function(object)
|
|||
#' Generic upload and download
|
||||
#'
|
||||
#' @param src,dest The source and destination files/URLs. Paths are allowed.
|
||||
#' @param ... Further arguments to pass to lower-level functions. In particular, use `key` and/or `sas` to supply an access key or SAS. Without a key or SAS, only unauthenticated (anonymous) access is possible.
|
||||
#' @param ... Further arguments to pass to lower-level functions. In particular, use `key` and/or `sas` to supply an access key or SAS. Without a key or SAS, only public (anonymous) access is possible.
|
||||
#' @param overwrite For downloading, whether to overwrite any destination files that exist.
|
||||
#'
|
||||
#' @details
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#' Get, list, create, or delete file shares.
|
||||
#'
|
||||
#' @param endpoint Either a file endpoint object as created by [storage_endpoint], or a character string giving the URL of the endpoint.
|
||||
#' @param key,sas If an endpoint object is not supplied, authentication details. If neither an access key nor a SAS are provided, only public (anonymous) access to the share is possible.
|
||||
#' @param key,sas If an endpoint object is not supplied, authentication details. If a key is provided, the SAS is not used. If neither an access key nor a SAS are provided, only public (anonymous) access to the share is possible.
|
||||
#' @param api_version If an endpoint object is not supplied, the storage API version to use when interacting with the host. Currently defaults to `"2017-07-29"`.
|
||||
#' @param name The name of the file share to get, create, or delete.
|
||||
#' @param confirm For deleting a share, whether to ask for confirmation.
|
||||
|
@ -163,8 +163,6 @@ delete_file_share.file_endpoint <- function(endpoint, name, confirm=TRUE)
|
|||
#' @return
|
||||
#' For `list_azure_files`, if `all_info=FALSE`, a vector of file/directory names. If `all_info=TRUE`, a data frame giving the file size and whether each object is a file or directory.
|
||||
#'
|
||||
#' For the other functions, NULL on successful completion.
|
||||
#'
|
||||
#' @seealso
|
||||
#' [file_share], [az_storage]
|
||||
#'
|
||||
|
|
13
R/storage.R
13
R/storage.R
|
@ -87,14 +87,14 @@ public=list(
|
|||
#self$do_operation("POST", "listServiceSas", body=parms, encode="json")$serviceSasToken
|
||||
#},
|
||||
|
||||
get_blob_endpoint=function(key=self$list_keys()[1])
|
||||
get_blob_endpoint=function(key=self$list_keys()[1], sas=NULL)
|
||||
{
|
||||
storage_endpoint(self$properties$primaryEndpoints$blob, key=key)
|
||||
storage_endpoint(self$properties$primaryEndpoints$blob, key=key, sas=sas)
|
||||
},
|
||||
|
||||
get_file_endpoint=function(key=self$list_keys()[1])
|
||||
get_file_endpoint=function(key=self$list_keys()[1], sas=NULL)
|
||||
{
|
||||
storage_endpoint(self$properties$primaryEndpoints$file, key=key)
|
||||
storage_endpoint(self$properties$primaryEndpoints$file, key=key, sas=sas)
|
||||
},
|
||||
|
||||
print=function(...)
|
||||
|
@ -111,8 +111,9 @@ public=list(
|
|||
cat(endp, "\n")
|
||||
cat("---\n")
|
||||
|
||||
cat(format_public_fields(self, exclude=c("subscription", "resource_group", "type", "name", "kind", "sku")))
|
||||
cat(format_public_methods(self))
|
||||
cat(AzureRMR::format_public_fields(self, exclude=c("subscription", "resource_group",
|
||||
"type", "name", "kind", "sku")))
|
||||
cat(AzureRMR::format_public_methods(self))
|
||||
invisible(NULL)
|
||||
}
|
||||
),
|
||||
|
|
|
@ -15,28 +15,21 @@ do_storage_call <- function(endpoint_url, path, options=list(), headers=list(),
|
|||
http_status_handler=c("stop", "warn", "message", "pass"))
|
||||
{
|
||||
verb <- match.arg(http_verb)
|
||||
|
||||
# use shared access signature if provided, otherwise key if provided, otherwise anonymous access
|
||||
if(!is.null(sas))
|
||||
{
|
||||
url <- paste0(endpoint_url, path, "/") # don't use file.path because it strips trailing / on Windows
|
||||
url <- paste0(url, "?", sas)
|
||||
url <- httr::parse_url(url)
|
||||
headers <- httr::add_headers(.headers=unlist(headers))
|
||||
}
|
||||
else
|
||||
{
|
||||
url <- httr::parse_url(endpoint_url)
|
||||
url$path <- path
|
||||
url$path <- URLencode(path)
|
||||
if(!is_empty(options))
|
||||
url$query <- options[order(names(options))]
|
||||
url$query <- options[order(names(options))] # must be sorted for access key signing
|
||||
|
||||
headers <- if(!is.null(key))
|
||||
sign_request(key, verb, url, headers, api_version)
|
||||
else httr::add_headers(.headers=unlist(headers))
|
||||
}
|
||||
# use key if provided, otherwise sas if provided, otherwise anonymous access
|
||||
if(!is.null(key))
|
||||
headers <- sign_request(key, verb, url, headers, api_version)
|
||||
else if(!is.null(sas))
|
||||
url <- add_sas(sas, url)
|
||||
|
||||
headers <- httr::add_headers(.headers=unlist(headers))
|
||||
verb <- get(verb, getNamespace("httr"))
|
||||
|
||||
# do actual http[s] call
|
||||
response <- verb(url, headers, body=body, ...)
|
||||
|
||||
handler <- match.arg(http_status_handler)
|
||||
|
@ -61,18 +54,10 @@ do_storage_call <- function(endpoint_url, path, options=list(), headers=list(),
|
|||
}
|
||||
|
||||
|
||||
storage_error_message <- function(response, for_httr=TRUE)
|
||||
add_sas <- function(sas, url)
|
||||
{
|
||||
cont <- suppressMessages(httr::content(response))
|
||||
msg <- if(inherits(cont, "xml_node"))
|
||||
{
|
||||
cont <- xml2::as_list(cont)
|
||||
paste0(unlist(cont), collapse="\n")
|
||||
}
|
||||
else NULL
|
||||
if(for_httr)
|
||||
paste0("complete Storage Services operation. Message:\n", sub("\\.$", "", msg))
|
||||
else msg
|
||||
full_url <- httr::build_url(url)
|
||||
paste0(full_url, if(is.null(url$query)) "?" else "&", sas)
|
||||
}
|
||||
|
||||
|
||||
|
@ -90,7 +75,7 @@ sign_request <- function(key, verb, url, headers, api)
|
|||
|
||||
sig <- make_signature(key, verb, acct_name, resource, url$query, headers)
|
||||
|
||||
httr::add_headers(Host=url$host, Authorization=sig, .headers=unlist(headers))
|
||||
c(Host=url$host, Authorization=sig, headers)
|
||||
}
|
||||
|
||||
|
||||
|
@ -125,6 +110,21 @@ make_signature <- function(key, verb, acct_name, resource, options, headers)
|
|||
}
|
||||
|
||||
|
||||
storage_error_message <- function(response, for_httr=TRUE)
|
||||
{
|
||||
cont <- suppressMessages(httr::content(response))
|
||||
msg <- if(inherits(cont, "xml_node"))
|
||||
{
|
||||
cont <- xml2::as_list(cont)
|
||||
paste0(unlist(cont), collapse="\n")
|
||||
}
|
||||
else NULL
|
||||
if(for_httr)
|
||||
paste0("complete Storage Services operation. Message:\n", sub("\\.$", "", msg))
|
||||
else msg
|
||||
}
|
||||
|
||||
|
||||
# keep only the scheme and host parts of a URL
|
||||
get_hostroot <- function(url)
|
||||
{
|
||||
|
|
|
@ -44,7 +44,7 @@ rdevstor1
|
|||
# retrieve admin keys
|
||||
rdevstor1$list_keys()
|
||||
|
||||
# create a shared access signature
|
||||
# create a shared access signature (SAS)
|
||||
rdevstor1$get_account_sas()
|
||||
|
||||
# obtain an endpoint object for accessing storage
|
||||
|
@ -74,7 +74,7 @@ bl <- rdevstor1$get_blob_endpoint()
|
|||
# for users without ARM credentials, use the storage_endpoint() function and provide a key
|
||||
bl <- storage_endpoint("https://rdevstor1.blob.core.windows.net", key="/Uq3rxh0lbYErt...")
|
||||
|
||||
# can also provide a SAS: will be used in preference to an access key
|
||||
# can also provide a shared access signature
|
||||
# providing neither a key nor SAS allows only public access
|
||||
bl <- storage_endpoint("https://rdevstor1.blob.core.windows.net", sas="sv=2015-04-05&ss=...")
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ delete_blob_container(endpoint, ...)
|
|||
|
||||
\item{...}{Further arguments passed to lower-level functions.}
|
||||
|
||||
\item{key, sas}{If an endpoint object is not supplied, authentication details. If neither an access key nor a SAS are provided, only public (anonymous) access to the share is possible.}
|
||||
\item{key, sas}{If an endpoint object is not supplied, authentication details. If a key is provided, the SAS is not used. If neither an access key nor a SAS are provided, only public (anonymous) access to the share is possible.}
|
||||
|
||||
\item{api_version}{If an endpoint object is not supplied, the storage API version to use when interacting with the host. Currently defaults to \code{"2017-07-29"}.}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ delete_file_share(endpoint, ...)
|
|||
|
||||
\item{...}{Further arguments passed to lower-level functions.}
|
||||
|
||||
\item{key, sas}{If an endpoint object is not supplied, authentication details. If neither an access key nor a SAS are provided, only public (anonymous) access to the share is possible.}
|
||||
\item{key, sas}{If an endpoint object is not supplied, authentication details. If a key is provided, the SAS is not used. If neither an access key nor a SAS are provided, only public (anonymous) access to the share is possible.}
|
||||
|
||||
\item{api_version}{If an endpoint object is not supplied, the storage API version to use when interacting with the host. Currently defaults to \code{"2017-07-29"}.}
|
||||
|
||||
|
|
|
@ -34,8 +34,6 @@ delete_azure_dir(share, dir, confirm = TRUE)
|
|||
}
|
||||
\value{
|
||||
For \code{list_azure_files}, if \code{all_info=FALSE}, a vector of file/directory names. If \code{all_info=TRUE}, a data frame giving the file size and whether each object is a file or directory.
|
||||
|
||||
For the other functions, NULL on successful completion.
|
||||
}
|
||||
\description{
|
||||
Upload, download, or delete a file; list files in a directory; create or delete directories.
|
||||
|
|
|
@ -12,13 +12,10 @@ upload_to_url(src, dest, ...)
|
|||
\arguments{
|
||||
\item{src, dest}{The source and destination files/URLs. Paths are allowed.}
|
||||
|
||||
\item{...}{Further arguments to pass to lower-level functions. In particular, use \code{key} and/or \code{sas} to supply an access key or SAS. Without a key or SAS, only unauthenticated (anonymous) access is possible.}
|
||||
\item{...}{Further arguments to pass to lower-level functions. In particular, use \code{key} and/or \code{sas} to supply an access key or SAS. Without a key or SAS, only public (anonymous) access is possible.}
|
||||
|
||||
\item{overwrite}{For downloading, whether to overwrite any destination files that exist.}
|
||||
}
|
||||
\value{
|
||||
NULL on successful completion.
|
||||
}
|
||||
\description{
|
||||
Generic upload and download
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ storage_endpoint(endpoint, key = NULL, sas = NULL,
|
|||
|
||||
\item{key}{The access key for the storage account.}
|
||||
|
||||
\item{sas}{A shared access signature for the account. If neither \code{key} nor \code{sas} are provided, only public (anonymous) access to the endpoint is possible.}
|
||||
\item{sas}{A shared access signature (SAS) for the account. If \code{key} is also provided, the SAS is not used. If neither \code{key} nor \code{sas} are provided, only public (anonymous) access to the endpoint is possible.}
|
||||
|
||||
\item{api_version}{The storage API version to use when interacting with the host. Currently defaults to \code{"2017-07-29"}.}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче