From 0dde061ff219dbc6847cb14ff882e55117bc70b3 Mon Sep 17 00:00:00 2001 From: Hong Ooi Date: Sun, 24 Mar 2019 22:47:59 +1100 Subject: [PATCH] class-specific do_operation --- R/az_app.r | 10 +++++----- R/az_group.R | 7 +++---- R/az_object.R | 22 ++++++++++------------ R/az_svc_principal.R | 1 + R/az_user.R | 15 ++++++--------- man/az_app.Rd | 1 + man/az_group.Rd | 1 + man/az_object.Rd | 1 + man/az_service_principal.Rd | 1 + man/az_user.Rd | 1 + 10 files changed, 30 insertions(+), 30 deletions(-) diff --git a/R/az_app.r b/R/az_app.r index bae5696..c236169 100644 --- a/R/az_app.r +++ b/R/az_app.r @@ -13,6 +13,7 @@ #' - `new(...)`: Initialize a new app object. Do not call this directly; see 'Initialization' below. #' - `delete(confirm=TRUE)`: Delete an app. By default, ask for confirmation first. #' - `update(...)`: Update the app data in Azure Active Directory. For what properties can be updated, consult the REST API documentation link below. +#' - `do_operation(...)`: Carry out an arbitrary operation on the app. #' - `sync_fields()`: Synchronise the R object with the app data in Azure Active Directory. #' - `list_group_memberships()`: Return the IDs of all groups this app is a member of. #' - `list_object_memberships()`: Return the IDs of all groups, administrative units and directory roles this app is a member of. @@ -96,9 +97,8 @@ public=list( )) ) - op <- file.path("applications", self$properties$id) - self$graph_op(op, body=properties, encode="json", http_verb="PATCH") - self$properties <- self$graph_op(op) + self$do_operation(body=properties, encode="json", http_verb="PATCH") + self$properties <- self$do_operation() self$password <- password password }, @@ -109,7 +109,7 @@ public=list( az_service_principal$new( self$token, self$tenant, - self$graph_op("servicePrincipals", body=properties, encode="json", http_verb="POST") + call_graph_endpoint(self$token, "servicePrincipals", body=properties, encode="json", http_verb="POST") ) }, @@ -119,7 +119,7 @@ public=list( az_service_principal$new( self$token, self$tenant, - self$graph_op(op)$value[[1]] + call_graph_endpoint(self$token, op)$value[[1]] ) }, diff --git a/R/az_group.R b/R/az_group.R index 8d7cff9..1e5a094 100644 --- a/R/az_group.R +++ b/R/az_group.R @@ -12,6 +12,7 @@ #' - `new(...)`: Initialize a new group object. Do not call this directly; see 'Initialization' below. #' - `delete(confirm=TRUE)`: Delete a group. By default, ask for confirmation first. #' - `update(...)`: Update the group information in Azure Active Directory. +#' - `do_operation(...)`: Carry out an arbitrary operation on the group. #' - `sync_fields()`: Synchronise the R object with the app data in Azure Active Directory. #' - `list_group_memberships()`: Return the IDs of all groups this group is a member of. #' - `list_object_memberships()`: Return the IDs of all groups, administrative units and directory roles this group is a member of. @@ -54,15 +55,13 @@ public=list( list_members=function(type=c("user", "group", "application", "servicePrincipal")) { - op <- file.path("groups", self$properties$id, "members") - res <- private$get_paged_list(self$graph_op(op)) + res <- private$get_paged_list(self$do_operation("members")) private$init_list_objects(private$filter_list(res, type)) }, list_owners=function(type=c("user", "group", "application", "servicePrincipal")) { - op <- file.path("groups", self$properties$id, "owners") - res <- private$get_paged_list(self$graph_op(op)) + res <- private$get_paged_list(self$do_operation("owners")) private$init_list_objects(private$filter_list(res, type)) }, diff --git a/R/az_object.R b/R/az_object.R index 699a03a..d9b242b 100644 --- a/R/az_object.R +++ b/R/az_object.R @@ -12,6 +12,7 @@ #' - `new(...)`: Initialize a new directory object. Do not call this directly; see 'Initialization' below. #' - `delete(confirm=TRUE)`: Delete an object. By default, ask for confirmation first. #' - `update(...)`: Update the object information in Azure Active Directory. +#' - `do_operation(...)`: Carry out an arbitrary operation on the object. #' - `sync_fields()`: Synchronise the R object with the data in Azure Active Directory. #' - `list_group_memberships()`: Return the IDs of all groups this object is a member of. #' - `list_object_memberships()`: Return the IDs of all groups, administrative units and directory roles this object is a member of. @@ -47,16 +48,14 @@ public=list( update=function(...) { - op <- file.path(private$get_endpoint(), self$properties$id) - self$graph_op(op, body=list(...), encode="json", http_verb="PATCH") - self$properties <- self$graph_op(op) + self$do_operation(body=list(...), encode="json", http_verb="PATCH") + self$properties <- self$do_operation() self }, sync_fields=function() { - op <- file.path(private$get_endpoint(), self$properties$id) - self$properties <- self$graph_op(op) + self$properties <- self$do_operation() invisible(self) }, @@ -71,15 +70,13 @@ public=list( return(invisible(NULL)) } - op <- file.path(private$get_endpoint(), self$properties$id) - self$graph_op(op, http_verb="DELETE") + self$do_operation(http_verb="DELETE") invisible(NULL) }, list_object_memberships=function() { - op <- file.path(private$get_endpoint(), self$properties$id, "getMemberObjects") - lst <- self$graph_op(op, body=list(securityEnabledOnly=TRUE), + lst <- self$do_operation("getMemberObjects", body=list(securityEnabledOnly=TRUE), encode="json", http_verb="POST") unlist(private$get_paged_list(lst)) @@ -87,15 +84,15 @@ public=list( list_group_memberships=function() { - op <- file.path(private$get_endpoint(), self$properties$id, "getMemberGroups") - lst <- self$graph_op(op, body=list(securityEnabledOnly=TRUE), + lst <- self$do_operation("getMemberGroups", body=list(securityEnabledOnly=TRUE), encode="json", http_verb="POST") unlist(private$get_paged_list(lst)) }, - graph_op=function(op="", ...) + do_operation=function(op="", ...) { + op <- construct_path(private$get_endpoint(), self$properties$id, op) call_graph_endpoint(self$token, op, ...) }, @@ -154,6 +151,7 @@ private=list( "group"="groups", "application"="applications", "service principal"="servicePrincipals", + "device"="devices", stop("Unknown directory object type")) } )) diff --git a/R/az_svc_principal.R b/R/az_svc_principal.R index a668158..f9ebca6 100644 --- a/R/az_svc_principal.R +++ b/R/az_svc_principal.R @@ -12,6 +12,7 @@ #' - `new(...)`: Initialize a new service principal object. Do not call this directly; see 'Initialization' below. #' - `delete(confirm=TRUE)`: Delete a service principal. By default, ask for confirmation first. #' - `update(...)`: Update the service principal information in Azure Active Directory. +#' - `do_operation(...)`: Carry out an arbitrary operation on the service principal. #' - `sync_fields()`: Synchronise the R object with the service principal data in Azure Active Directory. #' - `list_group_memberships()`: Return the IDs of all groups this service principal is a member of. #' - `list_object_memberships()`: Return the IDs of all groups, administrative units and directory roles this service principal is a member of. diff --git a/R/az_user.R b/R/az_user.R index 3e4276b..d3e3b56 100644 --- a/R/az_user.R +++ b/R/az_user.R @@ -12,6 +12,7 @@ #' - `new(...)`: Initialize a new user object. Do not call this directly; see 'Initialization' below. #' - `delete(confirm=TRUE)`: Delete a user account. By default, ask for confirmation first. #' - `update(...)`: Update the user information in Azure Active Directory. +#' - `do_operation(...)`: Carry out an arbitrary operation on the user account. #' - `sync_fields()`: Synchronise the R object with the app data in Azure Active Directory. #' - `list_group_memberships()`: Return the IDs of all groups this user is a member of. #' - `list_object_memberships()`: Return the IDs of all groups, administrative units and directory roles this user is a member of. @@ -78,31 +79,27 @@ public=list( ) )) - op <- file.path("users", self$properties$id) - self$graph_op(op, body=properties, encode="json", http_verb="PATCH") - self$properties <- self$graph_op(op) + self$do_operation(body=properties, encode="json", http_verb="PATCH") + self$properties <- self$do_operation() self$password <- password password }, list_owned_objects=function(type=c("user", "group", "application", "servicePrincipal")) { - op <- file.path("users", self$properties$id, "ownedObjects") - res <- private$get_paged_list(self$graph_op(op)) + res <- private$get_paged_list(self$do_operation("ownedObjects")) private$init_list_objects(private$filter_list(res, type)) }, list_created_objects=function(type=c("user", "group", "application", "servicePrincipal")) { - op <- file.path("users", self$properties$id, "createdObjects") - res <- private$get_paged_list(self$graph_op(op)) + res <- private$get_paged_list(self$do_operation("createdObjects")) private$init_list_objects(private$filter_list(res, type)) }, list_direct_memberships=function(id_only=TRUE) { - op <- file.path("users", self$properties$id, "memberOf") - res <- private$get_paged_list(self$graph_op(op)) + res <- private$get_paged_list(self$do_operation("memberOf")) if(id_only) sapply(res, function(grp) grp$id) diff --git a/man/az_app.Rd b/man/az_app.Rd index 7768986..a829ef4 100644 --- a/man/az_app.Rd +++ b/man/az_app.Rd @@ -28,6 +28,7 @@ Base class representing an AAD app. \item \code{new(...)}: Initialize a new app object. Do not call this directly; see 'Initialization' below. \item \code{delete(confirm=TRUE)}: Delete an app. By default, ask for confirmation first. \item \code{update(...)}: Update the app data in Azure Active Directory. For what properties can be updated, consult the REST API documentation link below. +\item \code{do_operation(...)}: Carry out an arbitrary operation on the app. \item \code{sync_fields()}: Synchronise the R object with the app data in Azure Active Directory. \item \code{list_group_memberships()}: Return the IDs of all groups this app is a member of. \item \code{list_object_memberships()}: Return the IDs of all groups, administrative units and directory roles this app is a member of. diff --git a/man/az_group.Rd b/man/az_group.Rd index b4f8165..3345415 100644 --- a/man/az_group.Rd +++ b/man/az_group.Rd @@ -27,6 +27,7 @@ Base class representing an AAD group. \item \code{new(...)}: Initialize a new group object. Do not call this directly; see 'Initialization' below. \item \code{delete(confirm=TRUE)}: Delete a group. By default, ask for confirmation first. \item \code{update(...)}: Update the group information in Azure Active Directory. +\item \code{do_operation(...)}: Carry out an arbitrary operation on the group. \item \code{sync_fields()}: Synchronise the R object with the app data in Azure Active Directory. \item \code{list_group_memberships()}: Return the IDs of all groups this group is a member of. \item \code{list_object_memberships()}: Return the IDs of all groups, administrative units and directory roles this group is a member of. diff --git a/man/az_object.Rd b/man/az_object.Rd index 629185f..5dab1d1 100644 --- a/man/az_object.Rd +++ b/man/az_object.Rd @@ -27,6 +27,7 @@ Base class representing a directory object in Microsoft Graph. \item \code{new(...)}: Initialize a new directory object. Do not call this directly; see 'Initialization' below. \item \code{delete(confirm=TRUE)}: Delete an object. By default, ask for confirmation first. \item \code{update(...)}: Update the object information in Azure Active Directory. +\item \code{do_operation(...)}: Carry out an arbitrary operation on the object. \item \code{sync_fields()}: Synchronise the R object with the data in Azure Active Directory. \item \code{list_group_memberships()}: Return the IDs of all groups this object is a member of. \item \code{list_object_memberships()}: Return the IDs of all groups, administrative units and directory roles this object is a member of. diff --git a/man/az_service_principal.Rd b/man/az_service_principal.Rd index 84063de..9d33dc1 100644 --- a/man/az_service_principal.Rd +++ b/man/az_service_principal.Rd @@ -27,6 +27,7 @@ Base class representing an AAD service principal. \item \code{new(...)}: Initialize a new service principal object. Do not call this directly; see 'Initialization' below. \item \code{delete(confirm=TRUE)}: Delete a service principal. By default, ask for confirmation first. \item \code{update(...)}: Update the service principal information in Azure Active Directory. +\item \code{do_operation(...)}: Carry out an arbitrary operation on the service principal. \item \code{sync_fields()}: Synchronise the R object with the service principal data in Azure Active Directory. \item \code{list_group_memberships()}: Return the IDs of all groups this service principal is a member of. \item \code{list_object_memberships()}: Return the IDs of all groups, administrative units and directory roles this service principal is a member of. diff --git a/man/az_user.Rd b/man/az_user.Rd index c9cbd20..a7a62e5 100644 --- a/man/az_user.Rd +++ b/man/az_user.Rd @@ -27,6 +27,7 @@ Base class representing an AAD user account. \item \code{new(...)}: Initialize a new user object. Do not call this directly; see 'Initialization' below. \item \code{delete(confirm=TRUE)}: Delete a user account. By default, ask for confirmation first. \item \code{update(...)}: Update the user information in Azure Active Directory. +\item \code{do_operation(...)}: Carry out an arbitrary operation on the user account. \item \code{sync_fields()}: Synchronise the R object with the app data in Azure Active Directory. \item \code{list_group_memberships()}: Return the IDs of all groups this user is a member of. \item \code{list_object_memberships()}: Return the IDs of all groups, administrative units and directory roles this user is a member of.