Skip to content

Commit

Permalink
use new con_iam iam client fetcher throughout #61
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Apr 3, 2024
1 parent ce0ba28 commit 7dcf7b8
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 25 deletions.
1 change: 1 addition & 0 deletions R/globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ utils::globalVariables(c(
"DBInstanceArn", # <aws_db_rds_list>
".", # <aws_group>
".", # <aws_policy>
"result", # <aws_policy_list_entities>
"type", # <aws_policy_list_entities>
".", # <aws_role>
"user", # <aws_bucket_remove_user>
Expand Down
10 changes: 5 additions & 5 deletions R/groups.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ group_list_tidy <- function(x) {
#' }
aws_groups <- function(username = NULL, ...) {
if (is.null(username)) {
paginate_aws_marker(env64$iam$list_groups, "Groups", ...) %>%
paginate_aws_marker(con_iam()$list_groups, "Groups", ...) %>%
group_list_tidy()
} else {
paginate_aws_marker(env64$iam$list_groups_for_user, "Groups",
paginate_aws_marker(con_iam()$list_groups_for_user, "Groups",
UserName = username, ...
) %>%
group_list_tidy()
Expand All @@ -49,7 +49,7 @@ aws_groups <- function(username = NULL, ...) {
#' aws_group(name = "users")
#' }
aws_group <- function(name) {
x <- env64$iam$get_group(name)
x <- con_iam()$get_group(name)
list(
group = x$Group %>% list(.) %>% group_list_tidy(),
users = x$Users %>% user_list_tidy(),
Expand Down Expand Up @@ -89,7 +89,7 @@ aws_group_exists <- function(name) {
#' aws_group_create("testgroup")
#' }
aws_group_create <- function(name, path = NULL) {
env64$iam$create_group(Path = path, GroupName = name) %>%
con_iam()$create_group(Path = path, GroupName = name) %>%
group_list_tidy()
}

Expand All @@ -105,5 +105,5 @@ aws_group_create <- function(name, path = NULL) {
#' aws_group_delete(name = "testgroup")
#' }
aws_group_delete <- function(name) {
env64$iam$delete_group(name)
con_iam()$delete_group(name)
}
3 changes: 3 additions & 0 deletions R/interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ is_testing <- function() {
}

#' Refresh creds for the s3fs package
#'
#' Refreshes only if not running tests
#'
#' @keywords internal
#' @details utility function to update creds for use with any
#' `s3fs` functions. We do load creds for `s3fs` on package load
Expand Down
14 changes: 7 additions & 7 deletions R/policies.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ all_policies <- memoise::memoise(function(...) {
if (Sys.getenv("TESTING64", FALSE)) {
return(policies_sample)
}
paginate_aws_marker(env64$iam$list_policies, "Policies", ...) %>%
paginate_aws_marker(con_iam()$list_policies, "Policies", ...) %>%
policy_list_tidy()
})

Expand Down Expand Up @@ -68,7 +68,7 @@ aws_policies <- function(refresh = FALSE, ...) {
#' aws_policy("arn:aws:iam::aws:policy/ReadOnlyAccess")
#' }
aws_policy <- function(name, local = FALSE) {
env64$iam$get_policy(as_policy_arn(name, local))$Policy %>%
con_iam()$get_policy(as_policy_arn(name, local))$Policy %>%
list(.) %>%
policy_list_tidy()
}
Expand Down Expand Up @@ -121,7 +121,7 @@ aws_policy_exists <- function(name) {
aws_policy_create <- function(
name, document, path = NULL,
description = NULL, tags = NULL) {
env64$iam$create_policy(
con_iam()$create_policy(
PolicyName = name,
PolicyDocument = document,
Path = path,
Expand Down Expand Up @@ -168,7 +168,7 @@ aws_policy_create <- function(
#' aws_policy_create("RdsAllow456", document = doc)
#' aws_policy_delete("RdsAllow456")
aws_policy_delete <- function(name) {
env64$iam$delete_policy(PolicyArn = figure_out_policy_arn(name))
con_iam()$delete_policy(PolicyArn = figure_out_policy_arn(name))
}

#' Figure out policy Arn from a name
Expand Down Expand Up @@ -211,7 +211,7 @@ figure_out_policy_arn <- function(name) {
#' aws_policy_create("RdsAllow456", document = doc)
#' aws_policy_delete_version("RdsAllow456", "v1")
aws_policy_delete_version <- function(name, version_id) {
env64$iam$delete_policy_version(
con_iam()$delete_policy_version(
PolicyArn = figure_out_policy_arn(name),
VersionId = version_id
)
Expand Down Expand Up @@ -241,7 +241,7 @@ aws_policy_delete_version <- function(name, version_id) {
#' }
#' aws_policy_list_entities("S3ReadOnlyAccessS64Test22")
aws_policy_list_entities <- function(name, ...) {
result <- env64$iam$list_entities_for_policy(
con_iam()$list_entities_for_policy(
PolicyArn = figure_out_policy_arn(name),
...
)
Expand Down Expand Up @@ -277,7 +277,7 @@ aws_policy_list_versions <- function(name, ...) {
vars <- c(
"Document", "VersionId", "IsDefaultVersion", "CreateDate"
)
env64$iam$list_policy_versions(
con_iam()$list_policy_versions(
PolicyArn = figure_out_policy_arn(name), ...
)$Versions %>%
tidy_generator(vars)(.)
Expand Down
8 changes: 4 additions & 4 deletions R/roles.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ role_list_tidy <- function(x) {
#' aws_roles()
#' }
aws_roles <- function(...) {
paginate_aws_marker(env64$iam$list_roles, "Roles") %>% role_list_tidy()
paginate_aws_marker(con_iam()$list_roles, "Roles") %>% role_list_tidy()
}

#' Get a role
Expand All @@ -52,7 +52,7 @@ aws_roles <- function(...) {
#' aws_role("AWSServiceRoleForRedshift")
#' }
aws_role <- function(name) {
df <- env64$iam$get_role(name)$Role %>%
df <- con_iam()$get_role(name)$Role %>%
list(.) %>%
role_list_tidy()
list(
Expand Down Expand Up @@ -110,7 +110,7 @@ aws_role_create <- function(
name, assume_role_policy_document, path = NULL,
description = NULL, max_session_duration = NULL, permission_boundary = NULL,
tags = NULL) {
env64$iam$create_role(
con_iam()$create_role(
Path = path,
RoleName = name,
AssumeRolePolicyDocument = assume_role_policy_document,
Expand All @@ -134,5 +134,5 @@ aws_role_create <- function(
#' aws_role_delete(name = "MyRole")
#' }
aws_role_delete <- function(name) {
env64$iam$delete_role(name)
con_iam()$delete_role(name)
}
6 changes: 3 additions & 3 deletions R/s3.R
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ AWS_REGION={Sys.getenv('AWS_REGION')}
#' aws_user_creds("jane", copy_to_cp = TRUE)
aws_user_creds <- function(username, copy_to_cp = FALSE) {
creds <- tryCatch(
env64$iam$create_access_key(UserName = username),
con_iam()$create_access_key(UserName = username),
error = function(e) e
)

Expand Down Expand Up @@ -435,13 +435,13 @@ permissions_groups <- function() {
}

latest_policy_version_id <- memoise::memoise(function(arn) {
vers <- env64$iam$list_policy_versions(arn)$Versions
vers <- con_iam()$list_policy_versions(arn)$Versions
Filter(function(z) z$IsDefaultVersion, vers)[[1]]$VersionId
})

#' @importFrom curl curl_unescape
latest_policy_doc <- memoise::memoise(function(arn) {
res <- env64$iam$get_policy_version(
res <- con_iam()$get_policy_version(
arn,
latest_policy_version_id(arn)
)
Expand Down
2 changes: 1 addition & 1 deletion R/users.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ aws_user_access_key <- function(username = NULL, ...) {
#' aws_user_access_key_delete(access_key_id = "adfasdfadfadfasdf")
#' aws_user_access_key_delete(access_key_id = "adfasdf", username = "jane")
aws_user_access_key_delete <- function(access_key_id, username = NULL) {
env64$iam$delete_access_key(UserName = username, AccessKeyId = access_key_id)
con_iam()$delete_access_key(UserName = username, AccessKeyId = access_key_id)
cli::cli_alert_success("Access Key ID {.strong {access_key_id}} deleted")
invisible()
}
Expand Down
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ path_as_s3 <- function(paths) {
#' @examples \dontrun{
#' # FIXME: could remove target param and poach the name of the fun
#' # e.g,. from list_roles we can get Roles
#' paginate_aws_marker(fun = env64$iam$list_roles, target = "Roles")
#' paginate_aws_marker(fun = env64$iam$list_policies, target = "Policies")
#' # paginate_aws_marker(fun = env64$iam$list_roles, target = "Roles")
#' # paginate_aws_marker(fun = env64$iam$list_policies, target = "Policies")
#' }
paginate_aws_marker <- function(fun, target, ...) {
res <- fun(...)
Expand Down
4 changes: 2 additions & 2 deletions man/paginate_aws_marker.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/s3fs_creds_refresh.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7dcf7b8

Please sign in to comment.