зеркало из https://github.com/Azure/AzureRMR.git
resource manager now, not service manager
This commit is contained in:
Родитель
6d585baaa9
Коммит
dbb5764c57
|
@ -4,5 +4,5 @@ export(AzureToken)
|
|||
export(az_context)
|
||||
export(az_resource_group)
|
||||
export(az_subscription)
|
||||
export(call_azure_sm)
|
||||
export(call_azure_rm)
|
||||
export(get_azure_token)
|
||||
|
|
19
R/az_auth.R
19
R/az_auth.R
|
@ -8,7 +8,6 @@ public=list(
|
|||
host=NULL,
|
||||
tenant=NULL,
|
||||
subscriptions=NULL,
|
||||
auth_type=NULL,
|
||||
token=NULL,
|
||||
|
||||
# authenticate and get subscriptions
|
||||
|
@ -18,7 +17,7 @@ public=list(
|
|||
{
|
||||
if(!is.null(config_file))
|
||||
{
|
||||
conf <- jsonlite::fromJSON(config_file)
|
||||
conf <- jsonlite::fromJSON(file(config_file))
|
||||
if(!is.null(conf$tenant)) tenant <- conf$tenant
|
||||
if(!is.null(conf$app)) app <- conf$app
|
||||
if(!is.null(conf$auth_type)) auth_type <- conf$auth_type
|
||||
|
@ -29,8 +28,7 @@ public=list(
|
|||
|
||||
self$host <- host
|
||||
self$tenant <- tenant
|
||||
self$auth_type <- match.arg(auth_type)
|
||||
self$token <- get_azure_token(aad_host, tenant, app, self$auth_type, secret, host)
|
||||
self$token <- get_azure_token(aad_host, tenant, app, match.arg(auth_type), secret, host)
|
||||
|
||||
private$set_subslist()
|
||||
NULL
|
||||
|
@ -39,7 +37,7 @@ public=list(
|
|||
# return a subscription object
|
||||
get_subscription=function(subscription)
|
||||
{
|
||||
if(is.null(self$subscriptions))
|
||||
if(is_empty(self$subscriptions))
|
||||
stop("No subscriptions associated with this app")
|
||||
if(is.numeric(subscription))
|
||||
subscription <- self$subscriptions[subscription]
|
||||
|
@ -52,15 +50,12 @@ private=list(
|
|||
# obtain subscription IDs owned by this app
|
||||
set_subslist=function()
|
||||
{
|
||||
cont <- call_azure_sm(self$token, subscription="", operation="")
|
||||
cont <- call_azure_rm(self$token, subscription="", operation="")
|
||||
self$subscriptions <- vapply(cont$value, `[[`, "subscriptionId", FUN.VALUE=character(1))
|
||||
|
||||
df <- lapply(cont$value, data.frame, stringsAsFactors=FALSE)
|
||||
df <- do.call(rbind, df)
|
||||
|
||||
# update subscription IDs; notify if more than one found
|
||||
if(length(df$subscriptionId) > 1)
|
||||
# notify if more than one subscription ID found
|
||||
if(length(self$subscriptions) > 1)
|
||||
message("Note: more than one subscription ID for this application")
|
||||
self$subscriptions <- df$subscriptionId
|
||||
NULL
|
||||
}
|
||||
))
|
||||
|
|
|
@ -9,7 +9,7 @@ public=list(
|
|||
managed_by=NULL,
|
||||
properties=NULL,
|
||||
tags=NULL,
|
||||
resources=NA, # NULL = no resources, NA = not yet populated
|
||||
resources=NULL, # char() = no resources, NULL = not yet populated
|
||||
token=NULL,
|
||||
|
||||
initialize=function(token, subscription, name) # TODO: also allow initialisation with explicit data args
|
||||
|
@ -19,7 +19,7 @@ public=list(
|
|||
self$name <- name
|
||||
|
||||
op <- paste0("resourcegroups/", self$name)
|
||||
cont <- call_azure_sm(self$token, self$subscription, op)
|
||||
cont <- call_azure_rm(self$token, self$subscription, op)
|
||||
self$id <- cont$id
|
||||
self$location <- cont$location
|
||||
self$managed_by <- cont$managedBy
|
||||
|
@ -31,6 +31,7 @@ public=list(
|
|||
},
|
||||
|
||||
create_resource=function(...) { },
|
||||
update_resource=function(...) { },
|
||||
get_resource=function(...) { },
|
||||
delete_resource=function(...) { },
|
||||
list_resources=function() { }
|
||||
|
@ -41,7 +42,7 @@ private=list(
|
|||
set_reslist=function()
|
||||
{
|
||||
op <- paste0("resourcegroups/", self$name, "/resources")
|
||||
cont <- call_azure_sm(self$token, self$subscription, op)
|
||||
cont <- call_azure_rm(self$token, self$subscription, op)
|
||||
self$resources <- sapply(cont$value, `[[`, "name")
|
||||
NULL
|
||||
}
|
||||
|
|
|
@ -9,14 +9,14 @@ public=list(
|
|||
state=NULL,
|
||||
policies=NULL,
|
||||
authorization_source=NULL,
|
||||
resource_groups=NA, # NULL = no resource groups, NA = not yet populated
|
||||
resource_groups=NULL, # char() = no resource groups, NULL = not yet populated
|
||||
token=NULL,
|
||||
|
||||
initialize=function(token, id)
|
||||
{
|
||||
self$token <- token
|
||||
self$id <- id
|
||||
info <- call_azure_sm(token, id, "")
|
||||
info <- call_azure_rm(token, id, "")
|
||||
self$name <- info$displayName
|
||||
self$state <- info$state
|
||||
self$policies <- info$subscriptionPolicies
|
||||
|
@ -29,7 +29,7 @@ public=list(
|
|||
# return a resource group object
|
||||
get_resource_group=function(resource_group)
|
||||
{
|
||||
if(is.null(self$resource_groups))
|
||||
if(is_empty(self$resource_groups))
|
||||
stop("No resource groups associated with this subscription")
|
||||
if(is.numeric(resource_group))
|
||||
resource_group <- self$resource_groups[resource_group]
|
||||
|
@ -37,6 +37,7 @@ public=list(
|
|||
},
|
||||
|
||||
create_resource_group=function(resource_group) { },
|
||||
update_resource_group=function(resource_group) { },
|
||||
delete_resource_group=function(resource_group) { },
|
||||
list_resource_groups=function() { },
|
||||
list_resources=function() { }
|
||||
|
@ -46,8 +47,8 @@ private=list(
|
|||
|
||||
set_rglist=function()
|
||||
{
|
||||
cont <- call_azure_sm(self$token, self$id, "resourcegroups")
|
||||
self$resource_groups <- sapply(cont$value, `[[`, "name")
|
||||
cont <- call_azure_rm(self$token, self$id, "resourcegroups")
|
||||
self$resource_groups <- vapply(cont$value, `[[`, "name", FUN.VALUE=character(1))
|
||||
NULL
|
||||
}
|
||||
))
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#' @export
|
||||
call_azure_sm <- function(token, subscription, operation, ...,
|
||||
call_azure_rm <- function(token, subscription, operation, ...,
|
||||
http_verb=c("GET", "DELETE", "PUT", "POST", "HEAD"),
|
||||
http_condition_handler=c("stop", "warn", "message", "pass"),
|
||||
api_version=getOption("azure_api_version"),
|
||||
|
@ -34,3 +34,10 @@ call_azure_sm <- function(token, subscription, operation, ...,
|
|||
}
|
||||
httr::content(res, as="parsed")
|
||||
}
|
||||
|
||||
|
||||
# TRUE for NULL and length-0 objects
|
||||
is_empty <- function(x)
|
||||
{
|
||||
length(x) == 0
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче