Export read.AzureSMR.config() and enable reading settings file in createAzureContext() #70

This commit is contained in:
Andrie de Vries 2017-06-06 12:15:23 -04:00
Родитель 66565d57c6
Коммит 51f14ba02d
5 изменённых файлов: 32 добавлений и 16 удалений

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

@ -57,6 +57,7 @@ export(azureVMStatus)
export(createAzureContext)
export(dumpAzureContext)
export(is.azureActiveContext)
export(read.AzureSMR.config)
export(setAzureContext)
importFrom(XML,htmlParse)
importFrom(XML,xmlValue)

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

@ -7,19 +7,30 @@
#' @inheritParams setAzureContext
#' @family azureActiveContext functions
#'
#' @seealso [setAzureContext()], [azureAuthenticate()]
#' @seealso [setAzureContext()], [azureAuthenticate()], [read.AzureSMR.config)]
#' @return An `azureActiveContext` object
#' @export
createAzureContext <- function(tenantID, clientID, authKey){
createAzureContext <- function(tenantID, clientID, authKey, configFile){
azEnv <- new.env(parent = emptyenv())
azEnv <- as.azureActiveContext(azEnv)
if (!missing(tenantID)) azEnv$tenantID <- tenantID else azEnv$tenantID <- "?"
if (!missing(clientID)) azEnv$clientID <- clientID else azEnv$tenantID <- "?"
if (!missing(authKey)) azEnv$authKey <- authKey else azEnv$tenantID <- "?"
list2env(
list(tenantID = "", clientID = "", authKey = ""),
envir = azEnv
)
if (!missing(configFile)) {
config <- read.AzureSMR.config(configFile)
list2env(config, envir = azEnv)
azureAuthenticate(azEnv)
} else {
if (!missing(tenantID)) azEnv$tenantID <- tenantID
if (!missing(clientID)) azEnv$clientID <- clientID
if (!missing(authKey)) azEnv$authKey <- authKey
if (!missing(tenantID) && !missing(clientID) && !missing(authKey)) {
azureAuthenticate(azEnv)
}
}
if (!missing(tenantID) && !missing(clientID) && !missing(authKey) )
azureAuthenticate(azEnv,tenantID, clientID, authKey)
return(azEnv)
}

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

@ -64,7 +64,6 @@ azureSAGetKey <- function(azureActiveContext, storageAccount,
rl <- content(r, "text", encoding = "UTF-8")
df <- fromJSON(rl)
azureActiveContext$storageAccount <- storageAccount
azureActiveContext$storageAccountK <- storageAccount
azureActiveContext$resourceGroup <- resourceGroup
azureActiveContext$storageKey <- df$keys$value[1]

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

@ -1,14 +1,17 @@
# Reads settings from configuration file in JSON format.
#' Reads settings from configuration file in JSON format.
#'
#' @param config location of file that contains configuration in JSON format
#' @export
#
# @param config location of file that contains configuration in JSON format
#
read.AzureSMR.config <- function(config = getOption("AzureSMR.config")){
z <- tryCatch(fromJSON(file(config)),
read.AzureSMR.config <- function(configFile = getOption("AzureSMR.config")) {
assert_that(is.character(configFile))
assert_that(file.exists(configFile))
z <- tryCatch(fromJSON(file(configFile)),
error = function(e)e
)
# Error check the settings file for invalid JSON
if(inherits(z, "error")) {
msg <- sprintf("Your config file contains invalid json", config)
msg <- sprintf("Your config file contains invalid json", configFile)
msg <- paste(msg, z$message, sep = "\n\n")
stop(msg, call. = FALSE)
}

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

@ -4,7 +4,7 @@
\alias{createAzureContext}
\title{Create an Azure Context.}
\usage{
createAzureContext(tenantID, clientID, authKey)
createAzureContext(tenantID, clientID, authKey, configFile)
}
\arguments{
\item{tenantID}{The Tenant ID provided during creation of the Active Directory application / service principal}
@ -23,7 +23,9 @@ Create a container (\code{azureActiveContext}) for holding variables used by the
See the Azure documentation (\url{https://azure.microsoft.com/en-us/documentation/articles/resource-group-create-service-principal-portal/}) for information to configure an Active Directory application.
}
\seealso{
\code{\link[=setAzureContext]{setAzureContext()}}, \code{\link[=azureAuthenticate]{azureAuthenticate()}}
\code{\link[=setAzureContext]{setAzureContext()}}, \code{\link[=azureAuthenticate]{azureAuthenticate()}}, [read.AzureSMR.config)]
[read.AzureSMR.config)]: R:read.AzureSMR.config)
Other azureActiveContext functions: \code{\link{setAzureContext}}
}