This commit is contained in:
Alex Kyllo 2022-10-10 23:22:54 -07:00
Родитель 84d66a9fb6
Коммит 54bdefadf0
4 изменённых файлов: 35 добавлений и 25 удалений

Просмотреть файл

@ -305,7 +305,7 @@ AzureTokenCLI <- R6::R6Class("AzureTokenCLI",
resource = self$resource,
tenant = self$tenant
)
result <- execute_az_token_cmd(cmd)
result <- execute_cmd(cmd)
# result is a multi-line JSON string, concatenate together
paste0(result)
},

Просмотреть файл

@ -240,7 +240,7 @@
#'
#' }
#' @export
get_azure_token <- function(resource, tenant, app=NULL, password=NULL, username=NULL, certificate=NULL, auth_type=NULL,
get_azure_token <- function(resource=NULL, tenant=NULL, app=NULL, password=NULL, username=NULL, certificate=NULL, auth_type=NULL,
aad_host="https://login.microsoftonline.com/", version=1,
authorize_args=list(), token_args=list(),
use_cache=NULL, on_behalf_of=NULL, auth_code=NULL, device_creds=NULL)
@ -281,7 +281,7 @@ get_azure_token <- function(resource, tenant, app=NULL, password=NULL, username=
#' @param confirm For `delete_azure_token`, whether to prompt for confirmation before deleting a token.
#' @rdname get_azure_token
#' @export
delete_azure_token <- function(resource, tenant, app=NULL, password=NULL, username=NULL, certificate=NULL, auth_type=NULL,
delete_azure_token <- function(resource=NULL, tenant=NULL, app=NULL, password=NULL, username=NULL, certificate=NULL, auth_type=NULL,
aad_host="https://login.microsoftonline.com/", version=1,
authorize_args=list(), token_args=list(), on_behalf_of=NULL,
hash=NULL, confirm=TRUE)
@ -346,7 +346,7 @@ list_azure_tokens <- function()
#' @rdname get_azure_token
#' @export
token_hash <- function(resource, tenant, app = NULL, password=NULL, username=NULL, certificate=NULL, auth_type=NULL,
token_hash <- function(resource=NULL, tenant=NULL, app=NULL, password=NULL, username=NULL, certificate=NULL, auth_type=NULL,
aad_host="https://login.microsoftonline.com/", version=1,
authorize_args=list(), token_args=list(), on_behalf_of=NULL)
{
@ -413,3 +413,22 @@ is_azure_v2_token <- function(object)
{
is_azure_token(object) && object$version == 2
}
#' @rdname az_login
#' @export
az_login <- function(...)
{
args <- list(...)
cmdargs <- list(command = "az", args = c("login"))
for (arg in names(args))
{
argval <- args[[arg]]
# CLI expects dashes, not underscores
argkey <- gsub("_", "-", arg)
if (is.logical(argval))
cmdargs$args <- c(cmdargs$args, paste0("--", argkey))
else
cmdargs$args <- c(cmdargs$args, paste0("--", argkey, " ", argval))
}
execute_cmd(cmdargs)
}

Просмотреть файл

@ -200,29 +200,11 @@ handle_az_cmd_errors <- function(cond)
}
}
capt <- function(...) {
print(list(...))
print("a" %in% list(...))
}
az_login <- function(command = "az",...)
{
args <- list(...)
cmdargs <- list(command = command, args = c("login"))
for (arg in c("username", "password", "tenant", "scope",
"service_principal", "use_device_code")) {
if (arg %in% names(args))
cmdargs$args <- c(cmdargs$args, paste0("--", arg, " ", args[arg]))
}
cat("Trying to open a web browser to log into Azure CLI...\n")
cat(cmdargs$command, paste(cmdargs$args), "\n")
do.call(system2, cmdargs)
}
execute_az_token_cmd <- function(cmd)
execute_cmd <- function(cmd)
{
tryCatch(
{
cat(cmd$command, paste(cmd$args), "\n")
result <- do.call(system2, append(cmd, list(stdout = TRUE)))
# result is a multi-line JSON string, concatenate together
paste0(result)
@ -237,4 +219,4 @@ execute_az_token_cmd <- function(cmd)
handle_az_cmd_errors(cond$message)
}
)
}
}

Просмотреть файл

@ -108,6 +108,15 @@ tok2 <- get_azure_token("resource2", "mytenant," "serviceapp_id",
password="serviceapp_secret", auth_type="on_behalf_of", on_behalf_of=tok0)
```
6. The **cli** method uses the
[Azure CLI](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli)
command `az account get-access-token` to retrieve an auth token. It is mostly
useful for interactive programming.
```r
get_azure_token(auth_type="cli")
```
If you don't specify the method, `get_azure_token` makes a best guess based on the presence or absence of the other authentication arguments, and whether httpuv is installed.
```r