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

Pass the dots from pin_write() through to s3_upload_file() #648

Merged
merged 5 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions R/board_s3.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
#' an EC2 instance, using a role from another profile, and using multifactor
#' authentication.
#'
#' # Caveats
#' # Details
#'
#' * If you point at a bucket that's not created by pins, some functions
#' like `pins_list()` will work, but won't return useful output.
#' * You can pass arguments for [paws.storage::s3_put_object] such as `Tagging`
#' and `ServerSideEncryption` through the dots of `pin_write()`.
#'
#' @inheritParams new_board
#' @param bucket Bucket name.
Expand All @@ -68,6 +70,10 @@
#' board_sales <- board_s3("company-pins", prefix = "sales/")
#' board_marketing <- board_s3("company-pins", prefix = "marketing/")
#' # You can make the hierarchy arbitrarily deep.
#'
#' # Pass arguments like `Tagging` through the dots of `pin_write`:
#' board %>% pin_write(mtcars, Tagging = "key1=value1&key2=value2")
#'
#' }
board_s3 <- function(
bucket,
Expand Down Expand Up @@ -209,14 +215,15 @@ pin_fetch.pins_board_s3 <- function(board, name, version = NULL, ...) {

#' @export
pin_store.pins_board_s3 <- function(board, name, paths, metadata,
versioned = NULL, ...) {
versioned = NULL, x = NULL, ...) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function signature here needed to be made the same as other pin_store methods.

ellipsis::check_dots_used()
check_name(name)
version <- version_setup(board, name, version_name(metadata), versioned = versioned)

version_dir <- fs::path(name, version)
s3_upload_yaml(board, fs::path(version_dir, "data.txt"), metadata)
for (path in paths) {
s3_upload_file(board, fs::path(version_dir, fs::path_file(path)), path)
s3_upload_file(board, fs::path(version_dir, fs::path_file(path)), path, ...)
}

name
Expand Down Expand Up @@ -267,12 +274,13 @@ s3_upload_yaml <- function(board, key, yaml) {
)
}

s3_upload_file <- function(board, key, path) {
s3_upload_file <- function(board, key, path, ...) {
body <- readBin(path, "raw", file.size(path))
board$svc$put_object(
Bucket = board$bucket,
Key = paste0(board$prefix, key),
Body = body
Body = body,
...
)
}

Expand Down
8 changes: 7 additions & 1 deletion man/board_s3.Rd

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