Skip to content

Commit

Permalink
Merge pull request #81 from getwilds/aws-has-creds
Browse files Browse the repository at this point in the history
Examples rework: add fxn `aws_has_creds`, use in one family of fxns
  • Loading branch information
sckott authored Jan 22, 2025
2 parents 5a26645 + d4cd6a0 commit 9e842a3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Imports:
lubridate,
magrittr,
paws,
paws.common,
purrr,
rlang,
tibble,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export(aws_group_create)
export(aws_group_delete)
export(aws_group_exists)
export(aws_groups)
export(aws_has_creds)
export(aws_policies)
export(aws_policy)
export(aws_policy_attach)
Expand Down Expand Up @@ -150,6 +151,7 @@ importFrom(paws,iam)
importFrom(paws,rds)
importFrom(paws,redshift)
importFrom(paws,s3)
importFrom(paws.common,locate_credentials)
importFrom(purrr,compact)
importFrom(purrr,discard)
importFrom(purrr,flatten)
Expand Down
5 changes: 2 additions & 3 deletions R/clients.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' See [connections] for more information.
#' @return An S3 list with class 'sixtyfour_client'
#' @seealso [paws_clients]
#' @examplesIf interactive()
#' @examplesIf aws_has_creds()
#' con <- con_s3fs()
#' con
#' con_s3fs()$file_copy
Expand Down Expand Up @@ -149,10 +149,9 @@ print.sixtyfour_client <- function(x, ...) {
#' - `con_ce`: a list with methods for interfacing with Cost Explorer;
#' <https://www.paws-r-sdk.com/docs/costexplorer/>
#'
#' @examplesIf interactive()
#' @examplesIf aws_has_creds()
#' z <- con_iam()
#' z
#' z$get_group
#'
#' withr::with_envvar(
#' c("AWS_PROFILE" = "localstack"),
Expand Down
13 changes: 13 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,16 @@ stop_if_not <- function(cond, msg, .envir = parent.frame()) {
stop_if <- function(cond, msg, .envir = parent.frame()) {
if (cond) cli::cli_abort(msg, .envir = .envir)
}

#' Check if appropriate AWS credentials are available
#' @export
#' @importFrom paws.common locate_credentials
#' @examples
#' aws_has_creds()
aws_has_creds <- function() {
res <- tryCatch(
paws.common::locate_credentials(),
error = \(e) e
)
!inherits(res, "error")
}
14 changes: 14 additions & 0 deletions man/aws_has_creds.Rd

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

3 changes: 1 addition & 2 deletions man/con_iam.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/con_s3fs.Rd

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

0 comments on commit 9e842a3

Please sign in to comment.