Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fxn families for groups, roles, policies, iam #19

Merged
merged 11 commits into from
Dec 7, 2023
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
^pkgdown$
^.lintr$
^README\.Rmd$
^data-raw$
8 changes: 6 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ Imports:
fs,
s3fs (>= 0.1.3),
cli,
glue
glue,
memoise
Suggests:
roxyglobals,
testthat (>= 3.0.0),
vcr (>= 0.6.0)
vcr (>= 0.6.0),
withr
Config/roxyglobals/filename: globals.R
Config/roxyglobals/unique: FALSE
Config/testthat/edition: 3
Remotes:
sckott/s3fs@sckott/file_download_vec
Depends:
R (>= 2.10)
30 changes: 28 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(as_policy_arn)
export(aws_bucket_acl_get)
export(aws_bucket_acl_modify)
export(aws_bucket_create)
export(aws_bucket_delete)
export(aws_bucket_download)
Expand All @@ -13,13 +16,34 @@ export(aws_file_delete)
export(aws_file_download)
export(aws_file_exists)
export(aws_file_upload)
export(aws_group)
export(aws_group_create)
export(aws_group_delete)
export(aws_groups)
export(aws_iam_client)
export(aws_policies)
export(aws_policy)
export(aws_policy_attach)
export(aws_policy_detach)
export(aws_policy_exists)
export(aws_role)
export(aws_role_create)
export(aws_role_delete)
export(aws_roles)
export(aws_user)
export(aws_user_access_key)
export(aws_user_create)
export(aws_user_current)
export(aws_user_delete)
export(aws_users)
export(billing)
export(create_user)
export(list_users)
export(s3_path)
export(set_s3_interface)
importFrom(cli,cli_inform)
importFrom(dplyr,bind_rows)
importFrom(dplyr,filter)
importFrom(dplyr,mutate)
importFrom(dplyr,pull)
importFrom(fs,file_exists)
importFrom(fs,fs_bytes)
importFrom(glue,glue)
Expand All @@ -28,10 +52,12 @@ importFrom(magrittr,"%>%")
importFrom(paws,costexplorer)
importFrom(paws,iam)
importFrom(paws,s3)
importFrom(purrr,flatten)
importFrom(purrr,list_rbind)
importFrom(purrr,map)
importFrom(purrr,map_chr)
importFrom(rlang,":=")
importFrom(rlang,has_name)
importFrom(s3fs,s3_dir_info)
importFrom(s3fs,s3_dir_tree)
importFrom(s3fs,s3_file_copy)
Expand Down
27 changes: 27 additions & 0 deletions R/bucket.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,30 @@ aws_buckets <- function(...) {
aws_bucket_tree <- function(bucket, recurse = TRUE, ...) {
s3fs::s3_dir_tree(bucket, recurse = recurse, ...)
}

#' Get a bucket ACL
#'
#' @export
#' @inheritParams aws_bucket_exists
#' @details see docs at <https://www.paws-r-sdk.com/docs/s3_get_bucket_acl/>
#' @return xxx
#' @examples \dontrun{
#' aws_bucket_acl_get("s3://s64-test-2")
#' }
aws_bucket_acl_get <- function(bucket) {
bucket <- path_s3_parser(bucket)[[1]]$bucket
env64$s3$get_bucket_acl(bucket)
}
#' Modify a bucket ACL
#'
#' @export
#' @inheritParams aws_bucket_exists
#' @param ... named params passed on to
#' <https://www.paws-r-sdk.com/docs/s3_put_bucket_acl/>
#' @examples \dontrun{
#' aws_bucket_acl_modify("s3://s64-test-2")
#' }
aws_bucket_acl_modify <- function(bucket, ...) {
bucket <- path_s3_parser(bucket)[[1]]$bucket
env64$s3$put_bucket_acl(bucket, ...)
}
9 changes: 7 additions & 2 deletions R/globals.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Generated by roxyglobals: do not edit by hand

utils::globalVariables(c(
"CreateDate", # <user_list_cleanup>
"PasswordLastUsed", # <user_list_cleanup>
".", # <aws_group>
".", # <aws_policy>
"PolicyName", # <as_policy_arn>
"Arn", # <as_policy_arn>
".", # <aws_role>
"PasswordLastUsed", # <user_list_tidy>
"CreateDate", # <tidy_generator>
NULL
))
86 changes: 86 additions & 0 deletions R/groups.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#' Group list cleanup
#'
#' @noRd
#' @param x (list) a nested list, from a call to
#' [list_users](https://www.paws-r-sdk.com/docs/iam_list_gtroups/)
#' @keywords internal
group_list_tidy <- function(x) {
vars <- c("GroupName", "GroupId", "Path", "Arn", "CreateDate")
tidy_generator(vars)(x)
}

#' List all groups or groups for a single user
#'
#' @export
#' @param username (character) a username. optional
#' @param ... parameters passed on to `paws` `list_groups_for_user`
#' if username is non-NULL, otherwise passed on to `list_users`
#' @return A tibble with information about groups
#' @examples \dontrun{
#' aws_groups()
#' aws_groups(username = aws_user_current())
#' }
aws_groups <- function(username = NULL, ...) {
if (is.null(username)) {
paginate_aws(env64$iam$list_groups, "Groups", ...) %>% group_list_tidy()
} else {
paginate_aws(env64$iam$list_groups_for_user, "Groups",
UserName = username, ...) %>%
group_list_tidy()
}
}

#' Get a group
#'
#' @export
#' @param name (character) the group name
#' @return a named list with slots for:
#' - group: information about the group (tibble)
#' - users: users in the group (tibble)
#' - policies (character)
#' - attached_policies (tibble)
#' @details see docs <https://www.paws-r-sdk.com/docs/iam_get_group/>
#' @autoglobal
#' @examples \dontrun{
#' aws_group(name="users")
#' }
aws_group <- function(name) {
x <- env64$iam$get_group(name)
list(
group = x$Group %>% list(.) %>% group_list_tidy(),
users = x$Users %>% user_list_tidy(),
policies = policies("group", name),
attached_policies = policies_attached("group", name)
)
}

#' Create a group
#'
#' @export
#' @param name (character) A group name. required
#' @param path (character) The path for the group name. optional.
#' If it is not included, it defaults to a slash (/).
#' @return A tibble with information about the group created
#' @details See <https://www.paws-r-sdk.com/docs/iam_create_group/>
#' docs for details on the parameters
#' @examples \dontrun{
#' aws_group_create("testgroup")
#' }
aws_group_create <- function(name, path = NULL) {
env64$iam$create_group(Path = path, GroupName = name) %>%
group_list_tidy()
}

#' Delete a group
#'
#' @export
#' @inheritParams aws_group_create
#' @return an empty list
#' @details See <https://www.paws-r-sdk.com/docs/iam_delete_group/>
#' docs for more details
#' @examples \dontrun{
#' aws_group_delete(name = "testgroup")
#' }
aws_group_delete <- function(name) {
env64$iam$delete_group(name)
}
9 changes: 9 additions & 0 deletions R/iam.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#' Get the `paws` Identity and Access Management (IAM) client
#'
#' @export
#' @return a list with methods for interfacing with IAM;
#' see <https://www.paws-r-sdk.com/docs/iam/>
#' @examples aws_iam_client()
aws_iam_client <- function() {
return(env64$iam)
}
Loading