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