This commit is contained in:
Hong Ooi 2019-03-15 00:57:28 +11:00
Родитель 9e5973b903
Коммит daa3c40d97
4 изменённых файлов: 51 добавлений и 7 удалений

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

@ -1,3 +1,18 @@
#' Registered app in Azure Active Directory
#'
#' Base class representing an AAD app.
#'
#' @docType class
#' @section Methods:
#' - `new(token, tenant, ...)`: Initialize a new app object. See 'Initialization' below.
#' - `delete(confirm=TRUE)`: Delete an app. By default, ask for confirmation first.
#' - `update(...)`: Update the details for an app.
#' - `sync_fields()`: Synchronise the R object with the app data in Azure Active Directory.
#' - `create_service_principal(...)`: Create a service principal for this app, by default in the current tenant.
#' - `get_service_principal()`: Get the service principal for this app.
#' - `delete_service_principal(confirm=TRUE)`: Delete the service principal for this app. By default, ask for confirmation first.
#'
#' @format An R6 object of class `az_app`.
#' @export
az_app <- R6::R6Class("az_app",

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

@ -4,7 +4,7 @@
#'
#' @docType class
#' @section Methods:
#' - `new(tenant, app, ...)`: Initialize a new ARM connection with the given credentials. See 'Authentication` for more details.
#' - `new(tenant, app, ...)`: Initialize a new Azure AD Graph connection with the given credentials. See 'Authentication` for more details.
#' - `create_app(name, ..., password=NULL, create_service_principal=TRUE)`: Creates a new registered app in Azure Active Directory. By default the app will have a randomly generated strong password with a duration of 1 year, and an associated service principal will also be created.
#' - `get_app(app_id, object_id)`: Retrieves an existing registered app, via either its app ID or object ID.
#' - `delete_app(app_id, object_id, confirm=TRUE)`: Deletes an existing registered app. Any associated service principal will also be deleted.

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

@ -11,7 +11,7 @@
#' @param refresh For `get_graph_login`, whether to refresh the authentication token on loading the client.
#' @param selection For `get_graph_login`, if you have multiple logins for a given tenant, which one to use. This can be a number, or the input MD5 hash of the token used for the login. If not supplied, `get_graph_login` will print a menu and ask you to choose a login.
#' @param confirm For `delete_azure_login`, whether to ask for confirmation before deleting.
#' @param ... Other arguments passed to `az_rm$new()`.
#' @param ... Other arguments passed to `az_graph$new()`.
#'
#' @details
#' `create_graph_login` creates a login client to authenticate with Azure AD Graph, using the supplied arguments. The authentication token is obtained using [get_azure_token], which automatically caches and reuses tokens for subsequent sessions. Note that credentials are only cached if you allowed AzureGraph to create a data directory at package startup.
@ -54,7 +54,7 @@
#' @rdname azure_login
#' @export
create_graph_login <- function(tenant="common", app=.az_cli_app_id, password=NULL, username=NULL, auth_type=NULL,
host="https://management.azure.com/", aad_host="https://login.microsoftonline.com/",
host="https://graph.windows.net/", aad_host="https://login.microsoftonline.com/",
config_file=NULL, ...)
{
if(!is.null(config_file))
@ -87,8 +87,8 @@ create_graph_login <- function(tenant="common", app=.az_cli_app_id, password=NUL
tenant <- normalize_tenant(tenant)
app <- normalize_guid(app)
message("Creating Azure Resource Manager login for ", format_tenant(tenant))
client <- az_rm$new(tenant, app, password, username, auth_type, host, aad_host, config_file, ...)
message("Creating Azure AD Graph login for ", format_tenant(tenant))
client <- az_graph$new(tenant, app, password, username, auth_type, host, aad_host, config_file, ...)
# save login info for future sessions
graph_logins <- load_graph_logins()
@ -149,7 +149,7 @@ get_graph_login <- function(tenant="common", selection=NULL, refresh=TRUE)
message("Loading Azure Resource Manager login for ", format_tenant(tenant))
token <- readRDS(file)
client <- az_rm$new(token=token)
client <- az_graph$new(token=token)
if(refresh)
client$token$refresh()
@ -197,7 +197,7 @@ list_graph_logins <- function()
sapply(tenant, function(hash)
{
file <- file.path(AzureR_dir(), hash)
az_rm$new(token=readRDS(file))
az_graph$new(token=readRDS(file))
}, simplify=FALSE)
}, simplify=FALSE)

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

@ -112,3 +112,32 @@ error_message <- function(cont)
paste0(strwrap(msg), collapse="\n")
}
# same as AzureRMR::named_list, do not export to avoid conflicts
named_list <- function(lst=NULL, name_fields="name")
{
if(is_empty(lst))
return(structure(list(), names=character(0)))
lst_names <- sapply(name_fields, function(n) sapply(lst, `[[`, n))
if(length(name_fields) > 1)
{
dim(lst_names) <- c(length(lst_names) / length(name_fields), length(name_fields))
lst_names <- apply(lst_names, 1, function(nn) paste(nn, collapse="/"))
}
names(lst) <- lst_names
dups <- duplicated(tolower(names(lst)))
if(any(dups))
{
duped_names <- names(lst)[dups]
warning("Some names are duplicated: ", paste(unique(duped_names), collapse=" "), call.=FALSE)
}
lst
}
# handle different behaviour of file_path on Windows/Linux wrt trailing /
construct_path <- function(...)
{
sub("/$", "", file.path(..., fsep="/"))
}