This commit is contained in:
hong-revo 2019-02-13 05:40:54 +11:00
Родитель aa32d3e85a
Коммит 511b71310a
3 изменённых файлов: 18 добавлений и 12 удалений

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

@ -1,6 +1,6 @@
#' Login to Azure Resource Manager #' Login to Azure Resource Manager
#' #'
#' @param tenant The Azure Active Directory tenant for which to obtain a login client. Can be a name ("myaadtenant"), a fully qualified domain name ("myaadtenant.onmicrosoft.com" or "mycompanyname.com"), or a GUID. #' @param tenant The Azure Active Directory tenant for which to obtain a login client. Can be a name ("myaadtenant"), a fully qualified domain name ("myaadtenant.onmicrosoft.com" or "mycompanyname.com"), or a GUID. The default is to login via the "common" tenant, which will infer your actual tenant from your credentials.
#' @param app The client/app ID to use to authenticate with Azure Active Directory. The default is to login interactively using the Azure CLI cross-platform app, but it's recommended to supply your own app credentials if possible. #' @param app The client/app ID to use to authenticate with Azure Active Directory. The default is to login interactively using the Azure CLI cross-platform app, but it's recommended to supply your own app credentials if possible.
#' @param password If `auth_type == "client_credentials"`, the app secret; if `auth_type == "resource_owner"`, your account password. #' @param password If `auth_type == "client_credentials"`, the app secret; if `auth_type == "resource_owner"`, your account password.
#' @param username If `auth_type == "resource_owner"`, your username. #' @param username If `auth_type == "resource_owner"`, your username.
@ -16,7 +16,7 @@
#' @details #' @details
#' `create_azure_login` creates a login client to authenticate with Azure Resource Manager (ARM), using the supplied arguments. The Azure Active Directory (AAD) 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 AzureRMR to create a data directory at package startup. #' `create_azure_login` creates a login client to authenticate with Azure Resource Manager (ARM), using the supplied arguments. The Azure Active Directory (AAD) 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 AzureRMR to create a data directory at package startup.
#' #'
#' `create_azure_login("tenant")` is roughly equivalent to the Azure CLI command `az login` without any arguments. #' `create_azure_login()` without any arguments is roughly equivalent to the Azure CLI command `az login`.
#' #'
#' `get_azure_login` returns a login client by retrieving previously saved credentials. It searches for saved credentials according to the supplied tenant; if multiple logins are found, it will prompt for you to choose one. #' `get_azure_login` returns a login client by retrieving previously saved credentials. It searches for saved credentials according to the supplied tenant; if multiple logins are found, it will prompt for you to choose one.
#' #'
@ -40,6 +40,9 @@
#' @examples #' @examples
#' \dontrun{ #' \dontrun{
#' #'
#' # without any arguments, this will create a client using your AAD credentials
#' az <- create_azure_login()
#'
#' # this will create a Resource Manager client for the AAD tenant 'microsoft.onmicrosoft.com', #' # this will create a Resource Manager client for the AAD tenant 'microsoft.onmicrosoft.com',
#' # using the client_credentials method #' # using the client_credentials method
#' az <- create_azure_login("microsoft", app="{app_id}", password="{password}") #' az <- create_azure_login("microsoft", app="{app_id}", password="{password}")
@ -54,7 +57,7 @@
#' } #' }
#' @rdname azure_login #' @rdname azure_login
#' @export #' @export
create_azure_login <- function(tenant, app=.az_cli_app_id, password=NULL, username=NULL, auth_type=NULL, create_azure_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://management.azure.com/", aad_host="https://login.microsoftonline.com/",
config_file=NULL, ...) config_file=NULL, ...)
{ {
@ -102,7 +105,7 @@ create_azure_login <- function(tenant, app=.az_cli_app_id, password=NULL, userna
#' @rdname azure_login #' @rdname azure_login
#' @export #' @export
get_azure_login <- function(tenant, selection=NULL, refresh=TRUE) get_azure_login <- function(tenant="common", selection=NULL, refresh=TRUE)
{ {
if(!dir.exists(AzureR_dir())) if(!dir.exists(AzureR_dir()))
stop("AzureR data directory does not exist; cannot load saved logins") stop("AzureR data directory does not exist; cannot load saved logins")
@ -156,7 +159,7 @@ get_azure_login <- function(tenant, selection=NULL, refresh=TRUE)
#' @rdname azure_login #' @rdname azure_login
#' @export #' @export
delete_azure_login <- function(tenant, confirm=TRUE) delete_azure_login <- function(tenant="common", confirm=TRUE)
{ {
if(!dir.exists(AzureR_dir())) if(!dir.exists(AzureR_dir()))
{ {

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

@ -26,7 +26,7 @@ library(AzureRMR)
# authenticate with Azure AD: # authenticate with Azure AD:
# - on first login to this client, call create_azure_login() # - on first login to this client, call create_azure_login()
# - on subsequent logins, call get_azure_login() # - on subsequent logins, call get_azure_login()
az <- create_azure_login("myaadtenant") az <- create_azure_login()
# get a subscription and resource group # get a subscription and resource group
sub <- az$get_subscription("{subscription_id}") sub <- az$get_subscription("{subscription_id}")

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

@ -7,20 +7,20 @@
\alias{list_azure_logins} \alias{list_azure_logins}
\title{Login to Azure Resource Manager} \title{Login to Azure Resource Manager}
\usage{ \usage{
create_azure_login(tenant, app = .az_cli_app_id, password = NULL, create_azure_login(tenant = "common", app = .az_cli_app_id,
username = NULL, auth_type = NULL, password = NULL, username = NULL, auth_type = NULL,
host = "https://management.azure.com/", host = "https://management.azure.com/",
aad_host = "https://login.microsoftonline.com/", config_file = NULL, aad_host = "https://login.microsoftonline.com/", config_file = NULL,
...) ...)
get_azure_login(tenant, selection = NULL, refresh = TRUE) get_azure_login(tenant = "common", selection = NULL, refresh = TRUE)
delete_azure_login(tenant, confirm = TRUE) delete_azure_login(tenant = "common", confirm = TRUE)
list_azure_logins() list_azure_logins()
} }
\arguments{ \arguments{
\item{tenant}{The Azure Active Directory tenant for which to obtain a login client. Can be a name ("myaadtenant"), a fully qualified domain name ("myaadtenant.onmicrosoft.com" or "mycompanyname.com"), or a GUID.} \item{tenant}{The Azure Active Directory tenant for which to obtain a login client. Can be a name ("myaadtenant"), a fully qualified domain name ("myaadtenant.onmicrosoft.com" or "mycompanyname.com"), or a GUID. The default is to login via the "common" tenant, which will infer your actual tenant from your credentials.}
\item{app}{The client/app ID to use to authenticate with Azure Active Directory. The default is to login interactively using the Azure CLI cross-platform app, but it's recommended to supply your own app credentials if possible.} \item{app}{The client/app ID to use to authenticate with Azure Active Directory. The default is to login interactively using the Azure CLI cross-platform app, but it's recommended to supply your own app credentials if possible.}
@ -50,7 +50,7 @@ Login to Azure Resource Manager
\details{ \details{
\code{create_azure_login} creates a login client to authenticate with Azure Resource Manager (ARM), using the supplied arguments. The Azure Active Directory (AAD) authentication token is obtained using \link{get_azure_token}, which automatically caches and reuses tokens for subsequent sessions. Note that credentials are only cached if you allowed AzureRMR to create a data directory at package startup. \code{create_azure_login} creates a login client to authenticate with Azure Resource Manager (ARM), using the supplied arguments. The Azure Active Directory (AAD) authentication token is obtained using \link{get_azure_token}, which automatically caches and reuses tokens for subsequent sessions. Note that credentials are only cached if you allowed AzureRMR to create a data directory at package startup.
\code{create_azure_login("tenant")} is roughly equivalent to the Azure CLI command \code{az login} without any arguments. \code{create_azure_login()} without any arguments is roughly equivalent to the Azure CLI command \code{az login}.
\code{get_azure_login} returns a login client by retrieving previously saved credentials. It searches for saved credentials according to the supplied tenant; if multiple logins are found, it will prompt for you to choose one. \code{get_azure_login} returns a login client by retrieving previously saved credentials. It searches for saved credentials according to the supplied tenant; if multiple logins are found, it will prompt for you to choose one.
@ -66,6 +66,9 @@ If the AzureRMR data directory for saving credentials does not exist, \code{get_
\examples{ \examples{
\dontrun{ \dontrun{
# without any arguments, this will create a client using your AAD credentials
az <- create_azure_login()
# this will create a Resource Manager client for the AAD tenant 'microsoft.onmicrosoft.com', # this will create a Resource Manager client for the AAD tenant 'microsoft.onmicrosoft.com',
# using the client_credentials method # using the client_credentials method
az <- create_azure_login("microsoft", app="{app_id}", password="{password}") az <- create_azure_login("microsoft", app="{app_id}", password="{password}")