зеркало из https://github.com/Azure/AzureRMR.git
tests passing
This commit is contained in:
Родитель
837fa0a18a
Коммит
b231ebc60f
|
@ -1,6 +1,6 @@
|
|||
# Generated by roxygen2: do not edit by hand
|
||||
|
||||
export(AzureRMR_dir)
|
||||
export(AzureR_dir)
|
||||
export(az_resource)
|
||||
export(az_resource_group)
|
||||
export(az_rm)
|
||||
|
|
34
R/AzureRMR.R
34
R/AzureRMR.R
|
@ -8,7 +8,7 @@ NULL
|
|||
azure_api_version="2018-05-01"
|
||||
options(azure_api_version=azure_api_version)
|
||||
|
||||
make_AzureRMR_dir()
|
||||
make_AzureR_dir()
|
||||
|
||||
invisible(NULL)
|
||||
}
|
||||
|
@ -19,40 +19,18 @@ NULL
|
|||
|
||||
|
||||
# create a directory for saving creds -- ask first, to satisfy CRAN requirements
|
||||
make_AzureRMR_dir <- function()
|
||||
make_AzureR_dir <- function()
|
||||
{
|
||||
AzureRMR_dir <- AzureRMR_dir()
|
||||
if(!dir.exists(AzureRMR_dir) && interactive())
|
||||
AzureR_dir <- AzureR_dir()
|
||||
if(!dir.exists(AzureR_dir) && interactive())
|
||||
{
|
||||
yn <- readline(paste0(
|
||||
"AzureRMR can cache Azure Resource Manager logins in the directory:\n\n",
|
||||
AzureRMR_dir, "\n\n",
|
||||
AzureR_dir, "\n\n",
|
||||
"This saves you having to re-authenticate with Azure in future sessions. Create this directory? (Y/n) "))
|
||||
if(tolower(substr(yn, 1, 1)) == "n")
|
||||
return(invisible(NULL))
|
||||
|
||||
dir.create(AzureRMR_dir, recursive=TRUE)
|
||||
dir.create(AzureR_dir, recursive=TRUE)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#' Data directory for AzureRMR
|
||||
#'
|
||||
#' @details
|
||||
#' AzureRMR can store authentication credentials and OAuth tokens in a user-specific directory, using the rappdirs package. On recent Windows versions, this will usually be in the location `C:\\Users\\(username)\\AppData\\Local\\AzureR\\AzureRMR`. On Unix/Linux, it will be in `~/.local/share/AzureRMR`, and on MacOS, it will be in `~/Library/Application Support/AzureRMR`. The working directory is not touched (which significantly lessens the risk of accidentally introducing cached tokens into source control).
|
||||
#'
|
||||
#' On package startup, if this directory does not exist, AzureRMR will prompt you for permission to create it. It's recommended that you allow the directory to be created, as otherwise you will have to reauthenticate with Azure every time. Note that many cloud engineering tools, including the [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/?view=azure-cli-latest), save authentication credentials in this way.
|
||||
#'
|
||||
#' @return
|
||||
#' A string containing the data directory.
|
||||
#'
|
||||
#' @seealso
|
||||
#' [get_azure_token], [get_azure_login]
|
||||
#'
|
||||
#' [rappdirs::user_data_dir]
|
||||
#'
|
||||
#' @export
|
||||
AzureRMR_dir <- function()
|
||||
{
|
||||
rappdirs::user_data_dir(appname="AzureRMR", appauthor="AzureR", roaming=FALSE)
|
||||
}
|
||||
|
|
20
R/az_login.R
20
R/az_login.R
|
@ -91,7 +91,7 @@ create_azure_login <- function(tenant, app=.az_cli_app_id, password=NULL, userna
|
|||
if(!is.null(conf$aad_host)) aad_host <- conf$aad_host
|
||||
}
|
||||
|
||||
hash <- token_hash_from_original_args(
|
||||
hash <- token_hash(
|
||||
resource=host,
|
||||
tenant=tenant,
|
||||
app=app,
|
||||
|
@ -100,7 +100,7 @@ create_azure_login <- function(tenant, app=.az_cli_app_id, password=NULL, userna
|
|||
auth_type=auth_type,
|
||||
aad_host=aad_host
|
||||
)
|
||||
tokenfile <- file.path(AzureRMR_dir(), hash)
|
||||
tokenfile <- file.path(AzureR_dir(), hash)
|
||||
if(file.exists(tokenfile))
|
||||
{
|
||||
message("Deleting existing Azure Active Directory token for this set of credentials")
|
||||
|
@ -126,7 +126,7 @@ create_azure_login <- function(tenant, app=.az_cli_app_id, password=NULL, userna
|
|||
#' @export
|
||||
get_azure_login <- function(tenant, selection=NULL, refresh=TRUE)
|
||||
{
|
||||
if(!dir.exists(AzureRMR_dir()))
|
||||
if(!dir.exists(AzureR_dir()))
|
||||
stop("AzureRMR data directory does not exist; cannot load saved logins")
|
||||
|
||||
tenant <- normalize_tenant(tenant)
|
||||
|
@ -142,7 +142,7 @@ get_azure_login <- function(tenant, selection=NULL, refresh=TRUE)
|
|||
else if(is.null(selection))
|
||||
{
|
||||
tokens <- lapply(this_login, function(f)
|
||||
readRDS(file.path(AzureRMR_dir(), f)))
|
||||
readRDS(file.path(AzureR_dir(), f)))
|
||||
|
||||
choices <- sapply(tokens, function(token)
|
||||
{
|
||||
|
@ -169,7 +169,7 @@ get_azure_login <- function(tenant, selection=NULL, refresh=TRUE)
|
|||
else if(is.character(selection))
|
||||
this_login[which(this_login == selection)] # force an error if supplied hash doesn't match available logins
|
||||
|
||||
file <- file.path(AzureRMR_dir(), file)
|
||||
file <- file.path(AzureR_dir(), file)
|
||||
if(is_empty(file) || !file.exists(file))
|
||||
stop("Azure Active Directory token not found for this login", call.=FALSE)
|
||||
|
||||
|
@ -188,7 +188,7 @@ get_azure_login <- function(tenant, selection=NULL, refresh=TRUE)
|
|||
#' @export
|
||||
delete_azure_login <- function(tenant, confirm=TRUE)
|
||||
{
|
||||
if(!dir.exists(AzureRMR_dir()))
|
||||
if(!dir.exists(AzureR_dir()))
|
||||
{
|
||||
warning("AzureRMR data directory does not exist; no logins to delete")
|
||||
return(invisible(NULL))
|
||||
|
@ -221,7 +221,7 @@ list_azure_logins <- function()
|
|||
{
|
||||
sapply(tenant, function(hash)
|
||||
{
|
||||
file <- file.path(AzureRMR_dir(), hash)
|
||||
file <- file.path(AzureR_dir(), hash)
|
||||
az_rm$new(token=readRDS(file))
|
||||
}, simplify=FALSE)
|
||||
}, simplify=FALSE)
|
||||
|
@ -232,7 +232,7 @@ list_azure_logins <- function()
|
|||
|
||||
load_arm_logins <- function()
|
||||
{
|
||||
file <- file.path(AzureRMR_dir(), "arm_logins.json")
|
||||
file <- file.path(AzureR_dir(), "arm_logins.json")
|
||||
if(!file.exists(file))
|
||||
return(structure(list(), names=character(0)))
|
||||
jsonlite::fromJSON(file)
|
||||
|
@ -241,7 +241,7 @@ load_arm_logins <- function()
|
|||
|
||||
save_arm_logins <- function(logins)
|
||||
{
|
||||
if(!dir.exists(AzureRMR_dir()))
|
||||
if(!dir.exists(AzureR_dir()))
|
||||
{
|
||||
message("AzureRMR data directory does not exist; login credentials not saved")
|
||||
return(invisible(NULL))
|
||||
|
@ -250,7 +250,7 @@ save_arm_logins <- function(logins)
|
|||
if(is_empty(logins))
|
||||
names(logins) <- character(0)
|
||||
|
||||
file <- file.path(AzureRMR_dir(), "arm_logins.json")
|
||||
file <- file.path(AzureR_dir(), "arm_logins.json")
|
||||
writeLines(jsonlite::toJSON(logins, auto_unbox=TRUE, pretty=TRUE), file)
|
||||
invisible(NULL)
|
||||
}
|
||||
|
|
|
@ -15,3 +15,6 @@ AzureAuth::is_guid
|
|||
|
||||
#' @export
|
||||
AzureAuth::list_azure_tokens
|
||||
|
||||
#' @export
|
||||
AzureAuth::AzureR_dir
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/AzureRMR.R
|
||||
\name{AzureRMR_dir}
|
||||
\alias{AzureRMR_dir}
|
||||
\title{Data directory for AzureRMR}
|
||||
\usage{
|
||||
AzureRMR_dir()
|
||||
}
|
||||
\value{
|
||||
A string containing the data directory.
|
||||
}
|
||||
\description{
|
||||
Data directory for AzureRMR
|
||||
}
|
||||
\details{
|
||||
AzureRMR can store authentication credentials and OAuth tokens in a user-specific directory, using the rappdirs package. On recent Windows versions, this will usually be in the location \code{C:\\Users\\(username)\\AppData\\Local\\AzureR\\AzureRMR}. On Unix/Linux, it will be in \code{~/.local/share/AzureRMR}, and on MacOS, it will be in \code{~/Library/Application Support/AzureRMR}. The working directory is not touched (which significantly lessens the risk of accidentally introducing cached tokens into source control).
|
||||
|
||||
On package startup, if this directory does not exist, AzureRMR will prompt you for permission to create it. It's recommended that you allow the directory to be created, as otherwise you will have to reauthenticate with Azure every time. Note that many cloud engineering tools, including the \href{https://docs.microsoft.com/en-us/cli/azure/?view=azure-cli-latest}{Azure CLI}, save authentication credentials in this way.
|
||||
}
|
||||
\seealso{
|
||||
\link{get_azure_token}, \link{get_azure_login}
|
||||
|
||||
\link[rappdirs:user_data_dir]{rappdirs::user_data_dir}
|
||||
}
|
|
@ -9,6 +9,7 @@
|
|||
\alias{is_azure_token}
|
||||
\alias{is_guid}
|
||||
\alias{list_azure_tokens}
|
||||
\alias{AzureR_dir}
|
||||
\title{Objects exported from other packages}
|
||||
\keyword{internal}
|
||||
\description{
|
||||
|
@ -16,6 +17,6 @@ These objects are imported from other packages. Follow the links
|
|||
below to see their documentation.
|
||||
|
||||
\describe{
|
||||
\item{AzureAuth}{\code{\link[AzureAuth]{clean_token_directory}}, \code{\link[AzureAuth]{delete_azure_token}}, \code{\link[AzureAuth]{get_azure_token}}, \code{\link[AzureAuth]{is_azure_token}}, \code{\link[AzureAuth]{is_guid}}, \code{\link[AzureAuth]{list_azure_tokens}}}
|
||||
\item{AzureAuth}{\code{\link[AzureAuth]{clean_token_directory}}, \code{\link[AzureAuth]{delete_azure_token}}, \code{\link[AzureAuth]{get_azure_token}}, \code{\link[AzureAuth]{is_azure_token}}, \code{\link[AzureAuth]{is_guid}}, \code{\link[AzureAuth]{list_azure_tokens}}, \code{\link[AzureAuth]{AzureR_dir}}}
|
||||
}}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ if(!interactive())
|
|||
|
||||
test_that("Authentication works",
|
||||
{
|
||||
suppressWarnings(file.remove(dir(AzureRMR:::AzureRMR_dir(), full.names=TRUE)))
|
||||
suppressWarnings(file.remove(dir(AzureR_dir(), full.names=TRUE)))
|
||||
|
||||
res <- "https://management.azure.com/"
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче